00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef MXFLIB__KLVOBJECT_H
00033 #define MXFLIB__KLVOBJECT_H
00034
00035
00036
00037 #include <string>
00038 #include <list>
00039 #include <map>
00040
00041
00042
00043 namespace mxflib
00044 {
00045 enum KeyFormat {
00046 KEY_NONE = 0,
00047 KEY_1_BYTE = 1,
00048 KEY_2_BYTE = 2,
00049 KEY_4_BYTE = 4,
00050 KEY_AUTO = 3
00051 };
00052
00053 enum LenFormat
00054 {
00055 LEN_NONE = 0,
00056 LEN_1_BYTE = 1,
00057 LEN_2_BYTE = 2,
00058 LEN_4_BYTE = 4,
00059 LEN_BER = 3
00060 };
00061 }
00062
00063
00064 namespace mxflib
00065 {
00066
00067 class KLVObject;
00068
00070 typedef SmartPtr<KLVObject> KLVObjectPtr;
00071
00073 typedef std::list<KLVObjectPtr> KLVObjectList;
00074
00075 typedef std::map<std::string, KLVObjectPtr> KLVObjectMap;
00076 }
00077
00078
00079 namespace mxflib
00080 {
00082
00084 class KLVReadHandler_Base : public RefCount<KLVReadHandler_Base>
00085 {
00086 public:
00088 virtual ~KLVReadHandler_Base();
00089
00091
00099 virtual size_t ReadData(DataChunk &Buffer, KLVObjectPtr Object, Position Start = 0, size_t Size = static_cast<size_t>(-1)) = 0;
00100
00101
00102
00103 };
00104
00106 typedef SmartPtr<KLVReadHandler_Base> KLVReadHandlerPtr;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00133
00143 class KLVObject : public RefCount<KLVObject>
00144 {
00145 protected:
00146 class KLVInfo
00147 {
00148 private:
00149 KLVInfo(KLVInfo &);
00150
00151 public:
00152 MXFFilePtr File;
00153 Position Offset;
00154 Length OuterLength;
00155 Int32 KLSize;
00156 bool Valid;
00157
00158 KLVInfo()
00159 {
00160 Valid = false;
00161 Offset = -1;
00162 OuterLength = 0;
00163 KLSize = -1;
00164 }
00165
00166 KLVInfo &operator=(const KLVInfo &RHS)
00167 {
00168 Valid = RHS.Valid;
00169 File = RHS.File;
00170 Offset = RHS.Offset;
00171 OuterLength = RHS.OuterLength;
00172 KLSize = RHS.KLSize;
00173
00174 return *this;
00175 }
00176 };
00177
00178 KLVInfo Source;
00179 KLVInfo Dest;
00180
00181 ULPtr TheUL;
00182 Length ValueLength;
00183
00184 DataChunk Data;
00185 Position DataBase;
00186
00187 KLVReadHandlerPtr ReadHandler;
00188
00189
00190
00191
00192
00193 friend class KLVEObject;
00194
00195 public:
00196 KLVObject(ULPtr ObjectUL = NULL);
00197 virtual void Init(void);
00198 virtual ~KLVObject() {};
00199
00201
00204 virtual void SetSource(MXFFilePtr File, Position Location = -1)
00205 {
00206 Source.Valid = true;
00207 Source.File = File;
00208 if(Location < 0) Source.Offset = File->Tell();
00209 else Source.Offset = Location;
00210
00211
00212 if(!Dest.Valid)
00213 {
00214 Dest = Source;
00215 }
00216 }
00217
00219
00222 virtual void SetDestination(MXFFilePtr File, Position Location = -1)
00223 {
00224 Dest.Valid = true;
00225 Dest.File = File;
00226
00227 if(Location < 0) Dest.Offset = File->Tell();
00228 else Dest.Offset = Location;
00229 }
00230
00232 virtual ULPtr GetUL(void) { return TheUL; }
00233
00235 virtual void SetUL(ULPtr NewUL) { TheUL = NewUL; }
00236
00238 virtual Position GetLocation(void) { return Source.Offset; }
00239
00241 virtual std::string GetSource(void);
00242
00244 std::string GetSourceLocation(void)
00245 {
00246 if(!Source.File) return std::string("KLVObject created in memory");
00247 return std::string("0x") + Int64toHexString(GetLocation(),8) + std::string(" in ") + GetSource();
00248 }
00249
00251 virtual Int32 GetKLSize(void) { return Source.KLSize >= 0 ? Source.KLSize : Dest.KLSize; }
00252
00254
00256 virtual void SetKLSize(Int32 NewKLSize) { Dest.KLSize = NewKLSize; }
00257
00259 virtual GCElementKind GetGCElementKind(void) { return mxflib::GetGCElementKind(TheUL); }
00260
00262 virtual UInt32 GetGCTrackNumber(void) { return mxflib::GetGCTrackNumber(TheUL); };
00263
00265
00267 virtual Position GetDataBase(void) { return DataBase; };
00268
00270
00272 virtual void SetDataBase(Position NewBase) { DataBase = NewBase; };
00273
00275
00277 virtual Int32 ReadKL(void) { return Base_ReadKL(); }
00278
00280
00286 Int32 Base_ReadKL(void);
00287
00289
00292 virtual size_t ReadData(size_t Size = static_cast<size_t>(-1)) { return Base_ReadDataFrom(0, Size); }
00293
00295
00299 virtual size_t ReadDataFrom(Position Offset, size_t Size = static_cast<size_t>(-1)) { return Base_ReadDataFrom(Offset, Size); }
00300
00302
00310 inline size_t Base_ReadDataFrom(Position Offset, size_t Size = static_cast<size_t>(-1)) { return Base_ReadDataFrom(Data, Offset, Size); }
00311
00313
00324 size_t Base_ReadDataFrom(DataChunk &Buffer, Position Offset, size_t Size = static_cast<size_t>(-1));
00325
00327
00330 virtual Int32 WriteKL(Int32 LenSize = 0) { return Base_WriteKL(LenSize); }
00331
00333
00341 Int32 Base_WriteKL(Int32 LenSize = 0, Length NewLength = -1);
00342
00343
00345
00348 virtual size_t WriteData(size_t Size = static_cast<size_t>(-1)) { return WriteDataFromTo(0, 0, Size); }
00349
00351
00355 virtual size_t WriteDataFrom(Position Start, size_t Size = static_cast<size_t>(-1)) { return WriteDataFromTo(0, Start, Size); }
00356
00358
00362 virtual size_t WriteDataTo(Position Offset, size_t Size = static_cast<size_t>(-1)) { return WriteDataFromTo(Offset, 0, Size); }
00363
00365
00370 virtual size_t WriteDataFromTo(Position Offset, Position Start, size_t Size = static_cast<size_t>(-1))
00371 {
00372
00373 Length BytesToWrite = Data.Size - Start;
00374
00375
00376 if((Size > 0) && (Size < BytesToWrite)) BytesToWrite = Size;
00377
00378
00379 if((sizeof(size_t) < 8) && (BytesToWrite > 0xffffffff))
00380 {
00381 error("Tried to write > 4GBytes, but this platform can only handle <= 4GByte chunks\n");
00382 return 0;
00383 }
00384
00385 return Base_WriteDataTo(&Data.Data[Start], Offset, static_cast<size_t>(BytesToWrite));
00386 }
00387
00389
00396 virtual size_t WriteDataTo(const UInt8 *Buffer, Position Offset, size_t Size) { return Base_WriteDataTo(Buffer, Offset, Size); }
00397
00399
00408 size_t Base_WriteDataTo(const UInt8 *Buffer, Position Offset, size_t Size);
00409
00410
00412
00414 virtual void SetReadHandler(KLVReadHandlerPtr Handler) { ReadHandler = Handler; }
00415
00416
00417
00418
00419
00420
00422 virtual Length GetLength(void) { return ValueLength; }
00423
00425 virtual void SetLength(Length NewLength) { ValueLength = Dest.OuterLength = Source.OuterLength = NewLength; }
00426
00428 virtual DataChunk& GetData(void) { return Data; }
00429 };
00430 }
00431
00432 #endif // MXFLIB__KLVOBJECT_H