Available as an Add-on to LEADTOOLS Multimedia toolkits. |
ILMKlvBuilder Interface
The ILMKlvBuilder interface is provided by the LEAD MPEG-2 Transport Multiplexer to simplify the task of parsing KLV data. It can be obtained from the multiplexer by reading the ILMMpg2MxT::KlvBuilder property.
typedefenum Mpg2MxT_SearchKey
{
Mpg2MxT_SearchKey_Exact = 1, /*
Find only the exact key. The key version number must match. */
Mpg2MxT_SearchKey_AnyVersion = 2, /*
Ignore the version number when doing the search. */
Mpg2MxT_SearchKey_DesignatorOnly = 3, /* Find the key
by the designator only. Ignore the key representation and version number
*/
} Mpg2MxT_SearchKey;
typedefenum Mpg2MxT_Errors
{
Mpg2MxT_E_KEY_NOT_FOUND = 0x80050010, /*
The KLV data was not found */
Mpg2MxT_E_BAD_KEY = 0x80050011, /*
The KLV key is bad */
} Mpg2MxT_Errors;
Type |
Property name |
Description |
long |
Count |
The number of complete top-level KLV keys contained in the internal interface buffer. An incomplete KLV key will not be included in the count. |
HRESULT AddData(VARIANT Data, long lDataLengh);
Parameters
Data |
Variant containing the private data. |
DataLength |
The size of data contained in Data. |
Description
Use this method to begin building private data containing KLV packets. It is particularly useful from ILMMpgDmxCallback::DataAvailable when processing a source file containing KLV data. Build up the KLV data using this method and then edit the individual keys afterwards. This method appends the supplied data to the internal buffer. You should call the Clear method to restart the process. The Data parameter must contain a pointer to a byte array. The AddData method uses the smaller of the DataLength parameter and the actual array size.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
E_POINTER [0x80004003] Data is NULL
E_INVALIDARG [0x80070057] Data is not a byte array variant
Parameters
ppBuilder |
A pointer to a location to store a new builder interface pointer. |
Description
Creates an independent builder for constructing subkeys.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
E_POINTER |
[0x80004003] ppBuilder is NULL |
Parameters
keyIndex |
The index of the key to delete. The index is 0-based, so allowed values are 0..Count – 1. |
Description
Deletes an existing key.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
DISP_E_BADINDEX |
[0x8002000B] keyIndex is invalid. |
Parameters
KeyToFind |
Variant describing which key to look for. |
searchFlags |
One of the flags in the Mpg2MxT_SearchKey enumeration. These flags tell the parser how whether the match should be exact or not. |
pKey |
Pointer to a VARIANT that will be updated with a key describing the data. The key will be a 16-byte array describing the variant data. This key tells you how to interpret the key data contained in pKeyData. |
pKeyData |
Pointer to a VARIANT that will be updated key data. The key data will be a byte array variant regardless of the real format of the key data. |
pDataSize |
Pointer to a long variable that will be updated with the number of bytes stored in pKeyData. This is the same as the size of the pKeyData variant. |
Description
Use searchFlags to specify whether you require an exact match for the key for which you are looking. Possible values for searchFlags are:
Mpg2MxT_SearchKey_Exact |
An exact match is required. All 16 bytes of the key must match. |
Mpg2MxT_SearchKey_AnyVersion |
For a match to be acceptable, all key bytes must match, with the exception of the version key (the 7th byte). |
Mpg2MxT_SearchKey_DesignatorOnly |
For a match to be acceptable, the key designator component must match. The key designator is stored in the last 8 bytes of the key. |
This function goes through the top keys in the buffer and compares them with the key passed in KeyToFind. If the key from the buffer matches exactly or partially (if permitted by searchFlags), then the key found is stored in pKey, the key data is stored in pKeyData and the key length is stored in pDataSize.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
E_POINTER |
[0x80004003] pKey, pKeyData or pDataSize is NULL. |
Mpg2MxT_E_KEY_NOT_FOUND |
[0x80050010] There is no key matching KeyToFind and searchFlags. |
E_OUTOFMEMORY |
[0x8007000E] Could not allocate memory for the pKey or pKeyData variants. |
Parameters
KeyToFind |
String describing which key to look for. |
searchFlags |
One of the flags in the Mpg2MxT_SearchKey enumeration. These flags tell the parser whether the match should be exact or not. |
pKey |
Pointer to a VARIANT that will be updated with a key describing the data. The key will be a 16-byte array describing the variant data. This key tells you how to interpret the key data contained in pKeyData. |
pKeyData |
Pointer to a VARIANT that will be updated key data. The key data will be a byte array variant regardless of the real format of the key data. |
pDataSize |
Pointer to a long variable that will be updated with the number of bytes stored in pKeyData. This is the same as the size of the pKeyData variant. |
Description
This method works exactly like FindKey, except that the key to search for is passed as a string, rather than a VARIANT.
KeyToFind is a string containing a hexadecimal representation of the bytes in the key. Each byte should be represented by two hexadecimal digits. Each digit can be:
‘0’..’9’ or
‘a’..’f’ or
‘A’..’F’
Space characters are ignored. For example, “06 0E 2B 34 01 0101 04 07 02 01 0101 05 00 00” is equivalent to “060E2B34010101040702010101050000”.
For more information on each parameter, see the description for FindKey.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
E_POINTER |
[0x80004003] pKey, pKeyData or pDataSize is NULL. |
Mpg2MxT_E_KEY_NOT_FOUND |
[0x80050010] There is no key matching KeyToFind and searchFlags. |
E_OUTOFMEMORY |
[0x8007000E] Could not allocate memory for the pKey or pKeyData variants. |
Mpg2MxT_E__BAD_KEY |
[0x80050011] The key string is invalid: the key string should contain a hexadecimal representation of a 16-byte value, with 2 digits per byte (32 digits total). |
Parameters
Data |
Pointer to a variant that is filled with a byte array copy of the current data. |
Description
Creates a copy of the current data.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
E_POINTER [0x80004003] Data is NULL
E_OUTOFMEMORY [0x80070057] The array for the copy could not be allocated.
keyIndex |
The index of the key to retrieve. The index is 0-based, so allowed values are 0..Count – 1 |
pKey |
Pointer to a VARIANT that will be updated with a key describing the data. The key will be a 16-byte array describing the variant data. This key tells you how to interpret the key data contained in pKeyData. |
pKeyData |
Pointer to a VARIANT that will be updated key data. The key data will be a byte array variant regardless of the real format of the key data. |
pDataSize |
Pointer to a long variable that will be updated with the number of bytes stored in pKeyData. This is the same as the size of the pKeyData variant. |
Description
Use this method to enumerate all the keys contained in a private data sample. This method enumerates all the data passed to AddData.
The method allocates data for the pKey and pKeyData variants. You should make sure you free the memory allocated in these variants if your programming language does not do so automatically. For example, VB automatically frees this memory, but C/C++ does not. In C++, you free the variant memory by calling VariantClear. Please consult the documentation for your programming language for more information on how to free the variant data.
You should examine pKey to find out how to interpret the key data. The IKlvBuilder will not interpret the key data for you. There is not a single document describing all the KLV keys that you might find in a stream. You will find various documents describing certain lists of currently defined keys. But each company that generates MPEG-2 transport streams or files might write their own internal keys in a private data stream. At the time of writing this documentation, the following documents contained information on KLV keys and how to interpret their content:
UAV Datalink Local Metadata Set (EG 0601 12 Jan 2006)
Predator UAV Basic Universal Metadata Set (MISB EG 0104.4 25 August 2005)
Based on information on this and other documents that you might find, you should interpret the key data accordingly. For example:
Key: 06 0E 2B 34 01 0101 04 07 02 01 0101 05 00 00
Is a “User Defined Time Stamp (microseconds since 1970)” in msb bit order and that the key should be 8 bytes long. In this case, you should verify that *pDataSize is 8. If *pDataSize is 8, you should convert the 8-byte array into a 64-bit unsigned integer (or a double floating point if your programming language does not support 64-bit integers). You would then convert the 64-bit value into a date and time by counting the microseconds since 1970.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
DISP_E_BADINDEX |
[0x8002000B] keyIndex is invalid (< 0). |
E_POINTER |
[0x80004003] pKey, pKeyData or pDataSize is NULL. |
Mpg2MxT_E_KEY_NOT_FOUND |
[0x80050010] The key was not found (keyIndex >= Count). |
E_OUTOFMEMORY |
[0x8007000E] Could not allocate memory for the pKey or pKeyData variants. |
Parameters
keyIndex |
The index of the keys insertion point. The index is 0-based, so allowed values are 0..Count – 1. However, a special value of -1 will append the key to the end of the current data. |
Key |
VARIANT a key describing the data. The key will be a 16-byte array describing the variant data. This key tells you how to interpret the key data contained in KeyData. |
KeyData |
VARIANT containing key data. The key data will be a byte array variant regardless of the real format of the key data. |
DataSize |
Long variable describing the number of bytes stored in KeyData. This is the same as the size of the KeyData variant. |
Description
Inserts a new key.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
DISP_E_BADINDEX |
[0x8002000B] keyIndex is invalid. |
E_OUTOFMEMORY |
[0x8007000E] Could not allocate memory for the new data. |
Parameters
keyIndex |
The index of the key to replace. The index is 0-based, so allowed values are 0..Count – 1 |
Key |
VARIANT a key describing the data. The key will be a 16-byte array describing the variant data. This key tells you how to interpret the key data contained in KeyData. |
KeyData |
VARIANT containing key data. The key data will be a byte array variant regardless of the real format of the key data. |
DataSize |
Long variable describing the number of bytes stored in KeyData. This is the same as the size of the KeyData variant. |
Description
Replaces an existing key.
Returns
S_OK if successful, < 0 if an error occurred.
Common error codes:
Value |
Meaning |
DISP_E_BADINDEX |
[0x8002000B] keyIndex is invalid. |
E_OUTOFMEMORY |
[0x8007000E] Could not allocate memory for the new data. |