00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #if ! defined( AVISTREAM_HH )
00032 #define AVISTREAM_HH
00033
00034
00035 #include "libpiave/plugin.hh"
00036 #include "libpiave/avstream.hh"
00037 #include "libpiave/videoformat.hh"
00038
00039 namespace PIAVE {
00040
00041 class PropertyNode;
00042 class Frame;
00043
00044
00045
00046
00047 class InAviStreamPlugin : public Plugin
00048 {
00049 public:
00050 InAviStreamPlugin();
00051 virtual PluginBase * newElement( const PropertyNode * p = 0 );
00052 };
00053
00054 class OutAviStreamPlugin : public Plugin
00055 {
00056 public:
00057 OutAviStreamPlugin();
00058 virtual PluginBase * newElement( const PropertyNode * p = 0 );
00059 };
00060
00061
00067 #define RIFF_NO_PARENT_IDX (-1)
00068 #define RIFF_LISTSIZE (4)
00069 #define RIFF_HEADERSIZE (8)
00070
00071 struct AviRect
00072 {
00073 int16_t top, bottom, left, right;
00074 };
00075
00076 struct AviStreamHeader
00077 {
00078 AviStreamHeader(){};
00079 FOURCC fccType;
00080 FOURCC fccHandler;
00081 int32_t dwFlags;
00082 int16_t wPriority;
00083 int16_t wLanguage;
00084 int32_t dwInitialFrames;
00085 int32_t dwScale;
00086 int32_t dwRate;
00087 int32_t dwStart;
00088 int32_t dwLength;
00089 int32_t dwSuggestedBufferSize;
00090 int32_t dwQuality;
00091 int32_t dwSampleSize;
00092 AviRect rcFrame;
00093 };
00094
00095 struct DVINFO
00096 {
00097 int32_t dwDVAAuxSrc;
00098 int32_t dwDVAAuxCtl;
00099 int32_t dwDVAAuxSrc1;
00100 int32_t dwDVAAuxCtl1;
00101 int32_t dwDVVAuxSrc;
00102 int32_t dwDVVAuxCtl;
00103 int32_t dwDVReserved[2];
00104 };
00105
00106 struct BITMAPINFOHEADER
00107 {
00108 int32_t biSize;
00109 uint32_t biWidth;
00110 uint32_t biHeight;
00111 int16_t biPlanes;
00112 int16_t biBitCount;
00113 uint32_t biCompression;
00114 int32_t biSizeImage;
00115 uint32_t biXPelsPerMeter;
00116 uint32_t biYPelsPerMeter;
00117 int32_t biClrUsed;
00118 int32_t biClrImportant;
00119 };
00120
00121 struct WAVEFORMATEX
00122 {
00123 int16_t wFormatTag;
00124 int16_t nChannels;
00125 int32_t nSamplesPerSec;
00126 int32_t nAvgBytesPerSec;
00127 int16_t nBlockAlign;
00128 int16_t wBitsPerSample;
00129 int16_t cbSize;
00130 int16_t dummy;
00131 };
00132
00133 struct AviSuperIndex
00134 {
00135 int16_t wLongsPerEntry;
00136 uint8_t bIndexSubType;
00137 uint8_t bIndexType;
00138 int32_t nEntriesInUse;
00139 int32_t dwChunkId;
00140 int32_t dwReserved[3];
00141 struct AviSuperIndexEntry
00142 {
00143 uint64_t qwOffset;
00144 int32_t dwSize;
00145 int32_t dwDuration;
00146 } aIndex[2014];
00147 };
00148
00149 struct AviStdIndex {
00150 int16_t wLongsPerEntry;
00151 uint8_t bIndexSubType;
00152 uint8_t bIndexType;
00153 int32_t nEntriesInUse;
00154 int32_t dwChunkId;
00155 uint64_t qwBaseOffset;
00156 int32_t dwReserved;
00157 struct AviStdIndexEntry {
00158 int32_t dwOffset;
00159 int32_t dwSize;
00160 } aIndex[4028];
00161 };
00162
00163 struct AviSimpleIndex {
00164 struct AviSimpleIndexEntry {
00165 FOURCC dwChunkId;
00166 int32_t dwFlags;
00167 int32_t dwOffset;
00168 int32_t dwSize;
00169 } aIndex[20000];
00170 int32_t nEntriesInUse;
00171 };
00172
00176 struct AviDirEntry
00177 {
00178 FOURCC type;
00179 FOURCC name;
00180 off_t length;
00181 off_t offset;
00182 int parentList;
00183 int writtenFlag;
00184
00185 AviDirEntry();
00186 AviDirEntry( const FOURCC& t, const FOURCC& n, int l, int o, int p);
00187 };
00188
00189 struct RIFFChunk
00190 {
00191 FOURCC type;
00192 int length;
00193 };
00194
00195 struct MainAVIHeader
00196 {
00198 int32_t dwMicroSecPerFrame;
00199
00201 int32_t dwMaxBytesPerSec;
00202
00204 int32_t dwPaddingGranularity;
00205
00207 int32_t dwFlags;
00208
00210 int32_t dwTotalFrames;
00211 int32_t dwInitialFrames;
00212 int32_t dwStreams;
00213 int32_t dwSuggestedBufferSize;
00214
00215 int32_t dwWidth;
00216 int32_t dwHeight;
00217
00218 int32_t dwReserved[4];
00219 };
00220
00221 class AviContainer
00222 {
00223 public:
00224 AviContainer();
00225 ~AviContainer();
00226
00227 public:
00228 #define AVI_SMALL_INDEX (0x01)
00229 #define AVI_LARGE_INDEX (0x02)
00230 #define AVI_INDEX_OF_INDEXES (0x00)
00231 #define AVI_INDEX_OF_CHUNKS (0x01)
00232 #define AVI_INDEX_2FIELD (0x01)
00233
00234 int newDirEntry( const FOURCC& type, const FOURCC& name,
00235 off_t length, int list );
00236 int getDirEntry( const FOURCC& type , int n=0 );
00237 int setDirEntry( int idx, const AviDirEntry& entry );
00238
00239 std::vector<AviDirEntry> dir;
00240
00241 MainAVIHeader mainHdr;
00242 AviSimpleIndex *idx1;
00243 int file_list;
00244 int riff_list;
00245 int hdrl_list;
00246 int avih_chunk;
00247 int movi_list;
00248 int junk_chunk;
00249 int idx1_chunk;
00250
00251 AviStreamHeader streamHdr[2];
00252 AviSuperIndex *indx[2];
00253 AviStdIndex *ix[2];
00254 int indx_chunk[2];
00255 int ix_chunk[2];
00256 int strl_list[2];
00257 int strh_chunk[2];
00258 int strf_chunk[2];
00259
00260 int index_type;
00261 int current_ix00;
00262
00263 int dmlh[62];
00264 int odml_list;
00265 int dmlh_chunk;
00266 bool isUpdateIdx1;
00267
00268 };
00269
00270
00271
00272
00273
00274
00275
00276 class InAviStream : public InAVFStream
00277 {
00278 public:
00279 InAviStream( const std::string& fileName ) throw(exception);
00280 virtual ~InAviStream();
00281
00282 virtual Frame getFrame( Time t );
00283
00284 virtual void decodeVideo( Frame & f, uint8_t * dest = 0 );
00285 virtual void decodeAudio( Frame & f, uint8_t * dest = 0 );
00286
00287 virtual PropertyNode * getProperties(PropertyNode * p=0) const;
00288
00289 private:
00290
00291 void parseHeader();
00292 void parseList( int parent_idx );
00293 void parseChunk( int parent_idx );
00294 void readChunk( int idx, void * data );
00295 void readIndex();
00296
00297 int findStreamWithType( FOURCC type );
00298 int findStreamWithHandler( FOURCC format );
00299
00300 private:
00301 AVDecoderIFace * _dvDecoder;
00302 bool _hasAviAudio;
00303 int _frameSize;
00304 AviContainer * _container;
00305 };
00306
00307 class OutAviStream : public OutAVFStream
00308 {
00309 public:
00310 OutAviStream( const std::string& fileName );
00311 ~OutAviStream();
00312 virtual void putFrame( Frame & f );
00313
00314 virtual PropertyNode * getProperties(PropertyNode * p=0) const;
00315
00316 private:
00317 AVEncoderIFace * _dvEncoder;
00318 int _frameSize;
00319 };
00320
00321
00322 }
00323
00324 #endif