MXFFile Class Reference

Holds data relating to an MXF file. More...

#include <mxffile.h>

Inheritance diagram for MXFFile:

RefCount IRefCount List of all members.

Public Member Functions

 MXFFile ()
 ~MXFFile ()
virtual bool Open (std::string FileName, bool ReadOnly=false)
 Open the named MXF file.
virtual bool OpenNew (std::string FileName)
 Create and open the named MXF file.
virtual bool OpenMemory (DataChunkPtr Buff=NULL, Position Offset=0)
virtual bool Close (void)
 Close the file.
bool ReadRunIn (void)
 Read the files run-in (if it exists).
bool ReadRIP (void)
 Read the RIP from the end of the open MXF file.
bool ScanRIP (Length MaxScan=1024 *1024)
 Build a RIP for the open MXF file by scanning partitions following links back from the footer.
bool BuildRIP (void)
 Build a RIP for the open MXF file by scanning the entire file for partitions.
bool GetRIP (Length MaxScan=1024 *1024)
 Get a RIP for the open MXF.
PartitionPtr ReadMasterPartition (Length MaxScan=1024 *1024)
 Locate and read a partition containing closed header metadata.
PartitionPtr ReadFooterPartition (Length MaxScan=1024 *1024)
 Locate and read the footer partition.
Position Tell (void)
 Report the position of the file pointer.
int Seek (Position Pos)
 Move the file pointer.
int SeekEnd (void)
bool Eof (void)
 Determine if the file pointer is at the end of the file.
DataChunkPtr Read (size_t Size)
 Read data from the file into a DataChunk.
size_t Read (UInt8 *Buffer, size_t Size)
 Read data from the file into a supplied buffer.
MDObjectPtr ReadObject (PrimerPtr UsePrimer=NULL)
PartitionPtr ReadPartition (void)
KLVObjectPtr ReadKLV (void)
 Read a KLVObject from the file.
void WritePartitionPack (PartitionPtr ThisPartition, PrimerPtr UsePrimer=NULL)
 Write a partition pack to the file.
