<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="l00004"></a><spanclass="lineno"> 4</span> </div><divclass="line"><aname="l00005"></a><spanclass="lineno"> 5</span> <spanclass="preprocessor">#include "packager/media/formats/mp2t/ts_packet.h"</span></div><divclass="line"><aname="l00006"></a><spanclass="lineno"> 6</span> </div><divclass="line"><aname="l00007"></a><spanclass="lineno"> 7</span> <spanclass="preprocessor">#include <memory></span></div><divclass="line"><aname="l00008"></a><spanclass="lineno"> 8</span> <spanclass="preprocessor">#include "packager/media/base/bit_reader.h"</span></div><divclass="line"><aname="l00009"></a><spanclass="lineno"> 9</span> <spanclass="preprocessor">#include "packager/media/formats/mp2t/mp2t_common.h"</span></div><divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> </div><divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span> <spanclass="keyword">namespace </span><aclass="code"href="../../d8/daf/namespaceshaka.html">shaka</a> {</div><divclass="line"><aname="l00012"></a><spanclass="lineno"> 12</span> <spanclass="keyword">namespace </span>media {</div><divclass="line"><aname="l00013"></a><spanclass="lineno"> 13</span> <spanclass="keyword">namespace </span>mp2t {</div><divclass="line"><aname="l00014"></a><spanclass="lineno"> 14</span> </div><divclass="line"><aname="l00015"></a><spanclass="lineno"> 15</span> <spanclass="keyword">static</span><spanclass="keyword">const</span> uint8_t kTsHeaderSyncword = 0x47;</div><divclass="line"><aname="l00016"></a><spanclass="lineno"> 16</span> </div><divclass="line"><aname="l00017"></a><spanclass="lineno"> 17</span> <spanclass="comment">// static</span></div><divclass="line"><aname="l00018"></a><spanclass="lineno"> 18</span> <spanclass="keywordtype">int</span> TsPacket::Sync(<spanclass="keyword">const</span> uint8_t* buf, <spanclass="keywordtype">int</span> size) {</div><divclass="line"><aname="l00019"></a><spanclass="lineno"> 19</span> <spanclass="keywordtype">int</span> k = 0;</div><divclass="line"><aname="l00020"></a><spanclass="lineno"> 20</span> <spanclass="keywordflow">for</span> (; k < size; k++) {</div><divclass="line"><aname="l00021"></a><spanclass="lineno"> 21</span> <spanclass="comment">// Verify that we have 4 syncwords in a row when possible,</span></div><divclass="line"><aname="l00022"></a><spanclass="lineno"> 22</span> <spanclass="comment">// this should improve synchronization robustness.</span></div><divclass="line"><aname="l00023"></a><spanclass="lineno"> 23</span> <spanclass="keywordtype">bool</span> is_header = <spanclass="keyword">true</span>;</div><divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i < 4; i++) {</div><divclass="line"><aname="l00025"></a><spanclass="lineno"> 25</span> <spanclass="keywordtype">int</span> idx = k + i * kPacketSize;</div><divclass="line"><aname="l00026"></a><spanclass="lineno"> 26</span> <spanclass="keywordflow">if</span> (idx >= size)</div><divclass="line"><aname="l00027"></a><spanclass="lineno"> 27</span> <spanclass="keywordflow">break</span>;</div><divclass="line"><aname="l00028"></a><spanclass="lineno"> 28</span> <spanclas