#ifndef __BASICLIBAV_H_INCL__ #define __BASICLIBAV_H_INCL__ #ifndef LRF_PROXY_ONLY #ifndef __linux__ #include #include #endif #include #ifdef _OPENCV_ #include // #include #include // using namespace cv; #else #ifdef _SDL_ #include #include #endif #endif #include "basicLogCollection.h" #include "basicTypes.h" #ifdef __linux__ #ifndef UINT64_C #define UINT64_C uint64_t #endif #endif #define _CRT_SECURE_NO_DEPRECIATE extern "C" { #include #include #include #include #include #include #include #include #include #include } // extern bool _FFD_REGISTER_ALL_FLAG; #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #define avcodec_free_context av_free #define AV_PIX_FMT_BGR24 PIX_FMT_BGR24 #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P #define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P #endif #define CLEAR(x) memset(&(x), 0, sizeof(x)) #ifndef V4L2_PIX_FMT_H264 #define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */ #endif #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 #define VIDEO_PICTURE_QUEUE_SIZE 30 #define BUFFER_ALIGN 32 #define AVLIB_SOURCE_NOTDEF 0 #define AVLIB_SOURCE_DDSHOW 1 #define AVLIB_SOURCE_V4L2 2 #define AVLIB_SOURCE_IPSTREAM 3 // #define PROCESS_YUV420P #define PROCESS_BGR24 #define _NOAUDIO_ #ifdef _OPENCV_ typedef std::vector _FrameQueue; #endif typedef float FrameAspectRatio; #define FAR_UNKNOWN .0f #define FAR_4X3 1.3333333333333333333333333333333f #define FAR_5X4 1.25f #define FAR_16X9 1.7777777777777777777777777777778f #define FAR_SQUARE 1.f #ifndef CODEC_FLAG_GLOBAL_HEADER // #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22) #define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER // #define AVFMT_RAWPICTURE 0x0020 #endif typedef enum MedaLaneType { ML_NONE = 0x00, ML_IN = 0x01, ML_OUT = 0x02, ML_IN_OUT = 0x03, ML_IMAGE = 0x04, ML_VIDEO = 0x08, ML_AUDIO = 0x10 } MedaLaneType; typedef enum AttachmentStatus { AS_NONE = 0, AS_SOURCE = 1, AS_DESTINATION = 2, AS_BOTH = 3 } AttachmentStatus; typedef union MediaFormatInfo { struct VIDEO_INFO { /**** video ****/ // PixelFormat PixelFMT; int ImageWidth; int ImageHeight; int VideoFPS; } VIDEO_INFO; struct AUDIO_INFO { /**** Audio ****/ AVSampleFormat AudioFMT; int AudioSPS; int AudioCHA; int no_use; } AUDIO_INFO; } MediaFormatInfo; typedef struct VideoPicture { #ifdef _OPENCV_ cv::Mat * m_pTexture; #else #ifdef _SDL_GUI_ SDL_Surface * m_pTexture; #endif #endif int width; int height; /* source height & width */ bool allocated; } VideoPicture; typedef struct VideoState { #ifndef _NOAUDIO_ int m_iAudioStreamID; AVStream * m_pAudioStr; AVCodecContext * m_pAudioCtx; AVCodec * m_pAudioCodec; //_PacketQueue *m_pAudioQQ; uint8_t m_mAudioBuf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; unsigned int m_iAudioBufSize; unsigned int m_iAudioBufIndex; AVPacket m_mAudioPack; uint8_t * m_pAudioPktData; int m_iAudioPktSize; #endif int m_iVideoStreamID; AVStream * m_pVideoStr; AVFormatContext * m_pFormatCtx; AVDictionary * m_pFormatOpts; AVCodecContext * m_pCodecCtx; AVCodec * m_pVideoCodec; SwsContext * m_pSwsCtx; char m_pFileName[MAX_PATH_LEN]; MediaStateStatus m_bStatus; } VideoState; FrameAspectRatio detectAspectRatio(int width, int height); bool initLibAV(void); cv::Mat avframeToCvmat(const AVFrame * frame); AVFrame * cvmatToAvframe(cv::Mat * image, AVFrame * frame); #endif // !LRF_PROXY_ONLY #endif // __BASICLIBAV_H_INCL__