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.

170 lines
3.9 KiB

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