rtmp協議 封包 參考red5
rtmp協議封包 由乙個包頭和乙個包體組成,包頭可以是4種長度的任意一種:12, 8, 4, 1 byte(s).完整的rtmp包頭應該是12bytes,包含了時間戳,head_type,amfsize,amftype,streamid資訊, 8位元組的包頭只紀錄了時間戳,head_type,amfsize,amftype, 4個位元組的包頭記錄了時間戳,head_type。1個位元組的包頭只記錄了head_type 。包體最大長度預設為128位元組,通過chunksize可改變包體最大長度,通常當一段afm資料超過128位元組後,超過128的部分就放到了其他的rtmp封包中,包頭為乙個位元組.
完整的rtmp包頭有12位元組,由下面5個部分組成:
用途大小(byte)
含義head_type1包頭
timer
3時間戳
amfsize
3資料大小
amftype
1資料型別
streamid
4流id
一、head_type - 包頭型別
head_type占用rtmp包的第乙個位元組,這個位元組裡面記錄了包的型別和包的channelid。head_type位元組的前兩個bit決定了包頭的長度.它可以用掩碼0xc0進行"與"計算:
head_type的前兩個bit和長度對應關係:
bits
header length
0012 bytes
018 bytes
104 bytes
111 byte
head_type的後面6個bit和streamid決定了channelid。 streamid和channelid對應關係:streamid=(channelid-4)/5+1 參考red5
channelid
用途02
ping 和byteread通道
03invoke通道 我們的connect() publish()和自字寫的netconnection.call() 資料都是在這個通道的
04audio和vidio通道
05 06 07
例如在rtmp包的資料中裡面,發現被插入了乙個0xc2,這個就是一位元組的包頭,並且channelid=2.
二、timmer - 時間戳
三、amfsize - 資料大小0×01
chunk size
changes the chunk size for packets
0×02
unknown
0×03
bytes read
send every x bytes read by both sides
0×04
ping
ping is a stream control message, has subtypes
0×05
server bw
the servers downstream bw
0×06
client bw
the clients upstream bw
0×07
unknown
0×08
audio data
packet containing audio
0×09
video data
packet containing video data
0x0a-0x0e
unknown
0x0f
flex_stream_send
type_flex_stream_send
0x10
flex_shared_object
type_flex_shared_object
0x11
flex_message
type_flex_message
0×12
notify
an invoke which does not expect a reply
0×13
shared object
has subtypes
0×14
invoke
like remoting call, used for stream actions too.
0×16
streamdata
這是fms3出來後新增的資料型別,這種型別資料中包含audiodata和videodata
五、streamid - 流id
六、封包分析
例如有乙個rtmp封包的資料
0300 00 00
00 01 02
1400 00 00 00
0200 07
63 6f 6e 6e 65 63 74
003f f0 00 00 00 00 00 00 08 ,,,
資料依次解析的含義
03表示12位元組頭,channelid=3
000000表示時間戳 timer=0
000102表示amfsize=18
14表示amftype=invoke 方法呼叫
00 00 00 00 表示streamid = 0
//到此,12位元組rtmp頭結束下面的是amf資料分析,具體的amf0資料格式請參考 rtmp協議 二、amf資料
02表示string
0007表示string長度7
63 6f 6e 6e 65 63 74 是string的ascall值"connect"
00表示double
3f f0 00 00 00 00 00 00 表示double的0.0
08表示map資料開始
RTMP協議分析 一 RTMP包頭
rtmp協議 封包 參考red5 rtmp協議封包 由乙個包頭和乙個包體組成,包頭可以是4種長度的任意一種 12,8,4,1 byte s 完整的rtmp包頭應該是12bytes,包含了時間戳,head type,amfsize,amftype,streamid資訊,8位元組的包頭只紀錄了時間戳,h...
RTMP協議分析
rtmp協議封包 由乙個包頭和乙個包體組成,包頭可以是4種長度的任意一種 12,8,4,1 byte s 完整的rtmp包頭應該是12bytes,包含了時間戳,amfsize,amftype,streamid資訊,8位元組的包頭只紀錄了時間戳,amfsize,amftype,其他位元組的包頭紀錄資訊...
RTMP協議分析
用途 大小 byte 含義head type1包頭 timer 3時間戳 amfsize 3資料大小 amftype 1資料型別 streamid 4流id 一 head type 包頭型別 head type占用rtmp包的第乙個位元組,這個位元組裡面記錄了包的型別和包的channelid。hea...