mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-11-24 18:20:12 +01:00
[Ryujinx.Graphics.Nvdec.FFmpeg] Address dotnet-format issues (#5370)
* dotnet format style --severity info Some changes were manually reverted. * Address or silence dotnet format CA1806 and a few CA1854 warnings * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass
This commit is contained in:
parent
2b2ce68f07
commit
7ffe7f8442
@ -12,8 +12,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
private readonly AVCodec_decode _decodeFrame;
|
private readonly AVCodec_decode _decodeFrame;
|
||||||
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
|
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
|
||||||
private readonly AVCodec* _codec;
|
private readonly AVCodec* _codec;
|
||||||
private AVPacket* _packet;
|
private readonly AVPacket* _packet;
|
||||||
private AVCodecContext* _context;
|
private readonly AVCodecContext* _context;
|
||||||
|
|
||||||
public FFmpegContext(AVCodecID codecId)
|
public FFmpegContext(AVCodecID codecId)
|
||||||
{
|
{
|
||||||
@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
FFmpegApi.av_packet_free(ppPacket);
|
FFmpegApi.av_packet_free(ppPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
FFmpegApi.avcodec_close(_context);
|
_ = FFmpegApi.avcodec_close(_context);
|
||||||
|
|
||||||
fixed (AVCodecContext** ppContext = &_context)
|
fixed (AVCodecContext** ppContext = &_context)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
|
|
||||||
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
|
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
|
||||||
|
|
||||||
private FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
|
private FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_H264);
|
||||||
|
|
||||||
private int _oldOutputWidth;
|
private int _oldOutputWidth;
|
||||||
private int _oldOutputHeight;
|
private int _oldOutputHeight;
|
||||||
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
byte[] output = new byte[data.Length + prep.Length];
|
byte[] output = new byte[data.Length + prep.Length];
|
||||||
|
|
||||||
prep.CopyTo(output);
|
prep.CopyTo(output);
|
||||||
data.CopyTo(new Span<byte>(output).Slice(prep.Length));
|
data.CopyTo(new Span<byte>(output)[prep.Length..]);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span<byte> AsSpan()
|
public readonly Span<byte> AsSpan()
|
||||||
{
|
{
|
||||||
return new Span<byte>(_workBuffer).Slice(0, _offset);
|
return new Span<byte>(_workBuffer)[.._offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
|
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
|
||||||
|
@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
{
|
{
|
||||||
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
|
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
|
||||||
{
|
{
|
||||||
H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer);
|
H264BitStreamWriter writer = new(workBuffer);
|
||||||
|
|
||||||
// Sequence Parameter Set.
|
// Sequence Parameter Set.
|
||||||
writer.WriteU(1, 24);
|
writer.WriteU(1, 24);
|
||||||
|
@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodec
|
struct AVCodec
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe byte* Name;
|
public unsafe byte* Name;
|
||||||
public unsafe byte* LongName;
|
public unsafe byte* LongName;
|
||||||
public int Type;
|
public int Type;
|
||||||
|
@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodec501
|
struct AVCodec501
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe byte* Name;
|
public unsafe byte* Name;
|
||||||
public unsafe byte* LongName;
|
public unsafe byte* LongName;
|
||||||
public int Type;
|
public int Type;
|
||||||
|
@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodecContext
|
struct AVCodecContext
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe IntPtr AvClass;
|
public unsafe IntPtr AvClass;
|
||||||
public int LogLevelOffset;
|
public int LogLevelOffset;
|
||||||
public int CodecType;
|
public int CodecType;
|
||||||
|
@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVFrame
|
struct AVFrame
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public Array8<IntPtr> Data;
|
public Array8<IntPtr> Data;
|
||||||
public Array8<int> LineSize;
|
public Array8<int> LineSize;
|
||||||
public IntPtr ExtendedData;
|
public IntPtr ExtendedData;
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
using System;
|
using AVBufferRef = System.IntPtr;
|
||||||
|
|
||||||
using AVBufferRef = System.IntPtr;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
||||||
{
|
{
|
||||||
struct AVPacket
|
struct AVPacket
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe AVBufferRef *Buf;
|
public unsafe AVBufferRef* Buf;
|
||||||
public long Pts;
|
public long Pts;
|
||||||
public long Dts;
|
public long Dts;
|
||||||
public unsafe byte* Data;
|
public unsafe byte* Data;
|
||||||
public int Size;
|
public int Size;
|
||||||
public int StreamIndex;
|
public int StreamIndex;
|
||||||
public int Flags;
|
public int Flags;
|
||||||
public IntPtr SizeData;
|
public AVBufferRef SizeData;
|
||||||
public int SizeDataElems;
|
public int SizeDataElems;
|
||||||
public long Duration;
|
public long Duration;
|
||||||
public long Position;
|
public long Position;
|
||||||
public IntPtr Opaque;
|
public AVBufferRef Opaque;
|
||||||
public unsafe AVBufferRef *OpaqueRef;
|
public unsafe AVBufferRef* OpaqueRef;
|
||||||
public AVRational TimeBase;
|
public AVRational TimeBase;
|
||||||
#pragma warning restore CS0649
|
#pragma warning restore CS0649
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
||||||
{
|
{
|
||||||
struct FFCodec<T> where T: struct
|
struct FFCodec<T> where T : struct
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public T Base;
|
public T Base;
|
||||||
public int CapsInternalOrCbType;
|
public int CapsInternalOrCbType;
|
||||||
public int PrivDataSize;
|
public int PrivDataSize;
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
||||||
{
|
{
|
||||||
struct FFCodecLegacy<T> where T: struct
|
struct FFCodecLegacy<T> where T : struct
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public T Base;
|
public T Base;
|
||||||
public uint CapsInternalOrCbType;
|
public uint CapsInternalOrCbType;
|
||||||
public int PrivDataSize;
|
public int PrivDataSize;
|
||||||
|
@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
public const string AvCodecLibraryName = "avcodec";
|
public const string AvCodecLibraryName = "avcodec";
|
||||||
public const string AvUtilLibraryName = "avutil";
|
public const string AvUtilLibraryName = "avutil";
|
||||||
|
|
||||||
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new Dictionary<string, (int, int)>
|
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new()
|
||||||
{
|
{
|
||||||
{ AvCodecLibraryName, (58, 59) },
|
{ AvCodecLibraryName, (58, 59) },
|
||||||
{ AvUtilLibraryName, (56, 57) }
|
{ AvUtilLibraryName, (56, 57) }
|
||||||
@ -61,9 +61,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
NativeLibrary.SetDllImportResolver(typeof(FFmpegApi).Assembly, (name, assembly, path) =>
|
NativeLibrary.SetDllImportResolver(typeof(FFmpegApi).Assembly, (name, assembly, path) =>
|
||||||
{
|
{
|
||||||
IntPtr handle;
|
|
||||||
|
|
||||||
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out handle))
|
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out nint handle))
|
||||||
{
|
{
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@ -106,7 +105,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
internal static unsafe partial AVCodecContext* avcodec_alloc_context3(AVCodec* codec);
|
internal static unsafe partial AVCodecContext* avcodec_alloc_context3(AVCodec* codec);
|
||||||
|
|
||||||
[LibraryImport(AvCodecLibraryName)]
|
[LibraryImport(AvCodecLibraryName)]
|
||||||
internal static unsafe partial int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void **options);
|
internal static unsafe partial int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void** options);
|
||||||
|
|
||||||
[LibraryImport(AvCodecLibraryName)]
|
[LibraryImport(AvCodecLibraryName)]
|
||||||
internal static unsafe partial int avcodec_close(AVCodecContext* avctx);
|
internal static unsafe partial int avcodec_close(AVCodecContext* avctx);
|
||||||
|
@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
public int RequestedWidth { get; }
|
public int RequestedWidth { get; }
|
||||||
public int RequestedHeight { get; }
|
public int RequestedHeight { get; }
|
||||||
|
|
||||||
public Plane YPlane => new Plane((IntPtr)Frame->Data[0], Stride * Height);
|
public Plane YPlane => new((IntPtr)Frame->Data[0], Stride * Height);
|
||||||
public Plane UPlane => new Plane((IntPtr)Frame->Data[1], UvStride * UvHeight);
|
public Plane UPlane => new((IntPtr)Frame->Data[1], UvStride * UvHeight);
|
||||||
public Plane VPlane => new Plane((IntPtr)Frame->Data[2], UvStride * UvHeight);
|
public Plane VPlane => new((IntPtr)Frame->Data[2], UvStride * UvHeight);
|
||||||
|
|
||||||
public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive;
|
public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
|
|||||||
{
|
{
|
||||||
public bool IsHardwareAccelerated => false;
|
public bool IsHardwareAccelerated => false;
|
||||||
|
|
||||||
private readonly FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_VP8);
|
private readonly FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_VP8);
|
||||||
|
|
||||||
public ISurface CreateSurface(int width, int height)
|
public ISurface CreateSurface(int width, int height)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
|
|||||||
frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
|
frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
bitstream.CopyTo(new Span<byte>(frame).Slice(uncompHeaderSize));
|
bitstream.CopyTo(new Span<byte>(frame)[uncompHeaderSize..]);
|
||||||
|
|
||||||
return _context.DecodeFrame(outSurf, frame) == 0;
|
return _context.DecodeFrame(outSurf, frame) == 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user