Microsoft KB Archive/824088

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

Article ID: 824088

Article Last Modified on 9/7/2004

-

APPLIES TO


 * Windows Media Services 9 Series Software Development Kit
 * 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, &quot;WMS_PRESENT_ALLOCATED_BANDWIDTH&quot;, 30 )

// Type: long // Description: Bandwidth allocated by network sink. DEFINE_NAME_AND_HINT( WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK, &quot;WMS_PRESENT_BANDWIDTH_ALLOCATED_BY_NETWORKSINK&quot;, 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;

