123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #pragma once
- /*************************************************
- Author: wangc
- Date:2023-05-06
- Name:CVideoSource
- Description::实现视频流的接收,会有多个数据源
- 1、实现打开网络流
- 2、解析流的重要参数,编码类型,视频宽高
- 3、读数据并将数据保存到队列
- **************************************************/
- extern "C"
- {
- #include "libavcodec/avcodec.h"
- };
- #define RECV_FAILED (-1)
- #define RECV_SUCCESS (0)
- #define RECV_SUCCESS_NOTPROC (1)
- class AVFormatContext;
- class AVCodecContext;
- class CVideoDataManager;
- class AVPacket;
- class CVideoSource
- {
- public:
- CVideoSource();
- ~CVideoSource();
- bool Init(const char * szUrl, CVideoDataManager * pDataManager);
- int GetFrameSize()
- {
- return m_nBitDepth == 8 ? m_nWidth * m_nHeight * 3 / 2 : m_nWidth * m_nHeight * 3;
- }
- AVCodecID GetVideoCodec()
- {
- return m_eVideoCodec;
- }
- int GetWidth()
- {
- return m_nWidth;
- }
- int GetHeight()
- {
- return m_nHeight;
- }
- int GetBitDepth()
- {
- return m_nBitDepth;
- }
-
- void Clear();
- AVCodecContext * GetVideoDecode()
- {
- return m_pCodecContextVideo;
- }
-
- static bool m_bUseHardDecode;
- static AVHWDeviceType m_HardType;
- static AVPixelFormat m_pixelFormat;
- static bool IsHardDecode();
- static AVPixelFormat GetpPixelFormat(AVCodecContext* ctx, const enum AVPixelFormat* fmts);
- private:
- static unsigned __stdcall RecvThread(void * param);
- void RecvThreadProcessor();
- int AudioProc(AVPacket * pktAudio);
- bool InitAudio();
- int RecvFrameSync();
- private:
- AVFormatContext *m_pFormatCtx{ nullptr};
- int m_nAudioIndex{1};
- AVCodecContext *m_pCodecContextAudio{ nullptr };
- int m_nVideoIndex{0};
- AVCodecContext* m_pCodecContextVideo{ nullptr };
- AVCodecID m_eVideoCodec{ AV_CODEC_ID_HEVC };
- int m_nWidth{3840};
- int m_nHeight{2160};
- int m_nBitDepth{8};
- double m_curAutdioPts{ -1 };
- CVideoDataManager * m_pDataManager{nullptr};
- };
|