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 and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Anuradha Suraparaju (Original Author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
28 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
29 * the GPL or the LGPL are applicable instead of those above. If you wish to
30 * allow use of your version of this file only under the terms of the either
31 * the GPL or LGPL and not to allow others to use your version of this file
32 * under the MPL, indicate your decision by deleting the provisions above
33 * and replace them with the notice and other provisions required by the GPL
34 * or LGPL. If you do not delete the provisions above, a recipient may use
35 * your version of this file under the terms of any one of the MPL, the GPL
37 * ***** END LICENSE BLOCK ***** */
41 #ifndef DIRAC_CPPPARSER_H
42 #define DIRAC_CPPPARSER_H
46 #include <libdirac_decoder/decoder_types.h> //for DecoderState
47 #include <libdirac_common/common.h>
48 #include <libdirac_byteio/dirac_byte_stream.h>
52 class SequenceDecompressor
;
55 //! Input Stream Buffer Class.
56 class InputStreamBuffer
: public std::streambuf
65 //! Rewind buffer to start of data
66 std::ios::pos_type
Rewind();
68 //! Seek to position specified by bytes offset from pos
71 \param bytes offset in bytes
72 \param pos the position from which the offset is applied
74 std::ios::pos_type
Seek(std::ios::pos_type bytes
,
75 std::ios::seekdir pos
= std::ios::cur
);
77 //! Return the current read position in the buffer
78 std::ios::pos_type
Tell();
80 //! Copy data into buffer
83 \param start memory area start
84 \param bytes number of bytes to copy starting from start
86 void Copy(char *start
, int bytes
);
88 //! Delete all processed data from buffer
89 void PurgeProcessedData();
93 //! Private body-less copy constructor
94 InputStreamBuffer (const InputStreamBuffer
& inbuf
);
96 //! Private body-less assignment operator
97 InputStreamBuffer
& operator = (const InputStreamBuffer
& inbuf
);
100 static const int m_buffer_size
= 1232896;
103 char *m_chunk_buffer
;
106 //! Dirac Stream Parser Class
108 This class is a wrapper around the SequenceDecompressor class. The
109 Sequence Decompressor class needs a full picture of data to be available
110 to decompress a picture successfully. So, the DiracParser class uses
111 the InputStreamBuffer class to store data until a chunk is available
112 to be processed and then invokes the SequenceDecompressor functions to
113 process data. A chunk of data can be a start of sequence, a picture or
114 end of sequence data. The istream used to instantiate the
115 SequenceDecompressor object is created using an InputStreamBuffer
116 object which is manipulated the DiracParser. This ensures that data is
117 always available for processing by the SequenceDecompressor object.
125 \param verbose boolean flag. Set to true for verbose output
127 DiracParser(bool verbose
= false );
132 //! Adds bytes to encoder
134 \param start Start of input buffer
135 \param end End of input buffer
137 void SetBuffer (char *start
, char *end
);
139 //! Parse the data in internal buffer
141 Parses the data in the input buffer. This function returns one
142 of the following values
143 \n STATE_BUFFER : Not enough data in internal buffer to process
144 \n STATE_SEQUENCE : Start of sequence detected
145 \n STATE_PICTURE_AVAIL : Decoded picture available
146 \n STATE_SEQUENCE_END : End of sequence detected
147 \n STATE_INVALID : Invalid stream. Stop further processing
149 DecoderState
Parse();
151 //! Return the parse parameters of the current sequence
152 const ParseParams
& GetParseParams() const;
154 //! Return the source parameters of the current sequence
155 const SourceParams
& GetSourceParams() const;
157 //! Return the picture parameters of the next picture to be decoded
158 const PictureParams
* GetNextPictureParams() const;
160 //! Return the decoded picture
161 const Picture
* GetNextPicture() const;
163 //! Return the coding parameters of the current sequence
164 const DecoderParams
& GetDecoderParams() const;
170 //! private body-less copy constructor
171 DiracParser (const DiracParser
&dp
);
172 //! private body-less assignement constructor
173 DiracParser
& operator = (const DiracParser
&dp
);
174 //! Current state of parser
175 DecoderState m_state
;
176 //! Next state the parser will enter
177 DecoderState m_next_state
;
178 //! picture number of last picture decoded in display order
180 //! Sequence decompressor object
181 SequenceDecompressor
*m_decomp
;
184 //! Byte Stream Buffer
185 DiracByteStream m_dirac_byte_stream
;