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.1 KiB

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