How To Determine Per-Client Bandwidth Usage with the Windows Media Services 9 Series SDK (824088)



The information in this article applies to:

  • Microsoft Windows Media Services 9 Series SDK
  • Microsoft Windows Media Services 9 Series

SUMMARY

Sometimes it is useful to know how much bandwidth an individual client that is connected to the server is using. Sometimes the bandwidth that is used may be more than the bitrate of the content because of features such as Fast Start and Fast Cache. This article describes how to add context values that a developer can use to retrieve this information programmatically.

MORE INFORMATION

To determine the most accurate per-client bandwidth statistics in Windows Media Services 9 Series, you must define the following two presentation context values. You must add these values to either a header file in the project or to WmsContextNames.h.
// Type: long
// Description: Bandwidth allocated.
DEFINE_NAME_AND_HINT( WMS_PRESENT_ALLOCATED_BANDWIDTH, "WMS_PRESENT_ALLOCATED_BANDWIDTH", 30 )

// Type: long
// Description: Bandwidth allocated by network sink.
DEFINE_NAME_AND_HINT( WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK, "WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK", 48)
After you have added the presentation context values, you can use the client's presentation context to quickly determine the total bandwidth usage by retrieving both values and then adding the totals together. The following code example shows how to do this:
// Declare variables.
long lSinkAllocatedBandwidth = 0;
long lDatapathAllocatedBandwidth = 0;
long lTotalBandwidth = 0;

hr = pPresentationContext->GetLongValue(
                        WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK,
                        WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK_ID,
                        &lSinkAllocatedBandwidth,
                        0);
if( FAILED( hr ) )
{
   hr = S_OK;
   lSinkAllocatedBandwidth = 0;
}

hr = pPresentationContext->GetLongValue(
                       WMS_PRESENT_ALLOCATED_BANDWIDTH,
                       WMS_PRESENT_ALLOCATED_BANDWIDTH_ID,
                       &lDatapathAllocatedBandwidth,
                       0);
if( FAILED( hr ) )
{
   hr = S_OK;
   lDatapathAllocatedBandwidth = 0;
}

lTotalBandwidth = lSinkAllocatedBandwidth + lDatapathAllocatedBandwidth;

REFERENCES

For more information, see the Windows Media Services 9 Series SDK documentation.

Modification Type:MinorLast Reviewed:9/7/2004
Keywords:kbDSWWMM2003Swept kbinfo KB824088 kbAudDeveloper