mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-11-28 12:39:21 +01:00
c5bddfeab8
* Remove dependency for FFMpeg.AutoGen Also prepare for FFMpeg 5.0 and 5.1 * Update Ryujinx.Graphics.Nvdec.Dependencies to 5.0.1-build10 * Address gdkchan's comments * Address Ack's comment * Address gdkchan's comment
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using Ryujinx.Graphics.Nvdec.FFmpeg.Native;
|
|
using Ryujinx.Graphics.Video;
|
|
using System;
|
|
|
|
namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|
{
|
|
public sealed class Decoder : IH264Decoder
|
|
{
|
|
public bool IsHardwareAccelerated => false;
|
|
|
|
private const int WorkBufferSize = 0x200;
|
|
|
|
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
|
|
|
|
private FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
|
|
|
|
private int _oldOutputWidth;
|
|
private int _oldOutputHeight;
|
|
|
|
public ISurface CreateSurface(int width, int height)
|
|
{
|
|
return new Surface(width, height);
|
|
}
|
|
|
|
public bool Decode(ref H264PictureInfo pictureInfo, ISurface output, ReadOnlySpan<byte> bitstream)
|
|
{
|
|
Surface outSurf = (Surface)output;
|
|
|
|
if (outSurf.RequestedWidth != _oldOutputWidth ||
|
|
outSurf.RequestedHeight != _oldOutputHeight)
|
|
{
|
|
_context.Dispose();
|
|
_context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
|
|
|
|
_oldOutputWidth = outSurf.RequestedWidth;
|
|
_oldOutputHeight = outSurf.RequestedHeight;
|
|
}
|
|
|
|
Span<byte> bs = Prepend(bitstream, SpsAndPpsReconstruction.Reconstruct(ref pictureInfo, _workBuffer));
|
|
|
|
return _context.DecodeFrame(outSurf, bs) == 0;
|
|
}
|
|
|
|
private static byte[] Prepend(ReadOnlySpan<byte> data, ReadOnlySpan<byte> prep)
|
|
{
|
|
byte[] output = new byte[data.Length + prep.Length];
|
|
|
|
prep.CopyTo(output);
|
|
data.CopyTo(new Span<byte>(output).Slice(prep.Length));
|
|
|
|
return output;
|
|
}
|
|
|
|
public void Dispose() => _context.Dispose();
|
|
}
|
|
}
|