esp_dvdif.h

Go to the documentation of this file.
00001 
00007 /*
00008  *  Copyright (c) 2003, Matt Beard
00009  *
00010  *  This software is provided 'as-is', without any express or implied warranty.
00011  *  In no event will the authors be held liable for any damages arising from
00012  *  the use of this software.
00013  *
00014  *  Permission is granted to anyone to use this software for any purpose,
00015  *  including commercial applications, and to alter it and redistribute it
00016  *  freely, subject to the following restrictions:
00017  *
00018  *    1. The origin of this software must not be misrepresented; you must
00019  *       not claim that you wrote the original software. If you use this
00020  *       software in a product, an acknowledgment in the product
00021  *       documentation would be appreciated but is not required.
00022  *  
00023  *    2. Altered source versions must be plainly marked as such, and must
00024  *       not be misrepresented as being the original software.
00025  *  
00026  *    3. This notice may not be removed or altered from any source
00027  *       distribution.
00028  */
00029 
00030 #ifndef MXFLIB__ESP_DVDIF_H
00031 #define MXFLIB__ESP_DVDIF_H
00032 
00033 
00034 #include <math.h>   // For "floor"
00035 
00036 #define DV_DIF_BUFFERSIZE  (256 * 1024)
00037 
00038 namespace mxflib
00039 {
00041     class DV_DIF_EssenceSubParser : public EssenceSubParserBase
00042     {
00043     protected:
00044         Rational NativeEditRate;                            
00045         Rational SelectedEditRate;                          
00046         unsigned int EditRatio;                             
00047 
00048         Position PictureNumber;                             
00049         Position CurrentPos;                                
00050 
00051         Position DIFStart;                                  
00052         Position DIFEnd;                                    
00053 
00054         int SeqCount;                                       
00055 
00056         bool isS314M;                                       
00057 
00058         UInt32 AVIFrameCount;                               
00059         int StreamNumber;                                   
00060 
00061         UInt32 AVIStreamID;                                 
00062         UInt32 AVIListRemaining;                            
00063         UInt32 AVIChunkRemaining;                           
00064 
00065         size_t CachedDataSize;                              
00066         UInt64 CachedCount;                                 
00067 
00068         // File buffering
00069         UInt8 *Buffer;                                      
00070 
00071         int BuffCount;                                      
00072         UInt8 *BuffPtr;                                     
00073 
00074         MDObjectParent CurrentDescriptor;                   
00075 
00077         // Options
00078         // None (yet)
00079 
00080     public:
00082         class ESP_EssenceSource : public EssenceSubParserBase::ESP_EssenceSource
00083         {
00084         public:
00086             ESP_EssenceSource(EssenceSubParserPtr TheCaller, FileHandle InFile, UInt32 UseStream, UInt64 Count = 1/*, IndexTablePtr UseIndex = NULL*/)
00087                 : EssenceSubParserBase::ESP_EssenceSource(TheCaller, InFile, UseStream, Count/*, UseIndex*/) 
00088             {
00089                 DV_DIF_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, DV_DIF_EssenceSubParser);
00090 
00091                 if(pCaller->SelectedWrapping->ThisWrapType == WrappingOption::Clip) RequestedCount = 0;
00092             };
00093 
00095 
00097             virtual size_t GetEssenceDataSize(void) 
00098             {
00099                 DV_DIF_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, DV_DIF_EssenceSubParser);
00100                 return pCaller->ReadInternal(File, Stream, RequestedCount/*, Index*/);
00101             };
00102 
00104 
00109             virtual DataChunkPtr GetEssenceData(size_t Size = 0, size_t MaxSize = 0)
00110             {
00111 /*              // Allow us to differentiate the first call
00112                 if(!Started)
00113                 {
00114                     // Move to the selected position
00115                     DV_DIF_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, DV_DIF_EssenceSubParser);
00116 
00117                     Started = true;
00118                 }
00119 */
00120 
00121                 return BaseGetEssenceData(Size, MaxSize);
00122             }
00123 
00125             virtual int GetBERSize(void) 
00126             { 
00127                 DV_DIF_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, DV_DIF_EssenceSubParser);
00128 
00129                 if(pCaller->SelectedWrapping->ThisWrapType == WrappingOption::Clip) return 8;
00130                 return 4;
00131             }
00132         };
00133 
00134         // Give our essence source class privilaged access
00135         friend class DV_DIF_EssenceSubParser::ESP_EssenceSource;
00136 
00137     public:
00138         DV_DIF_EssenceSubParser()
00139         {
00140             DIFStart = 0;
00141             DIFEnd = 0;
00142             SeqCount = 10;
00143             AVIFrameCount = 0;
00144             StreamNumber = 0;
00145             Buffer = NULL;
00146 
00147             CachedDataSize = static_cast<size_t>(-1);
00148             CachedCount = 0;
00149         }
00150 
00151         ~DV_DIF_EssenceSubParser()
00152         {
00153             // Free our buffer if we have allocated one
00154             if(Buffer) delete[] Buffer;
00155         }
00156 
00158         virtual EssenceSubParserPtr NewParser(void) const;
00159 
00161         virtual StringList HandledExtensions(void)
00162         {
00163             StringList ExtensionList;
00164 
00165             ExtensionList.push_back("AVI");
00166             ExtensionList.push_back("DV");
00167             ExtensionList.push_back("DIF");
00168 
00169             return ExtensionList;
00170         }
00171 
00173         virtual EssenceStreamDescriptorList IdentifyEssence(FileHandle InFile);
00174 
00176         virtual WrappingOptionList IdentifyWrappingOptions(FileHandle InFile, EssenceStreamDescriptor &Descriptor);
00177 
00179         virtual void Use(UInt32 Stream, WrappingOptionPtr &UseWrapping);
00180 
00182         virtual bool SetEditRate(Rational EditRate);
00183 
00185         virtual Rational GetEditRate(void) { return SelectedEditRate; }
00186 
00188         virtual UInt32 GetBytesPerEditUnit(UInt32 KAGSize = 1)
00189         {
00190             // FIXME: Assumes 25Mbps
00191             UInt32 Ret = (150 * 80 * SeqCount);
00192 
00193             if(SelectedWrapping->ThisWrapType == WrappingOption::Frame) 
00194             {
00195                 // FIXME: This assumes that 4-byte BER coding will be used - this needs to be adjusted or forced to be true!!
00196                 Ret += 16 + 4;
00197 
00198                 // Adjust for whole KAGs if required
00199                 if(KAGSize > 1)
00200                 {
00201                     // Work out how much short of the next KAG boundary we would be
00202                     UInt32 Remainder = Ret % KAGSize;
00203                     if(Remainder) Remainder = KAGSize - Remainder;
00204 
00205                     // Round up to the start of the next KAG
00206                     Ret += Remainder;
00207 
00208                     // If there is not enough space to fit a filler in the remaining space an extra KAG will be required
00209                     if((Remainder > 0) && (Remainder < 17)) Ret++;
00210                 }
00211             }
00212 
00213             return Ret;
00214         }
00215 
00217         virtual Position GetCurrentPosition(void);
00218 
00220         virtual DataChunkPtr Read(FileHandle InFile, UInt32 Stream, UInt64 Count = 1/*, IndexTablePtr Index = NULL*/);
00221 
00223         virtual EssenceSourcePtr GetEssenceSource(FileHandle InFile, UInt32 Stream, UInt64 Count = 1/*, IndexTablePtr Index = NULL*/)
00224         {
00225             return new ESP_EssenceSource(this, InFile, Stream, Count/*, Index*/);
00226         };
00227 
00229         virtual Length Write(FileHandle InFile, UInt32 Stream, MXFFilePtr OutFile, UInt64 Count = 1/*, IndexTablePtr Index = NULL*/);
00230 
00232 
00233         virtual bool SetOption(std::string Option, Int64 Param = 0);
00234 
00236 
00240         virtual std::string GetParserName(void) const { return "dvdif"; }
00241 
00242     protected:
00244         MDObjectPtr BuildCDCIEssenceDescriptor(FileHandle InFile, UInt64 Start = 0);
00245 
00247         MDObjectPtr BuildSoundEssenceDescriptor(FileHandle InFile, UInt64 Start = 0);
00248 
00250         MDObjectPtr BuildCDCIEssenceDescriptorFromAVI(FileHandle InFile, UInt64 Start);
00251 
00253         MDObjectPtr BuildSoundEssenceDescriptorFromAVI(FileHandle InFile, UInt64 Start);
00254 
00256         size_t ReadInternal(FileHandle InFile, UInt32 Stream, UInt64 Count/*, IndexTablePtr Index = NULL*/);
00257 
00259 
00260         DataChunkPtr AVIRead(FileHandle InFile, size_t Bytes);
00261     };
00262 
00263 
00265     class DV_DIF_EssenceSubParserFactory : public EssenceSubParserFactory
00266     {
00267     public:
00269         virtual EssenceSubParserPtr NewParser(void) const { return new DV_DIF_EssenceSubParser; }
00270     };
00271 
00272 }
00273 
00274 #endif // MXFLIB__ESP_DVDIF_H

Generated on Mon Apr 2 15:20:53 2007 for MXFLib by  doxygen 1.5.1-p1