You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.0 KiB

​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICLIBAV_H_INCL__
  2. #define __BASICLIBAV_H_INCL__
  3. #ifndef LRF_PROXY_ONLY
  4. #ifndef __linux__
  5. #include <winsock2.h>
  6. #include <ws2tcpip.h>
  7. #endif
  8. #include <math.h>
  9. #ifdef _OPENCV_
  10. #include <opencv2/opencv.hpp>
  11. // #include <opencv/highgui.h>
  12. #include <opencv2/videoio.hpp>
  13. // using namespace cv;
  14. #else
  15. #ifdef _SDL_
  16. #include <SDL.h>
  17. #include <SDL_render.h>
  18. #endif
  19. #endif
  20. #include "basicLogCollection.h"
  21. #include "basicTypes.h"
  22. #ifdef __linux__
  23. #ifndef UINT64_C
  24. #define UINT64_C uint64_t
  25. #endif
  26. #endif
  27. #define _CRT_SECURE_NO_DEPRECIATE
  28. extern "C"
  29. {
  30. #include <libavcodec/avcodec.h>
  31. #include <libavdevice/avdevice.h>
  32. #include <libavformat/avformat.h>
  33. #include <libavformat/avio.h>
  34. #include <libavutil/error.h>
  35. #include <libavutil/file.h>
  36. #include <libavutil/imgutils.h>
  37. #include <libavutil/mathematics.h>
  38. #include <libswresample/swresample.h>
  39. #include <libswscale/swscale.h>
  40. }
  41. // extern bool _FFD_REGISTER_ALL_FLAG;
  42. #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1)
  43. #define av_frame_alloc avcodec_alloc_frame
  44. #define av_frame_free avcodec_free_frame
  45. #define avcodec_free_context av_free
  46. #define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
  47. #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
  48. #define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P
  49. #endif
  50. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  51. #ifndef V4L2_PIX_FMT_H264
  52. #define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
  53. #endif
  54. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
  55. #define VIDEO_PICTURE_QUEUE_SIZE 30
  56. #define BUFFER_ALIGN 32
  57. #define AVLIB_SOURCE_NOTDEF 0
  58. #define AVLIB_SOURCE_DDSHOW 1
  59. #define AVLIB_SOURCE_V4L2 2
  60. #define AVLIB_SOURCE_IPSTREAM 3
  61. // #define PROCESS_YUV420P
  62. #define PROCESS_BGR24
  63. #define _NOAUDIO_
  64. #ifdef _OPENCV_
  65. typedef std::vector<cv::Mat *> _FrameQueue;
  66. #endif
  67. typedef float FrameAspectRatio;
  68. #define FAR_UNKNOWN .0f
  69. #define FAR_4X3 1.3333333333333333333333333333333f
  70. #define FAR_5X4 1.25f
  71. #define FAR_16X9 1.7777777777777777777777777777778f
  72. #define FAR_SQUARE 1.f
  73. #ifndef CODEC_FLAG_GLOBAL_HEADER
  74. // #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
  75. #define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
  76. // #define AVFMT_RAWPICTURE 0x0020
  77. #endif
  78. typedef enum MedaLaneType
  79. {
  80. ML_NONE = 0x00,
  81. ML_IN = 0x01,
  82. ML_OUT = 0x02,
  83. ML_IN_OUT = 0x03,
  84. ML_IMAGE = 0x04,
  85. ML_VIDEO = 0x08,
  86. ML_AUDIO = 0x10
  87. } MedaLaneType;
  88. typedef enum AttachmentStatus
  89. {
  90. AS_NONE = 0,
  91. AS_SOURCE = 1,
  92. AS_DESTINATION = 2,
  93. AS_BOTH = 3
  94. } AttachmentStatus;
  95. typedef union MediaFormatInfo
  96. {
  97. struct VIDEO_INFO
  98. {
  99. /**** video ****/
  100. // PixelFormat PixelFMT;
  101. int ImageWidth;
  102. int ImageHeight;
  103. int VideoFPS;
  104. } VIDEO_INFO;
  105. struct AUDIO_INFO
  106. {
  107. /**** Audio ****/
  108. AVSampleFormat AudioFMT;
  109. int AudioSPS;
  110. int AudioCHA;
  111. int no_use;
  112. } AUDIO_INFO;
  113. } MediaFormatInfo;
  114. typedef struct VideoPicture
  115. {
  116. #ifdef _OPENCV_
  117. cv::Mat * m_pTexture;
  118. #else
  119. #ifdef _SDL_GUI_
  120. SDL_Surface * m_pTexture;
  121. #endif
  122. #endif
  123. int width;
  124. int height; /* source height & width */
  125. bool allocated;
  126. } VideoPicture;
  127. typedef struct VideoState
  128. {
  129. #ifndef _NOAUDIO_
  130. int m_iAudioStreamID;
  131. AVStream * m_pAudioStr;
  132. AVCodecContext * m_pAudioCtx;
  133. AVCodec * m_pAudioCodec;
  134. //_PacketQueue *m_pAudioQQ;
  135. uint8_t m_mAudioBuf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
  136. unsigned int m_iAudioBufSize;
  137. unsigned int m_iAudioBufIndex;
  138. AVPacket m_mAudioPack;
  139. uint8_t * m_pAudioPktData;
  140. int m_iAudioPktSize;
  141. #endif
  142. int m_iVideoStreamID;
  143. AVStream * m_pVideoStr;
  144. AVFormatContext * m_pFormatCtx;
  145. AVDictionary * m_pFormatOpts;
  146. AVCodecContext * m_pCodecCtx;
  147. AVCodec * m_pVideoCodec;
  148. SwsContext * m_pSwsCtx;
  149. char m_pFileName[MAX_PATH_LEN];
  150. MediaStateStatus m_bStatus;
  151. } VideoState;
  152. FrameAspectRatio detectAspectRatio(int width, int height);
  153. bool initLibAV(void);
  154. cv::Mat avframeToCvmat(const AVFrame * frame);
  155. AVFrame * cvmatToAvframe(cv::Mat * image, AVFrame * frame);
  156. #endif // !LRF_PROXY_ONLY
  157. #endif // __BASICLIBAV_H_INCL__