2014-03-08 22:05:58
描述live555 client即openRTSP的流程,简单点说,playCommon.cpp,流为h264和g726。在实际项目中已成功应用。
以下为我所见所得,有错误之处请指正,谢谢!
1、live555的三种任务
socket handler,event handler,delay task。
这三种任务的特点是,前两个加入执行队列后会一直存在,而delay task在执行完一次后会立即弃掉。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
2、rtsp交互
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
3、以getOptions举例
getOptions(continueAfterOPTIONS),getOptions后怎么调用到continueAfterOPTIONS的,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
4、client get rtp_packet
● 先从setupStreams先入手吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
● 再从FileSink::continuePlaying入手
FileSink::continuePlaying()
FramedSource::getNextFrame()
MultiFramedRTPSource::doGetNextFrame()
MultiFramedRTPSource::doGetNextFrame1()
//以下::仅表示static func声明所在的类
static void FramedSource::afterGetting(FramedSource* source);
static void FileSink::afterGettingFrame(void* clientData, unsigned frameSize,unsigned numTruncatedBytes,
struct timeval presentationTime,unsigned durationInMicroseconds);
- MultiFramedRTPSource::doGetNextFrame1()
是递归函数,退出条件为
1 2 3 4 5 6 7 |
|
(Enter->Exit):即时
(Enter,) :和最近的(,Exit)配对
(,Exit):和最近的(Enter,)配对
static afterGetting::nth(Enter,) <--->static afterGetting::n+1th(,Exit)
从第一次调用continuePlaying()跟踪。可以直接跳到3th。
4.1 step1th
continuePlaying()--->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->......自己可以trace--->
startPlayingSession()--->setupStreams()--->SingleStep()::1th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,)--->
static afterGetting(Enter,)--->static afterGettingFrame(Enter,)--->H264or5VideoFileSink::afterGettingFrame()-->
FileSink::afterGettingFrame(){addData();continuePlaying()}-->
4.2 step2th
continuePlaying()-->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->static afterGettingFrame(,Exit)--->static afterGetting(,Exit)--->
doGetNextFrame1(,Exit[nextPacket == NULL])--->networkReadHandler1(,Eixt)--->
SingleStep()::2th--->incomingReportHandler1()--->
SingleStep()::3th--->incomingDataHandler1()--->continueAfterPLAY()--->
SingleStep()::4th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,)--->
static afterGetting(Enter,)--->static afterGettingFrame(Enter,)--->H264or5VideoFileSink::afterGettingFrame()-->
FileSink::afterGettingFrame(){addData();continuePlaying()}-->
//上述1/2th还有rtsp交互和一些初始化以及h264 SPS的处理,从3th就纯粹了。
//当接收到一帧完整的帧才会调用static afterGetting()
//FileSink::afterGettingFrame(){addData();continuePlaying()}
//addData():保存一帧h264到文件。continuePlaying()继续干活吧。
4.3 step3th
continuePlaying()-->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->static afterGettingFrame(,Exit)--->static afterGetting(,Exit)--->
doGetNextFrame1(,Exit[nextPacket == NULL])--->networkReadHandler1(,Eixt)--->
SingleStep()::5th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,)--->
static afterGetting(Enter,)--->static afterGettingFrame(Enter,)--->H264or5VideoFileSink::afterGettingFrame()-->
FileSink::afterGettingFrame(){addData();continuePlaying()}-->
?4.4 step4?th
continuePlaying()-->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->static afterGettingFrame(,Exit)--->static afterGetting(,Exit)--->
doGetNextFrame1( , Exit[nextPacket == NULL])--->networkReadHandler1(,Eixt)--->
//以上为针对3th的Exit,结合networkReadHandler1::3th(Enter,)和networkReadHandler1::4th(,Eixt)可以看出doGetNextFrame1为递归函数。
//networkReadHandler1--->doGetNextFrame1--->static afterGetting--->continuePlaying()--->doGetNextFrame1
// SingleStep()生生不息,networkReadHandler1()进进出出
SingleStep()::6th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,)--->
static afterGetting(Enter,)--->static afterGettingFrame(Enter,)--->H264or5VideoFileSink::afterGettingFrame()-->
FileSink::afterGettingFrame(){addData();continuePlaying()}-->
//nth :multi-packet frame,会有多次SingleStep(),但不会调用static afterGetting()
//只有在收完所有的sliece,即一个完整的frame后,才会调用static afterGetting()
continuePlaying()-->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->static afterGettingFrame(,Exit)--->static afterGetting(,Exit)--->
doGetNextFrame1(,Exit[nextPacket == NULL])--->networkReadHandler1(,Eixt)--->
SingleStep()::nth--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,Exit)--->
networkReadHandler1(,Exit)--->
SingleStep()::n+1th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,Exit)--->
networkReadHandler1(,Exit)--->
。。。。。。。。。。。。。
//最后一个packet
SingleStep()::n+mth--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,)--->
//此处才会调用static afterGetting
static afterGetting(Enter,)--->static afterGettingFrame(Enter,)--->H264or5VideoFileSink::afterGettingFrame()-->
FileSink::afterGettingFrame(){addData();continuePlaying()}-->
//n+1th
continuePlaying()-->getNextFrame()--->doGetNextFrame()--->
doGetNextFrame1(Enter->Exit[nextPacket == NULL])--->static afterGettingFrame(,Exit)--->static afterGetting(,Exit)--->?
doGetNextFrame1(,Exit[nextPacket == NULL])--->networkReadHandler1(,Eixt)--->
SingleStep()::n+m+1th--->
networkReadHandler1(Enter,)--->doGetNextFrame1(Enter,Exit)--->
networkReadHandler1(,Exit)--->
。。。。。。。。。。。。。。。。