1.概述

liveMedia 库中有一系列类,基类是Medium,这些类针对不同的流媒体类型和编码。 其中的StreamFrame类文件(如MPEG4VideoStreamFramer)为流传输关键。

2 重要概念:

StreamFrame类:该类继承FramedSource基类,实现数据流的控制和传输。

StreamFrame(H264VideoStreamFramer) -->FramedFilter--> FramedSource----> MediaSource

FramedSource 派继承MediaSource父类,一帧码流的实现。

注意:unsigned char* fTo;为指向发送的码流的指针,采集到视频数据后填充到该指针中即可实现码流的传输。

主要步骤:1.定义自己的StreamFramer类,实现getNextFrame重写。

 getNextFrame函数来自live\liveMedia\FramedSource文件,代码见下

[cpp] view
plain
 copy

  1. void FramedSource::getNextFrame(unsignedchar* to, unsigned maxSize,
  2. afterGettingFunc*afterGettingFunc,
  3. void*afterGettingClientData,
  4. onCloseFunc*onCloseFunc,
  5. void*onCloseClientData) {
  6. // Make sure we're not already beingread:
  7. if (fIsCurrentlyAwaitingData){
  8. envir() <<"FramedSource[" <<this <<"]::getNextFrame(): attempting to read more than once at the sametime!\n";
  9. envir().internalError();
  10. }
  11. fTo = to;
  12. fMaxSize = maxSize;
  13. fNumTruncatedBytes = 0; // by default;could be changed by doGetNextFrame()
  14. fDurationInMicroseconds = 0; // bydefault; could be changed by doGetNextFrame()
  15. fAfterGettingFunc = afterGettingFunc;
  16. fAfterGettingClientData =afterGettingClientData;
  17. fOnCloseFunc = onCloseFunc;
  18. fOnCloseClientData = onCloseClientData;
  19. fIsCurrentlyAwaitingData = True;
  20. doGetNextFrame();
  21. }

其中最后的doGetNextFrame(); 是一个虚函数,具体各种编码模式,我们可以根据自己的码流类型定义一个派生自FramedSource的类(本工程H264FramedLiveSource类), 重新再定义doGetNextFrame如何获得下一帧的码流,在自己重定义的doGetNextFrame() 中将fTo指向要发送的缓存即可。这样我们就实现了流的传输而非文件传输。

本工程中doGetNextFrame()代码如下:

[cpp] view
plain
 copy

  1. voidH264FramedLiveSource::doGetNextFrame()
  2. {
  3. printf("doGetNextFrame\n");
  4. if( filesize(fp) >  fMaxSize)
  5. fFrameSize = fread(fTo,1,fMaxSize,fp);
  6. else
  7. {
  8. fFrameSize =fread(fTo,1,filesize(fp),fp);
  9. fseek(fp, 0, SEEK_SET);
  10. }
  11. //fFrameSize = fMaxSize;
  12. nextTask() =envir().taskScheduler().scheduleDelayedTask( 0,
  13. (TaskFunc*)FramedSource::afterGetting, this);
  14. return;
  15. }

2.实现fTO与会话连接,自定义ServerMediaSubsession

 定义ServerMediaSubsession类H264LiveVideoServerMediaSubssion,该类由ServerMediaSubsession 派生而来。该类中有私有函数virtual FramedSource* createNewStreamSource,在该函数中进行重新定义即可实现。

[cpp] view
plain
 copy

  1. FramedSource*H264LiveVideoServerMediaSubssion::createNewStreamSource( unsignedclientSessionId, unsigned& estBitrate )
  2. {
  3. /* Remain to do : assign estBitrate */
  4. estBitrate = 1000; // kbps, estimate
  5. // Create the video source:
  6. H264FramedLiveSource* liveSource =H264FramedLiveSource::createNew(envir(), fFileName);
  7. if (liveSource == NULL)
  8. {
  9. return NULL;
  10. }
  11. // Create a framer for the Video ElementaryStream:
  12. returnH264VideoStreamFramer::createNew(envir(), liveSource);
  13. }

主要最后返回的H264VideoStreamFramer继承自FramedSource,定义了从文件获取source的方法,从而将ServerMedia 与source联系起来。

代码为vs2008工程,采用VLC测试,测试结果如下图所示

代码见http://download.csdn.NET/detail/xiahua882/9619900

