NvDecoderImpl.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <cuda.h>
  3. #include <common_video/h264/h264_bitstream_parser.h>
  4. #include <common_video/include/video_frame_buffer_pool.h>
  5. #include "NvCodec.h"
  6. #include "NvDecoder/NvDecoder.h"
  7. using namespace webrtc;
  8. namespace unity
  9. {
  10. namespace webrtc
  11. {
  12. using NvDecoderInternal = ::NvDecoder;
  13. class H264BitstreamParser : public ::webrtc::H264BitstreamParser
  14. {
  15. public:
  16. absl::optional<SpsParser::SpsState> sps() { return sps_; }
  17. absl::optional<PpsParser::PpsState> pps() { return pps_; }
  18. };
  19. class ProfilerMarkerFactory;
  20. class NvDecoderImpl : public unity::webrtc::NvDecoder
  21. {
  22. public:
  23. NvDecoderImpl(CUcontext context, ProfilerMarkerFactory* profiler);
  24. NvDecoderImpl(const NvDecoderImpl&) = delete;
  25. NvDecoderImpl& operator=(const NvDecoderImpl&) = delete;
  26. ~NvDecoderImpl() override;
  27. virtual int32_t InitDecode(const VideoCodec* codec_settings, int32_t number_of_cores) override;
  28. virtual int32_t Decode(const EncodedImage& input_image, bool missing_frames, int64_t render_time_ms) override;
  29. virtual int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
  30. virtual int32_t Release() override;
  31. virtual DecoderInfo GetDecoderInfo() const override;
  32. private:
  33. CUcontext m_context;
  34. std::unique_ptr<NvDecoderInternal> m_decoder;
  35. bool m_isConfiguredDecoder;
  36. VideoCodec m_codec;
  37. DecodedImageCallback* m_decodedCompleteCallback = nullptr;
  38. webrtc::VideoFrameBufferPool m_buffer_pool;
  39. H264BitstreamParser m_h264_bitstream_parser;
  40. ProfilerMarkerFactory* m_profiler;
  41. const UnityProfilerMarkerDesc* m_marker;
  42. };
  43. } // end namespace webrtc
  44. } // end namespace unity