Chapter 17. Getting Started with the IndigoVideo Library

This chapter describes the features and capabilities of the IndigoVideo board and presents an annotated sample program that displays live video input in a graphics window to help you get started with the IndigoVideo Library.

In this chapter:

For an introduction to basic video concepts, read Chapter 11, “Video Basics,” in Part III, “Video Programming,” and consult the Glossary at the end of this guide for definitions of video terms.

IndigoVideo Basics

This section describes the IndigoVideo board and its I/O interface.

IndigoVideo

The IndigoVideo board attaches to the Indigo Entry Graphics board in your Indigo workstation. On the back of the board is an I/O panel with a number of video connectors, which you can use to attach video devices to the IndigoVideo board. The IndigoVideo board translates video signals into a form usable by the IRIS Indigo workstation. It also does the reverse, translating graphics from the IRIS Indigo display into video signals.

Broadcast Standards

The IndigoVideo hardware supports the two most popular broadcast standards, the National Television Systems Committee (NTSC) composite video standard and the Phase Alternated by Line (PAL) standard.

Video and Videotape Formats

You can record video signals in a variety of videotape formats: S-VHS and Hi-8mm are two examples of common videotape formats. Although IndigoVideo doesn't distinguish between individual tape formats, you need to know what kind of connector your video equipment uses. The IndigoVideo board has two kinds of input connectors: composite and S-Video.

Most home VCRs use composite connectors. S-Video, on the other hand, carries the color and brightness components of the picture on separate wires; hence, S-Video connectors are also called Y/C connectors. Most S-VHS and Hi-8mm VCRs feature S-Video connectors.

In addition to composite and S-Video output, the IndigoVideo board provides analog RGB output, in which the image data is carried as three separate components: red, green, and blue intensity. The RGB output can be used in conjunction with an external encoder to produce formats that IndigoVideo does not support, or it can be used to drive an external video monitor.

See “Videotape Formats” in Chapter 11 for more information about videotape formats, which are summarized in Table 11-1 in that chapter.

IndigoVideo Data Formats

This section describes the image data formats used by IndigoVideo. IndigoVideo uses three formats for image data: 32-bit RGB, 8-bit RGB, and 4:1:1 YUV. You should note that data coming from or going to the IndigoVideo board is always ordered top-to-bottom. The IRIS Indigo, on the other hand, commonly stores image data with lines ordered bottom-to-top. Both IRIS Indigo and IndigoVideo store pixels from left to right within lines.

In the diagrams that follow, the bits are numbered from right to left, with the least significant (rightmost) bit numbered zero.

32-bit RGB

IndigoVideo uses 32-bit RGB format for single frame output, and it is produced by some of the video capture convenience routines. This format could also be called 24-bit RGB data, since each 32-bit pixel consists of 24 bits of RGB data and 8 bits of unused space.

The format of these pixels is shown in Figure 17-1.

Figure 17-1. Format of 32-bit RGB Pixels


32-bit RGB is produced by the functions svCaptureOneFrame(), svYUVtoRGB(), and svRGB8toRGB32(). The IRIS GL lrectwrite() function also uses this format, but it expects rows of pixels to be ordered bottom-to-top unless the default ordering has been changed using the IRIS GL pixmode() function. As noted above, data sent to the IndigoVideo board using the svPut24Frame() function should be ordered top-to-bottom. The svYUVtoRGB() and svRGB8toRGB32() functions will return data ordered top-to-bottom unless the invert parameter is TRUE.

8-bit RGB

The 8-bit RGB format stores 2 bits of blue and 3 bits each of red and green in an 8-bit pixel. The format of the 8-bit RGB pixels is shown in Figure 17-2.

Figure 17-2. Format of 8-bit RGB Pixels


When you capture 8-bit RGB frames using IndigoVideo, you receive them with the fields uninterleaved, that is, the data contains all of the even lines (from top to bottom) followed by all of the odd lines.

4:1:1 YUV

The 4:1:1 YUV format is much closer in form to the original video signal than the RGB formats described above. The YUV format is also much more complicated. Each pixel is described by three components: one luminance value (Y) and a pair of chrominance values (U and V); however, there are four luminance samples to each pair of chrominance samples has (hence 4:1:1 YUV). This means that sets of 4 pixels share the same chrominance values but have individual luminance values.

To further complicate matters, data from odd and even lines are interleaved within individual 32-bit words. The format of these words is shown in Figure 17-3.

Figure 17-3. Format of YUV Data Words


Each 32-bit word consists of 8 bits of unused space, followed by one Y sample (8 bits) and 2 bits each of U and V from the odd line, then a Y sample and 2 bits each of U and V from the even line.