注:工程中CaremaLive为该博客代码,MediaServer为live555标准服务器工程也可以运行。代码工程图见下

【视频开发】【Live555】live555实现h264码流RTSP传输的更多相关文章

  1. 从H264码流中获取视频宽高 (SPS帧) 升级篇

    之前写过 <从H264码流中获取视频宽高 (SPS帧)> . 但发现很多局限性,而且有时解出来是错误的. 所以重新去研究了. 用了 官方提供的代码库来解析. 花了点时间,从代码库里单独把解 ...

  2. 从H264码流中获取视频宽高 (SPS帧)

    获取.h264视频宽高的方法 花了2个通宵终于搞定.(后面附上完整代码) http://write.blog.csdn.net/postedit/7852406 图像的高和宽在H264的SPS帧中.在 ...

  3. H264码流打包分析(精华)

    H264码流打包分析 SODB 数据比特串-->最原始的编码数据 RBSP 原始字节序列载荷-->在SODB的后面填加了结尾比特(RBSP trailing bits 一个bit“1”)若 ...

  4. H264码流解析及NALU

    ffmpeg 从mp4上提取H264的nalu http://blog.csdn.net/gavinr/article/details/7183499 639     /* bitstream fil ...

  5. RTP协议全解析(H264码流和PS流)

    转自:http://blog.csdn.net/chen495810242/article/details/39207305 写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个 ...

  6. (转)RTP协议全解(H264码流和PS流)

    写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...

  7. H264码流中SPS PPS详解<转>

    转载地址:https://zhuanlan.zhihu.com/p/27896239 1 SPS和PPS从何处而来? 2 SPS和PPS中的每个参数起什么作用? 3 如何解析SDP中包含的H.264的 ...

  8. RTP协议全解(H264码流和PS流)

    写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...

  9. H264编码原理以及I帧、B和P帧详解, H264码流结构分析

    H264码流结构分析 http://blog.csdn.net/chenchong_219/article/details/37990541 1.码流总体结构: h264的功能分为两层,视频编码层(V ...

随机推荐

  1. SpringBoot集成MyBatis的Bean配置方式

    SpringBoot集成MyBatis的Bean配置方式 SpringBoot是一款轻量级开发的框架,简化了很多原先的xml文件配置方式,接下来就介绍一下如何不适用XML来配置Mybatis spri ...

  2. windows 10 下使用Navicat for oracle 数据库还原

    一.前期准备 1.安装windows 10系统 2.安装oracle 11g 数据库 3.安装PLsql(也不需要) 4.安装sqlplus(这个必须有) 5.使用下面这个东西新建数据库(不懂创建的话 ...

  3. pandas 常用方法使用示例

    from pandas import DataFrame import numpy as np import pandas as pd t={ , , np.nan, , np.nan, ], &qu ...

  4. np.mean()函数

    1. 数组的操作: import numpy as np a = np.array([[1, 2], [3, 4]]) print(a) print(type(a)) print(np.mean(a) ...

  5. OKR的两个基本原则

    <启示录>作者,前易贝高级副总裁,硅谷产品集团创始人马蒂·卡根在<OKR工作法>的序言中提到了目标管理法的两个原则: 不要告诉下属具体怎么做,要告诉他们你要什么,他们就会给你满 ...

  6. WinDbg常用命令系列---显示当前异常处理程序链!exchain

    !exchain 这个!exchain扩展命令显示当前异常处理程序链. !exchain [Options] 参数: Options下列值之一: /c  如果检测到异常,则显示与调试C++ try/c ...

  7. 关于redash 自定义可视化以及query runner 开发的几篇文章

    以下是几篇关于如如何编码redash 自定义可视化插件以及query runner 的连接,很有借鉴价值 参考连接 https://discuss.redash.io/t/how-to-create- ...

  8. CURL shell 使用

    #! /bin/bash requrl="http://www.baidu.com/xxxxxx" while true do html=$(curl -s "$requ ...

  9. 洛谷 P4071 [SDOI2016]排列计数 题解

    P4071 [SDOI2016]排列计数 题目描述 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳 ...

  10. vscode 添加eslint插件

    1. 安装vscode中的eslint插件 Ctrl + Shift + P 调出控制台,输入install,再在插件版块查找ESLint,安装 2. 安装node,安装npm 3. 全局安装ESLi ...