cuvid_decoder.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef CUVID_DECODER_HPP
  2. #define CUVID_DECODER_HPP
  3. #include <memory>
  4. // 就不用在这里包含cuda_runtime.h
  5. struct CUstream_st;
  6. namespace FFHDDecoder{
  7. #define IcudaVideoCodec_H264 4
  8. typedef CUstream_st* ICUStream;
  9. typedef unsigned int IcudaVideoCodec;
  10. struct CropRect {
  11. int l, t, r, b;
  12. };
  13. struct ResizeDim {
  14. int w, h;
  15. };
  16. class CUVIDDecoder{
  17. public:
  18. virtual int get_frame_bytes() = 0;
  19. virtual int get_width() = 0;
  20. virtual int get_height() = 0;
  21. virtual unsigned int get_frame_index() = 0;
  22. virtual unsigned int get_num_decoded_frame() = 0;
  23. virtual uint8_t* get_frame(int64_t* pTimestamp = nullptr, unsigned int* pFrameIndex = nullptr) = 0;
  24. virtual int decode(const uint8_t *pData, int nSize, int64_t nTimestamp=0) = 0;
  25. virtual ICUStream get_stream() = 0;
  26. virtual int device() = 0;
  27. virtual bool is_gpu_frame() = 0;
  28. };
  29. IcudaVideoCodec ffmpeg2NvCodecId(int ffmpeg_codec_id);
  30. /* max_cache 取 -1 时,无限缓存,根据实际情况缓存。实际上一般不超过5帧 */
  31. // gpu_id = -1, current_device_id
  32. std::shared_ptr<CUVIDDecoder> create_cuvid_decoder(
  33. bool use_device_frame, IcudaVideoCodec codec, int max_cache = -1, int gpu_id = -1,
  34. const CropRect *crop_rect = nullptr, const ResizeDim *resize_dim = nullptr, bool output_bgr = false
  35. );
  36. }; // FFHDDecoder
  37. #endif // CUVID_DECODER_HPP