By collecting the chrominance data from 4 consecutive 32-bit words, you get a pair of chrominance samples for the odd line, and a pair of chrominance samples for the even line. The upper 2 bits of U and V come in the first word, the next highest set of bits comes in the next word, and so on. By putting these chrominance samples together with the 4 odd and 4 even luminance samples, you can reconstruct 8 YUV pixels. You can derive 8-bit red, green, and blue values from the YUV values using the following formulas:

R = 1.164 × (Y - 16) + 1.596 × (V - 128)
G = 1.164 × (Y - 16) - 0.392 × (U - 128) -0.813 × (V - 128)
B = 1.164 × (Y - 16) + 2.017 × (U - 128)

As with the other forms of video data, lines of YUV data are ordered top-to-bottom.

IndigoVideo I/O

Figure 17-4 shows the IndigoVideo I/O panel, which is accessible from the back of the Indigo workstation.

Figure 17-4. IndigoVideo I/O Ports


IndigoVideo Board Input Port Specifications

At the top of the panel are three pairs of input connectors, labeled 1, 2, and 3. Each pair is made up of a composite video connector and an S-Video connector. You can use only one of the connectors in a given pair at a time—if you connect a composite video source and an S-Video source to the same input pair, the IndigoVideo hardware will not be able to decode either source properly.

The three input port pairs on the IndigoVideo board have the following specifications:

  • Composite VIDEO: 1.0 Vpp, 75\xbd , sync negative

  • S-VIDEO: DIN 4-pin

Below the input connectors, there are three output connectors—one composite connector, one S-Video connector, and one RGB connector.

IndigoVideo Board Output Port Specifications

The three output ports on IndigoVideo board have the following specifications:

  • Composite VIDEO output: 1.0 Vpp, 75\xbd , sync negative

  • S-VIDEO output: DIN 4-pin

  • RGB output: 15 pin D-connector, .714 Vpp, 75\xbd

The sync specification is:

  • Sync: RS-170 television sync: -4Vpp @ 75\xbd

Figure 17-5 shows video equipment connected to the I/O panel of the IndigoVideo board.

Figure 17-5. Connecting Video Equipment to the Indigo Video Board


The next two sections briefly describe how the IndigoVideo board operates.

Video Input

Five basic steps are used to convert a video input signal to pixels that can be displayed on the Indigo workstation:

  1. The IndigoVideo board synchronizes with the video source by looking for sync information in the video signal (see Figure 11-3).

  2. The analog video signal is converted to a digital signal.

  3. The digital signal is decoded into a series of pixels in 4:1:1 YUV colorspace.

    A colorspace is simply a way of encoding color information. In RGB colorspace, a color is defined by its red, green, and blue levels. In YUV colorspace, a color is defined by its luminance and by two chrominance components that determine its color. 4:1:1 means that the chrominance components are subsampled; that is, for each four Y samples, there is only one U sample and one V sample.

  4. The YUV pixels are converted to 24-bit RGB pixels.

  5. The 24-bit pixels are dithered down to 8-bit pixels.

    Before they can be displayed on the Indigo workstation, the video pixels must be reduced to 8-bit RGB pixels. IndigoVideo accomplishes this by dithering the video image. Dithering uses a small number of colors to simulate a larger number of colors using patterns of different colored pixels; for example, a pattern of red and yellow pixels can be used to represent orange.

  6. The video image is scaled down, if necessary.

Video Output

In live video output mode, IndigoVideo receives 8-bit RGB pixels from the Indigo graphics subsystem. These 8-bit pixels are converted to 24-bit RGB pixels using a set of look-up tables. These 24-bit pixels drive a set of digital-to-analog converters, which produce the analog RGB output, and also a digital encoder, which produces composite and S-Video output. The digital encoder also generates a composite sync signal, which can be used to synchronize video devices with the IndigoVideo board. The timing for this signal can be generated by the IndigoVideo board itself, or it can be derived from either the input source or from a separate composite sync signal connected to input #3.

A Simple Program for Getting Started with IndigoVideo

This section presents a sample program to help you get started with writing a simple video application. Source code for the sample programs is located in the /usr/people/4Dgifts/examples/dmedia/video/indigovideo directory, which is also referred to as 4Dgifts. You must have the svideodev option installed to get the gifts source, svideodev.sw.gifts. You also must have the IRIS Development Option, dev, and the C language software, c, loaded before you can compile the sample programs (use the versions command to find out which software is loaded on your system). See the Svideo Release Notes for complete system software requirements. Login as 4Dgifts to compile the examples and copy files to your home directory before modifying them.

Example 17-1 contains a listing of simpleinput.c, a program that opens up a window and displays live video input. This process has five basic steps:

  1. Create a GL/X window.

  2. Open the video device.

  3. Set video parameters.

  4. Associate video input with the GL/X window.

  5. Wait for the user to quit.

