live555之openRTSP----- continueAfterSETUP()视频接收并存储

发送SETUP之后,接受到返回信息,然后就是创建Sink,没有其他的操作了。

SETUP
客户端提醒服务器建立会话,并确定传输模式:
SETUP rtsp://192.168.20.136:5000/xxx666/trackID=0 RTSP/1.0
CSeq: 3
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
//uri中 带有trackID=0, 表示对该通道进行设置. Transport参数设置了传输模式, 包的结构. 接下来的数据包头部第二个字节位置就是 interleaved, 它的值是每个通道都不同的, trackID=0的interleaved值有两个0或1, 0表示rtp包, 1表示rtcp包, 接 受端根据interleaved的值来区别是哪种数据包.

服务器回应信息:
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 3
Session: 6310936469860791894 //服务器回应的会话标识符
Cache-Control: no-cache
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=6B8B4567

在这里面我们可以根据自己的需求定制不同的sink。
setupStream()
|—foreach subsession, setupSubsession()
……….|—foreach subsession, fileSink = H264VideoFileSink::createNew
……….|—subsession->sink->startPlaying(readSource,subsessionAfterPlaying, subsession)
……….|—startPlayingsession(continueAfterPLAY)发送Play请求

play的流程如下
sink->startPlaying(*(subsession->readSource()), subsessionAfterPlaying,subsession);
…………|–continuePlaying()//虚函数,根据你的sink是否重写,动态调用
……………….|–fSource->getNextFrame(fBuffer, fBufferSize,afterGettingFrame,this,onSourceClosure, this);
…………………….|–doGetNextFrame()//虚函数
………………………….|–fRTPInterface.startNetworkReading(networkReadHandler);//将networkReadHandler读取rtp包的操作添加到任务队列。
…………………….|–doGetNextFrame1();
………………………….|–taskScheduler().scheduleDelayedTask(afterGetting);//将afterGetting添加到任务队列

上面流程可以看出添加了两个任务。一个是read 一个是afterGetting(读取完数据之后,消费数据)
networkReadHandler()
……|–bPacket->fillInData()//在里面调用了read操作,将rtp包读到BufferedPacket中

因为

Boolean XXXSink::continuePlaying() {
  if (fSource == NULL) return False;

  fSource->getNextFrame(fBuffer, fBufferSize,
            afterGettingFrame, this,
            onSourceClosure, this);

  return True;
}

所以
afterGetting()
…..|–afterGettingFrame
………….|–addData(fBuffer, frameSize, presentationTime);//在这里你就可以随意处理视频数据了。我的视频源采用的h264,fBuffer就,是es流可以直接解码播放,也可以封装后存储成文件

猜你喜欢

转载自blog.csdn.net/sstya/article/details/52385489
今日推荐