Working with TV Tuners in DirectShow

Working with TV Tuners in DirectShow

Although the DirectShow filters that provide TV tuner functionality are as easy to use as any other DirectShow filters because their internal operations are effectively hidden from view the filter graphs created can be enormously complex. For example, the WinCap application creates the filter graph shown in Figure 7-1 when my ATI Rage Theatre Video Capture device is selected.

figure 7-1 the directshow filter graph created for a tv tuner, which contains 11 filters

Figure 7-1. The DirectShow filter graph created for a TV tuner, which contains 11 filters

No fewer than 11 filters are required to fully implement a TV tuner in DirectShow and that s without any capture or buffering capabilities that we might want in a PVR. However, this number of filters is a pretty common state of affairs for TV tuners, and although your own filter graphs might be less complex depending on the TV tuner hardware and its associated drivers your filter graphs are likely to be at least this crowded with filters. We ll walk through this filter graph step-by-step to get a sense of how the TV data stream passes from capture to display. Again, your own filter graphs might look a bit different.

To begin with, the ATI TV Tuner filter acts as a control node where the programmer can set the tuner channel and adjust other hardware features of the tuner card. Although the filter graph shows streams for Analog Video and Analog Audio, these streams are just abstractions and are not flowing through the filter graph. Nonetheless, a lot of processing can be done on these abstract signals before they enter the filter graph, so the Analog Audio output pin is connected to the TV Audio In input pin on the ATI TV Audio filter. This filter controls the audio capabilities of the stream. Broadcast television can be received in either monaural or stereo sound, and this filter can switch between these two modes. In addition, many broadcasts also have a Secondary Audio Program (SAP), often in a foreign language (in the United States, generally Spanish), and the ATI TV Audio filter can also be used to choose between audio channels. Within the filter, these audio channels are identified as Language A and Language B.

The TV Audio Out pin of the ATI TV Audio filter and the Analog Video output pin of the ATI TV Tuner are connected, respectively, to the Audio Tuner In pin and Video Tuner In pin of the ATI TV Audio Crossbar. A crossbar, a hardware feature found on many TV tuner cards, routes various analog inputs across the hardware (in this case, the ATI Rage 8500 TV Tuner card) to determine which of several inputs will be sent to the hardware that translates the analog signal into a digital data stream. These signals are then passed to another crossbar, the ATI Rage Video Theatre Crossbar filter; the Video Tuner Out pin is connected to the Video Tuner In pin, the Video SVideo Out pin is connected to the Video SVideo In pin, and the Video Composite Out pin (which contains both audio and video signals) is passed to the Video Composite In pin. This filter passes the signal through to a single output pin on the ATI Rage Video Theatre Crossbar filter, Video Decoder Out. After everything has been correctly routed by the crossbar circuitry of the TV tuner, the hardware begins the process of analog-to-digital conversion.

The Capture Filter has four output pins. The VBI pin (named after the vertical blanking interval) is used for closed captioning (CC), the text description and narration that s carried within most broadcast TV signals for people who are hard of hearing, which can be decoded by nearly all televisions manufactured after 1995. (If you ve never seen how closed captioning works, launch WinCap and select a TV tuner device. You ll see closed captioning in action because it s enabled by default in WinCap. If you don t see any text overlaid across the video image, try changing channels the program you re viewing might not have closed captioning.)

The output of the VBI pin is passed along to the Communication Transform input pin of the Tee/Sink-to-Sink Converter filter. Like the Smart Tee and Infinite Tee, this filter creates multiple output streams from a single input stream. The signal is divided into two streams, each presented on a Splitter output pin. One of these outputs is passed along to the CC Decoder filter, which translates the VBI signal into closed-captioning data. (If you re working with international TV signals, DirectShow supports World Standard Teletext level 1.5, but you ll have to consult the Microsoft DirectX SDK documentation for details on how to decode that signal.) The closed-captioning data (pairs of bytes) is passed along through the CC output pin to the input pin of the Line 21 Decoder filter, a standard DirectShow filter that translates the closed-captioning data into a bitmap with the closed-captioned text drawn onto it. That stream is presented on the filter s output pin.

