部標JT1078協議RTP包解析

2021-09-11 01:24:19 字數 1550 閱讀 5758

@slf4j

public class jt1078mediaframedecoder extends bytetomessagedecoder

}private object decode(channelhandlercontext ctx, bytebuf buf) ", bytebufutil.hexdump(buf));

return null;

}//尋找包頭0x30316364

int headeridx = -1;

int readeridx = buf.readerindex();

for (int i = readeridx; i < buf.writerindex() - 3; i++)

}if (headeridx == -1) ", bytebufutil.hexdump(buf));

buf.skipbytes(buf.readablebytes());

return null;

}//檢測後續包長度

buf.skipbytes(headeridx - readeridx);

if (buf.readablebytes() < base_len) ", bytebufutil.hexdump(buf));

return null;

}buf.markreaderindex();

int fullpacketlen = base_len;

//解析出資料型別

int datatype = buf.getbyte(15 + headeridx) >> 4;

//時間戳,標識此rtp包當前幀的相對時間,單位毫秒,資料型別為0b0100時則沒有該欄位

if (datatype != constants.rtp_data_type_0100) else ", bytebufutil.hexdump(buf));

return null;}}

if (datatype != constants.rtp_data_type_0011 && datatype != constants.rtp_data_type_0100) else ", bytebufutil.hexdump(buf));

return null;}}

//資料體長度

int bodylen = buf.getshort(headeridx + fullpacketlen - 2);

//資料體長度太小則將讀指標重置到包頭,等待下一包後再解碼

if (buf.readablebytes() < fullpacketlen + bodylen) ", bodylen);

buf.resetreaderindex();

return null;

}//解析出完整包,交給下乙個處理器處理

fullpacketlen += bodylen;

bytebuf frame = buf.readretainedslice(fullpacketlen);

return frame;

}}

官方**: