Available in LEADTOOLS Multimedia toolkits. |
ILMMpgDmx Interface
typedef enum DemuxFlagConstants
{
DemuxFlag_IgnoreCorruptedPackets = 1, /* Ignore corrupted
packets */
}
DemuxFlagConstants;
typedef enum StreamFlagConstants
{
StreamFlag_IsImportant = 0x1, /* This stream is important.
The demux will not start streaming until samples from this stream are
received */
}
StreamFlagConstants;
typedef enum LOADSTATUSConstant
{
AM_LOADSTATUS_PROGRAM_PACKET_RECEIVED = 0x100, /* The demux will send the
EC_LOADSTATUS (0x43) event to the DirectShow graph and set lParam1 to
this value when it identifies the number and type of elementary streams
present in the MPEG2 stream. */
} LOADSTATUSConstant;
Type |
Name |
Description |
|
|
The demultiplexer calls this user callback with event notifications and with the user data packets. |
||
VARIANT_BOOL |
CallInSameThread |
Enables or disables the calling of the ILMMpgDmxCallback notifications in the same thread that set the CallbackObj property. The default value is VARIANT_TRUE. Possible values are: |
|
|
|
Value |
Meaning |
|
|
VARIANT_TRUE |
Call the notifications in the same thread that set the callback. This reduces the performance and requires the application to process messages, otherwise the callback will not get called. It is the default and is required for platforms that have problem with multithreading. VB 6.0 and dotnet applications should use this mode. |
|
|
VARIANT_FALSE |
Call the notifications in any thread of the process. Use this setting for best performance in platforms that can handle this. This is the recommended mode for C/C++ applications. |
VARIANT_BOOL |
IsStreaming |
(Read-only) This property tells you whether you are streaming. Possible values are: |
|
|
|
Value |
Meaning |
|
|
VARIANT_TRUE |
You are streaming. |
|
|
VARIANT_FALSE |
You are playing a file. |
long |
Flags |
This property is a collection of flags that influence the demuxer's behavior. The default value is DemuxFlag_IgnoreCorruptedPackets. The following flags are defined: |
|
|
|
Value |
Meaning |
|
|
DemuxFlag_IgnoreCorruptedPackets |
Ignore corrupted packets. Use this property to minimize the amount of corrupted frames being displayed. When this option is turned on, the video is cleaner but can freeze in streaming situations while the demux is waiting for a good frame. When this option is turned off, the video is smoother, but has more corrupted frames when the stream has lost packets and there is greater instability (more likely to crash). The default is on (the corrupted packets are not displayed). |
double |
StreamPosition |
(Read-only) This property tells you the current stream position, in seconds. The current stream position is position of the video and audio playing on the screen (if the demux is in a play graph). This property is designed to work together with the ConvertPTSToStreamPosition method. See the ConvertPTSToStreamPosition method for more details on how to use this method. |
|
double |
StartStreamOffset |
(Read only) This property represents the start of the stream in bytes. It can change if the source filter uses circular buffer and the playback is stopped and restarted. |
|
double |
BaseStreamOffset |
(Read only) This property represents the base stream offset in bytes. The base stream position is the position of the last seek operation. |
|
double |
CurrentStreamOffset |
This property tells you the current offset in bytes for the main elementary stream The main stream is the video stream (if the MPEG2 stream contains video), or the audio stream (if the MPEG2 stream has audio but not video) or the first stream (if the MPEG2 stream has neither audio or video). Most MPEG2 streams do contain video, so the main stream is usually the video stream.. This property is the file offset for the most recently delivered media sample. You can get or set this property. Setting this property is equivalent to a seeking operation. NOTE: When setting this property it is possible to use negative values to indicate a position relative to the live stream position. Ex: A value of -1024 will be interpreted as 1024 bytes behind the live stream. |
|
double |
FirstStreamOffset |
(Read only) This property represents the offset of the first sample present in the circular buffer queue. Any samples before this position have been overwritten. |
|
double |
LastStreamOffset |
(Read only) This property represents the offset of the last byte in the stream. It also represents the length of the stream. |
|
double |
CurrentStreamPTS |
This property tells you the current stream position in PTS units for the main elementary stream The main stream is the video stream (if the MPEG2 stream contains video), or the audio stream (if the MPEG2 stream has audio but not video) or the first stream (if the MPEG2 stream has neither audio or video). Most MPEG2 streams do contain video, so the main stream is usually the video stream.. You can get or set this property. The current stream PTS is the current presentation timestamp that controls audio / video sample presentation. This property is the presentation time stamp for the most recently delivered media sample. NOTE: When setting this property it is possible to use negative values to specify position relative to the LIVE stream. Ex: A value of -90,000 will be interpreted as last sample time stamp - 90,000, which would be 1 second behind the actual live stream time. See Introduction to the LEADTOOLS DVR Module for more information on presentation time stamps. |
|
double |
BaseStreamPTS |
(Read only) This property represents the base stream position in PTS units. The base stream position is the position after a seek operation. This property is also time adjusted to account for discontinuities in media samples. |
|
double |
FirstStreamPTS |
(Read only) This property represents the first stream position in PTS units. It is the timestamp for the oldest sample present in the circular buffer queue. Any samples prior to the first stream PTS have been overwritten. |
|
double |
LastStreamPTS |
(Read only) This property represents the last stream position in PTS units. The last stream PTS is the timestamp of the last sample available in the circular buffer queue. |
|
double |
StartStreamPTS |
(Read only) This property represents the start stream position in PTS units. The start stream PTS is presentation timestamp of the first sample delivered at the start of streaming. |
|
double |
BaseStreamTime |
(Read only) This property represents the base stream position in seconds. The base stream position is the position in seconds of the last seek operation. |
|
double |
CurrentStreamTime |
This property tells you the current stream position in seconds for the main elementary stream The main stream is the video stream (if the MPEG2 stream contains video), or the audio stream (if the MPEG2 stream has audio but not video) or the first stream (if the MPEG2 stream has neither audio or video). Most MPEG2 streams do contain video, so the main stream is usually the video stream.. This property is the time stamp for the most recently delivered media sample. You can get or set this property. Setting this property is equivalent to a seeking operation. NOTE: When setting this property it is possible to use negative values to indicate a position relative to the live stream position. Ex: A value of -0.5 will be interpreted as 0.5 seconds behind the live stream. See Introduction to the LEADTOOLS DVR Module for more information on presentation time stamps. |
|
double |
FirstStreamTime |
(Read only) This property represents the first stream position in seconds. It is the timestamp for the first sample present in the circular buffer queue. Any samples before this position have been overwritten. |
|
double |
LastStreamTime |
(Read only) This property represents the last stream position in seconds. It is the time of the last sample available in the circular buffer queue. |
|
double |
DurationCheckInterval |
Gets or sets the frequency (in seconds) with which the duration is updated. This property determines how often the internal first and last stream properties are updated. When a circular buffer is used, the internal FirstStreamXXX properties are updated after DurationCheckInterval seconds. Then the internal LastStreamXXX properties are updated DurationCheckInterval seconds later. After DurationCheckInterval seconds the first stream properties are recalculated and so on. The default value is 5 seconds. See Programming With MPEG2 Demux for more information. |
|
long |
Gets the number of streams described in the last program map. |
||
long |
StreamFlags(StreamPID) |
This property is a collection of flags that will determine how the stream is handled by the demultiplexor. This property takes StreamPID as the index parameter. You can use the GetStreamInfo method to get enumerate the streams and obtain the possible values for StreamPID. This is a write-only property and it is useful only while the stream is rendered (ie while you set the SourceFile property of the Playback or Convert object). It is pointless to call this property after the SourceFile has returned. Use this property to reduce the amount of time to start playback if you are not interested in data containing from some streams. By default, StreamFlag_IsImportant is considered to be on, so the demux will wait until data from this stream arrives before starting the playback. This could cause undesired delays. If you wish to reduce the amount of time it takes to the smallest possible value, you can enumerate all the streams present in the MPEG2 stream and set the StreamFlags for all streams except the video stream to 0. But if you do this, you run the risk that some of the streams that you deemed as not important might not be detected. This is designed to work together with the (EC_LOADSTATUS, AM_LOADSTATUS_PROGRAM_PACKET_RECEIVED) event notification. See Programming With MPEG2 Demux for more information. The following flags are defined: |
|
|
|
Value |
Meaning |
|
|
StreamFlag_IsImportant |
If set, this flag is considered important and the demux will wait until it receives some data for it before starting playback. If the data doesn't come within a certain amount of time (picked by the demux), the stream might still be dropped. If not set, the demux will not wait for data from this stream. A pin will be created only if data for this stream is received before all the important streams are identified. So you might still get a pin for this stream, but it is less likely than if the stream was deemed important. |
VARIANT_BOOL |
AutoLive |
Indicates whether the demux should automatically show the live stream. If this property is set to VARIANT_TRUE (AutoLive is enabled), then the demux will automatically jump ahead to the live stream position when it detects it has fallen behind live by more than AutoLiveTolerance seconds. You should enable this feature only if you are streaming. Note that if you enable this property, it will override any seeking commands. If you wish to seek to a position other than live, you should set this property to VARIANT_FALSE and then perform the seeking operation. The default value is VARIANT_FALSE (AutoLive is disabled). The check of the latency to live is made whenever a new LastStream position is detected. This check occurs every 2 * DurationCheckInterval seconds. The following values are defined: |
|
|
|
Value |
Meaning |
|
|
VARIANT_TRUE |
The demux will always try to keep up with the live stream and will automatically jump ahead if it falls behind too much. The playback might not be smooth if the network packets don't come at regular intervals. |
|
|
VARIANT_FALSE |
The demux will play at the normal rate and will allow data to be buffered more if necessary in order to achieve a smooth playback. |
double |
AutoLiveTolerance |
When AutoLive is set to VARIANT_TRUE, this property indicates by how many seconds is the playback allowed to drift back compared to the live stream. If AutoLive is VARIANT_FALSE, this property is ignored. It is not recommended to set this property to a value that is too low, otherwise the playback might become too jerky due to constant playback adjustments. The default value is 0.5. |
Parameters
streamPID |
The stream PID for which you want to receive the KLV parser interface. |
pVal |
A pointer to pointer to an ILMKlvParser interface. This pointer will be updated by the method if successful. |
Description
Use this method to facilitate parsing of KLV data conforming to SMPTE 336M-2001. There might be more than one private data stream and you should use a different parser for each stream. You identify each stream by its PID (-Packet IDentifier-). The PID is usually the same as the streamPID passed to ILMMpgDmxCallback::DataAvailable , but you can pass any value as the streamPID.
The ILMKlvParser interface can be used to easily enumerate the KLV keys and for getting the KLV data. It keeps track of incomplete keys and enumerates them when you get sufficient data.
Returns
S_OK if successful
E _POINTER if ppszFilename is NULL.
E_OUTOFMEMORY if there is not enough memory to create the interface.
Parameters
PTS |
The PTS you are trying to convert. |
pStreamPosition |
A pointer to a double value. This pointer gets updated by the method if successful. |
Description
Use this method to convert a PTS for the current MPEG stream into a stream position (in seconds). The PTS must have come from the current stream; otherwise the conversion will be incorrect. In other words, you cannot use a mpeg demux instance to convert PTS timestamps coming from a stream inside another MPEG demux.
This method it is intended to be used to find the correct display time
for extra data samples received through ILMMpgDmxCallback::DataAvailable
as follows:
1) Call ConvertPTSToStreamPosition(PTS, &PTSStreamPosition) to fill
PTSStreamPosition with the desired stream position.
2) Call get_StreamPosition(¤tStreamPosition) to find the current
stream position. (Add the "get_" prefix as it is usually done
in C++ programs)
3) Determine when to display the data:
a) if PTSStreamPosition >= currentStreamPosition,
then the data is early (the usual case) and you need to wait for PTSStreamPosition
- currentStreamPosition seconds before displaying it.
b) if PTSStreamPosition < currentStreamPosition,
then the data is late and you should display it right away. This is usually
an indication that the video and extra data streams are not multiplexed
properly.
Returns
S_OK if successful
S_FALSE if it fails (in this case, *pCurrentPosition will be set to -1)
Parameters
Flags |
The flags for which bits to update. |
Description
Updates the values of the position properties (CurrentStreamPTS, StartStreamPTS, FirstStreamPTS, LastStreamPTS)
This method is intended to be used to update all PTS, Time and Offset properties.
Important note: You MUST call this method, otherwise
properties like CurrentStreamPTS, CurrentStreamTime and CurrentStreamOffset
never get updated.
Returns
S_OK if successful
S_FALSE if it fails
Parameters
PTS |
The PTS value to be converted. |
pFrame |
A pointer to a double variable that will hold the converted frame number result. This pointer gets updated by the method if successful. |
Description
Converts a PTS value to a frame number.
Use this method to convert a PTS value for the current mpeg stream to a frame number. The PTS must have come from the current stream; otherwise the conversion will be incorrect. In other words, you cannot use a mpeg demux instance to convert PTS timestamps coming from a stream inside another MPEG demux.
Returns
S_OK if successful
S_FALSE if it fails
Parameters
Frame |
A double value containing the frame number to convert. |
pPTS |
A pointer to the double variable that holds the converted PTS value result. This pointer gets updated by the method if successful. |
Description
Converts a frame number value to a PTS value.
Use this method to convert a frame number for the current mpeg stream to a PTS value.
Returns
S_OK if successful
S_FALSE if it fails
Parameters
StreamIndex |
A long value containing the stream index of the desired information. This value should be between 0 and StreamCount - 1. |
|
pStreamID |
A pointer to the long variable that will hold the stream Program identifier. The value pointed to gets updated by the method if successful. |
|
pStreamType |
A pointer to the long variable that will hold the stream type value (stream_type values can be found in Table 2-29 (page 66) of ISO/IEC 13818-1 : 2000 spec). The value pointed to gets updated by the method if successful. A few common stream types are listed in the following table for convenience: |
|
|
Value |
Meaning |
|
0x02 |
MPEG-2 Video |
|
0x03 |
MPEG-2 Audio |
|
0x06 |
PES packets containing private data (usually KLV stream) |
|
0x0F |
AAC Audio |
|
0x10 |
MPEG-4 Video |
|
0x1B |
H.264 Video |
|
0x81 |
User data (can be AC3/LPCM audio) |
Description
Gets information for a specific stream.
Use this method to get the stream's PID, type and descriptor. Use the StreamCount property to determine the number of available elementary streams in the MPEG-2 stream.
It is best to call this method after receiving the EC_LOADSTATUS notification event with the AM_LOADSTATUS_PROGRAM_PACKET_RECEIVED parameter. See the Programming with the MPEG-2 Transport Demultiplexer topic for more details.
Returns
S_OK if successful
S_FALSE if it fails
See also