Microsoft DirectX 9.0 |
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:
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.
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