This blog is only to remind myself of what I've learned (from others or by myself) and only for knowledge sharing. External sources will be clearly stated in [Reference] of each article. I hope this blog won't infringe any copyrights and that it can be useful for interested blog readers.

2008年2月19日 星期二

mpeg4-generic-parsing for H264 over RFC3640 / RFC3 016


Preface

The following method applies to DVB-H CA channels
scrambled by Nagra and Irdeto CA servers

---
RTP header (there are 4 bytes per line)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X| CC |M| PT | sequence number
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| timestamp
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| synchronization source (SSRC) identifier
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| contributing source (CSRC) identifiers
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| .... payload 1....
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| .... payload 2....
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| .... payload N.... | ... padding bytes .... | padding count = 3
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

P => padding flag
The last byte of RTP packets => padding count

Steps explained in Psuedo code:

1) calculate real au_header_len_in_bytes

// get the number of bits of au header
au_header_len_in_bytes =
ntohs(*((unsigned short *)&pRTPBuffer[RTP_payload_start_index]));

// don't know why this? need further checking RFC3640/3016
if(au_headers_len_in_bytes % 8 != 0){
au_headers_len_in_bytes = au_headers_len_in_
bytes / 8 + 1;
}else{
au_headers_len_in_bytes = au_headers_len_in_
bytes / 8;
}

2) Find the
first_NALU_start_offset by searching ANNEX_B_START_CODE (0x00000001)

first_NALU_start_offset =
RTP_HEADER_SIZE + 2 + au_headers_len_in_bytes +
ANNEX_B_START_CODE_offset_from_payload;

3) Copy all the rest of RTP payload except padding bytes depending on
P flag of RTP header to a output buffer

ps: the payload might contain one NALU, part of a NALU, or multiple NALUs.

4) Send the resulted output buffer to H264 decoder for decoding

!!NOTES by Mark:
Because SPS/PPS might not be in SDP file,
remember to find SPS/PPS first, I-Frame first for H264 decoder from RTP packets
---

沒有留言: