Dirac Video Codec

# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

# pic_io.h

Go to the documentation of this file.

    00001 /* ***** BEGIN LICENSE BLOCK *****
    00002 *
    00003 * $Id: pic_io.h,v 1.19 2008/06/19 10:17:17 tjdwave Exp $ $Name: Dirac_1_0_0 $
    00004 *
    00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
    00006 *
    00007 * The contents of this file are subject to the Mozilla Public License
    00008 * Version 1.1 (the "License"); you may not use this file except in compliance
    00009 * with the License. You may obtain a copy of the License at
    00010 * http://www.mozilla.org/MPL/
    00011 *
    00012 * Software distributed under the License is distributed on an "AS IS" basis,
    00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
    00014 * the specific language governing rights and limitations under the License.
    00015 *
    00016 * The Original Code is BBC Research and Development code.
    00017 *
    00018 * The Initial Developer of the Original Code is the British Broadcasting
    00019 * Corporation.
    00020 * Portions created by the Initial Developer are Copyright (C) 2004.
    00021 * All Rights Reserved.
    00022 *
    00023 * Contributor(s): Thomas Davies (Original Author),
    00024 *                 Scott Robert Ladd,
    00025 *                 Stuart Cunningham,
    00026 *                 Tim Borer,
    00027 *                 Anuradha Suraparaju
    00028 *
    00029 * Alternatively, the contents of this file may be used under the terms of
    00030 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
    00031 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
    00032 * the GPL or the LGPL are applicable instead of those above. If you wish to
    00033 * allow use of your version of this file only under the terms of the either
    00034 * the GPL or LGPL and not to allow others to use your version of this file
    00035 * under the MPL, indicate your decision by deleting the provisions above
    00036 * and replace them with the notice and other provisions required by the GPL
    00037 * or LGPL. If you do not delete the provisions above, a recipient may use
    00038 * your version of this file under the terms of any one of the MPL, the GPL
    00039 * or the LGPL.
    00040 * ***** END LICENSE BLOCK ***** */
    00041
    00042 #ifndef _PIC_IO_H_
    00043 #define _PIC_IO_H_
    00044
    00045 #include <iostream>
    00046 #include <fstream>
    00047 #include <streambuf>
    00048
    00049 #include <libdirac_common/common.h>
    00050 #include <libdirac_common/picture.h>
    00051
    00052 namespace dirac
    00053 {
    00054
    00056     //--------------------------------------//
    00057     //-                                    -//
    00058     //-Uncompressed picture file IO wrapper-//
    00059     //-                                    -//
    00060     //--------------------------------------//
    00062
    00063     // Stream classes for writing/reading frames of uncompressed/decoded data
    00064     // to stream. Streams currently supported are Memory based streams and
    00065     // File based streams. These classes need further restructuring.
    00066     // Anu - 19-11-2004
    00067
    00068     // Subclass these to provide functionality for different file formats and
    00069     // for streaming.
    00070
    00071
    00073
    00074
    00078     class StreamPicOutput
    00079     {
    00080         public:
    00082
    00087             StreamPicOutput( std::ostream* op_ptr, const SourceParams& sp);
    00088
    00090             virtual ~StreamPicOutput();
    00091
    00093             virtual bool WriteToNextFrame(const Picture& myframe) = 0;
    00094
    00096             SourceParams& GetSourceParams() {return m_sparams;}
    00097
    00098         protected:
    00100             SourceParams m_sparams;
    00102             std::ostream* m_op_pic_ptr;
    00103
    00105             StreamPicOutput();
    00106         private:
    00107
    00108     };
    00109
    00110     class StreamFrameOutput : public StreamPicOutput
    00111     {
    00112         public:
    00113
    00119             StreamFrameOutput( std::ostream *op_ptr, const SourceParams& sp);
    00120
    00122             virtual ~StreamFrameOutput();
    00123
    00125             bool WriteToNextFrame(const Picture& myframe);
    00126
    00127         protected:
    00129             bool WriteFrameComponent(const PicArray& pic_data,
    00130                                      const CompSort& cs);
    00131         private:
    00133             StreamFrameOutput();
    00134     };
    00135
    00136     class StreamFieldOutput : public StreamPicOutput
    00137     {
    00138         public:
    00140
    00145             StreamFieldOutput( std::ostream *op_ptr, const SourceParams& sp);
    00146
    00148             virtual ~StreamFieldOutput();
    00149
    00151             bool WriteToNextFrame(const Picture& myfield);
    00152
    00153         protected:
    00155             bool WriteFieldComponent(const PicArray& pic_data,
    00156                                      int field_num,
    00157                                      const CompSort& cs);
    00158
    00159         private:
    00161             StreamFieldOutput();
    00162             unsigned char *m_frame_store;
    00163     };
    00164
    00168     class MemoryStreamOutput
    00169     {
    00170         public:
    00172             MemoryStreamOutput(SourceParams &sparams, bool interlace);
    00173
    00175             ~MemoryStreamOutput();
    00176
    00178             SourceParams& GetSourceParams()
    00179             { return m_op_pic_str->GetSourceParams();}
    00180
    00181             StreamPicOutput *GetStream() { return m_op_pic_str; }
    00183             void SetMembufReference (unsigned char *buf, int buf_size);
    00184
    00185         protected:
    00187             MemoryStreamOutput();
    00189             MemoryStreamOutput(const MemoryStreamOutput&);
    00191             MemoryStreamOutput & operator =(const MemoryStreamOutput&);
    00192
    00193         protected:
    00194
    00196             class OutputMemoryBuffer : public std::streambuf
    00197             {
    00198             public:
    00200                 OutputMemoryBuffer () :
    00201                 m_op_buf(0),
    00202                 m_op_buf_size(0),
    00203                 m_op_idx(0)
    00204                 {}
    00205
    00207
    00211                 void SetMembufReference (unsigned char *buffer, int buffer_size)
    00212                 {
    00213                     m_op_buf = buffer;
    00214                     m_op_buf_size = buffer_size;
    00215                     m_op_idx = 0;
    00216                 }
    00217
    00218             protected:
    00220                 unsigned char *m_op_buf;
    00222                 int m_op_buf_size;
    00224                 int m_op_idx;
    00225
    00227                 virtual int overflow (int c)
    00228                 {
    00229                     if ( c != EOF)
    00230                     {
    00231                         if (m_op_idx == m_op_buf_size)
    00232                             return EOF;
    00233
    00234                         m_op_buf[m_op_idx] = (char)c;
    00235                         m_op_idx++;
    00236                     }
    00237                     return c;
    00238                 }
    00239
    00241                 virtual std::streamsize xsputn (const char *s,
    00242                                             std::streamsize num)
    00243                 {
    00244                     std::streamsize bytes_left = m_op_buf_size - m_op_idx;
    00245                     std::streamsize bytes_written = bytes_left > num
    00246                                                         ? num : bytes_left;
    00247                     memcpy (&m_op_buf[m_op_idx], (unsigned char *)s,
    00248                             bytes_written);
    00249                     m_op_idx += bytes_written;
    00250                     return bytes_written;
    00251                 }
    00252
    00253             private:
    00255                 OutputMemoryBuffer(const OutputMemoryBuffer&);
    00257                 OutputMemoryBuffer& operator =(const OutputMemoryBuffer&);
    00258             };
    00259
    00260         private:
    00262             OutputMemoryBuffer m_membuf;
    00264             std::ostream* m_op_pic_ptr;
    00266             StreamPicOutput *m_op_pic_str;
    00267     };
    00268
    00272     class FileStreamOutput
    00273     {
    00274         public:
    00275
    00277
    00283             FileStreamOutput (const char* output_name,
    00284               const SourceParams& sp, bool interlace);
    00285
    00287             virtual ~FileStreamOutput ();
    00288
    00289             StreamPicOutput *GetStream() { return m_op_pic_str; }
    00290         private:
    00292             std::ostream* m_op_pic_ptr;
    00294             StreamPicOutput *m_op_pic_str;
    00295     };
    00296
    00298
    00302     class StreamPicInput
    00303     {
    00304         public:
    00305
    00307             StreamPicInput();
    00309
    00314             StreamPicInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
    00315
    00317             virtual ~StreamPicInput();
    00318
    00320             virtual void Skip( const int n)= 0;
    00321
    00323             virtual bool ReadNextPicture(Picture& mypic) = 0;
    00324
    00326             SourceParams& GetSourceParams() const {return m_sparams;}
    00327
    00329             bool End() const ;
    00330
    00331         protected:
    00332
    00334             mutable SourceParams m_sparams;
    00335
    00337             std::istream* m_ip_pic_ptr;
    00338
    00339     };
    00340
    00341     class StreamFrameInput : public StreamPicInput
    00342     {
    00343         public:
    00344
    00346             StreamFrameInput();
    00348
    00353             StreamFrameInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
    00354
    00356             virtual ~StreamFrameInput();
    00357
    00359             virtual void Skip( const int n);
    00360
    00362             virtual bool ReadNextPicture(Picture& myframe);
    00363
    00364         private:
    00365
    00367             bool ReadFrameComponent(PicArray& pic_data,const CompSort& cs);
    00368
    00369     };
    00370
    00371     class StreamFieldInput : public StreamPicInput
    00372     {
    00373         public:
    00374
    00376             StreamFieldInput();
    00378
    00383             StreamFieldInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
    00384
    00386             virtual ~StreamFieldInput();
    00387
    00389             virtual void Skip( const int n);
    00390
    00392             virtual bool ReadNextPicture(Picture& myfield);
    00393
    00395             bool ReadNextFrame(Picture& field1, Picture& field2);
    00396
    00397         protected:
    00399             bool ReadFieldComponent(PicArray& pic_data1,
    00400                                     PicArray& pic_data2,
    00401                                     const CompSort& cs);
    00402
    00404             bool ReadFieldComponent(bool is_field1, PicArray& pic_data,
    00405                                     const CompSort& cs);
    00406     };
    00410     class MemoryStreamInput
    00411     {
    00412         public:
    00414
    00418             MemoryStreamInput(SourceParams& sparams, bool field_input);
    00419
    00421             ~MemoryStreamInput();
    00422
    00423             SourceParams& GetSourceParams ( )
    00424             { return m_inp_str->GetSourceParams(); }
    00425
    00427
    00431             void SetMembufReference (unsigned char *buf, int buf_size);
    00432
    00434             StreamPicInput *GetStream() { return m_inp_str; }
    00435         protected:
    00437             MemoryStreamInput(const MemoryStreamInput&);
    00439             MemoryStreamInput & operator =(const MemoryStreamInput&);
    00440
    00441         protected:
    00443             class InputMemoryBuffer : public std::streambuf
    00444             {
    00445             public:
    00447                 InputMemoryBuffer() : m_buffer(0), m_buffer_size(0)
    00448                 {
    00449                     setg ((char *)m_buffer, (char *)m_buffer, (char *)m_buffer);
    00450                 }
    00451
    00453                 ~InputMemoryBuffer(){}
    00454
    00456
    00460                 void SetMembufReference (unsigned char *buffer, int buffer_size)
    00461                 {
    00462                     m_buffer = buffer;
    00463                     m_buffer_size = buffer_size;
    00464
    00465                     setg ((char *)m_buffer, (char *)m_buffer,
    00466                                 (char *)(m_buffer + buffer_size));
    00467                 }
    00468
    00469             private:
    00471                 InputMemoryBuffer (const InputMemoryBuffer& inbuf);
    00473                 InputMemoryBuffer& operator = (const InputMemoryBuffer& inbuf);
    00474
    00476                 unsigned char *m_buffer;
    00478                 int m_buffer_size;
    00479             };
    00480
    00481         private:
    00483             InputMemoryBuffer m_membuf;
    00484
    00486             StreamPicInput *m_inp_str;
    00487
    00489             std::istream* m_ip_pic_ptr;
    00490     };
    00491
    00493
    00496     class FileStreamInput
    00497     {
    00498         public:
    00499
    00501
    00507             FileStreamInput (const char* input_name, const SourceParams &sparams, bool interlace);
    00508
    00510             virtual ~FileStreamInput ();
    00511
    00512             SourceParams& GetSourceParams ( )
    00513             { return m_inp_str->GetSourceParams(); }
    00514
    00516             StreamPicInput *GetStream() { return m_inp_str; }
    00517
    00518         private:
    00519             StreamPicInput *m_inp_str;
    00520
    00522             std::istream* m_ip_pic_ptr;
    00523
    00524     };
    00525
    00526 } // namespace dirac
    00527
    00528 #endif

© 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.