1 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2007.
21 * All Rights Reserved.
23 * Contributor(s): Andrea Gabriellini (Original Author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
27 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
28 * the GPL or the LGPL are applicable instead of those above. If you wish to
29 * allow use of your version of this file only under the terms of the either
30 * the GPL or LGPL and not to allow others to use your version of this file
31 * under the MPL, indicate your decision by deleting the provisions above
32 * and replace them with the notice and other provisions required by the GPL
33 * or LGPL. If you do not delete the provisions above, a recipient may use
34 * your version of this file under the terms of any one of the MPL, the GPL
36 * ***** END LICENSE BLOCK ***** */
42 #include <parser/parse_info.hpp>
44 #include <common/util.hpp>
48 namespace parser_project
50 ParseInfo::ParseInfoPrefix::value_type const
51 ParseInfo::ParseInfoPrefix::prefix_[] = { 0x42, 0x42, 0x43, 0x44 };
52 ParseInfo::ParseInfoPrefix ParseInfo::prefix_;
56 , PI_PREFIX_LENGTH = 4
59 , CHECK_SEQUENCE_HEADER = 0xFF
60 , SEQUENCE_HEADER_VALUE = 0x00
62 , CHECK_END_OF_SEQUENCE = 0xFF
63 , END_OF_SEQUENCE_VALUE = 0x10
65 , CHECK_AUXILIARY_DATA = 0xF8
66 , AUXILIARY_DATA_VALUE = 0x20
68 , CHECK_PADDING_DATA = 0xFF // I think, rather than F8, is appr. here
69 , PADDING_DATA_VALUE = 0x30
71 , CHECK_PICTURE = 0x08
72 , PICTURE_VALUE = 0x08
74 , CHECK_CORE_SYNTAX = 0x88
75 , CORE_SYNTAX_VALUE = 0x08
77 , CHECK_LOW_DELAY_SYNTAX = 0x88
78 , LOW_DELAY_SYNTAX_VALUE = 0x88
80 , CHECK_USING_AC = 0x48
81 , USING_AC_VALUE = 0x08
83 , CHECK_IS_REFERENCE = 0x0C
84 , IS_REFERENCE_VALUE = 0x0C
86 , CHECK_IS_NON_REFERENCE = 0x0C
87 , IS_NON_REFERENCE_VALUE = 0x08
89 , NUMBER_OF_REFERENCES = 0x03
92 , PC_OFFSET = 4 // parse code offset
93 , NPO_OFFSET = 5 // next parse offset's offset
94 , PPO_OFFSET = 9 // previous parse offset's offset
95 , RPPO_OFFSET = 5 // previous parse offset's offset
96 // from the reverse cursor's base
103 } /* parser_project */
108 namespace parser = ::dirac::parser_project;
109 using namespace parser;
111 /* ParseInfo::ParseInfoPrefix */
113 ParseInfo::ParseInfoPrefix::const_iterator
114 ParseInfo::ParseInfoPrefix::begin()
119 ParseInfo::ParseInfoPrefix::const_iterator
120 ParseInfo::ParseInfoPrefix::end()
122 return prefix_ + DIRAC_ARRAY_SIZE ( prefix_ );
125 ParseInfo::ParseInfoPrefix::size_type
126 ParseInfo::ParseInfoPrefix::size()
128 return PI_PREFIX_LENGTH;
131 ParseInfo::ParseInfoPrefix::const_reverse_iterator
132 ParseInfo::ParseInfoPrefix::rbegin()
134 return std::reverse_iterator<const_iterator> ( end() );
137 ParseInfo::ParseInfoPrefix::const_reverse_iterator
138 ParseInfo::ParseInfoPrefix::rend()
140 return std::reverse_iterator<const_iterator> ( begin() );
144 ParseInfo::ParseInfoPrefix::isParseInfo ( const_iterator cursor, size_type size )
146 DIRAC_MESSAGE_ASSERT ( "cursor cannot be null", 0 != cursor );
147 return ( !( PI_HEADER_LENGTH > size )
148 && prefix_[0] == cursor[0] && prefix_[1] == cursor[1]
149 && prefix_[2] == cursor[2] && prefix_[3] == cursor[3] );
152 ParseInfo::const_iterator
153 ParseInfo::prefixBegin()
155 return prefix_.begin();
158 ParseInfo::const_iterator
159 ParseInfo::prefixEnd()
161 return prefix_.end();
164 ParseInfo::const_reverse_iterator
165 ParseInfo::prefixRbegin()
167 return prefix_.rbegin();
170 ParseInfo::const_reverse_iterator
171 ParseInfo::prefixRend()
173 return prefix_.rend();
177 ParseInfo::prefixSize()
179 return prefix_.size();
185 ParseInfo::ParseInfo ( const_iterator cursor )
191 ParseInfo::~ParseInfo()
197 ParseInfo::checkValidity() const
199 DIRAC_MESSAGE_ASSERT ( "parse info header cannot be null", 0 != cursor_ );
202 ParseInfo::value_type
203 ParseInfo::getParseCode() const
205 return cursor_[PC_OFFSET];
209 ParseInfo::isParseInfo ( const_iterator buffer, size_type size )
211 DIRAC_MESSAGE_ASSERT ( "buffer cannot be null", 0 != buffer );
212 return prefix_.isParseInfo ( buffer, size );
216 ParseInfo::isSequenceHeader() const
219 return SEQUENCE_HEADER_VALUE == ( CHECK_SEQUENCE_HEADER & getParseCode() );
223 ParseInfo::isEndOfSequence() const
226 return END_OF_SEQUENCE_VALUE == ( CHECK_END_OF_SEQUENCE & getParseCode() );
230 ParseInfo::isAuxiliaryData() const
233 return AUXILIARY_DATA_VALUE == ( CHECK_AUXILIARY_DATA & getParseCode() );
237 ParseInfo::isPaddingData() const
240 return PADDING_DATA_VALUE == ( CHECK_PADDING_DATA & getParseCode() );
244 ParseInfo::isPicture() const
247 return PICTURE_VALUE == ( CHECK_PICTURE & getParseCode() );
251 ParseInfo::isCoreSyntax() const
254 return CORE_SYNTAX_VALUE == ( CHECK_CORE_SYNTAX & getParseCode() );
258 ParseInfo::isLowDelaySyntax() const
261 return LOW_DELAY_SYNTAX_VALUE == ( CHECK_LOW_DELAY_SYNTAX & getParseCode() );
265 ParseInfo::isUsingArithmeticCoding() const
268 return USING_AC_VALUE == ( CHECK_USING_AC & getParseCode() );
272 ParseInfo::isReference() const
275 return IS_REFERENCE_VALUE == ( CHECK_IS_REFERENCE & getParseCode() );
279 ParseInfo::isNotReference() const
282 return IS_NON_REFERENCE_VALUE == ( CHECK_IS_NON_REFERENCE & getParseCode() );
285 ParseInfo::value_type
286 ParseInfo::getNumberOfReferences() const
289 return NUMBER_OF_REFERENCES & getParseCode();
293 ParseInfo::isIntra() const
296 return isPicture() && 0 == getNumberOfReferences();
300 ParseInfo::isInter() const
303 return isPicture() && getNumberOfReferences();
307 ParseInfo::hasPayload() const
310 return END_OF_SEQUENCE_VALUE != getParseCode();
313 ParseInfo::const_iterator
314 ParseInfo::payload() const
317 return cursor_ + PI_HEADER_LENGTH;
320 ParseInfo::const_iterator
321 ParseInfo::next() const
325 return cursor_ + readFourBytes ( cursor_ + NPO_OFFSET );
328 ParseInfo::const_iterator
329 ParseInfo::previous() const
333 return cursor_ - readFourBytes ( cursor_ + PPO_OFFSET );
337 ParseInfo::size() const
340 size_type next = readFourBytes ( cursor_ + NPO_OFFSET );
341 return 0 == next ? PI_HEADER_LENGTH : next;