00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef MXFLIB__ESP_TEMPLATE_H
00031 #define MXFLIB__ESP_TEMPLATE_H
00032
00033 #include <math.h>
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)
00075 : EssenceSubParserBase::ESP_EssenceSource(TheCaller, InFile, UseStream, Count)
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
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
00114
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
00128
00129
00130
00131
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
00159 bool Ret = CalcWrappingSequence(EditRate);
00160
00161
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
00183 if((ConstSamples == 0) && (SampleSequenceSize == 0)) CalcWrappingSequence(UseEditRate);
00184
00185 UInt32 Ret = SampleSize*ConstSamples;
00186
00187 if(Ret && (SelectedWrapping->ThisWrapType == WrappingOption::Frame))
00188 {
00189
00190 Ret += 16 + 4;
00191
00192
00193 if(KAGSize > 1)
00194 {
00195
00196 UInt32 Remainder = Ret % KAGSize;
00197 if(Remainder) Remainder = KAGSize - Remainder;
00198
00199
00200 Ret += Remainder;
00201
00202
00203
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
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