Decoder.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Ryujinx.Graphics.Video;
  2. using System;
  3. namespace Ryujinx.Graphics.Nvdec.H264
  4. {
  5. public sealed class Decoder : IH264Decoder
  6. {
  7. public bool IsHardwareAccelerated => false;
  8. private const int WorkBufferSize = 0x200;
  9. private readonly byte[] _workBuffer = new byte[WorkBufferSize];
  10. private readonly FFmpegContext _context = new FFmpegContext();
  11. public ISurface CreateSurface(int width, int height)
  12. {
  13. return new Surface();
  14. }
  15. public bool Decode(ref H264PictureInfo pictureInfo, ISurface output, ReadOnlySpan<byte> bitstream)
  16. {
  17. Span<byte> bs = Prepend(bitstream, SpsAndPpsReconstruction.Reconstruct(ref pictureInfo, _workBuffer));
  18. return _context.DecodeFrame((Surface)output, bs) == 0;
  19. }
  20. private static byte[] Prepend(ReadOnlySpan<byte> data, ReadOnlySpan<byte> prep)
  21. {
  22. byte[] output = new byte[data.Length + prep.Length];
  23. prep.CopyTo(output);
  24. data.CopyTo(new Span<byte>(output).Slice(prep.Length));
  25. return output;
  26. }
  27. public void Dispose() => _context.Dispose();
  28. }
  29. }