Bewerken

Delen via


Supported Protocols

Media Foundation supports the following protocols:

  • Real Time Streaming Protocol (RTSP)

    RTSP is mainly used for streaming media content. It can use UDP or TCP as transport protocols. UDP is the most efficient for content delivery because the bandwidth overhead is less than with TCP-based protocols. Even though the TCP protocol ensures reliable packet delivery, TCP is not well suited for digital media streams, where efficient use of bandwidth is more important than occasional lost packets.

  • Hypertext Transfer Protocol (HTTP)

    HTTP uses TCP and is used by web servers. The "httpd://" scheme indicates that the source is downloadable from a web server. HTTP is also used in case of firewalls, which are usually configured to accept HTTP requests and typically reject other streaming protocols.

The application can get the protocols supported by Media Foundation by using the IMFNetSchemeHandlerConfig interface. To do this, the application must first retrieve the number of protocols, by calling IMFNetSchemeHandlerConfig::GetNumberOfSupportedProtocols and then get the protocol type based on the index by calling IMFNetSchemeHandlerConfig::GetSupportedProtocolType. This method returns one of the values defined in the MFNETSOURCE_PROTOCOL_TYPE enumeration.

The application can also get the schemes supported by the source resolver by calling the MFGetSupportedSchemes function.

Protocol Rollover

When an application specifies "mms://" as the URL scheme, the source resolver performs a protocol rollover operation. In this process, the source resolver determines the best protocol for the network source to use for getting the content. Typically, for media steaming, RTSP with UDP (RTSPU) is more efficient than HTTP. However, if the content is hosted on a web server, HTTP is a better choice.

Protocol rollover can also occur when an attempt to use the protocol specified in the URL scheme fails. For example, a protocol can fail when a firewall blocks UDP packets. In this case, the source resolver switches to HTTP.

Protocol rollover does not apply if the URL scheme contains a specific protocol, such as "rtspu://". Also, rollover is not performed if authentication fails or the server has reached a limit of client connections. It is recommended that applications specify the "mms://" scheme and allow the source resolver to select the best protocol for the scenario.

The following table lists the rollover order.

Schemes allowed Protocol rollover order
mms:// or rtsp:// Fast Cache enabled:
  1. RTSP with TCP (RTSPT)
  2. RTSP with UDP (RTSPU)
  3. HTTP Streaming
  4. HTTP download (HTTPD)
Fast Cache disabled:
  1. RTSPU
  2. RTSPT
  3. HTTP Streaming
  4. HTTP Download
rtspu:// RTSPU
rtspt:// RTSPT
https://
  1. HTTP
  2. HTTPD
httpd:// HTTPD

 

Retrieving the Current Protocol

After a protocol rollover operation, the network source might use a protocol other than the one specified by the application in the URL scheme. The protocol rollover result is available to the application after the network source establishes the connection with the media server.

To get the protocol and transport that are used for getting the content, the application can retrieve the property values for the MFNETSOURCE_PROTOCOL property and the MFNETSOURCE_TRANSPORT property of an IPropertyStore object from the network source.

The following code shows how to get these values.

// Create an IPropertyStore object.
    IPropertyStore *pProp = NULL;
    hr = CreatePropertyStore(&pProp);

    PROPVARIANT var;
    PropVariantInit(&var);

// Get the property store from the network source.
// The network source is created by the source resolver. Not shown.
    if (SUCCEEDED(hr))
    {
        hr = pNetworkSource->QueryInterface 
                (__uuidof(IPropertyStore), 
                (void**)&pProp);
    }
    if (SUCCEEDED(hr))
    {
        // Create a property key.
        PROPERTYKEY key;
        // Get the MFNETSOURCE_PROTOCOL property value.
        key.fmtid = MFNETSOURCE_PROTOCOL;
        hr = pProp->GetValue (key, &var);

        // Get the MFNETSOURCE_TRANSPORT property value.
        key.fmtid = MFNETSOURCE_TRANSPORT;
        key.pid = 0;
        hr = pProp->GetValue (key, &var);

    }

In the preceding example code, IPropertyStore::GetValue retrieves the MFNETSOURCE_PROTOCOL value, which is a member of the MFNETSOURCE_PROTOCOL_TYPE enumeration. For MFNETSOURCE_TRANSPORT, the value is a member of the MFNETSOURCE_TRANSPORT_TYPE enumeration.

Alternately, the application can get the same values by using the MFNETSOURCE_STATISTICS_SERVICE service. To use this service, the application can call the MFGetService function to get the property store from the network source. This property store contains network statistics in the MFNETSOURCE_STATISTICS property. Protocol and transport values can be retrieved by specifying MFNETSOURCE_PROTOCOL_ID and MFNETSOURCE_TRANSPORT_ID—defined in the MFNETSOURCE_STATISTICS_IDS enumeration. The following code shows how to get the protocol and transport values by using the MFNETSOURCE_STATISTICS_SERVICE service.

// Create an IPropertyStore object.
    IPropertyStore *pProp = NULL;
    hr = CreatePropertyStore(&pProp);

    HRESULT hr = S_OK;

    hr = MFGetService(
        pMediaSource, 
        MFNETSOURCE_STATISTICS_SERVICE, 
        IID_IPropertyStore, 
        (void**) & pProp); 

    if (SUCCEEDED(hr))
    {
        // Create a property key.
        PROPERTYKEY key;
        // Get the property value.
        key.fmtid = MFNETSOURCE_STATISTICS;
        key.pid = MFNETSOURCE_PROTOCOL_ID;
        hr = pProp->GetValue (key, &var);

        // Get the transport value.
        key.fmtid = MFNETSOURCE_STATISTICS;
        key.pid = MFNETSOURCE_TRANSPORT_ID;
        hr = pProp->GetValue (key, &var);

    }

Enabling and Disabling Protocols

The application can configure the network source so that certain protocols are skipped during the rollover process. To do this, network source properties are used to disable specific protocols. The following table shows the properties and the protocols they control.

Property Description
MFNETSOURCE_ENABLE_HTTP Enables or disables HTTP and HTTPD.
MFNETSOURCE_ENABLE_RTSP Enables or disables RTSPU and RTSPT.
MFNETSOURCE_ENABLE_TCP Enables or disables RTSPT.
MFNETSOURCE_ENABLE_UDP Enables or disables RTSPU.
MFNETSOURCE_ENABLE_DOWNLOAD Enables or disables HTTPD.
MFNETSOURCE_ENABLE_STREAMING Enables or disables RTSPU, RTSPT, and HTTP.

 

Networking in Media Foundation