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.

147 lines
3.4 KiB

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