void WritePartition (PartitionPtr ThisPartition, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and associated metadata (no index table segments).
void WritePartitionWithIndex (PartitionPtr ThisPartition, DataChunkPtr IndexData, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and associated metadata and preformatted index table segments.
void WritePartition (PartitionPtr ThisPartition, PrimerPtr UsePrimer, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and associated metadata (no index table segments).
void WritePartitionWithIndex (PartitionPtr ThisPartition, DataChunkPtr IndexData, PrimerPtr UsePrimer, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and associated metadata and preformatted index table segments.
void WritePartition (PartitionPtr ThisPartition, bool IncludeMetadata, PrimerPtr UsePrimer=NULL, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and (optionally) associated metadata (no index table segments).
void WritePartitionWithIndex (PartitionPtr ThisPartition, DataChunkPtr IndexData, bool IncludeMetadata, PrimerPtr UsePrimer=NULL, UInt32 Padding=0, UInt32 MinPartitionSize=0)
 Write a partition pack and (optionally) associated metadata and preformatted index table segments.
bool ReWritePartition (PartitionPtr ThisPartition, PrimerPtr UsePrimer=NULL)
 Re-write a partition pack and associated metadata (no index table segments).
bool ReWritePartitionWithIndex (PartitionPtr ThisPartition, DataChunkPtr IndexData, PrimerPtr UsePrimer=NULL)
 Re-write a partition pack and associated metadata and preformatted index table segments.
void WriteRIP (void)
 Write the RIP.
UInt32 FillerSize (UInt64 FillPos, UInt32 KAGSize, UInt32 MinSize=0)
 Calculate the size of a filler to align to a specified KAG.
UInt32 FillerSize (bool ForceBER4, UInt64 FillPos, UInt32 KAGSize, UInt32 MinSize=0)
 Calculate the size of a filler to align to a specified KAG.
UInt64 Align (UInt32 KAGSize, UInt32 MinSize=0)
 Write a filler to align to a specified KAG.
UInt64 Align (bool ForceBER4, UInt32 KAGSize, UInt32 MinSize=0)
 Write a filler to align to a specified KAG.
ULPtr ReadKey (void)
 Read a Key length from the open file.
Length ReadBER (void)
 Read a BER length from the open file.
UInt32 WriteBER (UInt64 Length, UInt32 Size=0)
 Write a BER length.
size_t Write (const UInt8 *Buffer, size_t Size)
 Write raw data.
size_t Write (const DataChunk &Data)
 Write the contents of a DataChunk by reference.
size_t Write (DataChunkPtr Data)
 Write the contents of a DataChunk by SmartPtr.
void WriteU8 (UInt8 Val)
 Write 8-bit unsigned integer.
void WriteU16 (UInt16 Val)
 Write 16-bit unsigned integer.
void WriteU32 (UInt32 Val)
 Write 32-bit unsigned integer.
void WriteU64 (UInt64 Val)
 Write 64-bit unsigned integer.
void WriteI8 (Int8 Val)
 Write 8-bit signed integer.
void WriteI16 (Int16 Val)
 Write 16-bit signed integer.
void WriteI32 (Int32 Val)
 Write 32-bit signed integer.
void WriteI64 (Int64 Val)
 Write 64-bit signed integer.
UInt8 ReadU8 (void)
 Read 8-bit unsigned integer.
UInt16 ReadU16 (void)
 Read 16-bit unsigned integer.
UInt32 ReadU32 (void)
 Read 32-bit unsigned integer.
UInt64 ReadU64 (void)
 Read 64-bit unsigned integer.
Int8 ReadI8 (void)
 Read 8-bit signed integer (casts from unsigned version).
Int16 ReadI16 (void)
 Read 16-bit signed integer (casts from unsigned version).
Int32 ReadI32 (void)
 Read 32-bit signed integer (casts from unsigned version).
Int64 ReadI64 (void)
 Read 64-bit signed integer (casts from unsigned version).
void SetMemoryBuffer (DataChunkPtr Buff, UInt32 Offset)
void SetBlockAlign (UInt32 Size, Int32 EssenceOffset=0, Int32 IndexOffset=0)
 Set the block alignment block size.
bool IsBlockAligned (void)
 Determine if this file used block alignment.

Public Attributes

RIP FileRIP
DataChunk RunIn
std::string Name

Protected Member Functions

bool WritePartitionInternal (bool ReWrite, PartitionPtr ThisPartition, bool IncludeMetadata, DataChunkPtr IndexData, PrimerPtr UsePrimer, UInt32 Padding, UInt32 MinPartitionSize)
 Write or re-write a partition pack and associated metadata (and index table segments?).
Position ScanRIP_FindFooter (Length MaxScan)
 Scan for the footer.
virtual size_t MemoryWrite (UInt8 const *Data, size_t Size)
 Write to memory file buffer.
virtual size_t MemoryRead (UInt8 *Data, size_t Size)
 Read from a memory file buffer.

Protected Attributes

bool isOpen
 True when the file is open.
bool isMemoryFile
 True is the file is a "memory file".
FileHandle Handle
 File hanlde.
UInt32 RunInSize
 Size of run-in in physical file.
DataChunkPtr Buffer
 Memory file buffer pointer.
UInt64 BufferOffset
 Offset of the start of the buffer from the start of the memory file.
UInt64 BufferCurrentPos
 Offset of the current position from the start of the memory file.
UInt32 BlockAlign
 Some systems can run more efficiently if the essence and index data start on a block boundary - if used this is the block size.
Int32 BlockAlignEssenceOffset
 Fixed distance from the block grid at which to align essence (+ve is after the grid, -ve before).
Int32 BlockAlignIndexOffset
 Fixed distance from the block grid at which to align index (+ve is after the grid, -ve before).

Detailed Description

Holds data relating to an MXF file.


Constructor & Destructor Documentation

MXFFile (  )  [inline]

~MXFFile (  )  [inline]


Member Function Documentation

0 ( |td class="paramkey">
bool Open ( std::string  FileName,
bool  ReadOnly = false 
) [virtual]

Open the named MXF file.

bool OpenNew ( std::string  FileName  )  [virtual]

Create and open the named MXF file.

bool OpenMemory ( DataChunkPtr  Buff = NULL,
Position  Offset = 0 
) [virtual]

bool Close ( void   )  [virtual]

Close the file.

bool ReadRunIn ( void   ) 

Read the files run-in (if it exists).

The run-in is placed in property run-in After this function the file pointer is at the start of the non-run in data

bool ReadRIP ( void   ) 

Read the RIP from the end of the open MXF file.

The new RIP is placed in property FileRIP

Note:
Partition packs will not be loaded. Partition pointers in the new RIP will be NULL

This new RIP will represent what is in the physical file so any data in memory will not be considered

The current contents of FileRIP will be destroyed

bool ScanRIP ( Length  MaxScan = 1024*1024  ) 

Build a RIP for the open MXF file by scanning partitions following links back from the footer.

The new RIP is placed in property FileRIP

Note:
Each partition pack will be loaded and referenced from the new RIP

This new RIP will represent what is in the physical file so any data in memory will not be considered

The current contents of FileRIP will be destroyed

How the file is scanned

An ideal file will not need scanning because it will contain a RIP (handled by ReadRIP).

The next best situation is for the header to hold the location of the footer in the FooterPartition property. If this is the case the scan will happen as follows:

  1. The header is read to locate the footer
  2. The footer is read, and added to the RIP
  3. The PreviousPartition property is used to locate the previous partition
  4. The previous partition is read, and added to the RIP

If the last partition processed was not the header then goto step 3

If the header doesn't hold the location of the footer then a search is performed to find the footer. This is somewhat optimised and is performed as follows:

Each 4Kb block is scanned forwards (CPU optimisations work better scanning forwards) looking for bytes with the value 0x06

If the lookup shows this as a footer then the search is over and steps 2-5 of the above method are used

TODO: There should be some way to scan without loading every partition into memory (it could be millions!) TODO: We could read the IndexSID as we go and build an enhanced RIP or Greater-RIP

bool BuildRIP ( void   ) 

Build a RIP for the open MXF file by scanning the entire file for partitions.

The new RIP is placed in property FileRIP

Note:
Each partition pack will be loaded and referenced from the new RIP

This new RIP will represent what is in the physical file so any data in memory will not be considered

The current contents of FileRIP will be destroyed

bool GetRIP ( Length  MaxScan = 1024*1024  ) 

Get a RIP for the open MXF.

The RIP is read using ReadRIP() if possible. Otherwise it is Scanned using ScanRIP(). If that fails it is built the hard way using BuildRIP().

PartitionPtr ReadMasterPartition ( Length  MaxScan = 1024 *1024  ) 

Locate and read a partition containing closed header metadata.

NULL if none found

PartitionPtr ReadFooterPartition ( Length  MaxScan = 1024 *1024  ) 

Locate and read the footer partition.

NULL if not found

Position Tell ( void   )  [inline]

Report the position of the file pointer.

int Seek ( Position  Pos  )  [inline]

Move the file pointer.

int SeekEnd ( void   )  [inline]

bool Eof ( void   )  [inline]

Determine if the file pointer is at the end of the file.

DataChunkPtr Read ( size_t  Size  ) 

Read data from the file into a DataChunk.

size_t Read ( UInt8 Buffer,
size_t  Size 
)

Read data from the file into a supplied buffer.

MDObjectPtr ReadObject ( PrimerPtr  UsePrimer = NULL  )  [inline]

PartitionPtr ReadPartition ( void   )  [inline]

KLVObjectPtr ReadKLV ( void   ) 

Read a KLVObject from the file.

void WritePartitionPack ( PartitionPtr  ThisPartition,
PrimerPtr  UsePrimer = NULL 
)

Write a partition pack to the file.

The property "ThisPartition" is updated to reflect the correct location in the file

Note:
This function only writes the partition pack, unlike WritePartition which writes the metadata (and index table segments as well - possibly)

void WritePartition ( PartitionPtr  ThisPartition,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and associated metadata (no index table segments).

void WritePartitionWithIndex ( PartitionPtr  ThisPartition,
DataChunkPtr  IndexData,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and associated metadata and preformatted index table segments.

Note:
The value of IndexSID must be set prior to calling WritePartitionWithIndex

void WritePartition ( PartitionPtr  ThisPartition,
PrimerPtr  UsePrimer,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and associated metadata (no index table segments).

void WritePartitionWithIndex ( PartitionPtr  ThisPartition,
DataChunkPtr  IndexData,
PrimerPtr  UsePrimer,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and associated metadata and preformatted index table segments.

Note:
The value of IndexSID must be set prior to calling WritePartitionWithIndex

void WritePartition ( PartitionPtr  ThisPartition,
bool  IncludeMetadata,
PrimerPtr  UsePrimer = NULL,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and (optionally) associated metadata (no index table segments).

void WritePartitionWithIndex ( PartitionPtr  ThisPartition,
DataChunkPtr  IndexData,
bool  IncludeMetadata,
PrimerPtr  UsePrimer = NULL,
UInt32  Padding = 0,
UInt32  MinPartitionSize = 0 
) [inline]

Write a partition pack and (optionally) associated metadata and preformatted index table segments.

Note:
The value of IndexSID must be set prior to calling WritePartitionWithIndex

bool ReWritePartition ( PartitionPtr  ThisPartition,
PrimerPtr  UsePrimer = NULL 
) [inline]

Re-write a partition pack and associated metadata (no index table segments).

Note:
Partition properties are updated from the linked metadata
Returns:
true if re-write was successful, else false

bool ReWritePartitionWithIndex ( PartitionPtr  ThisPartition,
DataChunkPtr  IndexData,
PrimerPtr  UsePrimer = NULL 
) [inline]

Re-write a partition pack and associated metadata and preformatted index table segments.

Note:
Partition properties are updated from the linked metadata
Returns:
true if re-write was successful, else false

bool WritePartitionInternal ( bool  ReWrite,
PartitionPtr  ThisPartition,
bool  IncludeMetadata,
DataChunkPtr  IndexData,
PrimerPtr  UsePrimer,
UInt32  Padding,
UInt32  MinPartitionSize 
) [protected]

Write or re-write a partition pack and associated metadata (and index table segments?).

Note:
Partition properties are updated from the linked metadata
Returns:
true if (re-)write was successful, else false

Length of the partition pack for calculating block alignment

Essence BodySID for calculating block alignment

Length of block alignment padding after the header metadata (if required)

Length of block alignment padding after the index table (if required)

Previous partition if re-writing

void WriteRIP ( void   )  [inline]

Write the RIP.

UInt32 FillerSize ( UInt64  FillPos,
UInt32  KAGSize,
UInt32  MinSize = 0 
) [inline]

Calculate the size of a filler to align to a specified KAG.

UInt32 FillerSize ( bool  ForceBER4,
UInt64  FillPos,
UInt32  KAGSize,
UInt32  MinSize = 0 
)

Calculate the size of a filler to align to a specified KAG.

Note: Maximum supported filler size is 0x00ffffff bytes

UInt64 Align ( UInt32  KAGSize,
UInt32  MinSize = 0 
) [inline]

Write a filler to align to a specified KAG.

UInt64 Align ( bool  ForceBER4,
UInt32  KAGSize,
UInt32  MinSize = 0 
)

Write a filler to align to a specified KAG.

Returns:
The position after aligning

ULPtr ReadKey ( void   ) 

Read a Key length from the open file.

Length ReadBER ( void   ) 

Read a BER length from the open file.

Returns:
-1 on error

UInt32 WriteBER ( UInt64  Length,
UInt32  Size = 0 
) [inline]

Write a BER length.

Parameters:
Length The length to be written
Size The total number of bytes to use for BER length (or 0 for auto)
Note:
If the size is specified it will be overridden for lengths that will not fit. However an error message will be produced.

size_t Write ( const UInt8 Buffer,
size_t  Size 
) [inline]

Write raw data.

size_t Write ( const DataChunk Data  )  [inline]

Write the contents of a DataChunk by reference.

size_t Write ( DataChunkPtr  Data  )  [inline]

Write the contents of a DataChunk by SmartPtr.

void WriteU8 ( UInt8  Val  )  [inline]

Write 8-bit unsigned integer.

void WriteU16 ( UInt16  Val  )  [inline]

Write 16-bit unsigned integer.

void WriteU32 ( UInt32  Val  )  [inline]

Write 32-bit unsigned integer.

void WriteU64 ( UInt64  Val  )  [inline]

Write 64-bit unsigned integer.

void WriteI8 ( Int8  Val  )  [inline]

Write 8-bit signed integer.

void WriteI16 ( Int16  Val  )  [inline]

Write 16-bit signed integer.

void WriteI32 ( Int32  Val  )  [inline]

Write 32-bit signed integer.

void WriteI64 ( Int64  Val  )  [inline]

Write 64-bit signed integer.

UInt8 ReadU8 ( void   )  [inline]

Read 8-bit unsigned integer.

UInt16 ReadU16 ( void   )  [inline]

Read 16-bit unsigned integer.

UInt32 ReadU32 ( void   )  [inline]

Read 32-bit unsigned integer.

UInt64 ReadU64 ( void   )  [inline]

Read 64-bit unsigned integer.

Int8 ReadI8 ( void   )  [inline]

Read 8-bit signed integer (casts from unsigned version).

Int16 ReadI16 ( void   )  [inline]

Read 16-bit signed integer (casts from unsigned version).

Int32 ReadI32 ( void   )  [inline]

Read 32-bit signed integer (casts from unsigned version).

Int64 ReadI64 ( void   )  [inline]

Read 64-bit signed integer (casts from unsigned version).

void SetMemoryBuffer ( DataChunkPtr  Buff,
UInt32  Offset 
) [inline]

void SetBlockAlign ( UInt32  Size,
Int32  EssenceOffset = 0,
Int32  IndexOffset = 0 
) [inline]

Set the block alignment block size.

bool IsBlockAligned ( void   )  [inline]

Determine if this file used block alignment.

Position ScanRIP_FindFooter ( Length  MaxScan  )  [protected]

Scan for the footer.

Returns:
The location of the footer, or 0 if scan failed

size_t MemoryWrite ( UInt8 const *  Data,
size_t  Size 
) [protected, virtual]

Write to memory file buffer.

Note:
This can be overridden in classes derived from MXFFile to give different memory write behaviour

size_t MemoryRead ( UInt8 Data,
size_t  Size 
) [protected, virtual]

Read from a memory file buffer.

Note:
This can be overridden in classes derived from MXFFile to give different memory read behaviour


Member Data Documentation

bool isOpen [protected]

True when the file is open.

bool isMemoryFile [protected]

True is the file is a "memory file".

FileHandle Handle [protected]

File hanlde.

UInt32 RunInSize [protected]

Size of run-in in physical file.

DataChunkPtr Buffer [protected]

Memory file buffer pointer.

UInt64 BufferOffset [protected]

Offset of the start of the buffer from the start of the memory file.

UInt64 BufferCurrentPos [protected]

Offset of the current position from the start of the memory file.

UInt32 BlockAlign [protected]

Some systems can run more efficiently if the essence and index data start on a block boundary - if used this is the block size.

Int32 BlockAlignEssenceOffset [protected]

Fixed distance from the block grid at which to align essence (+ve is after the grid, -ve before).

Int32 BlockAlignIndexOffset [protected]

Fixed distance from the block grid at which to align index (+ve is after the grid, -ve before).

RIP FileRIP

DataChunk RunIn

std::string Name


The documentation for this class was generated from the following files:
Generated on Mon Apr 2 15:21:01 2007 for MXFLib by  doxygen 1.5.1-p1