2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "VC1BitstreamParser.h"
11 #include "BitstreamReader.h"
24 VC1_END_OF_SEQ
= 0x0A,
28 VC1_ENTRYPOINT
= 0x0E,
30 VC1_SLICE_USER
= 0x1B,
31 VC1_FIELD_USER
= 0x1C,
32 VC1_FRAME_USER
= 0x1D,
33 VC1_ENTRY_POINT_USER
= 0x1E,
34 VC1_SEQUENCE_USER
= 0x1F
39 VC1_FRAME_PROGRESSIVE
= 0x0,
40 VC1_FRAME_INTERLACE
= 0x10,
41 VC1_FIELD_INTERLACE
= 0x11
44 CVC1BitstreamParser::CVC1BitstreamParser()
49 void CVC1BitstreamParser::Reset()
51 m_Profile
= VC1_PROFILE_NOPROFILE
;
54 bool CVC1BitstreamParser::IsRecoveryPoint(const uint8_t *buf
, int buf_size
)
56 return vc1_parse_frame(buf
, buf
+ buf_size
, true);
59 bool CVC1BitstreamParser::IsIFrame(const uint8_t *buf
, int buf_size
)
61 return vc1_parse_frame(buf
, buf
+ buf_size
, false);
64 bool CVC1BitstreamParser::vc1_parse_frame(const uint8_t *buf
, const uint8_t *buf_end
, bool sequence_only
)
69 buf
= find_start_code(buf
, buf_end
, &state
);
72 if (buf
[-1] == VC1_SEQUENCE
)
74 if (m_Profile
!= VC1_PROFILE_NOPROFILE
)
76 CBitstreamReader
br(buf
, buf_end
- buf
);
78 m_Profile
= static_cast<uint8_t>(br
.ReadBits(2));
79 if (m_Profile
== VC1_PROFILE_ADVANCED
)
82 m_AdvInterlace
= br
.ReadBits(1);
89 if (br
.ReadBits(1)) //rangered
92 m_MaxBFrames
= br
.ReadBits(3);
94 br
.SkipBits(2); // quantizer
95 if (br
.ReadBits(1)) //finterpflag
101 else if (buf
[-1] == VC1_FRAME
)
103 CBitstreamReader
br(buf
, buf_end
- buf
);
107 if (m_Profile
== VC1_PROFILE_ADVANCED
)
110 if (m_AdvInterlace
) {
111 fcm
= br
.ReadBits(1);
113 fcm
= br
.ReadBits(1) + 1;
116 fcm
= VC1_FRAME_PROGRESSIVE
;
117 if (fcm
== VC1_FIELD_INTERLACE
) {
118 uint8_t pic
= br
.ReadBits(3);
119 return pic
== 0x00 || pic
== 0x01;
124 while (pic
< 4 && br
.ReadBits(1))++pic
;
129 else if (m_Profile
!= VC1_PROFILE_NOPROFILE
)
131 br
.SkipBits(m_SimpleSkipBits
); // quantizer
132 uint8_t pic(br
.ReadBits(1));
135 pic
= br
.ReadBits(1);