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_MPEG2VES_H
00031 #define MXFLIB__ESP_MPEG2VES_H
00032
00033
00034 #include <math.h>
00035
00036 #define MPEG2_VES_BUFFERSIZE 8192
00037
00038 namespace mxflib
00039 {
00041 class MPEG2_VES_EssenceSubParser : public EssenceSubParserBase
00042 {
00043 protected:
00044 Rational NativeEditRate;
00045 Rational SelectedEditRate;
00046 unsigned int EditRatio;
00047
00048 Position PictureNumber;
00049 Position AnchorFrame;
00050
00051 size_t CachedDataSize;
00052 UInt64 CachedCount;
00053
00054 Position CurrentPos;
00055
00057 int GOPOffset;
00058
00060 bool ClosedGOP;
00061
00062
00063 UInt8 Buffer[MPEG2_VES_BUFFERSIZE];
00064 int BuffCount;
00065 UInt8 *BuffPtr;
00066
00067 bool EditPoint;
00068
00071 bool SelectiveIndex;
00072
00073 bool EndOfStream;
00074
00075 MDObjectParent CurrentDescriptor;
00076
00078 public:
00080 class ESP_EssenceSource : public EssenceSubParserBase::ESP_EssenceSource
00081 {
00082 protected:
00083 size_t BytesRemaining;
00084
00085 public:
00087 ESP_EssenceSource(EssenceSubParserPtr TheCaller, FileHandle InFile, UInt32 UseStream, UInt64 Count = 1)
00088 : EssenceSubParserBase::ESP_EssenceSource(TheCaller, InFile, UseStream, Count)
00089 {
00090 BytesRemaining = 0;
00091 };
00092
00094
00096 virtual size_t GetEssenceDataSize(void)
00097 {
00098 MPEG2_VES_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, MPEG2_VES_EssenceSubParser);
00099
00100 if(pCaller->SelectedWrapping->ThisWrapType == WrappingOption::Clip) return pCaller->ReadInternal(File, Stream, 0);
00101
00102 return pCaller->ReadInternal(File, Stream, RequestedCount);
00103 };
00104
00106
00111 virtual DataChunkPtr GetEssenceData(size_t Size = 0, size_t MaxSize = 0);
00112
00114
00120 virtual bool EndOfItem(void)
00121 {
00122
00123 return !BytesRemaining;
00124 }
00125
00127 virtual int GetBERSize(void)
00128 {
00129 MPEG2_VES_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, MPEG2_VES_EssenceSubParser);
00130
00131 if(pCaller->SelectedWrapping->ThisWrapType == WrappingOption::Clip) return 8;
00132 return 4;
00133 }
00134
00136 virtual bool IsEditPoint(void)
00137 {
00138 MPEG2_VES_EssenceSubParser *pCaller = SmartPtr_Cast(Caller, MPEG2_VES_EssenceSubParser);
00139 return pCaller->EditPoint;
00140 }
00141 };
00142
00143
00144 friend class MPEG2_VES_EssenceSubParser::ESP_EssenceSource;
00145
00146 public:
00147
00148 MPEG2_VES_EssenceSubParser()
00149 {
00150 CachedDataSize = static_cast<size_t>(-1);
00151 CachedCount = 0;
00152
00153 EditPoint = false;
00154 EndOfStream = false;
00155 }
00156
00158 virtual EssenceSubParserPtr NewParser(void) const { return new MPEG2_VES_EssenceSubParser; }
00159
00161 virtual StringList HandledExtensions(void);
00162
00164 virtual EssenceStreamDescriptorList IdentifyEssence(FileHandle InFile);
00165
00167 virtual WrappingOptionList IdentifyWrappingOptions(FileHandle InFile, EssenceStreamDescriptor &Descriptor);
00168
00170 virtual void Use(UInt32 Stream, WrappingOptionPtr &UseWrapping);
00171
00173 virtual bool SetEditRate(Rational EditRate);
00174
00176 virtual Rational GetEditRate(void) { return SelectedEditRate; }
00177
00179 virtual Position GetCurrentPosition(void);
00180
00181
00182
00183
00185
00186 virtual void SetIndexManager(IndexManagerPtr &TheManager, int StreamID = 0)
00187 {
00188 EssenceSubParserBase::SetIndexManager(TheManager, StreamID);
00189 TheManager->SetPosTableIndex(StreamID, -1);
00190 }
00191
00193 virtual DataChunkPtr Read(FileHandle InFile, UInt32 Stream, UInt64 Count = 1);
00194
00196 virtual EssenceSourcePtr GetEssenceSource(FileHandle InFile, UInt32 Stream, UInt64 Count = 1)
00197 {
00198 return new ESP_EssenceSource(this, InFile, Stream, Count);
00199 };
00200
00202 virtual Length Write(FileHandle InFile, UInt32 Stream, MXFFilePtr OutFile, UInt64 Count = 1);
00203
00205
00206 virtual bool SetOption(std::string Option, Int64 Param = 0);
00207
00209
00213 virtual std::string GetParserName(void) const { return "mpeg2ves"; }
00214
00215 protected:
00217 MDObjectPtr BuildMPEG2VideoDescriptor(FileHandle InFile, UInt64 Start = 0);
00218
00220 size_t ReadInternal(FileHandle InFile, UInt32 Stream, UInt64 Count);
00221
00223 int BuffGetU8(FileHandle InFile);
00224 };
00225
00226 }
00227
00228
00229 #endif // MXFLIB__ESP_MPEG2VES_H