ILMFMpgSource Interface

Data Types

DemuxFlagConstants

Summary

Specifies whether to enable or disable ignore corrupted packets.

Syntax

typedef enum DemuxFlagConstants 
{ 
   DemuxFlag_IgnoreCorruptedPackets = 1, /* Ignore corrupted packets */ 
} DemuxFlagConstants; 

StreamFlagConstants

Summary

Specifies how important the stream is handled by the demultiplexor.

Syntax

typedef enum StreamFlagConstants 
{ 
   StreamFlag_IsImportant = 0x1, /* This stream is important. The demux will not start streaming until samples from this stream are received */ 
} StreamFlagConstants; 

LOADSTATUSConstant

Summary

Enumeration values are used with the EC_LOADSTATUS DirectShow event to provide status of a load operation.

Syntax

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; 

FindSampleConstants

Summary

Specifies the sample to search for.

Syntax

typedef enum FindSampleConstants 
{ 
   FindSample_NearestKeyFrame = 0,  /* Search for nearest key frame.  */ 
   FindSample_NextKeyFrame = 1,     /* Search for next key frame.     */ 
   FindSample_PreviousKeyFrame = 2, /* Search for previous key frame. */ 
} FindSampleConstants; 

ProgramInfoConstants

Summary

Specifies the attribute to retrieve.

Syntax

typedef enum ProgramInfoConstants 
{ 
   ProgramInfo_ProgramMapPID = 0,	        /* PID of Program Map containing the program */ 
   ProgramInfo_Name	 = ( ProgramInfo_ProgramMapPID + 1 ),			/* Program Name */ 
   ProgramInfo_StreamCount = ( ProgramInfo_Name + 1 ),		/* Number of streams in this Program */ 
   ProgramInfo_SummaryInfo = ( ProgramInfo_StreamCount + 1 ),		/* Program Summary Info */ 
   ProgramInfo_DetailedInfo = ( ProgramInfo_SummaryInfo + 1 )		/* Program Detailed Info */ 
} ProgramInfoConstants; 

Properties

Type Name Description
IUnknown * CallbackObj The media source calls this user callback with event notifications and with the user data packets.
VARIANT_BOOL CallInSameThread Enables or disables the calling of the ILMFMpgSourceCallback notifications in the same thread that set the CallbackObj property. The default value is VARIANT_TRUE. Possible values are:
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 problems with multithreading. VB 6.0 and .NET 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:
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:
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
double CurrentStreamOffset This property tells you the current offset in bytes for the main elementary 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 1: 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.
NOTE 2: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
double LastStreamOffset (Read only) This property represents the offset of the last byte in the stream. It also represents the length of the stream.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
double CurrentStreamPTS This property tells you the current stream position in PTS units for the main elementary 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 1: 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.
NOTE 2: This position is updated only when the RefreshPosition method is called.
If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called.
If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called.
If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called.
If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called.
If you do not call RefreshPosition, this property will not change its value.
double CurrentStreamTime This property tells you the current stream position in seconds for the main elementary 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 1: 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.
NOTE 2: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
NOTE: This position is updated only when the RefreshPosition method is called. If you do not call RefreshPosition, this property will not change its value.
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.
long StreamCount 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.
The following flags are defined:
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 does not 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:
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 do not 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.

Methods

HRESULT GetKlvSubkeyParser(VARIANT Key, ILMKlvParser **pVal);

Parameters

VARIANT Key

A variant value that holds the group's key.

ILMKlvParser **pVal

A pointer to pointer to an ILMKlvParser interface. This pointer will be updated by the method if successful.

Description

Gets an ILMKlvParser interface for a certain group. Use this method to facilitate parsing of KLV data conforming to SMPTE 336M-2001.

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 connected; otherwise, S_FALSE.

HRESULT EventNotification(EventNotificationConstants lEventType, double Param1, double Param2);

Parameters

EventNotificationConstants lEventType

Type of event. See the EventNotificationConstants enumeration for possible values.

double Param1

First parameter. The value depends on the type of event. See the EventNotificationConstants enumeration to see which events use this parameter.

double Param2

Second parameter. The value depends on the type of event. See the EventNotificationConstants enumeration to see which events use this parameter.

Description

This method is called when certain events occur. See the EventNotificationConstants enumeration to see which events are currently defined.

Returns

S_OK if connected; otherwise, S_FALSE.

HRESULT GetKlvParser (long streamPID, ILMKlvParser **pVal);

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 ILMFMpgSourceCallback::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.

HRESULT ConvertPTSToStreamPosition(double PTS, double *pStreamPosition);

Members

Value Meaning
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 ILMFMpgSourceCallback::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:
    • if PTSStreamPosition >= currentStreamPosition, then the data is early (the usual case) and you need to wait for PTSStreamPosition - currentStreamPosition seconds before displaying it.
    • 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)

HRESULT RefreshPosition(long Flags);

Parameters

Value Meaning
Flags The flags for which bits to update.

Description

Updates the values of the position properties (BaseStreamXXX, CurrentStreamXXX, StartStreamXXX, FirstStreamXXX, LastStreamXXX), where XXX indicates be PTS, Time and Offset version of the properties.

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.

Here is the complete list of properties updated by this method:

BaseStreamPTS, CurrentStreamPTS, StartStreamPTS, FirstStreamPTS, LastStreamPTS 
 
BaseStreamTime, CurrentStreamTime, StartStreamTime, FirstStreamTime, LastStreamTime 
 
BaseStreamOffset, CurrentStreamOffset, StartStreamOffset, FirstStreamOffset, LastStreamOffset   

Returns

S_OK if successful

S_FALSE if it fails

HRESULT ConvertPTSToFrame(double PTS, double *pFrame);

Parameters

Value Meaning
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

HRESULT ConvertFrameToPTS(double Frame, double *pPTS);

Parameters

Value Meaning
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

HRESULT GetStreamInfo(long streamIndex, long *pStreamPID, long *pStreamType, VARIANT *pStreamDescriptor);

Parameters

Value Meaning
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.

Returns

S_OK if successful

S_FALSE if it fails

Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Transforms C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.