From 7ffe7f8442eb70980da55832a293fab52ff58cf1 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:03:48 +0200 Subject: [PATCH] [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 --- .../FFmpegContext.cs | 6 +++--- .../H264/Decoder.cs | 4 ++-- .../H264/H264BitStreamWriter.cs | 6 +++--- .../H264/SpsAndPpsReconstruction.cs | 2 +- .../Native/AVCodec.cs | 2 +- .../Native/AVCodec501.cs | 2 +- .../Native/AVCodecContext.cs | 2 +- .../Native/AVFrame.cs | 2 +- .../Native/AVPacket.cs | 16 +++++++--------- .../Native/FFCodec.cs | 4 ++-- .../Native/FFCodecLegacy.cs | 4 ++-- .../Native/FFmpegApi.cs | 7 +++---- src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs | 6 +++--- src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs | 6 +++--- 14 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs index 572ceaaabb..284a35a24d 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs @@ -12,8 +12,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg private readonly AVCodec_decode _decodeFrame; private static readonly FFmpegApi.av_log_set_callback_callback _logFunc; private readonly AVCodec* _codec; - private AVPacket* _packet; - private AVCodecContext* _context; + private readonly AVPacket* _packet; + private readonly AVCodecContext* _context; public FFmpegContext(AVCodecID codecId) { @@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg FFmpegApi.av_packet_free(ppPacket); } - FFmpegApi.avcodec_close(_context); + _ = FFmpegApi.avcodec_close(_context); fixed (AVCodecContext** ppContext = &_context) { diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs index d8b213e551..7dd643ce39 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 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 _oldOutputHeight; @@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 byte[] output = new byte[data.Length + prep.Length]; prep.CopyTo(output); - data.CopyTo(new Span(output).Slice(prep.Length)); + data.CopyTo(new Span(output)[prep.Length..]); return output; } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs index 3d3b32933b..57ab9fb535 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs @@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 Flush(); } - public Span AsSpan() + public readonly Span AsSpan() { - return new Span(_workBuffer).Slice(0, _offset); + return new Span(_workBuffer)[.._offset]; } public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize); @@ -118,4 +118,4 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 WriteBits((int)value, size - 1); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs index 57fb65d506..d8bf6f7461 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 { public static Span Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer) { - H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer); + H264BitStreamWriter writer = new(workBuffer); // Sequence Parameter Set. writer.WriteU(1, 24); diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs index 46d3ad61c6..434b9b29b7 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs @@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { struct AVCodec { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public unsafe byte* Name; public unsafe byte* LongName; public int Type; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs index 47d4969ac0..7b82b5ddf2 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs @@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { struct AVCodec501 { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public unsafe byte* Name; public unsafe byte* LongName; public int Type; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs index 6c9fbc8932..a9605c63f4 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { struct AVCodecContext { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public unsafe IntPtr AvClass; public int LogLevelOffset; public int CodecType; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs index faaf5c7d85..cdc9ebfdcb 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { struct AVFrame { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public Array8 Data; public Array8 LineSize; public IntPtr ExtendedData; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs index d5b0210409..47b9bef986 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs @@ -1,26 +1,24 @@ -using System; - -using AVBufferRef = System.IntPtr; +using AVBufferRef = System.IntPtr; namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { struct AVPacket { -#pragma warning disable CS0649 - public unsafe AVBufferRef *Buf; +#pragma warning disable CS0649 // Field is never assigned to + public unsafe AVBufferRef* Buf; public long Pts; public long Dts; public unsafe byte* Data; public int Size; public int StreamIndex; public int Flags; - public IntPtr SizeData; + public AVBufferRef SizeData; public int SizeDataElems; public long Duration; public long Position; - public IntPtr Opaque; - public unsafe AVBufferRef *OpaqueRef; + public AVBufferRef Opaque; + public unsafe AVBufferRef* OpaqueRef; public AVRational TimeBase; #pragma warning restore CS0649 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs index 4df45af462..89a33697cb 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs @@ -2,9 +2,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { - struct FFCodec where T: struct + struct FFCodec where T : struct { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public T Base; public int CapsInternalOrCbType; public int PrivDataSize; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs index 910270a550..630e2c179d 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs @@ -2,9 +2,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { - struct FFCodecLegacy where T: struct + struct FFCodecLegacy where T : struct { -#pragma warning disable CS0649 +#pragma warning disable CS0649 // Field is never assigned to public T Base; public uint CapsInternalOrCbType; public int PrivDataSize; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs index d173a41293..262d26431a 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public const string AvCodecLibraryName = "avcodec"; public const string AvUtilLibraryName = "avutil"; - private static readonly Dictionary _librariesWhitelist = new Dictionary + private static readonly Dictionary _librariesWhitelist = new() { { AvCodecLibraryName, (58, 59) }, { AvUtilLibraryName, (56, 57) } @@ -61,9 +61,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { 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; } @@ -106,7 +105,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native internal static unsafe partial AVCodecContext* avcodec_alloc_context3(AVCodec* codec); [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)] internal static unsafe partial int avcodec_close(AVCodecContext* avctx); diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs index 1ca9d1d539..959791b6eb 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs @@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg public int RequestedWidth { get; } public int RequestedHeight { get; } - public Plane YPlane => new Plane((IntPtr)Frame->Data[0], Stride * Height); - public Plane UPlane => new Plane((IntPtr)Frame->Data[1], UvStride * UvHeight); - public Plane VPlane => new Plane((IntPtr)Frame->Data[2], UvStride * UvHeight); + public Plane YPlane => new((IntPtr)Frame->Data[0], Stride * Height); + public Plane UPlane => new((IntPtr)Frame->Data[1], UvStride * UvHeight); + public Plane VPlane => new((IntPtr)Frame->Data[2], UvStride * UvHeight); public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs index 3570c3eccf..5e38c8c8e0 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8 { 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) { @@ -43,11 +43,11 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8 frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F); } - bitstream.CopyTo(new Span(frame).Slice(uncompHeaderSize)); + bitstream.CopyTo(new Span(frame)[uncompHeaderSize..]); return _context.DecodeFrame(outSurf, frame) == 0; } public void Dispose() => _context.Dispose(); } -} \ No newline at end of file +}