Creating the Multiplexer Object

The ASF multiplexer is a WMContainer layer object that works with the ASF Data Object and gives an application the ability to generate ASF data packets for media streams.

The multiplexer object exposes the IMFASFMultiplexer interface. To create the multiplexer, call MFCreateASFMultiplexer. This function returns a pointer to an empty object. If the application is writing a new ASF file, the application must initialize the multiplexer with a ContentInfo object. To do this, call IMFASFMultiplexer::Initialize. The specified ContentInfo object represents the ASF Header Object of the new file. For information about creating and initializing the ContentInfo object for a new file, see Initializing the ContentInfo Object of a New ASF File.

The Initialize method parses the ContentInfo object to collect stream configuration information such as the number of streams, packet size, preroll. Optionally, the multiplexer might also need leaky bucket parameters, and the payload extension units. This information is required in order to generate data packets that match the requirements defined in the ASF Header Object. The Initialize method configures the multiplexer based on the media type and configuration settings of the streams. For example, if a stream is configured to have payload extensions (see Creating and Configuring ASF Streams), and then the multiplexer is configured to add those values to the generated data packets.

The Initialize method also gets a handle to the initial data object that was created during the creation of the ContentInfo object for writing. During data packet generation, the multiplexer adds packets to the data object and updates it appropriately. After the multiplexer generates all the data packets, it updates the supplied ContentInfo object so that certain values, such as number of data packets, are updated.

The following code example shows how to create a multiplexer and initialize it with a ContentInfo object.

//-------------------------------------------------------------------
// CreateOutputGenerators
//
// Creates the ASF mux and the ASF Content Info object for the 
// output file.
//-------------------------------------------------------------------

HRESULT CreateOutputGenerators(
    IMFASFProfile *pProfile, 
    IMFASFContentInfo **ppContentInfo, 
    IMFASFMultiplexer **ppMux
    )
{
    IMFASFContentInfo *pContentInfo = NULL;
    IMFASFMultiplexer *pMux = NULL;

    // Use the ASF profile to create the ContentInfo object.
    HRESULT hr = MFCreateASFContentInfo(&pContentInfo);

    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->SetProfile(pProfile);
    }

    // Create the ASF Multiplexer object.
    if (SUCCEEDED(hr))
    {
        hr = MFCreateASFMultiplexer(&pMux);
    }
    
    // Initialize it using the new ContentInfo object.
    if (SUCCEEDED(hr))
    {
        hr = pMux->Initialize(pContentInfo);
    }

    // Return the pointers to the caller.
    if (SUCCEEDED(hr))
    {
        *ppContentInfo = pContentInfo;
        (*ppContentInfo)->AddRef();

        *ppMux = pMux;
        (*ppMux)->AddRef();
    }

    SafeRelease(&pContentInfo);
    SafeRelease(&pMux);

    return hr;
}

To see this function used in a complete application, see Tutorial: Copying ASF Streams from One File to Another.

Multiplexer Initialization and Leaky Bucket Settings

The IMFASFMultiplexer::Initialize method configures the multiplexer to determine the leaky bucket data flow. To configure these parameters, make sure that the following property values are set on the specified ContentInfo object. For information about setting these properties, see Setting Properties in the ContentInfo Object.

  • MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE property: This indicates whether the multiplexer needs to adjust the bit rate automatically, to maintain the data flow in the leaky bucket. This setting can be changed by the application by calling IMFASFMultiplexer::SetFlags and passing the MFASF_MULTIPLEXER_AUTOADJUST_BITRATE flag.

  • MFPKEY_ASFMEDIASINK_BASE_SENDTIME property: The send time indicates when the payload inside the leaky bucket will be released. Send times must be equal to or earlier than the presentation time because the payload must have time to get to the destination before the presentation time.

    This property value is the first send time. The multiplexer uses this value to calculate the subsequent send times to ensure that data flows through the bucket steadily. If the MFASF_MULTIPLEXER_AUTOADJUST_BITRATE flag has been set on the multiplexer, the multiplexer will adjust the bit rate so that the payload is sent out when the buffer window is close to being full. If the flag is not set, the multiplexer fails to generate data packets due to bandwidth overrun.

The multiplexer obtains stream configuration information from the ASF profile associated with the ContentInfo object specified in the Initialize method. The stream configuration information includes leaky bucket parameters. This value is required by the multiplexer to generate data packets.

To specify the leaky bucket parameters, set the values in the MF_ASFSTREAMCONFIG_LEAKYBUCKET1 attribute on the stream configuration object that represents the stream in the profile. To use the buffer window value, which is used by the encoder, call IWMCodecLeakyBucket::GetBufferSizeBits. The actual buffer window value is known only after setting the output media type of the encoder. For information about setting the output media type, see Media Type Negotiation on the Encoder.

Note

The leaky bucket values used by the encoder might be different in the ContentInfo object that was provided by the ASF Profile that was used to create the multiplexer.

 

The Initialize method updates the ContentInfo object so that the correct values are reflected in the final ASF Header Object.

ASF Multiplexer

Generating New ASF Data Packets