Microsoft DirectX 9.0

DSNetwork Filters Sample

Description

The DSNetwork sample shows how to multicast an MPEG-2 transport stream. It includes two related filters:

Both filters support a custom interface, IMulticastConfig, for setting the multicast address and Network Interface Card (NIC) address.

Path

Source: (SDK root)\Samples\C++\DirectShow\Filters\DSNetwork

User's Guide

To use this sample, compile and build the Visual Studio project. It creates a DLL named dsnet.ax in the Filter\Debug or Filter\Release subdirectories. Use the Regsvr32 utility to register the DLL.

You will need an MPEG-2 transport stream in push mode. This can be a digital television tuner, an IEEE 1394 MPEG-2 camcorder, or anything else that delivers an MPEG-2 transport stream (other than a file source). You will need two graphs, a sending graph and a receiving graph.

You can test the filters in GraphEdit as follows:

  1. Launch GraphEdit and create the sending graph. Connect the MPEG-2 source to the Multicast Sender filter. You may need additional filters to connect them; the details will depend on the source.

    Multicast Sender graph

    If the source is a network provider, the graph must have a TIF filter. Use the Infinite Pin Tee filter to split the transport stream, and send one stream to the TIF (through the MPEG-2 Demultiplexer) and the other stream to the Multicast Sender.

    Multicast Sender graph with network provider

  2. Use the property page on the Multicast Sender to set the desired multicast address, port, and NIC.
  3. Run the graph. If you have a tool that monitors multicast packets, this is useful to make sure the graph is actually delivering data.
  4. Launch a second instance of GraphEdit and create the receiving graph. Connect the Multicast Receiver to the MPEG-2 Demultiplexer.

    Multicast Receiver graph

  5. Use the property page on the Multicast Receiver to set the IP address, port, and NIC. These must match the settings that you used for the Multicast Sender.
  6. Use the property page on the Demultiplexer filter to create one or more output pins. Map the transport stream PIDs to the appropriate pins. (You will need to know the PID mappings in the original source stream, or use the PSI Parser Filter Sample.)
  7. Render the output pins on the demux and run the graph.

An application should use the IMulticastConfig interface to configure the Multicast Sender and Receiver filters. Both filters expose this interface.

Call IMulticastConfig::SetMulticastGroup to set the multicast address and the port number. Both numbers must be in network byte order; the Windows Sockets library has some helper functions for converting them into the correct byte order. For example, the following code configures the filter for the multicast address 235.1.1.1, port number 5000:

// IP address.
const char ip_address[] = "235.1.1.1";
unsigned long ulIP = inet_addr(ip_address);
if (ulIP == INADDR_NONE)
{
    cout << "Invalid IP address: " << ip_address << "\n";
    return;
}
// Port number.
unsigned short usPort = htons(5000);
hr = pConfig->SetMulticastGroup(ulIP, usPort);
if (FAILED(hr))
{
    cout << "SetMulticastGroup failed\n";
    return;
}

The inet_addr function converts a "dot notation" string into network byte order, and the htons function converts the port number (represented as an unsigned short).

Next, call IMulticastConfig::SetNetworkInterface to specify the Network Interface Card (NIC) address. You will need to use the Windows Sockets library to obtain a list of valid NIC addresses on the user's system. You can use the CInterface class, defined in the DSNetwork sample, as a starting point. The following example uses this class to get the NIC address:

CInterface NIC;
hr = NIC.Initialize();
if (FAILED(hr))
{
    cout << "Could not initialize the NIC helper class\n";
    return;
}
// Use the first NIC address in the list.
unsigned long ulNIC = NIC[0]->iiAddress.AddressIn.sin_addr.S_un.S_addr;
hr = pConfig->SetNetworkInterface(ulNIC);
if (FAILED(hr))
{
    cout << "SetNetworkInterface failed: " << ulNIC << "\n";
    return;
}

For information about configuring the MPEG-2 Demultiplexer filter in the receiving graph, see Using the MPEG-2 Demultiplexer.

See Also