esp_template.h

Go to the documentation of this file.
00001 
00007 /*
00008  *  Copyright (c) 2004, 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_TEMPLATE_H
00031 #define MXFLIB__ESP_TEMPLATE_H
00032 
00033 #include <math.h>   // For "floor"
00034 
00035 
00036 namespace mxflib
00037 {
00038     class TEMPLATE_EssenceSubParser : public EssenceSubParserBase
00039     {
00040     protected:
00041         UInt32 SampleRate;                                  
00042         Rational UseEditRate;                               
00043 
00044         Position DataStart;                                 
00045         Length DataSize;                                    
00046         Position CurrentPos;                                
00047 
00053         size_t CachedDataSize;                              
00054         UInt64 CachedCount;                                 
00055 
00056         int SampleSize;                                     
00057         UInt32 ConstSamples;                                
00058         int SampleSequenceSize;                             
00059         UInt32 *SampleSequence;                             
00060         int SequencePos;                                    
00061 
00062         MDObjectParent CurrentDescriptor;                   
00063 
00065     public:
00067         class ESP_EssenceSource : public EssenceSubParserBase::ESP_EssenceSource
00068         {
00069         protected:
00070             size_t BytesRemaining;                          
00071 
00072         public:
00074             ESP_EssenceSource(EssenceSubParserPtr TheCaller, FileHandle InFile, UInt32 UseStream, UInt64 Count = 1/*, IndexTablePtr UseIndex = NULL*/)
00075                 : EssenceSubParserBase::ESP_EssenceSource(TheCaller, InFile, UseStream, Count/*, UseIndex*/) 
00076             {
00077                 BytesRemaining = 0;
00078             };
00079 
00081 
00083             virtual size_t GetEssenceDataSize(void) 
00084             {
00085                 TEMPLATE_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, TEMPLATE_EssenceSubParser);
00086                 return pCaller->ReadInternal(File, Stream, RequestedCount);
00087             };
00088 
00090 
00095             virtual DataChunkPtr GetEssenceData(size_t Size = 0, size_t MaxSize = 0);
00096         };
00097 
00098         // Give our essence source class privilaged access
00099         friend class TEMPLATE_EssenceSubParser::ESP_EssenceSource;
00100 
00101     public:
00102         TEMPLATE_EssenceSubParser()
00103         {
00104             SampleRate = 1;
00105             ConstSamples = 0;
00106             SampleSequenceSize = 0;
00107             SampleSequence = NULL;
00108             SequencePos = 0;
00109             DataStart = 0;
00110             DataSize = 0;
00111             CurrentPos = 0;
00112 
00113             // Use a sensible default if no edit rate is set - not ideal, but better than one sample!
00114             // It should always be possible to wrap at this rate, but the end of the data may not be a whole edit unit
00115             UseEditRate.Numerator = 1;
00116             UseEditRate.Denominator = 1;
00117         }
00118 
00120         virtual EssenceSubParserPtr NewParser(void) const { return new TEMPLATE_EssenceSubParser; }
00121 
00123         virtual StringList HandledExtensions(void)
00124         {
00125             StringList ExtensionList;
00126 
00127             // TODO: Add any supported extentions here
00128             //       This is used as a hint to the overall essence parser to decide which sub-parsers to try.
00129             //       Calls may still be made to this sub-parser for files of different extensions, but this is a starting point.
00130 
00131             // ExtensionList.push_back("XXX");
00132 
00133             return ExtensionList;
00134         }
00135 
00137         virtual EssenceStreamDescriptorList IdentifyEssence(FileHandle InFile);
00138 
00140         virtual WrappingOptionList IdentifyWrappingOptions(FileHandle InFile, EssenceStreamDescriptor &Descriptor);
00141 
00143 
00144         virtual void Use(UInt32 Stream, WrappingOptionPtr UseWrapping)
00145         {
00146             SelectedWrapping = UseWrapping;
00147 
00148             CurrentPos = 0;
00149         }
00150 
00151 
00153 
00156         virtual bool SetEditRate(Rational EditRate)
00157         {
00158             // See if we can figure out a sequence for this rate
00159             bool Ret = CalcWrappingSequence(EditRate);
00160 
00161             // If we can then set the rate
00162             if(Ret)
00163             {
00164                 SequencePos = 0;
00165                 UseEditRate = EditRate;
00166             }
00167 
00168             return Ret;
00169         }
00170 
00172         virtual Rational GetEditRate(void) { return UseEditRate; }
00173 
00175 
00177         virtual Rational GetPreferredEditRate(void);
00178 
00180         virtual UInt32 GetBytesPerEditUnit(UInt32 KAGSize = 1)
00181         {
00182             // If we haven't determined the sample sequence we do it now
00183             if((ConstSamples == 0) && (SampleSequenceSize == 0)) CalcWrappingSequence(UseEditRate);
00184 
00185             UInt32 Ret = SampleSize*ConstSamples;
00186 
00187             if(Ret && (SelectedWrapping->ThisWrapType == WrappingOption::Frame))
00188             {
00189                 // FIXME: This assumes that 4-byte BER coding will be used - this needs to be adjusted or forced to be true!!
00190                 Ret += 16 + 4;
00191 
00192                 // Adjust for whole KAGs if required
00193                 if(KAGSize > 1)
00194                 {
00195                     // Work out how much short of the next KAG boundary we would be
00196                     UInt32 Remainder = Ret % KAGSize;
00197                     if(Remainder) Remainder = KAGSize - Remainder;
00198 
00199                     // Round up to the start of the next KAG
00200                     Ret += Remainder;
00201 
00202                     // If there is not enough space to fit a filler in the remaining space an extra KAG will be required
00203                     // DRAGONS: For very small KAGSizes we may need to add several KAGs
00204                     while((Remainder > 0) && (Remainder < 17))
00205                     {
00206                         Ret += KAGSize;
00207                         Remainder += KAGSize;
00208                     }
00209                 }
00210             }
00211 
00212             return Ret;
00213         }
00214 
00215 
00217         virtual Position GetCurrentPosition(void);
00218 
00220         virtual DataChunkPtr Read(FileHandle InFile, UInt32 Stream, UInt64 Count = 1);
00221 
00223         virtual EssenceSubParserBase::ESP_EssenceSource *GetEssenceSource(FileHandle InFile, UInt32 Stream, UInt64 Count = 1)
00224         {
00225             return new ESP_EssenceSource(this, InFile, Stream, Count);
00226         };
00227 
00229         virtual Length Write(FileHandle InFile, UInt32 Stream, MXFFilePtr OutFile, UInt64 Count = 1);
00230 
00231 
00233 
00237         // TODO: Fill in the parser name
00238         virtual std::string GetParserName(void) const { return "template"; }
00239 
00240 
00241     protected:
00243         bool CalcWrappingSequence(Rational EditRate);
00244 
00246         MDObjectPtr BuildDescriptor(FileHandle InFile, UInt64 Start = 0);
00247 
00249         size_t ReadInternal(FileHandle InFile, UInt32 Stream, UInt64 Count);
00250     };
00251 
00252 
00254     class TEMPLATE_EssenceSubParserFactory : public EssenceSubParserFactory
00255     {
00256     public:
00258         virtual EssenceSubParserPtr NewParser(void) const { return new TEMPLATE_EssenceSubParser; }
00259     };
00260 }
00261 
00262 #endif // MXFLIB__ESP_TEMPLATE_H

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