Quality-Control Management
Quality control is a mechanism for adjusting the rate of data flow through the filter graph in response to run-time performance. If a renderer filter is receiving too much data or too little data, it can send a quality message. The quality message requests an adjustment in the data rate. By default, quality messages travel upstream from the renderer until they reach a filter that can respond (if any). An application can also implement a custom quality manager. In that case, the renderer passes quality messages directly to the application's quality manager.
This topic addresses the following subjects:
- Quality Messages
- Default Quality Control
Quality Messages
Quality messages are defined with the Quality structure. This structure contains the following members:
- Type: Either Famine, indicating that the filter is receiving too little data, or Flood, indicating that the filter is receiving too much data.
- Proportion: The requested adjustment in the data rate, from a baseline of 1000. For example, 750 indicates 75% and 1500 indicates 150%.
- Late: Reference time indicating how late the most recent sample arrived. The value is negative if the sample arrived early.
- TimeStamp: The time stamp on the most recent sample.
For example, suppose that a sample with a time stamp of 240 milliseconds (ms) reaches the renderer at 280 ms, stream time. The renderer creates a quality message of type Famine. The sample arrived 40 ms late, so the **Late****member is 400000. (All reference times are in 100-nanosecond units.) The TimeStamp member is 2400000.
For the Proportion member, the renderer might use a running average to calculate the value. Perhaps samples have been arriving on time, and this sample is an anomaly. In that case the renderer might request only a small correction. On the other hand, if samples are consistently late, the renderer might request a larger correction.
Quality control is handled through the IQualityControl interface. It contains two methods:
An object that implements IQualityControl receives quality messages through its Notify method. It can either handle the message or pass the message to another object. If the application calls the object's SetSink method, the object should delegate quality control to the specified quality manager.
Default Quality Control
The filter base classes implement some default behaviors for video quality control.
Quality messages start at the renderer. The base class for video renderers is CBaseVideoRenderer, which has the following behavior:
When the video renderer receives a sample, it compares the time stamp on the sample with the current reference time.
The video renderer generates a quality message. In the base class, the Proportion member of the quality message is limited to a range of 500 (50%) to 2000 (200%). Values outside this range could result in abrupt quality changes.
By default, the video renderer sends the quality message to the upstream output pin (the pin connected to its input pin). Applications can override this behavior by calling the SetSink method.
What happens next depends on the upstream filter. Typically, this is a transform filter. The base class for transform filters is CTransformFilter, which uses the CTransformInputPin and CTransformOutputPin classes to implement input and output pins. Together, these classes have the following behavior:
The CTransformOutputPin::Notify method calls CTransformFilter::AlterQuality, a private method on the filter base class.
Derived filters can override AlterQuality to handle the quality message. By default, AlterQuality ignores the quality message.
If AlterQuality does not handle the quality message, the output pin calls CBaseInputPin::PassNotify, a private method on the filter's input pin.
PassNotify passes the quality message to the appropriate place — the next upstream output pin, or a custom quality manager.
Assuming that no transform filter handles the quality message, the message eventually reaches the output pin on the source filter. In the base classes, CBasePin::Notify returns E_NOTIMPL. How a particular source filter handles quality messages depends on the nature of the source. Some sources, such as live video capture, cannot perform meaningful quality control. Other sources can adjust the rate at which they deliver samples.
The base video renderer implements IQualityControl::Notify, which means you can pass quality messages to the renderer itself. If you set the Proportion member to a value less than 1000, the video renderer inserts a wait period between each frame that it renders, in effect slowing down the renderer. (You might do this to reduce system usage, for example.) For more information, see CBaseVideoRenderer::ThrottleWait. Setting the Proportion member to a value greater than 1000 has no effect.
Last updated on Wednesday, April 13, 2005
© 2005 Microsoft Corporation. All rights reserved.