The VPVBI output pin is directly connected to a specialized DirectShow filter, the VBI Surface Allocator. The VBI Surface Allocator filter reserves some space within the dedicated graphics memory of the TV tuner card (which, in this case, is also a video display card) so that the decoded VBI signal can be written directly to a hardware buffer on the graphics card. Although it s not a renderer filter, the VBI Surface Allocator has no downstream connections to other filters although it does have an output pin, Null, that connects to nothing else.

Now that the closed-captioning data has been successfully decoded, it s brought into Input 2 of the Overlay Mixer filter, which mixes text captioning data with a video stream. There are two situations in which you re likely to encounter a mix of video and text streams: closed-captioned TV broadcasts, as explored here, and DVD playback when the subtitling feature has been turned on. The third output pin on the Capture filter, VP (for video port), which provides the digitized video stream from the TV tuner, is connected to Input 1 on the Overlay Mixer filter.

The video port connection between the Capture filter and the Overlay Mixer filter is performed using kernel streaming to pass the bits very quickly from one filter to the other. Kernel streaming has always been a core feature of DirectX because it allows slow computers (such as those of just a few years ago) to handle high bit-rate devices, such as video digitizers. The downside of kernel streaming through a video port is that it s not possible to add filters into the stream between the Capture filter and the Overlay Mixer. The video port connection is dedicated and can t be interfered with in any way. Now that computers have gotten much faster, video ports are being deemphasized by Microsoft and will soon be a thing of the past, but as of this writing, many TV tuners support capture through a video port.

The connection of video and closed-captioning streams to the Overlay Mixer creates a text overlay (closed captioning) on the broadcast video image. Finally the Output pin of the Overlay Mixer filter is connected to the Input pin on the Video Renderer (which we ve seen many times before), and the filter graph is complete. The TV signal has been received, processed, digitized, broken into separate streams for video and closed captioning, and then recombined into a single video image. In this case, the Overlay Mixer is doing the actual on-screen rendering of the digitized TV signal, while the Video Renderer is managing only the on-screen window in which the video appears.

Although there s no explicit path for audio rendering in this filter graph, when the filter graph is run, audio does come through the speakers. How does this happen? There s a bit of magic in the ATI TV Audio Crossbar hidden from view that connects the audio output to the appropriate sound hardware and keeps it all properly synchronized.

Now that we ve walked through a filter graph for a TV tuner, let s turn back to WinCap to gain an understanding of the DirectShow programming that creates these complex filter graphs. It s easier to do than you might think. Note that what follows applies only to analog TV signals. DirectShow has a set of filters designed for digital television and high-definition television (HDTV), but they re well beyond the scope of this book. If you d like more information on those filters, you can find it in the DirectX SDK documentation.

Video Control

When creating TV applications, an alternative approach is to use the Video Control, an ActiveX control that supports analog TV tuners, DVD, file playback, and also a new generation of digital TV tuners based on the Microsoft Broadcast Driver Architecture (BDA). The Video Control is used in Windows XP Media Center Edition, and in many ways, it greatly simplifies the creation of TV filter graphs. In this chapter, we build a TV application the old-fashioned way to demonstrate the underlying concepts that the Video Control hides from view. Also, this chapter doesn t cover digital TV support. At the time of writing, digital TV tuners are not yet widely available. That situation is expected to change in the near future, however, so if you re looking to create a digital TV application, or even an analog TV application using Microsoft Visual Basic or a scripting language, check out the DirectShow SDK documentation under Microsoft TV Technologies.



Programming Microsoft DirectShow for Digital Video and Television
Programming Microsoft DirectShow for Digital Video and Television (Pro-Developer)
ISBN: 0735618216
EAN: 2147483647
Year: 2002
Pages: 108
Authors: Mark D. Pesce

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net