Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

frame.hh

Go to the documentation of this file.
00001 /*
00002  * PIAVE - PIAVE Is A Video Editor
00003  *
00004  * Copyright (C) 2002 Rolf Dubitzky, rolf@dubitzky.de
00005  */
00006 
00007 /*
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software Foundation,
00020  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00037 #if ! defined ( FRAME_HH )
00038 #define FRAME_HH
00039 
00040 // std c
00041 #include <time.h> 
00042 
00043 // std c++
00044 #include <string>
00045 #include <vector>
00046 #include <map>
00047 
00048 // PIAVE
00049 #include "piave_base.hh"
00050 #include "videoformat.hh"
00051 #include "bufferpool.hh"
00052 
00053 namespace PIAVE {
00054 
00055     class PropertyNode;
00056     class InAVStreamIFace;
00057 
00062     class VideoBuffer
00063     {
00064       public:
00065         VideoBuffer( int width  = Global::renderFmt.width, 
00066                      int height = Global::renderFmt.height, 
00067                      bool allocate = false );
00068         ~VideoBuffer();
00069 
00070         int   getWidth() const { return _width; }
00071         int   getHeight() const { return _height; }
00072         int   getSizePixels() const { return _width * _height; }
00073         int   getSizeBytes() const { return _sizeBytes; }
00074         int   getLineStride() const { return _lineStride; }
00075 
00077         bool  hasAlpha() const { return _alphaPixels!=0; }
00078         void  addAlpha() {};
00079 
00080         uint8_t * getPixels() const { return _pixels->buf(); }
00081         uint8_t * getAlphaPixels() const { return _alphaPixels->buf(); }
00082 
00088         void lock( bool l = true ) { _is_locked = l; };
00089         bool isLocked() const { return _is_locked; };
00090 
00091         void dropRef();
00092 
00094         const VideoBuffer & operator=( const VideoBuffer & o );
00095 
00096       private:
00097         int          _width;
00098         int          _height;
00099         int          _lineStride;
00100         int          _sizeBytes;
00101 
00102         Buffer     * _pixels;       
00103         Buffer     * _alphaPixels;       
00104         bool         _is_locked;    
00105         bool         _is_allocated;    
00106     };
00107 
00112     class AudioBuffer
00113     {
00114       public:
00116         AudioBuffer();
00118         virtual ~AudioBuffer();
00119 
00121         Buffer  ** getChannels() { return _channels; };
00122         int16_t *  getChannel( int i ) const { return _channels[i]?(int16_t*)_channels[i]->buf():0; };
00123         int        getNChannels() const { return _nChannels; }
00124         int        getNSamples() const { return _nSamples; }
00125         bool       isInterleaved() const { return _isInterleaved; }
00126  
00127         void  setNChannels( int n ) {  _nChannels = n; };
00128         void  setNSamples( int n ) {  _nSamples = n; };
00129         void  setInterleaved( bool s ) {  _isInterleaved = s; };
00130         
00131 
00132         /*  if the audio data has more than one channel, and the
00133          *  channels are stored in seperate buffers, they will be
00134          *  interleaved into a single buffer in channel 0
00135          */
00136         Buffer * interleave();
00137 
00139         static const uint MAX_CHANNELS = 10;
00141         static const uint MAX_SAMPLES = 3000;
00142 
00143         void dropRef();
00144 
00145       private:
00146         /* number of channels; they may be interleaved into a single
00147          * buffer 
00148          */
00149         int _nChannels; 
00150         /* are the channels interleaved in a single buffer ?? */
00151         int _isInterleaved;
00152         /* number of samples per channel in this buffer */
00153         int _nSamples;
00154         
00155         Buffer * _channels[ MAX_CHANNELS ];
00156     };
00157 
00158 
00162     class Frame
00163     {
00164       public:
00165 
00167         Frame();
00168         Frame( const Frame & o );
00169 
00170         // @{
00172         Time getPos()    const { return _pos; }
00173         Time getLength() const { return _length; }
00174         void setPos( const Time pos )       {  _pos = pos; }
00175         void setLength( const Time length ) { _length = length; }
00176         // @}
00177 
00178         // @{
00180         VideoBuffer  * getVBuf()    const { return _vBuf; };
00181         AudioBuffer  * getABuf()    const { return _aBuf; };
00182         // @}
00183 
00184         // @{
00186         Buffer  * getRawVBuf()    const { return _rawVBuf; };
00187         Buffer  * getRawABuf()    const { return _rawABuf; };
00188         // @}
00189 
00190         /* the encoded data is only usefull in context with the
00191          * the stream where t comes from, i.e. a decoder and maybe
00192          * surrounding frames
00193          */
00194         InAVStreamIFace * getAVContext() const { return _avContext; }
00195         InAVStreamIFace * getAudioContext() const { return _audioContext; }
00196         PropertyNode * getProperties();
00197 
00198         /* get properties of this video frame. In case _properties==0
00199          * decodeMetaData() is called
00200          */
00201         PropertyNode * getMetaData();
00202 
00203 
00204         /*   the following methods handle the actual decodeing
00205          *   they are only called if necessary
00206          */
00207 
00209         void decodeMetaData();
00210 
00216         void decodeVideo( uint8_t * dest = 0 );
00217 
00223         void decodeAudio( uint8_t * dest = 0  );
00224 
00226         bool  getVideoIsDecoded()  const { return _videoIsDecoded; }
00228         bool  getAudioIsDecoded()  const { return _audioIsDecoded; }
00229 
00230         // @{
00232         void setRawVBuf( Buffer * evb ) { _rawVBuf = evb; };
00233         void setRawABuf( Buffer * eab ) { _rawABuf = eab; };
00234         void setVBuf( VideoBuffer* vb ) { _vBuf = vb; };
00235         void setABuf( AudioBuffer* ab ) { _aBuf = ab; };
00236         void setVideoIsDecoded( bool is ) { _videoIsDecoded = is; }
00237         void setAudioIsDecoded( bool is ) { _audioIsDecoded = is; }
00238         void setAVContext( InAVStreamIFace * v ) { _avContext = v; }
00239         void setAudioContext( InAVStreamIFace * a ) { _audioContext = a; }
00240         void setProperties( PropertyNode * p ) { _properties = p; }
00241         // @}
00242 
00244         const Frame & operator=( const Frame & o ) { copy(o); };
00245         const Frame & copy( const Frame & o );
00246         const Frame & copyVideo( const Frame & o );
00247         const Frame & copyAudio( const Frame & o );
00248 
00250         void makeWriteableVBuf();
00251 
00252         /* decode data if necessary
00253          * if target == 0 a new buffer is allocated
00254          */
00255         VideoBuffer * makeVBuf();
00256 
00257         /* decode data if necessary
00258          * if target == 0 a new buffers are allocated
00259          */
00260         AudioBuffer * makeABuf();
00261 
00265         void dropRefs();
00266         void dropVRefs();
00267         void dropARefs();
00268 
00269       private:
00271         void addAlpha();
00272 
00274         void flattenAlpha();
00275 
00276       private:
00277         // the buffers
00278         VideoBuffer  * _vBuf;
00279         AudioBuffer  * _aBuf;
00280         Buffer       * _rawVBuf;
00281         Buffer       * _rawABuf;
00282 
00283         Time           _pos;
00284         Time           _length;
00285 
00286         bool           _videoIsDecoded;
00287         bool           _audioIsDecoded;
00288 
00289         InAVStreamIFace     * _avContext;
00290         InAVStreamIFace  * _audioContext;
00291 
00292         PropertyNode   * _properties;
00293 
00294     };
00295 
00296 };
00297 
00298 #endif 

Generated on Tue Oct 14 20:45:36 2003 for piave by doxygen1.2.18