misc: Code cleanups & improvements, again
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
||||
int avCodecMajorVersion = avCodecRawVersion >> 16;
|
||||
int avCodecMinorVersion = (avCodecRawVersion >> 8) & 0xFF;
|
||||
|
||||
// libavcodec 59.24 changed AvCodec to move its private API and also move the codec function to an union.
|
||||
// libavcodec 59.24 changed AvCodec to move its private API and also move the codec function to a union.
|
||||
if (avCodecMajorVersion > 59 || (avCodecMajorVersion == 59 && avCodecMinorVersion > 24))
|
||||
{
|
||||
_decodeFrame = Marshal.GetDelegateForFunctionPointer<AVCodec_decode>(((FFCodec<AVCodec>*)_codec)->CodecCallback);
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
{
|
||||
Surface outSurf = (Surface)output;
|
||||
|
||||
if (outSurf.RequestedWidth != _oldOutputWidth ||
|
||||
outSurf.RequestedHeight != _oldOutputHeight)
|
||||
if (outSurf.RequestedWidth != _oldOutputWidth || outSurf.RequestedHeight != _oldOutputHeight)
|
||||
{
|
||||
_context.Dispose();
|
||||
_context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
|
||||
@@ -38,7 +37,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
|
||||
Span<byte> bs = Prepend(bitstream, SpsAndPpsReconstruction.Reconstruct(ref pictureInfo, _workBuffer));
|
||||
|
||||
return _context.DecodeFrame(outSurf, bs) == 0;
|
||||
return _context.DecodeFrame(outSurf, bs) is 0;
|
||||
}
|
||||
|
||||
private static byte[] Prepend(ReadOnlySpan<byte> data, ReadOnlySpan<byte> prep)
|
||||
|
||||
@@ -3,23 +3,13 @@ using System.Numerics;
|
||||
|
||||
namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
{
|
||||
struct H264BitStreamWriter
|
||||
struct H264BitStreamWriter(byte[] workBuffer)
|
||||
{
|
||||
private const int BufferSize = 8;
|
||||
|
||||
private readonly byte[] _workBuffer;
|
||||
|
||||
private int _offset;
|
||||
private int _buffer;
|
||||
private int _bufferPos;
|
||||
|
||||
public H264BitStreamWriter(byte[] workBuffer)
|
||||
{
|
||||
_workBuffer = workBuffer;
|
||||
_offset = 0;
|
||||
_buffer = 0;
|
||||
_bufferPos = 0;
|
||||
}
|
||||
private int _offset = 0;
|
||||
private int _buffer = 0;
|
||||
private int _bufferPos = 0;
|
||||
|
||||
public void WriteBit(bool value)
|
||||
{
|
||||
@@ -59,9 +49,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
private int GetFreeBufferBits()
|
||||
{
|
||||
if (_bufferPos == BufferSize)
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
|
||||
return BufferSize - _bufferPos;
|
||||
}
|
||||
@@ -70,7 +58,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
{
|
||||
if (_bufferPos != 0)
|
||||
{
|
||||
_workBuffer[_offset++] = (byte)_buffer;
|
||||
workBuffer[_offset++] = (byte)_buffer;
|
||||
|
||||
_buffer = 0;
|
||||
_bufferPos = 0;
|
||||
@@ -84,10 +72,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
||||
Flush();
|
||||
}
|
||||
|
||||
public readonly Span<byte> AsSpan()
|
||||
{
|
||||
return new Span<byte>(_workBuffer)[.._offset];
|
||||
}
|
||||
public readonly Span<byte> AsSpan()
|
||||
=> new Span<byte>(workBuffer)[.._offset];
|
||||
|
||||
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
|
||||
public void WriteSe(int value) => WriteExpGolombCodedInt(value);
|
||||
|
||||
Reference in New Issue
Block a user