·您当前的位置:首页 > 技术教程 > live555技术 >

[Live555]监控摄像头采集264编码用live555做直播

时间:2015-04-21 15:09酷播
[Live555]监控摄像头采集264编码用live555做直播

[Live555]监控摄像头采集264编码用live555做直播

  1. H264FramedLiveSource.hh 
  2.  
  3. /* 
  4.  * Filename: H264FramedLiveSource.hh 
  5.  * Auther: chenbin 
  6.  * Create date: 2013/ 1/22 
  7.  */ 
  8.  
  9. #ifndef _H264FRAMEDLIVESOURCE_HH 
  10. #define _H264FRAMEDLIVESOURCE_HH 
  11.  
  12. #include <FramedSource.hh> 
  13.  
  14.  
  15. class H264FramedLiveSource : public FramedSource 
  16. public: 
  17.     static H264FramedLiveSource* createNew(UsageEnvironment& env, 
  18.         char const* fileName, 
  19.         unsigned preferredFrameSize = 0
  20.         unsigned playTimePerFrame = 0);  
  21.  
  22. protected: 
  23.     H264FramedLiveSource(UsageEnvironment& env, 
  24.         char const* fileName,  
  25.         unsigned preferredFrameSize, 
  26.         unsigned playTimePerFrame); 
  27.     // called only by createNew() 
  28.     ~H264FramedLiveSource(); 
  29.  
  30. private: 
  31.     // redefined virtual functions: 
  32.     virtual void doGetNextFrame(); 
  33.     int TransportData( unsigned char* to, unsigned maxSize ); 
  34.  
  35. protected: 
  36.     FILE *fp; 
  37. }; 
  38.  
  39. #endif 

 

  1. H264FramedLiveSource.cpp 
  2.  
  3. /* 
  4.  * Filename:  H264FramedLiveSource.cpp 
  5.  * Auther:  mlj 
  6.  * Create date: 2013/ 1/22 
  7.  */ 
  8.  
  9. #include "H264FramedLiveSource.hh" 
  10.   
  11.  
  12.  
  13. H264FramedLiveSource::H264FramedLiveSource( UsageEnvironment& env,   
  14.     char const* fileName,  
  15.     unsigned preferredFrameSize,  
  16.     unsigned playTimePerFrame ) 
  17.     : FramedSource(env) 
  18.      fp = fopen( fileName, "rb" );  
  19.  
  20. H264FramedLiveSource* H264FramedLiveSource::createNew( UsageEnvironment& env, 
  21.                                            char const* fileName,  
  22.                                            unsigned preferredFrameSize /*= 0*/,  
  23.                                            unsigned playTimePerFrame /*= 0*/ ) 
  24. {  
  25.     H264FramedLiveSource* newnewSource = new H264FramedLiveSource(env, fileName, preferredFrameSize, playTimePerFrame); 
  26.   
  27.     return newSource; 
  28.  
  29. H264FramedLiveSource::~H264FramedLiveSource() 
  30.     fclose(fp); 
  31.  
  32.  
  33. long filesize(FILE *stream) 
  34.     long curpos, length; 
  35.     curpos = ftell(stream); 
  36.     fseek(stream, 0L, SEEK_END); 
  37.     length = ftell(stream); 
  38.     fseek(stream, curpos, SEEK_SET); 
  39.     return length; 
  40.  
  41. void H264FramedLiveSource::doGetNextFrame() 
  42.  
  43.     if( filesize(fp) >  fMaxSize) 
  44.       fFrameSize = fread(fTo,1,fMaxSize,fp);  
  45.     else 
  46.     { 
  47.         fFrameSize = fread(fTo,1,filesize(fp),fp); 
  48.         fseek(fp, 0, SEEK_SET); 
  49.     } 
  50.     //fFrameSize = fMaxSize
  51.     nextTask() = envir().taskScheduler().scheduleDelayedTask( 0, 
  52.         (TaskFunc*)FramedSource::afterGetting, this);//表示延迟0秒后再执行 afterGetting 函数 
  53.     return; 

在 H264FramedLiveSource::doGetNextFrame() 中,将要发送的内容复制到 fTo,最大为fMaxSize,fFrameSize指示实际发送的内容是多少字节。这里暂时还是从文件读作为测试。

  1. H264LiveVideoServerMediaSubssion.hh 
  2.  
  3. /* 
  4.  * Filename: H264LiveVideoServerMediaSubssion.hh 
  5.  * Auther: mlj  
  6.  * Create date: 2013/ 1/22 
  7.  */ 
  8. #ifndef _H264_LIVE_VIDEO_SERVER_MEDIA_SUBSESSION_HH 
  9. #define _H264_LIVE_VIDEO_SERVER_MEDIA_SUBSESSION_HH 
  10. #include "H264VideoFileServerMediaSubsession.hh" 
  11.  
  12. class H264LiveVideoServerMediaSubssion: public H264VideoFileServerMediaSubsession { 
  13.  
  14. public: 
  15.   static H264LiveVideoServerMediaSubssion* 
  16.   createNew( UsageEnvironment& env, 
  17.                char const* fileName,  
  18.                 Boolean reuseFirstSource ); 
  19.  
  20. protected: // we're a virtual base class 
  21.   H264LiveVideoServerMediaSubssion( UsageEnvironment& env, char const* fileName, Boolean reuseFirstSource ); 
  22.    ~H264LiveVideoServerMediaSubssion(); 
  23.  
  24. protected: // redefined virtual functions 
  25.    FramedSource* createNewStreamSource(unsigned clientSessionId, 
  26.                           unsigned& estBitrate); 
  27. public:  
  28.    char fFileName[100]; 
  29.  
  30. }; 
  31.  
  32. #endif 

 

使用 ffplay.exe rtsp://115.156.164.19:8554/h264ESVideoTest 可以播放test.264的视频.

相关配置:live555的四个库放在lib文件夹下。

库目录:G:\workspace\avs\live555test\live555test\lib

包含目录:G:\workspace\avs\live555test\live555test\BasicUsageEnvironment \include;G:\workspace\avs\live555test\live555test\UsageEnvironment\include;G:\workspace\avs\live555test\live555test\liveMedia\include;G:\workspace\avs\live555test\live555test\groupsock\include

源代码 :

svn checkout http://live555-send-test.googlecode.com/svn/trunk/ live555-send-test-read-only

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器