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 ***** */
38 #ifndef _ACCESSUNIT_HPP_
39 #define _ACCESSUNIT_HPP_
45 #include <common/dirac.h>
46 #include <common/util.hpp>
48 #include <parser/parser.h>
56 namespace parser_project
58 struct AccessUnitException : public std::runtime_error
60 AccessUnitException ( std::string const& msg )
61 : std::runtime_error ( msg ) {}
66 friend class ValidityChecker<AccessUnit>;
68 public: // type definitions
69 typedef AccessUnit class_type;
70 typedef std::vector<uint8> Buffer;
71 typedef Buffer::value_type value_type;
72 typedef Buffer::pointer pointer;
73 typedef Buffer::const_pointer const_pointer;
74 typedef Buffer::size_type size_type;
76 public: // constructors
77 AccessUnit() : buffer_() {}
78 AccessUnit ( const_pointer begin, size_type size )
83 ~AccessUnit() { checkValidity(); }
84 private: // compiler generated methods are not allowed
85 AccessUnit ( AccessUnit const& );
86 AccessUnit& operator= ( AccessUnit const& );
88 public: // main interface
89 void setp ( const_pointer begin, size_type size )
91 ValidityChecker<class_type> checker ( *this );
93 if ( !dirac_parser_is_access_unit ( begin, size ) )
94 throw AccessUnitException ( "this is not an access unit" );
95 Buffer tmp ( begin, begin + size );
99 //! release internal buffer - it doesn't check whether the buffer is empty
100 Buffer* releaseBuffer()
102 ValidityChecker<class_type> checker ( *this );
104 Buffer* buf = new Buffer;
105 std::swap ( buffer_, *buf );
109 const_pointer begin() const
110 { checkValidity(); return empty() ? 0 : &( *buffer_.begin() ); }
112 { checkValidity(); return empty() ? 0 : &( *buffer_.begin() ); }
113 const_pointer end() const
114 { checkValidity(); return empty() ? 0 : &(*buffer_.begin() ) + size(); }
115 size_type size() const
116 { checkValidity(); return buffer_.size(); }
118 { checkValidity(); return buffer_.empty(); }
120 bool isSequenceHeader() const
123 return dirac_parser_is_sequence_header ( begin(), size() );
125 bool isPicture() const
128 return dirac_parser_is_picture ( begin(), size() );
130 bool isIPicture() const
133 return dirac_parser_is_i_picture ( begin(), size() );
135 bool isAuxiliaryData() const
138 return dirac_parser_is_auxiliary_data ( begin(), size() );
140 bool isPaddingData() const
143 return dirac_parser_is_padding_data ( begin(), size() );
145 bool isEndOfSequence() const
148 return dirac_parser_is_end_of_sequence ( begin(), size() );
150 bool isLastEndOfSequence() const
153 return dirac_parser_is_last_end_of_sequence ( begin(), size() );
156 private: // helper methods
157 void checkValidity() const
159 DIRAC_MESSAGE_ASSERT ( "buffer empty or must hold access unit"
161 || dirac_parser_is_access_unit ( &buffer_[0], buffer_.size() ) );
166 } /* parser_project */
171 #endif /* _ACCESSUNIT_HPP_ */