<divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="comment">// Copyright 2014 The Chromium Authors. All rights reserved.</span></div>
<divclass="line"><aname="l00002"></a><spanclass="lineno"> 2</span> <spanclass="comment">// Use of this source code is governed by a BSD-style license that can be</span></div>
<divclass="line"><aname="l00003"></a><spanclass="lineno"> 3</span> <spanclass="comment">// found in the LICENSE file.</span></div>
<divclass="line"><aname="l00005"></a><spanclass="lineno"> 5</span> <spanclass="comment">// This file contains an implementation of an H264 Annex-B video stream parser.</span></div>
<divclass="line"><aname="l00018"></a><spanclass="lineno"> 18</span> <spanclass="comment">// A class to provide bit-granularity reading of H.264/H.265 streams.</span></div>
<divclass="line"><aname="l00019"></a><spanclass="lineno"> 19</span> <spanclass="comment">// This is not a generic bit reader class, as it takes into account</span></div>
<divclass="line"><aname="l00020"></a><spanclass="lineno"> 20</span> <spanclass="comment">// H.264 stream-specific constraints, such as skipping emulation-prevention</span></div>
<divclass="line"><aname="l00021"></a><spanclass="lineno"> 21</span> <spanclass="comment">// bytes and stop bits. See spec for more details.</span></div>
<divclass="line"><aname="l00027"></a><spanclass="lineno"> 27</span> <spanclass="comment">// Initialize the reader to start reading at |data|, |size| being size</span></div>
<divclass="line"><aname="l00028"></a><spanclass="lineno"> 28</span> <spanclass="comment">// of |data| in bytes.</span></div>
<divclass="line"><aname="l00029"></a><spanclass="lineno"> 29</span> <spanclass="comment">// Return false on insufficient size of stream..</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"> 32</span> <spanclass="comment">// Read |num_bits| next bits from stream and return in |*out|, first bit</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"> 33</span> <spanclass="comment">// from the stream starting at |num_bits| position in |*out|.</span></div>
<divclass="line"><aname="l00034"></a><spanclass="lineno"> 34</span> <spanclass="comment">// |num_bits| may be 1-32, inclusive.</span></div>
<divclass="line"><aname="l00035"></a><spanclass="lineno"> 35</span> <spanclass="comment">// Return false if the given number of bits cannot be read (not enough</span></div>
<divclass="line"><aname="l00036"></a><spanclass="lineno"> 36</span> <spanclass="comment">// bits in the stream), true otherwise.</span></div>
<divclass="line"><aname="l00039"></a><spanclass="lineno"> 39</span> <spanclass="comment">// Read a single bit and return in |*out|.</span></div>
<divclass="line"><aname="l00040"></a><spanclass="lineno"> 40</span> <spanclass="comment">// Return false if the bit cannot be read (not enough bits in the stream),</span></div>
<divclass="line"><aname="l00050"></a><spanclass="lineno"> 50</span> <spanclass="comment">// Skips the given number of bits (does not have to be less than 32 bits).</span></div>
<divclass="line"><aname="l00051"></a><spanclass="lineno"> 51</span> <spanclass="comment">// Return false if there aren't enough bits in the stream, true otherwise.</span></div>
<divclass="line"><aname="l00054"></a><spanclass="lineno"> 54</span> <spanclass="comment">// Exp-Golomb code parsing as specified in chapter 9.1 of the spec.</span></div>
<divclass="line"><aname="l00055"></a><spanclass="lineno"> 55</span> <spanclass="comment">// Read one unsigned exp-Golomb code from the stream and return in |*val|.</span></div>
<divclass="line"><aname="l00058"></a><spanclass="lineno"> 58</span> <spanclass="comment">// Read one signed exp-Golomb code from the stream and return in |*val|.</span></div>
<divclass="line"><aname="l00061"></a><spanclass="lineno"> 61</span> <spanclass="comment">// Return the number of bits left in the stream.</span></div>
<divclass="line"><aname="l00064"></a><spanclass="lineno"> 64</span> <spanclass="comment">// See the definition of more_rbsp_data() in spec.</span></div>
<divclass="line"><aname="l00067"></a><spanclass="lineno"> 67</span> <spanclass="comment">// Return the number of emulation prevention bytes already read.</span></div>
<divclass="line"><aname="l00071"></a><spanclass="lineno"> 71</span> <spanclass="comment">// Advance to the next byte, loading it into curr_byte_.</span></div>
<divclass="line"><aname="l00072"></a><spanclass="lineno"> 72</span> <spanclass="comment">// Return false on end of stream.</span></div>
<divclass="line"><aname="l00075"></a><spanclass="lineno"> 75</span> <spanclass="comment">// Pointer to the next unread (not in curr_byte_) byte in the stream.</span></div>
<divclass="line"><aname="l00078"></a><spanclass="lineno"> 78</span> <spanclass="comment">// Bytes left in the stream (without the curr_byte_).</span></div>
<divclass="line"><aname="l00081"></a><spanclass="lineno"> 81</span> <spanclass="comment">// Contents of the current byte; first unread bit starting at position</span></div>
<divclass="line"><aname="l00082"></a><spanclass="lineno"> 82</span> <spanclass="comment">// 8 - num_remaining_bits_in_curr_byte_ from MSB.</span></div>
<divclass="line"><aname="l00088"></a><spanclass="lineno"> 88</span> <spanclass="comment">// Used in emulation prevention three byte detection (see spec).</span></div>
<divclass="line"><aname="l00089"></a><spanclass="lineno"> 89</span> <spanclass="comment">// Initially set to 0xffff to accept all initial two-byte sequences.</span></div>
<divclass="line"><aname="l00092"></a><spanclass="lineno"> 92</span> <spanclass="comment">// Number of emulation preventation bytes (0x000003) we met.</span></div>