IWMSTransportProperties.GetStreamProperties (C#)

banner art

Previous Next

IWMSTransportProperties.GetStreamProperties (C#)

The GetStreamProperties method retrieves properties of a stream.

  • **Note   **This method is available only on Windows Server 2003, Enterprise Edition with Service Pack 1; Windows Server 2003, Datacenter Edition with Service Pack 1; and Windows Server 2008.

Syntax

  void IWMSTransportProperties
  .GetStreamProperties(
  uint  dwStreamId,
  uint  dwAlternateIndex,
  out IWMSContext  ppProps
);

Parameters

dwStreamId

uint that contains the stream ID of the stream.

dwAlternateIndex

uint that contains the unique alternate index of the stream.

ppProps

Reference to an IWMSContext object that contains the properties of the stream.

Return Values

This method does not return a value.

Remarks

If you are using RTSP to stream content, you can retrieve the UDP port number of a connected client. To retrieve this value, you must create a custom event notification plug-in that accesses the RTSP SETUP request sent by the client during the initial setup process. You can then use GetStreamProperties to retrieve an IWMSContext object that contains the transport settings that were defined in the SETUP request.

Example Code

The following example shows how to retrieve the UDP port number of a connected client through the use of a user-defined method. Add WMS_EVENT_SELECT_STREAMS to the list of handled events for your plug-in and call this user-defined method within the IWMSEventNotificationPlugin.OnEvent method.

int GetPortNumber(IWMSCommandContext pCommandCtx)
{
    // Declare variables.
    Guid TransportProperties_Guid = typeof(IWMSTransportProperties).GUID;
    Guid StreamSwitchDescriptionList_Guid = 
                            typeof( IWMSStreamSwitchDescriptionList).GUID;
    object oUnknownXPort; 
    object oUnknownSS;
    int iPortNumber = 0;
    Int64 dwStreamId = -1;
    IWMSContext cmdCtx;
    IWMSContext transCtx;
    IWMSTransportProperties oTransProps;
    IWMSStreamSwitchDescriptionList oSwitchList;
    uint dwCount = 0;

    try
    {
        // Retrieve the command request context.
        pCommandCtx.GetCommandRequest(out cmdCtx);

        // Retrieve an object and explicitly cast it as an 
        // IWMSStreamSwitchDescriptionList object.
        cmdCtx.GetAndQueryIUnknownValue(
                    WMSDefines.WMS_COMMAND_CONTEXT_STREAM_SWITCH, 
                    WMSDefines.WMS_COMMAND_CONTEXT_STREAM_SWITCH_ID, 
                    ref StreamSwitchDescriptionList_Guid,
                    out oUnknownSS, 
                    0);
        oSwitchList = (IWMSStreamSwitchDescriptionList) oUnknownSS;

        // Retrieve the number of stream descriptions in the stream 
        // descriptions list.
        oSwitchList.GetDescriptionCount( out dwCount );

        // After the correct stream is found, retrieve the new stream 
        // number for that stream.
        for( int z=0; z<(int)dwCount; z++)
        {
            CWMSStreamSwitch objStreamSwitch;
            oSwitchList.GetIndexedDescription((uint) z,
                                              out objStreamSwitch);

            if ((objStreamSwitch.ModifierType == 
                            WMS_STREAM_MODIFIERS.WMS_NO_MODIFIER) ||
                            ((objStreamSwitch.ModifierType == 
                            WMS_STREAM_MODIFIERS.WMS_THINNING_MODIFIER) &&
                            ((objStreamSwitch.dwModifier == 0) || 
                            (objStreamSwitch.dwModifier == 1))))
            {
                dwStreamId = objStreamSwitch.dwNewStreamNumber;
                break;
            }
        }

        // Retrieve an object and explicitly cast it as an 
        // IWMSTransportProperties object.
        cmdCtx.GetAndQueryIUnknownValue(
                    WMSDefines.WMS_COMMAND_CONTEXT_TRANSPORT,
                    WMSDefines.WMS_COMMAND_CONTEXT_TRANSPORT_ID,
                    ref TransportProperties_Guid,
                    out oUnknownXPort,
                    0);
        oTransProps = (IWMSTransportProperties) oUnknownXPort;

        // Use the new stream number to retrieve the UDP port number 
        // through the stream properties.
        if (dwStreamId != -1)
        {
            oTransProps.GetStreamProperties((uint)dwStreamId,
                                            0,
                                            out transCtx);

            // Retrieve the UDP port number of the client.
            transCtx.GetLongValue(
                          WMSDefines.WMS_TRANSPORT_CONTEXT_CLIENT_PORT,
                          WMSDefines.WMS_TRANSPORT_CONTEXT_CLIENT_PORT_ID,
                          out iPortNumber,
                          0);
        }
    }
    catch (Exception ex)
    {
        if (!ex.Message.ToLower().StartsWith("invalid index"))
        {
            // TODO: Handle exception.
        }
    }

    // Return the port number.
    return iPortNumber;
}

Requirements

Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition with Service Pack 1; Windows Server 2003, Datacenter Edition with Service Pack 1; Windows Server 2008.

See Also

Previous Next