欢迎关注公众号:冒泡的肥皂
1.数据快结构
2.Basic Header说明
basic heaher占用的字节大小数是不固定的,大小有1个或2个或3个字节;
下面是数据结构的描述: chunk type(即fmt)占2bit, chunk stream id一般被简写为CSID
3 .Basic Header解析
public class RtmpHeader {
int csid;
int fmt;
}
private RtmpHeader readHeader(ByteBuf in) {
RtmpHeader rtmpHeader = new RtmpHeader();
//最短一个字节
int headerLength = 1;
//读取一个字节
byte firstByte = in.readByte();
//向右移6位保留两位
int fmt = (firstByte & 0xff) >> 6;
//开头两位置为0 计算后面的6位
int csid = (firstByte & 0x3f);
if (csid == 0) {//两个字节大小计算
csid = in.readByte() & 0xff + 64;
headerLength += 1;
} else if (csid == 1) {//三个字节大小结算
byte secondByte = in.readByte();
byte thirdByte = in.readByte();
csid = (thirdByte & 0xff) << 8 + (secondByte & 0xff) + 64;
headerLength += 2;
} else if (csid >= 2) {//一个字节的
}
rtmpHeader.setCsid(csid);
rtmpHeader.setFmt(fmt);