[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:
TSRBerry 2023-06-25 19:03:48 +02:00 committed by GitHub
parent 2b2ce68f07
commit 7ffe7f8442
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 33 additions and 36 deletions

View file

@ -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)
{

View file

@ -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<byte>(output).Slice(prep.Length));
data.CopyTo(new Span<byte>(output)[prep.Length..]);
return output;
}

View file

@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
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);
@ -118,4 +118,4 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
WriteBits((int)value, size - 1);
}
}
}
}

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
{
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
{
H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer);
H264BitStreamWriter writer = new(workBuffer);
// Sequence Parameter Set.
writer.WriteU(1, 24);

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<IntPtr> Data;
public Array8<int> LineSize;
public IntPtr ExtendedData;

View file

@ -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
}
}
}

View file

@ -2,9 +2,9 @@
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 int CapsInternalOrCbType;
public int PrivDataSize;

View file

@ -2,9 +2,9 @@
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 uint CapsInternalOrCbType;
public int PrivDataSize;

View file

@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
public const string AvCodecLibraryName = "avcodec";
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) },
{ 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);

View file

@ -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;

View file

@ -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<byte>(frame).Slice(uncompHeaderSize));
bitstream.CopyTo(new Span<byte>(frame)[uncompHeaderSize..]);
return _context.DecodeFrame(outSurf, frame) == 0;
}
public void Dispose() => _context.Dispose();
}
}
}