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.

67 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SERVLET_CHANNEL_WEB_SOCKET_HEADER__
  2. #define __SERVLET_CHANNEL_WEB_SOCKET_HEADER__
  3. #include "../../components/base/basicThread.h"
  4. extern "C" {
  5. #include <libavdevice/avdevice.h>
  6. #include <libavcodec/avcodec.h>
  7. #include <libavformat/avio.h>
  8. #include <libavformat/avformat.h>
  9. #include <libswscale/swscale.h>
  10. #include <libavutil/file.h>
  11. #include <libavutil/mathematics.h>
  12. #include <libavutil/error.h>
  13. #include <libavutil/imgutils.h>
  14. };
  15. #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
  16. #define av_frame_alloc avcodec_alloc_frame
  17. #define av_frame_free avcodec_free_frame
  18. #define avcodec_free_context av_free
  19. #define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
  20. #endif
  21. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  22. #include <vector>
  23. #include <queue>
  24. typedef std::queue<AVPacket *> pipeAVPacket;
  25. #define PKT_BUF_LEN 1
  26. class servletChannelWS:basicThread{
  27. private:
  28. basicLogCollection * m_pLog;
  29. bool b_is_waiting_;
  30. bool b_new_pkt;
  31. bool b_fill_buf;
  32. bool b_streaming;
  33. pthread_mutex_t new_pkt_mutex;
  34. pthread_cond_t new_pkt_cond;
  35. pthread_mutex_t fill_buff_mutex;
  36. pthread_cond_t fill_buff_cond;
  37. pipeAVPacket m_qMediaBus;
  38. /* Encoder fields */
  39. AVFormatContext * m_pFormatCtx;
  40. AVCodecContext * m_pCodecCtx;
  41. AVCodec * m_pCodec;
  42. uint32_t m_fFrameRate;
  43. uint32_t m_nWidth;
  44. uint32_t m_nHeight;
  45. int m_iVideoStreamID;
  46. bool initLibAV(void);
  47. protected:
  48. virtual void m_fThreadProc( void );
  49. public:
  50. servletChannelWS();
  51. virtual ~servletChannelWS();
  52. bool create( CSTR MediaURI );
  53. pipeAVPacket * getPipe( void ){ return &m_qMediaBus; };
  54. };
  55. typedef std::vector<servletChannelWS *> vectorChannelsWS;
  56. #endif