# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

seq_compress.h
Go to the documentation of this file.
1/* ***** BEGIN LICENSE BLOCK *****
2*
3* $Id: seq_compress.h,v 1.33 2008/10/20 04:20:12 asuraparaju Exp $ $Name: Dirac_1_0_2 $
4*
5* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6*
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/
11*
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.
15*
16* The Original Code is BBC Research and Development code.
17*
18* The Initial Developer of the Original Code is the British Broadcasting
19* Corporation.
20* Portions created by the Initial Developer are Copyright (C) 2004.
21* All Rights Reserved.
22*
23* Contributor(s): Thomas Davies (Original Author),
24* Scott R Ladd,
25* Anuradha Suraparaju
26* Andrew Kennedy
27*
28* Alternatively, the contents of this file may be used under the terms of
29* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
30* Public License Version 2.1 (the "LGPL"), in which case the provisions of
31* the GPL or the LGPL are applicable instead of those above. If you wish to
32* allow use of your version of this file only under the terms of the either
33* the GPL or LGPL and not to allow others to use your version of this file
34* under the MPL, indicate your decision by deleting the provisions above
35* and replace them with the notice and other provisions required by the GPL
36* or LGPL. If you do not delete the provisions above, a recipient may use
37* your version of this file under the terms of any one of the MPL, the GPL
38* or the LGPL.
39* ***** END LICENSE BLOCK ***** */
40
41#ifndef _SEQ_COMPRESS_H_
42#define _SEQ_COMPRESS_H_
43
45//-------------------------------------//
46//Class to manage compressing sequences//
47//-------------------------------------//
49
50#include <libdirac_byteio/dirac_byte_stream.h>
51#include <libdirac_common/common.h>
52#include <libdirac_encoder/enc_queue.h>
53#include <libdirac_common/pic_io.h>
54#include <libdirac_common/dirac_assertions.h>
55#include <libdirac_encoder/quality_monitor.h>
56#include <libdirac_encoder/picture_compress.h>
57#include <libdirac_encoder/rate_control.h>
58
59#include <fstream>
60
61 namespace dirac
62{
63
65
73 class SequenceCompressor{
74 public:
76
84 SequenceCompressor(StreamPicInput* pin,
85 EncoderParams& encp,
86 DiracByteStream& dirac_byte_stream);
87
89
92 virtual ~SequenceCompressor();
93
95
103 virtual bool LoadNextFrame() = 0;
104
106
125 const EncPicture *CompressNextPicture();
126
128 virtual void SetPicTypeAndRefs( PictureParams& pparams ) = 0;
129
131 const EncPicture *GetPictureEncoded();
132
133 DiracByteStats EndSequence();
134
136
141 bool Finished(){return m_all_done;}
142
144 void SignalEOS() { m_eos_signalled = true; }
145
147 int PTSOffset(){return m_delay;}
148
149 protected:
150
152 void SetMotionParameters();
153
155
161 virtual int CodedToDisplay(const int pnum) = 0;
162
164 void MakeSequenceReport();
165
167 virtual void CleanBuffers();
168
170 //Purely virtual. The child class will have to define it.
171 virtual void UpdateCBRModel(EncPicture& my_picture, const PictureByteIO* picture_byteio) = 0;
172
174 void UpdateIntraPicCBRModel( const PictureParams& , const bool is_a_cut );
175
177 bool CanEncode();
178
180 bool m_all_done;
181
183
188 bool m_just_finished;
189
191 OLBParams* m_basic_olb_params0;
192
194 OLBParams* m_basic_olb_params1;
195
197 const OLBParams* m_basic_olb_params2;
198
200 OLBParams* m_intra_olbp;
201
203 SourceParams& m_srcparams;
204
206 EncoderParams& m_encparams;
207
209 PicturePredParams& m_predparams;
210
212 int m_L1_sep;
213
215 PictureParams m_pparams;
216
218 StreamPicInput* m_pic_in;
219
221 EncQueue m_enc_pbuffer;
222
223 //state variables for CompressNextPicture
224
226 int m_current_display_pnum;
227
229 int m_current_code_pnum;
230
232 int m_show_pnum;
233
235 int m_last_picture_read;
236
238 int m_gop_start_num;
239
241 int m_delay;
242
244 QualityMonitor m_qmonitor;
245
247 RateController* m_ratecontrol;
248
250 PictureCompressor m_pcoder;
251
253 DiracByteStream& m_dirac_byte_stream;
254
256 bool m_eos_signalled;
257
258 private:
260
264 SequenceCompressor(const SequenceCompressor& cpy);
265
267
271 SequenceCompressor& operator=(const SequenceCompressor& rhs);
272
273
274 };
275
277
283 class FrameSequenceCompressor : public SequenceCompressor
284 {
285 public:
287
296 FrameSequenceCompressor(StreamPicInput* pin,
297 EncoderParams& encp,
298 DiracByteStream& dirac_byte_stream);
299
301
304 virtual ~FrameSequenceCompressor(){};
305
307
313 virtual bool LoadNextFrame();
314
316 virtual void SetPicTypeAndRefs( PictureParams& pparams );
317
318 protected:
319 virtual int CodedToDisplay(const int pnum);
320 virtual void UpdateCBRModel(EncPicture& my_picture, const PictureByteIO* picture_byteio);
321
322 };
323
325
331 class FieldSequenceCompressor : public SequenceCompressor
332 {
333 public:
335
343 FieldSequenceCompressor(StreamPicInput* pin,
344 EncoderParams& encp,
345 DiracByteStream& dirac_byte_stream);
346
348
351 virtual ~FieldSequenceCompressor();
352
354
361 virtual bool LoadNextFrame();
362
363
365 virtual void SetPicTypeAndRefs( PictureParams& pparams );
366
367 protected:
368
369 virtual int CodedToDisplay(const int pnum);
370
371 virtual void UpdateCBRModel(EncPicture& my_picture, const PictureByteIO* picture_byteio);
372 private:
374
378 void PreMotionEstmationFilter (PicArray& comp);
379
380 // Field1 bytes
381 int m_field1_bytes;
382 // Field2 bytes
383 int m_field2_bytes;
384 };
385} // namespace dirac
386
387#endif
dirac_byte_stream.h
dirac_assertions.h
common.h
pic_io.h
rate_control.h
quality_monitor.h
picture_compress.h
enc_queue.h
dirac
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:52
dirac::DiracByteStats
Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream.
Definition: dirac_byte_stats.h:71
dirac::DiracByteStream
Represents a series of bytes in the Dirac bytestream specfication format.
Definition: dirac_byte_stream.h:61
dirac::PictureByteIO
A compressed picture in Dirac bytestream format.
Definition: picture_byteio.h:61
dirac::SourceParams
Parameters relating to the source material being encoded/decoded.
Definition: common.h:289
dirac::PictureParams
Parameters for initialising picture class objects.
Definition: common.h:533
dirac::PicArray
A class for picture component data.
Definition: common.h:719
dirac::OLBParams
Parameters for overlapped block motion compensation.
Definition: common.h:818
dirac::PicturePredParams
Structure to hold motion parameters when motion comp is used.
Definition: common.h:968
dirac::EncoderParams
Parameters for the encoding process.
Definition: common.h:1280
dirac::StreamPicInput
Picture input class.
Definition: pic_io.h:303
dirac::EncPicture
Definition: enc_picture.h:65
dirac::EncQueue
Holds pictures both for reference and to overcome reordering delay.
Definition: enc_queue.h:59
dirac::PictureCompressor
Compress a single image picture.
Definition: picture_compress.h:62
dirac::QualityMonitor
Class to monitor the quality of pictures and adjust coding parameters appropriately.
Definition: quality_monitor.h:49
dirac::RateController
A clas for allocation the bits to each and every types of frames in a GOP.
Definition: rate_control.h:92
dirac::SequenceCompressor
Compresses a sequence of frames/fields from a stream.
Definition: seq_compress.h:73
dirac::SequenceCompressor::EndSequence
DiracByteStats EndSequence()
dirac::SequenceCompressor::m_delay
int m_delay
A delay so that we don't display what we haven't coded.
Definition: seq_compress.h:241
dirac::SequenceCompressor::m_predparams
PicturePredParams & m_predparams
The parameters used for ME/MC.
Definition: seq_compress.h:209
dirac::SequenceCompressor::GetPictureEncoded
const EncPicture * GetPictureEncoded()
Return a pointer to the most recent picture encoded.
dirac::SequenceCompressor::m_encparams
EncoderParams & m_encparams
The parameters used for encoding.
Definition: seq_compress.h:206
dirac::SequenceCompressor::CanEncode
bool CanEncode()
Returns true if the encoder can encode a picture.
dirac::SequenceCompressor::SetMotionParameters
void SetMotionParameters()
Set up the motion block parameters.
dirac::SequenceCompressor::LoadNextFrame
virtual bool LoadNextFrame()=0
Load data.
dirac::SequenceCompressor::MakeSequenceReport
void MakeSequenceReport()
Make a report to screen on the coding results for the whole sequence.
dirac::SequenceCompressor::m_pcoder
PictureCompressor m_pcoder
A class to hold the picture compressor object.
Definition: seq_compress.h:250
dirac::SequenceCompressor::operator=
SequenceCompressor & operator=(const SequenceCompressor &rhs)
Assignment = is private and body-less.
dirac::SequenceCompressor::m_basic_olb_params0
OLBParams * m_basic_olb_params0
A class to hold the basic block parameters.
Definition: seq_compress.h:191
dirac::SequenceCompressor::m_qmonitor
QualityMonitor m_qmonitor
A class for monitoring the quality of pictures and adjusting parameters appropriately.
Definition: seq_compress.h:244
dirac::SequenceCompressor::m_intra_olbp
OLBParams * m_intra_olbp
A class to hold block parameters to use when there are lots of intra blocks.
Definition: seq_compress.h:200
dirac::SequenceCompressor::Finished
bool Finished()
Determine if compression is complete.
Definition: seq_compress.h:141
dirac::SequenceCompressor::SignalEOS
void SignalEOS()
Signal end of sequence.
Definition: seq_compress.h:144
dirac::SequenceCompressor::m_pparams
PictureParams m_pparams
Generic picture parameters for initialising pictures.
Definition: seq_compress.h:215
dirac::SequenceCompressor::CleanBuffers
virtual void CleanBuffers()
Remove unwanted pictures from picture buffers.
dirac::SequenceCompressor::CompressNextPicture
const EncPicture * CompressNextPicture()
Compress the next picture in sequence.
dirac::SequenceCompressor::m_eos_signalled
bool m_eos_signalled
Flag to check if End of Sequence has been signalled by the end user.
Definition: seq_compress.h:256
dirac::SequenceCompressor::m_L1_sep
int m_L1_sep
The L1 separation currently in use.
Definition: seq_compress.h:212
dirac::SequenceCompressor::UpdateCBRModel
virtual void UpdateCBRModel(EncPicture &my_picture, const PictureByteIO *picture_byteio)=0
Update the CBR model based on the data we've compressed.
dirac::SequenceCompressor::m_show_pnum
int m_show_pnum
The number of the picture which should be output for concurrent display or storage.
Definition: seq_compress.h:232
dirac::SequenceCompressor::m_last_picture_read
int m_last_picture_read
The index, in display order, of the last picture read.
Definition: seq_compress.h:235
dirac::SequenceCompressor::UpdateIntraPicCBRModel
void UpdateIntraPicCBRModel(const PictureParams &, const bool is_a_cut)
Update the parameters to be used in advance of coding an intra frame.
dirac::SequenceCompressor::m_ratecontrol
RateController * m_ratecontrol
A class for monitoring and controlling bit rate.
Definition: seq_compress.h:247
dirac::SequenceCompressor::SequenceCompressor
SequenceCompressor(const SequenceCompressor &cpy)
Copy constructor is private and body-less.
dirac::SequenceCompressor::m_all_done
bool m_all_done
Completion flag, returned via the Finished method.
Definition: seq_compress.h:180
dirac::SequenceCompressor::m_basic_olb_params2
const OLBParams * m_basic_olb_params2
A class to hold the basic block parameters.
Definition: seq_compress.h:197
dirac::SequenceCompressor::SetPicTypeAndRefs
virtual void SetPicTypeAndRefs(PictureParams &pparams)=0
Set up the appropriate prediction parameters for a picture.
dirac::SequenceCompressor::m_pic_in
StreamPicInput * m_pic_in
Pointer pointing at the picture input.
Definition: seq_compress.h:218
dirac::SequenceCompressor::m_current_code_pnum
int m_current_code_pnum
The number of the current picture to be coded, in coded order.
Definition: seq_compress.h:229
dirac::SequenceCompressor::m_enc_pbuffer
EncQueue m_enc_pbuffer
A picture buffer used for local storage of pictures whilst pending re-ordering or being used for refe...
Definition: seq_compress.h:221
dirac::SequenceCompressor::m_just_finished
bool m_just_finished
Flag indicating whether we've just finished.
Definition: seq_compress.h:188
dirac::SequenceCompressor::m_srcparams
SourceParams & m_srcparams
The parameters of the input source.
Definition: seq_compress.h:203
dirac::SequenceCompressor::PTSOffset
int PTSOffset()
The delay required for correct timestamps.
Definition: seq_compress.h:147
dirac::SequenceCompressor::~SequenceCompressor
virtual ~SequenceCompressor()
Destructor.
dirac::SequenceCompressor::SequenceCompressor
SequenceCompressor(StreamPicInput *pin, EncoderParams &encp, DiracByteStream &dirac_byte_stream)
Constructor.
dirac::SequenceCompressor::m_basic_olb_params1
OLBParams * m_basic_olb_params1
A class to hold the basic block parameters.
Definition: seq_compress.h:194
dirac::SequenceCompressor::CodedToDisplay
virtual int CodedToDisplay(const int pnum)=0
Uses the GOP parameters to convert picture numbers in coded order to display order.
dirac::SequenceCompressor::m_dirac_byte_stream
DiracByteStream & m_dirac_byte_stream
Output destination for compressed data in bitstream format.
Definition: seq_compress.h:253
dirac::SequenceCompressor::m_current_display_pnum
int m_current_display_pnum
The number of the current picture to be coded, in display order.
Definition: seq_compress.h:226
dirac::SequenceCompressor::m_gop_start_num
int m_gop_start_num
The picture number of the last GOP start.
Definition: seq_compress.h:238
dirac::FrameSequenceCompressor
Compresses a sequence of frames from a stream.
Definition: seq_compress.h:284
dirac::FrameSequenceCompressor::CodedToDisplay
virtual int CodedToDisplay(const int pnum)
Uses the GOP parameters to convert picture numbers in coded order to display order.
dirac::FrameSequenceCompressor::~FrameSequenceCompressor
virtual ~FrameSequenceCompressor()
Destructor.
Definition: seq_compress.h:304
dirac::FrameSequenceCompressor::LoadNextFrame
virtual bool LoadNextFrame()
Load data.
dirac::FrameSequenceCompressor::FrameSequenceCompressor
FrameSequenceCompressor(StreamPicInput *pin, EncoderParams &encp, DiracByteStream &dirac_byte_stream)
Constructor.
dirac::FrameSequenceCompressor::SetPicTypeAndRefs
virtual void SetPicTypeAndRefs(PictureParams &pparams)
Set up the appropriate prediction parameters for a picture.
dirac::FrameSequenceCompressor::UpdateCBRModel
virtual void UpdateCBRModel(EncPicture &my_picture, const PictureByteIO *picture_byteio)
Update the CBR model based on the data we've compressed.
dirac::FieldSequenceCompressor
Compresses a sequence of fields from a stream.
Definition: seq_compress.h:332
dirac::FieldSequenceCompressor::SetPicTypeAndRefs
virtual void SetPicTypeAndRefs(PictureParams &pparams)
Set up the appropriate prediction parameters for a picture.
dirac::FieldSequenceCompressor::m_field1_bytes
int m_field1_bytes
Definition: seq_compress.h:381
dirac::FieldSequenceCompressor::CodedToDisplay
virtual int CodedToDisplay(const int pnum)
Uses the GOP parameters to convert picture numbers in coded order to display order.
dirac::FieldSequenceCompressor::~FieldSequenceCompressor
virtual ~FieldSequenceCompressor()
Destructor.
dirac::FieldSequenceCompressor::PreMotionEstmationFilter
void PreMotionEstmationFilter(PicArray &comp)
Filter fields.
dirac::FieldSequenceCompressor::m_field2_bytes
int m_field2_bytes
Definition: seq_compress.h:383
dirac::FieldSequenceCompressor::LoadNextFrame
virtual bool LoadNextFrame()
Load data.
dirac::FieldSequenceCompressor::UpdateCBRModel
virtual void UpdateCBRModel(EncPicture &my_picture, const PictureByteIO *picture_byteio)
Update the CBR model based on the data we've compressed.
dirac::FieldSequenceCompressor::FieldSequenceCompressor
FieldSequenceCompressor(StreamPicInput *pin, EncoderParams &encp, DiracByteStream &dirac_byte_stream)
Constructor.

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.