2 * (C) 2006-2012 see Authors.txt
4 * This file is part of MPC-HC.
6 * MPC-HC is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * MPC-HC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 void CH264Nalu::SetBuffer(BYTE
* pBuffer
, int nSize
, int nNALSize
)
28 m_nNALSize
= nNALSize
;
35 if (!nNALSize
&& nSize
) {
36 MoveToNextAnnexBStartcode();
40 bool CH264Nalu::MoveToNextAnnexBStartcode()
42 int nBuffEnd
= m_nSize
- 4;
44 for (int i
= m_nCurPos
; i
< nBuffEnd
; i
++) {
45 if ((*((DWORD
*)(m_pBuffer
+ i
)) & 0x00FFFFFF) == 0x00010000) {
46 // Find next AnnexB Nal
56 bool CH264Nalu::MoveToNextRTPStartcode()
58 if (m_nNextRTP
< m_nSize
) {
59 m_nCurPos
= m_nNextRTP
;
67 bool CH264Nalu::ReadNext()
69 if ((m_nCurPos
>= m_nSize
) || (m_nCurPos
< 0)) {
73 if ((m_nNALSize
!= 0) && (m_nCurPos
== m_nNextRTP
)) {
74 // RTP Nalu type : (XX XX) XX XX NAL..., with XX XX XX XX or XX XX equal to NAL size
75 m_nNALStartPos
= m_nCurPos
;
76 m_nNALDataPos
= m_nCurPos
+ m_nNALSize
;
78 for (int i
= 0; i
< m_nNALSize
; i
++) {
79 nTemp
= (nTemp
<< 8) + m_pBuffer
[m_nCurPos
++];
81 m_nNextRTP
+= nTemp
+ m_nNALSize
;
82 MoveToNextRTPStartcode();
84 // Remove trailing bits
85 while (m_pBuffer
[m_nCurPos
] == 0x00 && ((*((DWORD
*)(m_pBuffer
+ m_nCurPos
)) & 0x00FFFFFF) != 0x00010000)) {
89 // AnnexB Nalu : 00 00 01 NAL...
90 m_nNALStartPos
= m_nCurPos
;
92 m_nNALDataPos
= m_nCurPos
;
93 MoveToNextAnnexBStartcode();
96 forbidden_bit
= (m_pBuffer
[m_nNALDataPos
] >> 7) & 1;
97 nal_reference_idc
= (m_pBuffer
[m_nNALDataPos
] >> 5) & 3;
98 nal_unit_type
= (NALU_TYPE
)(m_pBuffer
[m_nNALDataPos
] & 0x1f);