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.

175 lines
4.2 KiB

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