00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00037 #if ! defined ( FRAME_HH )
00038 #define FRAME_HH
00039
00040
00041 #include <time.h>
00042
00043
00044 #include <string>
00045 #include <vector>
00046 #include <map>
00047
00048
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
00133
00134
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
00147
00148
00149 int _nChannels;
00150
00151 int _isInterleaved;
00152
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
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
00181 AudioBuffer * getABuf() const { return _aBuf; };
00182
00183
00184
00186
00187 Buffer * getRawABuf() const { return _rawABuf; };
00188
00189
00190
00191
00192
00193
00194 InAVStreamIFace * getAVContext() const { return _avContext; }
00195 InAVStreamIFace * getAudioContext() const { return _audioContext; }
00196 PropertyNode * getProperties();
00197
00198
00199
00200
00201 PropertyNode * getMetaData();
00202
00203
00204
00205
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
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
00253
00254
00255 VideoBuffer * makeVBuf();
00256
00257
00258
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
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