codec.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <queue>
  7. #include "common/common_types.h"
  8. #include "video_core/command_classes/nvdec_common.h"
  9. extern "C" {
  10. #if defined(__GNUC__) || defined(__clang__)
  11. #pragma GCC diagnostic push
  12. #pragma GCC diagnostic ignored "-Wconversion"
  13. #endif
  14. #include <libavcodec/avcodec.h>
  15. #if defined(__GNUC__) || defined(__clang__)
  16. #pragma GCC diagnostic pop
  17. #endif
  18. }
  19. namespace Tegra {
  20. class GPU;
  21. struct VicRegisters;
  22. void AVFrameDeleter(AVFrame* ptr);
  23. using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>;
  24. namespace Decoder {
  25. class H264;
  26. class VP9;
  27. } // namespace Decoder
  28. class Codec {
  29. public:
  30. explicit Codec(GPU& gpu, const NvdecCommon::NvdecRegisters& regs);
  31. ~Codec();
  32. /// Initialize the codec, returning success or failure
  33. void Initialize();
  34. /// Sets NVDEC video stream codec
  35. void SetTargetCodec(NvdecCommon::VideoCodec codec);
  36. /// Call decoders to construct headers, decode AVFrame with ffmpeg
  37. void Decode();
  38. /// Returns next decoded frame
  39. [[nodiscard]] AVFramePtr GetCurrentFrame();
  40. /// Returns the value of current_codec
  41. [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const;
  42. /// Return name of the current codec
  43. [[nodiscard]] std::string_view GetCurrentCodecName() const;
  44. private:
  45. bool initialized{};
  46. NvdecCommon::VideoCodec current_codec{NvdecCommon::VideoCodec::None};
  47. AVCodec* av_codec{nullptr};
  48. AVCodecContext* av_codec_ctx{nullptr};
  49. GPU& gpu;
  50. const NvdecCommon::NvdecRegisters& state;
  51. std::unique_ptr<Decoder::H264> h264_decoder;
  52. std::unique_ptr<Decoder::VP9> vp9_decoder;
  53. std::queue<AVFramePtr> av_frames{};
  54. };
  55. } // namespace Tegra