diff options
| author | Ac_K <Acoustik666@gmail.com> | 2021-10-12 22:55:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-12 22:55:57 +0200 |
| commit | d1604aa762a3f669a3fecff0a30b7360399954bc (patch) | |
| tree | 1996eec4b3937354aedc4d31b5b7b931ae4e321b /Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs | |
| parent | a7109c767bdc014327b574012794156c92174495 (diff) | |
nvdec: Adding Vp8 codec support (#2707)
* first try
* second try
* working update
* Final impl
* Fixes nits
* Fix everything
* remove leftover
* Update FFmpegContext.cs
* Update Surface.cs
* Addresses gdkchan feedback
* bool not byte
* Addresses gdkchan feedback
Diffstat (limited to 'Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs')
| -rw-r--r-- | Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs b/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs new file mode 100644 index 00000000..8deda42a --- /dev/null +++ b/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs @@ -0,0 +1,56 @@ +using FFmpeg.AutoGen; +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(); + } +} |
