IFileSinkFilter Interface

Interface Methods:

HRESULT GetCurFile(LPOLESTR *ppszFileName, AM_MEDIA_TYPE *pmt);

Parameters

ppszFileName

A valid pointer to a pointer that will receive a copy of the URL string. This cannot be NULL.

pmt

A pointer to an AM_MEDIA_TYPE structure. This pointer is optional and you can pass NULL if you do not need the media type.

Description

Gets the current URL string. This string contains the IP address, the port and (optional) the network card address. See the SetFileName method for more information on the format of the URL string.

If the function succeeds, the ppszFileName pointer will be updated with a pointer to a buffer containing the URL. This buffer has been allocated with CoTaskMemAlloc. You are responsible for freeing this buffer when you are done with it by calling CoTaskMemFree.

If the function succeeds and you set pmt to a valid pointer to AM_MEDIA_TYPE structure, this structure will be initialized with a copy of the stream media type. You are responsible for freeing the data allocated in this structure by calling the FreeMediaType function. Please refer to the Microsoft documentation for more information on this function.

Returns

S_OK if successful, < 0 if an error occurred.

Common error codes:

Value

Meaning

E_POINTER

ppszFilename is NULL

 

HRESULT SetFileName(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt);

Parameters

pszFileName

A valid pointer to a buffer containing the URL of the stream. This cannot be NULL.

pmt

A pointer to an AM_MEDIA_TYPE structure indicating the media type of the data being streamed. This pointer can be NULL, in which case a default media type will be assumed.

Description

This function sets the URL of UDP or TCP stream. This string specifies the:

1.       IP address of the server sending the data

2.       (Optional) The UDP or TCP port on which the data will be received. If no port is specified, 9005 will be used.

3.       (Optional) The IP address of network card receiving the data. If no network card is specified, the default network connection will be used. This can be used only with multicast UDP streaming.

The format of the string for UDP streaming is as follows:

   udp://ip_address[:udp_port][/network_card]

 ip_address

The IP address where the data should be sent to. This can be in the usual Ipv4 format (xx.xx.xx.xx) or it can be a valid host address accepted by the standard function inet_addr. For example, localhost is equivalent to 127.0.0.1

The stream is considered to be multicast if the first number in the Ipv4 address is between 224..239 (0xE0 .. 0xEF). If the first number is not in this range, the stream is unicast.

The stream is considered to be broadcast if the last number is 255. For example, streaming to 10.1.1.255 will send to all the computers whose IP address starts with 10.1.1

network_card

(Optional) The address of the network card receiving the data. This is optional – if it is missing, the default network card will be used. This is used only for multicast streams.

udp_port

(Optional) The port on which to send data to. The port must be a number from 1 to 65535. Note that you must make sure the port is open if you are running firewall software. If you do not specify a port number, 9005 will be used.

 

The format of the string for TCP streaming is as follows:

 

ip_address

The IP address of on which to listen for connections and send the data. This can be in the usual Ipv4 format (xx.xx.xx.xx) or it can be a valid host address accepted by the standard function inet_addr. For example, localhost is equivalent to 127.0.0.1. This is usually the IP address of the sending (server) computer.

TCP streams cannot be multicast or broadcast. All TCP streams are assumed to be unicast.

tcp_port

(Optional) The port on which to listen. The port must be a number from 1 to 65535. Note that you must make sure the port is open if you are running firewall software. If you do not specify a port number, 9005 will be used.

 

Examples of valid strings:

udp://127.0.0.1:9005 – send the Unicast UDP stream to 127.0.0.1 (local computer) on port 9005

udp://224.1.1.1:9005/20.5.1.200 - send the Multicast UDP stream 224.1.1.1 on port 9005 using the network card with the IP address of 20.5.1.200

udp://10.1.1.255:9005 - send the Broadcast UDP stream on port 9005 to all computers with an IP address of 10.1.1.x

tcp://127.0.0.1:9005 – send the TCP stream from 127.0.0.1 (local computer) on port 9005

Note that you can find out the IP addresses of the network connections on your computer on Windows XP by typing the ipconfig command at the DOS prompt. For more information on obtaining your machine's host name, refer to How to Get Your Own IP Address Programmatically.

One might want to use a particular network card if you have two network connections and one is faster than the other. For example, a laptop might be connected to the network with a wireless network card and a regular network wire. In this case, it would be better to using the wired connection because it is faster and more reliable.

You should keep in mind that not all the routers will forward multicast and broadcast UDP packets. In most cases, UDP packets will not be sent out of the current network. This makes UDP unsuitable for streaming over the Internet. For streaming over the Internet, use TCP streaming.

The packets of data in TCP streaming are guaranteed to reach the remote destination and are resent if packets are lost. This means TCP streaming requires higher bandwidth than UDP streaming. Also, a bottleneck in the network traffic could impact the server performance. You should weigh the advantages and disadvantages of UDP vs TCP when you pick which type of streaming you should use.

In TCP streaming mode, the server will disconnect a remote client if it has not read any data in a certain amount of time.

Only one connection at a time is supported for TCP streaming.

Returns

S_OK if successful, < 0 if an error occurred.   

Common error codes:

Value

Meaning

E_OUTOFMEMORY

(0x8007000E) Out of memory

E_FAIL                                                                           

 (0x80004005) Unspecified error

HRESULT_FROM_WIN32(xxx)

Windows error xxx has occurred. You can consult the Microsoft documentation for the definition of the HRESULT_FROM_WIN32 macro and the complete list of Windows error codes.