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.

163 lines
3.7 KiB

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