To compile simpleinput.c, enter:

cc -o simpleinput simpleinput.c -lsvideo -lXext -lgl_s

You must link with the IndigoVideo Library (-lsvideo) to use the IndigoVideo software. The linking order is specific: -lsvideo must appear first, followed by -lXext to link with the X extensions Library.

Programs that use IRIS GL windowing and event handling must include gl/gl.h and gl/device.h and must link with the shared IRIS GL (-lgl_s). Programs that use that use the X Window System must include X11/Xlib.h before including svideo.h, and must link with the X11 shared library (-lX11_s).


Note: This program uses IRIS GL windowing and event handling; however, a mixed-model GL/X window and X11 event handling is recommended for greater portability.



Note: CPU-intensive programs that use IRIS GL windowing and event handling should do a qtest() followed by sginap() if no events are waiting.


Example 17-1. Opening a Window to Display Live Video Input: simpleinput,c

#include <stdlib.h>
#include <svideo.h>
#include <gl/gl.h>
#include <gl/device.h>

main()
{
    long win, dev, params[2];
    short val;
    SVhandle V;

    /* Step 1: Open window */
    prefsize(SV_NTSC_XMAX, SV_NTSC_YMAX);
    win = winopen("video test");

    /* Step 2: Open video device */
    if ((V = svOpenVideo()) == NULL) {
        svPerror("open");
        exit(1);
    }

    /* Step 3: Set video source */
    params[0] = SV_SOURCE;
    params[1] = SV_SOURCE1;
    if (svSetParam(V, params, 2) < 0) {
        svCloseVideo(V);
        svPerror("set param");
        exit(1);
    }

    /* Step 4: Associate video input with window */
    if (svBindGLWindow(V, win, SV_IN_REPLACE) < 0) {
        svPerror("bind gl window");
        svCloseVideo(V);
        exit(1);
    }
    /* Step 5: wait for user to quit */
    qdevice(ESCKEY);
    qdevice(WINQUIT);
    qdevice(WINSHUT);
    while (1) {
        dev = qread(&val);
        switch (dev) {
        case ESCKEY:
            if (val)    /* exit on key up */
                break;
        case WINQUIT:
        case WINSHUT:
            svCloseVideo(V);
            exit(0);
            break;
        }
    }
}

This program isn't very flexible—it assumes that a composite NTSC video source is connected to input #1—however, it demonstrates the basic principles of programming with the IndigoVideo Library. Here's a step-by-step description of what the program does:

  1. The program opens a window in which to display the video. First it specifies the preferred size for the window using prefsize(), then it calls winopen() to create the window. The winopen() routine returns a window identifier, which is used in step 4 to associate the video input with the window. The symbolic constants SV_NTSC_XMAX and SV_NTSC_YMAX represent the dimensions of an NTSC video frame.

  2. The program opens the video device. The svOpenVideo() routine returns a video handle that is passed to other routines in the IndigoVideo Library. This step also demonstrates the use of the IndigoVideo error reporting routine, svPerror().

  3. The program sets up the IndigoVideo board to receive video input from source #1. This is the default input, so you could omit this step; however, this step is included to demonstrate the use of the svSetParam() routine. The svSetParam() routine can be used to select input source, broadcast standard, and more. Note that it is not necessary to set these parameters before associating video input with a window; video parameters can be changed at any time. Also note that once set up, live video display requires no CPU intervention.

    One of the arguments to svSetParam() is an array of long integers. Even-numbered elements of this array represent parameters to be changed, and the corresponding odd-numbered elements represent parameter values. In this program, the parameter being set is represented by the symbolic constant SV_SOURCE, and the value is represented by the symbolic constant SV_SOURCE1.

  4. After the setup is complete, the program attaches the video input to the window, using the svBindGLWindow() routine. This routine takes three arguments: a video handle, a window identifier, and a third argument indicating how to display the video input. The sample program uses the symbolic constant SV_IN_REPLACE for the third argument, indicating that video should replace the contents of the window. The other possible values for the third argument are SV_IN_UNDER, for video underlay, SV_IN_OVER, for video overlay, and SV_IN_OFF, to deactivate video display in the window.

  5. Finally, the program enters an IRIS GL event handling loop, displaying video input until the user elects to quit by pressing the <Esc> key. Once set up, live video display requires no CPU intervention. When the user exits, the program closes the video device by using the svCloseVideo() routine. This routine deallocates the data structures associated with the video handle.

    More sophisticated event handling methods are presented later in this guide—new development should use X event handling rather than IRIS GL event handling. See Chapter 21, “Handling IndigoVideo Events,”for more information on handling events.