librtmp使用扩展时间戳时服务器会将连接断开解释资料.docx
- 文档编号:1310987
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:10
- 大小:722.76KB
librtmp使用扩展时间戳时服务器会将连接断开解释资料.docx
《librtmp使用扩展时间戳时服务器会将连接断开解释资料.docx》由会员分享,可在线阅读,更多相关《librtmp使用扩展时间戳时服务器会将连接断开解释资料.docx(10页珍藏版)》请在冰点文库上搜索。
librtmp使用扩展时间戳时服务器会将连接断开解释资料
rtmpdump的librtmp时间戳有问题,服务器会断开连接
分类:
ffmpegc++linuxopen-source2013-10-2821:
49700人阅读评论(7)收藏举报
#header
0x44
0xff0xff0xff0x000x010x190x08
#extendedtimestamp
0x7f0xff0xf80x00
#body
0xaf0x010x010x40
0x220x800xa30x7f0xf80x850x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d
#header
0xc4
#extendedtimestamp
#errorhere
#body
0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
0x2d0x2d0x2d0x2d0x2d0x2d0x2d0x2d
对于0xC这种后续的chunk包的extendedtimestamp该不该发,rtmp协议中说是不发,但是FMLE是发的,推流超过4.5小时就需要用extendedtimestamp了。
rtmpdump里面的librtmp,不会发这个包,(ffmpeg里面用--enable-librtmp就会使用这个rtmp的库),而且是在开始就会发这个包。
6.1.3.ExtendedTimestamp
[plain]viewplaincopyprint?
1Thisfieldistransmittedonlywhenthenormaltimestampinthe
2chunkmessageheaderissetto0x00ffffff.Ifnormaltimestampis
3settoanyvaluelessthan0x00ffffff,thisfieldMUSTNOTbe
4present.ThisfieldMUSTNOTbepresentifthetimestampfieldisnot
5present. rgb(255,0,0);">Type3chunksMUSTNOThavethisfield. Thisfieldistransmittedonlywhenthenormaltimestampinthe chunkmessageheaderissetto0x00ffffff.Ifnormaltimestampis settoanyvaluelessthan0x00ffffff,thisfieldMUSTNOTbe present.ThisfieldMUSTNOTbepresentifthetimestampfieldisnot present.Type3chunksMUSTNOThavethisfield. 有可能是adobe变更了这个协议,也就是说,FMLE给FMS,FMS给flash-player,都是带这个时间戳的。 收包时,服务器端则需要检测下,若接下来的4字节不是extendedtimestamp,那么就忽略就好了。 发包时,只能采取配置,要么发,要么不发。 默认发就好了。 看nginx-rtmp代码: [cpp]viewplaincopyprint? 6ngx_rtmp_recv(ngx_event_t*rev) 7{ 8for(;;){ 9/*parseheaders*/ 10if(b->pos==b->start){ 11/*chunkbasicheader*/ 12fmt=(*p>>6)&0x03; 13csid=*p++&0x3f; 14if(fmt<=2){ 15/*timestamp: big-endian3b->little-endian4b*/ 16pp=(u_char*)timestamp; 17ext=(timestamp==0x00ffffff); 18if(fmt<=1){ 19/*size: big-endian3b->little-endian4btype*/ 20pp=(u_char*)&h->mlen; 21h->type=*(uint8_t*)p++; 22if(fmt==0){ 23/*stream: little-endian4b->little-endian4b*/ 24pp=(u_char*)&h->msid; 25} 26} 27} 28/*extendedheader*/ 29if(ext){ 30pp=(u_char*)timestamp; 31pp[3]=*p++; 32pp[2]=*p++; 33pp[1]=*p++; 34pp[0]=*p++; 35} ngx_rtmp_recv(ngx_event_t*rev) { for(;;){ /*parseheaders*/ if(b->pos==b->start){ /*chunkbasicheader*/ fmt=(*p>>6)&0x03; csid=*p++&0x3f; if(fmt<=2){ /*timestamp: big-endian3b->little-endian4b*/ pp=(u_char*)timestamp; ext=(timestamp==0x00ffffff); if(fmt<=1){ /*size: big-endian3b->little-endian4btype*/ pp=(u_char*)&h->mlen; h->type=*(uint8_t*)p++; if(fmt==0){ /*stream: little-endian4b->little-endian4b*/ pp=(u_char*)&h->msid; } } } /*extendedheader*/ if(ext){ pp=(u_char*)timestamp; pp[3]=*p++; pp[2]=*p++; pp[1]=*p++; pp[0]=*p++; } 可见,不管是什么chunk,只要有extended-timestamp,nginx-rtmp都会读这个。 所以nginx-rtmp对接FMLE是没有问题的,对接librtmp有问题。 更好的做法是判断下读出来的extendedtimestamp是否是和之前的一样,如果不是一样说明没有发,就忽略。 nginx-rtmp发包的逻辑: [cpp]viewplaincopyprint? 36ngx_rtmp_prepare_message 37{ 38/*createfmt3headerforsuccessivefragments*/ 39thsize=p-out->buf->pos; 40ngx_memcpy(th,out->buf->pos,thsize); 41th[0]|=0xc0; 42/*messageheader*/ 43if(fmt<=2){ 44} 45 46/*extendedheader*/ 47if(ext_timestamp){ 48pp=(u_char*)&ext_timestamp; 49*p++=pp[3]; 50*p++=pp[2]; 51*p++=pp[1]; 52*p++=pp[0]; 53 54/*ThisCONTRADICTSthestandard 55*butthat'sthewayflashclient 56*wantsdatatobeencoded; 57*ffmpegcomplains*/ 58if(cscf->play_time_fix){ 59ngx_memcpy(&th[thsize],p-4,4); 60thsize+=4; 61} 62} ngx_rtmp_prepare_message { /*createfmt3headerforsuccessivefragments*/ thsize=p-out->buf->pos; ngx_memcpy(th,out->buf->pos,thsize); th[0]|=0xc0; /*messageheader*/ if(fmt<=2){ } /*extendedheader*/ if(ext_timestamp){ pp=(u_char*)&ext_timestamp; *p++=pp[3]; *p++=pp[2]; *p++=pp[1]; *p++=pp[0]; /*ThisCONTRADICTSthestandard *butthat'sthewayflashclient *wantsdatatobeencoded; *ffmpegcomplains*/ if(cscf->play_time_fix){ ngx_memcpy(&th[thsize],p-4,4); thsize+=4; } } nginx-rtmp还特意说明了flash客户端就是和rtmp规范不一样。 out->buf->pos就是指向包的第一个chunk,若有extended-timestamp,那么肯定会在第一个包加上extendedtimestamp;后面还有个th和thsize,就是给后续的type=3的chunk包的,会加上这4字节的extendedtimestamp: [cpp]viewplaincopyprint? 63/*ThisCONTRADICTSthestandard 64*butthat'sthewayflashclient 65*wantsdatatobeencoded; 66*ffmpegcomplains*/ 67if(cscf->play_time_fix){ 68ngx_memcpy(&th[thsize],p-4,4); 69thsize+=4; 70} 71 72/*appendheaderstosuccessivefragments*/ 73for(out=out->next;out;out=out->next){ 74out->buf->pos-=thsize; 75ngx_memcpy(out->buf->pos,th,thsize); 76} /*ThisCONTRADICTSthestandard *butthat'sthewayflashclient *wantsdatatobeencoded; *ffmpegcomplains*/ if(cscf->play_time_fix){ ngx_memcpy(&th[thsize],p-4,4); thsize+=4; } /*appendheaderstosuccessivefragments*/ for(out=out->next;out;out=out->next){ out->buf->pos-=thsize; ngx_memcpy(out->buf->pos,th,thsize); } 所以nginx-rtmp收发包都是需要这个extended-timestamp,对于chunktype为3的包。 另外,把chunksize设置大一点,最大是65536,避免发type=3的chunk包,也是一个很好的方法。 不过视频的I帧一般较大,超过64KB也有可能。 Themaximumchunksizecanbe65536bytesandminimum128bytes. 按照这种规则,即type=3的chunk也发extended-timestamp,是没有问题: FMLE一直没有断开,客户端也没有断开。 服务器端是srs(simplertmpserver),也没有断开: 时间已经超过了24位,使用extended-timestamp: [plain]viewplaincopyprint? 77(gdb)p/x21039918 78$1=0x1410b2e (gdb)p/x21039918 $1=0x1410b2e 而nginx呢,是采用第一个包发完全的extended-timestamp,但是后续都是发type=1的chunk,即时间戳差值。 完毕。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- librtmp 使用 扩展 时间 服务器 连接 断开 解释 资料