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.

88 lines
2.2 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __VIDEO_INPUT_LIBAV_HEADER__
  2. #define __VIDEO_INPUT_LIBAV_HEADER__
  3. #include <stdarg.h>
  4. #include "video_in.h"
  5. extern "C" {
  6. #include <libavdevice/avdevice.h>
  7. #include <libavcodec/avcodec.h>
  8. #include <libavformat/avformat.h>
  9. #include <libswscale/swscale.h>
  10. #include <libavutil/imgutils.h>
  11. };
  12. #include "../core/exit_error_codes.h"
  13. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
  14. #define VIDEO_PICTURE_QUEUE_SIZE 30
  15. #define BUFFER_ALIGN 32
  16. //#define PROCESS_YUV420P
  17. #define PROCESS_BGR24
  18. //extern bool _FFD_REGISTER_ALL_FLAG;
  19. typedef struct VideoPicture {
  20. cv::Mat *m_pTexture;
  21. int width;
  22. int height; /* source height & width */
  23. bool allocated;
  24. } VideoPicture;
  25. typedef struct VideoState {
  26. AVFormatContext *m_pFormatCtx;
  27. #ifndef _NOAUDIO_
  28. int m_iAudioStreamID;
  29. AVStream *m_pAudioStr;
  30. AVCodecContext *m_pAudioCtx;
  31. AVCodec *m_pAudioCodec;
  32. _PacketQueue *m_pAudioQQ;
  33. uint8_t m_mAudioBuf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
  34. unsigned int m_iAudioBufSize;
  35. unsigned int m_iAudioBufIndex;
  36. AVPacket m_mAudioPack;
  37. uint8_t *m_pAudioPktData;
  38. int m_iAudioPktSize;
  39. #endif
  40. int m_iVideoStreamID;
  41. AVStream *m_pVideoStr;
  42. AVCodecContext *m_pVideoCtx;
  43. AVCodec *m_pVideoCodec;
  44. VideoPicture m_mPictQ[VIDEO_PICTURE_QUEUE_SIZE];
  45. int m_iPictQSize;
  46. int m_iPictQ_rindex;
  47. int m_iPictQ_windex;
  48. char m_pFileName[1024];
  49. uint8_t m_bStatus;
  50. //int quit;
  51. } VideoState;
  52. class _LIBAV_VideoInput: public _VideoInput {
  53. private:
  54. VideoState *m_pVideoState;
  55. AVFrame *m_pFrame;
  56. AVFrame *m_pFrameBGR;
  57. cv::Mat m_pMat;
  58. cv::Mat m_pOMat;
  59. uint8_t *m_pOut_buffer;
  60. AVPacket *m_pPacket;
  61. int m_iY_size;
  62. struct SwsContext *img_convert_ctx;
  63. //static void *m_tVideoProc(void *args);
  64. #ifndef _NOAUDIO_
  65. static void *m_tAudioProc(void *args);
  66. #endif
  67. bool initLBAV( void );
  68. bool openSource( char *URI );
  69. bool closeSource( void );
  70. protected:
  71. void m_fInputProc( void );
  72. public:
  73. _LIBAV_VideoInput();
  74. _LIBAV_VideoInput( char *Source );
  75. ~_LIBAV_VideoInput();
  76. };
  77. #endif