CVideoSource.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. /*************************************************
  3. Author: wangc
  4. Date:2023-05-06
  5. Name:CVideoSource
  6. Description::实现视频流的接收,会有多个数据源
  7. 1、实现打开网络流
  8. 2、解析流的重要参数,编码类型,视频宽高
  9. 3、读数据并将数据保存到队列
  10. **************************************************/
  11. extern "C"
  12. {
  13. #include "libavcodec/avcodec.h"
  14. };
  15. #define RECV_FAILED (-1)
  16. #define RECV_SUCCESS (0)
  17. #define RECV_SUCCESS_NOTPROC (1)
  18. class AVFormatContext;
  19. class AVCodecContext;
  20. class CVideoDataManager;
  21. class AVPacket;
  22. class CVideoSource
  23. {
  24. public:
  25. CVideoSource();
  26. ~CVideoSource();
  27. bool Init(const char * szUrl, CVideoDataManager * pDataManager);
  28. int GetFrameSize()
  29. {
  30. return m_nBitDepth == 8 ? m_nWidth * m_nHeight * 3 / 2 : m_nWidth * m_nHeight * 3;
  31. }
  32. AVCodecID GetVideoCodec()
  33. {
  34. return m_eVideoCodec;
  35. }
  36. int GetWidth()
  37. {
  38. return m_nWidth;
  39. }
  40. int GetHeight()
  41. {
  42. return m_nHeight;
  43. }
  44. int GetBitDepth()
  45. {
  46. return m_nBitDepth;
  47. }
  48. void Clear();
  49. AVCodecContext * GetVideoDecode()
  50. {
  51. return m_pCodecContextVideo;
  52. }
  53. static bool m_bUseHardDecode;
  54. static AVHWDeviceType m_HardType;
  55. static AVPixelFormat m_pixelFormat;
  56. static bool IsHardDecode();
  57. static AVPixelFormat GetpPixelFormat(AVCodecContext* ctx, const enum AVPixelFormat* fmts);
  58. private:
  59. static unsigned __stdcall RecvThread(void * param);
  60. void RecvThreadProcessor();
  61. int AudioProc(AVPacket * pktAudio);
  62. bool InitAudio();
  63. int RecvFrameSync();
  64. private:
  65. AVFormatContext *m_pFormatCtx{ nullptr};
  66. int m_nAudioIndex{1};
  67. AVCodecContext *m_pCodecContextAudio{ nullptr };
  68. int m_nVideoIndex{0};
  69. AVCodecContext* m_pCodecContextVideo{ nullptr };
  70. AVCodecID m_eVideoCodec{ AV_CODEC_ID_HEVC };
  71. int m_nWidth{3840};
  72. int m_nHeight{2160};
  73. int m_nBitDepth{8};
  74. double m_curAutdioPts{ -1 };
  75. CVideoDataManager * m_pDataManager{nullptr};
  76. };