esp_mpeg2ves.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_MPEG2VES_H
00031 #define MXFLIB__ESP_MPEG2VES_H
00032 
00033 
00034 #include <math.h>   // For "floor"
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         // File buffering
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                 // Items end when there is no data remaining from the last read
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         // Give our essence source class privilaged access
00144         friend class MPEG2_VES_EssenceSubParser::ESP_EssenceSource;
00145 
00146     public:
00147         // TODO: Check why properties are not initialised here!
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         // Index table functions
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/*, Index*/);
00199         };
00200 
00202         virtual Length Write(FileHandle InFile, UInt32 Stream, MXFFilePtr OutFile, UInt64 Count = 1/*, IndexTablePtr Index = NULL*/);
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

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