<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">Then I do not see how you can make a "generic" parser without<br class="">knowing in advance whether the start code is 3 or 4 bytes.<br class=""></div></blockquote><div><br class=""></div></div>No, it’s actually quite easy. If you know that the start code is either 0x00 0x00 0x01 or 0x00 0x00 0x00 0x01, then the following code (taken from our H.264/5 stream parser, used in “H264or5VideoStreamFramer”) does the trick:<div class=""><br class=""></div><div class=""> while (next4Bytes != 0x00000001 && (next4Bytes&0xFFFFFF00) != 0x00000100) {<br class=""> // We save at least some of "next4Bytes". <br class=""> if ((unsigned)(next4Bytes&0xFF) > 1) {<br class=""> // Common case: 0x00000001 or 0x000001 definitely doesn't begin anywhere in "next4Bytes", so we save all of it: <br class=""> save4Bytes(next4Bytes);<br class=""> skipBytes(4);<br class=""> } else {<br class=""> // Save the first byte, and continue testing the rest: <br class=""> saveByte(next4Bytes>>24);<br class=""> skipBytes(1);<br class=""> }<br class=""> setParseState(); // ensures forward progress <br class=""> next4Bytes = test4Bytes();<br class=""> }<br class=""> // Assert: next4Bytes starts with 0x00000001 or 0x000001, and we've saved all previous bytes (forming a complete NAL unit). <br class=""> // Skip over these remaining bytes, up until the start of the next NAL unit: <br class=""> if (next4Bytes == 0x00000001) {<br class=""> skipBytes(4);<br class=""> } else {<br class=""> skipBytes(3);<br class=""> }<br class=""></div><div class=""> }</div><br class=""><div apple-content-edited="true" class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Ross Finlayson<br class="">Live Networks, Inc.<br class=""><a href="http://www.live555.com/" class="">http://www.live555.com/</a></span></span>
</div>
<br class=""></body></html>