Skip to content

Commit

Permalink
fix: Support FFmpeg 5.1.x for decoding (#3816)
Browse files Browse the repository at this point in the history
For some reason FFmpeg 5.1.x reverted part of the changes made in 5.0.x
on AVCodec.

This fix decoding issues with it.
  • Loading branch information
marysaka authored Nov 2, 2022
1 parent 3d98e13 commit 7d8e198
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
10 changes: 6 additions & 4 deletions Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
{
unsafe class FFmpegContext : IDisposable
{
private readonly FFCodec.AVCodec_decode _decodeFrame;
private unsafe delegate int AVCodec_decode(AVCodecContext* avctx, void* outdata, int* got_frame_ptr, AVPacket* avpkt);

private readonly AVCodec_decode _decodeFrame;
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
private readonly AVCodec* _codec;
private AVPacket* _packet;
Expand Down Expand Up @@ -53,17 +55,17 @@ public FFmpegContext(AVCodecID codecId)
// libavcodec 59.24 changed AvCodec to move its private API and also move the codec function to an union.
if (avCodecMajorVersion > 59 || (avCodecMajorVersion == 59 && avCodecMinorVersion > 24))
{
_decodeFrame = Marshal.GetDelegateForFunctionPointer<FFCodec.AVCodec_decode>(((FFCodec*)_codec)->CodecCallback);
_decodeFrame = Marshal.GetDelegateForFunctionPointer<AVCodec_decode>(((FFCodec<AVCodec>*)_codec)->CodecCallback);
}
// libavcodec 59.x changed AvCodec private API layout.
else if (avCodecMajorVersion == 59)
{
_decodeFrame = Marshal.GetDelegateForFunctionPointer<FFCodec.AVCodec_decode>(((FFCodecLegacy<AVCodec>*)_codec)->Decode);
_decodeFrame = Marshal.GetDelegateForFunctionPointer<AVCodec_decode>(((FFCodecLegacy<AVCodec501>*)_codec)->Decode);
}
// libavcodec 58.x and lower
else
{
_decodeFrame = Marshal.GetDelegateForFunctionPointer<FFCodec.AVCodec_decode>(((FFCodecLegacy<AVCodecLegacy>*)_codec)->Decode);
_decodeFrame = Marshal.GetDelegateForFunctionPointer<AVCodec_decode>(((FFCodecLegacy<AVCodec>*)_codec)->Decode);
}
}

Expand Down
1 change: 1 addition & 0 deletions Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct AVCodec
public unsafe IntPtr PrivClass;
public IntPtr Profiles;
public unsafe byte* WrapperName;
public IntPtr ChLayouts;
#pragma warning restore CS0649
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVCodecLegacy
struct AVCodec501
{
#pragma warning disable CS0649
public unsafe byte* Name;
Expand All @@ -20,7 +20,6 @@ struct AVCodecLegacy
public unsafe IntPtr PrivClass;
public IntPtr Profiles;
public unsafe byte* WrapperName;
public IntPtr ChLayouts;
#pragma warning restore CS0649
}
}
2 changes: 1 addition & 1 deletion Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct AVCodecContext
public unsafe IntPtr AvClass;
public int LogLevelOffset;
public int CodecType;
public unsafe AVCodecLegacy* Codec;
public unsafe AVCodec* Codec;
public AVCodecID CodecId;
public uint CodecTag;
public IntPtr PrivData;
Expand Down
6 changes: 2 additions & 4 deletions Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct FFCodec
struct FFCodec<T> where T: struct
{
public unsafe delegate int AVCodec_decode(AVCodecContext* avctx, void* outdata, int* got_frame_ptr, AVPacket* avpkt);

#pragma warning disable CS0649
public AVCodec Base;
public T Base;
public int CapsInternalOrCbType;
public int PrivDataSize;
public IntPtr UpdateThreadContext;
Expand Down

0 comments on commit 7d8e198

Please sign in to comment.