	What does each file do?
	-----------------------
v4linterface.c 	 -> Builds GUI elements dependant on the v4l capabilities.
interface.c      -> Interface to libglade, manages the interface.
zmisc.c		 -> Useful routines for Zapping.
zconf.c		 -> Manager for the Zapping config.
channel_editor.c -> Manages the channel editor dialog.
plugin_properties.c -> Manages the plugin properties dialog.
callbacks.c      -> Contains all the code that handles callbacks.
main.c           -> Main loop and config saving/loading routines.
frequencies.c    -> Different channels for different countries.
io.c 		 -> PNG saving functions.
tveng.c		 -> V4L(2) wrappers, uses tveng1 and tveng2.
plugins.c	 -> This file communicates with the plugins.
plugin_common.h  -> Shared between Zapping and the plugins.
sound.c		 -> Sound capturing through esd.
support.c	 -> Autogenerated by Glade, useful routines.
videodev(2).h    -> V4L(2) header files, are only needed by tveng1.c and
		    tveng2.c
tveng1.c	 -> Interface to V4L, should only be used by tveng.c
tveng2.c	 -> Interface to V4L2, should only be used by tveng.c
Makefile.am      -> Automake Makefile Template
Makefile.in      -> Autogenerated from Makefile.am by automake
Makefile         -> Autogenerated from Makefile.in by autoconf
zapping_setup_fb/zapping_setup_fb.c -> Small program intended to be
		installed as suid root that sets up the Framebuffer.

tv_?_device
  - video inputs
  - audio inputs
  - video standards
  - controls
  - audio mode
tv_~?_device
  - video outputs
  - audio outputs
  - video standards
  - controls
  - audio mode
tv_overlay_device
  - target
  - window
tv_capture_device
  - ?
??

------------------------------------------------------------------------------

Mixer (AC97)

             ------------------------------------
 DAC3 ===> | ============================ * ==> | ---> Center/LFE
 DAC2 ===> | == * =========+=====> / ==== * ==> | ---> Aux out (headphones, rear, level)
            |   pcm2        v       +->-+- * --> | ---> Mono out
 DAC1  ===> | == * ======(-Sum-)====+===|= * ==> | ---> Line out
            |   pcm      // | \\    |   |        |
            |           / | | | \   |   ^        |  / switch
            |           * * * * *   |   |        |  * vol/mute or gain
            |  igain    | | | | |   v   |        |   optional
 ADC1  <=== | == * ====(-----Mux-----)  |        |
            | mic gain  ^ ^ ^ ^ ^       |        |
 ADC2 <--- | -- * -----|-|-|-|-+--mic--+        |
             ------------------------------------
                        ^ ^ ^ ^ ^
                    Line in, Mic, CD, ...

* view config: line in vol (volume, mute)
* rec config: line in vol (volume, mute), mux, igain.
* rec/play config: line in vol muted, pcm or pcm2 vol (volume, mute), mux
* bilingual rec config: mux, line in vol muted. Either no sound
  from line (bkg recording), or full duplex w/software lang mux
  and pcm vol (volume, mute). L/R -> L/L,R/R is not
  supported by AC97, although different sources can be selected
  L and R.

  Device may support more than one/two pcm playback channels,
  eventually move pcm volume into codec and leave master pcm
  volume alone. If necessary rec gain can be implemented in
  codec as well.

PCM Device

  Digital sources
   | | |  Analog sources, mixer and other
   v v v   v   v   v
  ---------------------------------
 | | | |  ADC ADC ADC              |
 |---------------------------------|
 |  DSP Mux / Effects              |
  ---------------------------------
             v v v v v
 (--PCM input channels-------------)
        v
             software
                          v
 (--PCM output channels------------)
    v v v v v v v v v v v v v v v
  ---------------------------------
 |  DSP Sum / Mux / Vol / Effects  |
 |---------------------------------|
 | | | |  DAC DAC DAC              |
  ---------------------------------
   | | |   v   v   v
   v v v  Analog destinations, mixer, modem etc
  Digital destinations, S/PDIF etc

TV Card

   Tuner & audio demodulator
    |  Optional other tuner & audio demodulator
    |   |  Digital / analog inputs (1)
    |   |   | | | |
    *   *   | | * *   volume/mute, effects
    |   |   | | | |
  (-------Mux-------)
           +== (2) ==> Line out, loopback
           | hw may support more outputs, but there's no API to select
          (2)
           | mux may support other than line out, but no API
           v
        PCM ADC, OSS/ALSA interface, optional

  (1) V4L2-2.5 can tell if mono or stereo capability.
  (2) Expect no volume control here.

Audio demodulator

* A2 / NICAM / EIA-J / satellite
  Capabilites mono, stereo, bilingual (primary left channel, secondary
    right); typically stereo with bilingual.
  Reception mono, stereo, bilingual.
  Selection mono/mono (stereo mix), left/right, left/left,
  right/right; possibly not l/r when bilingual, l/l or r/r when stereo.
* BTSC
  Capabilities mono, stereo, sap; typically stereo with sap.
  Reception mono, stereo, mono + sap, stereo + sap
  Selection mono, stereo, sap (monaural)
* VBI/EPG
  Augment mode info from VPS, TTX, XDS, EPG: mono/stereo/bi/sap reception,
  surround, language name, video description etc.
* Recording
  Automatic mode selection.

A/V Matrix

* Video and audio from tuner with
  * audio from tv card (volume, mute, ev. pcm)
  * loopback to any soundcard
  -> device configuration
* Video from line in, audio from
  * same tv card line in
    -> channel configuration
  * other tv card line in (?)
    -> device configuration
  * any soundcard line in
    -> device configuration

Virtual tv device

+ Kernel video device (V4L, V4L2 0.20, V4L2 2.5, BKTR),
    eventually mixed V4L / V4L2 if orthogonal interfaces
+ Kernel vbi device (V4L, V4L2 0.20, V4L2 2.5, BKTR)
+ Xv port (X11 Xvideo)
+ PCM device (soundcard or tv card) (OSS, ALSA)
+ Mixer (soundcard loopback) (OSS, ALSA)

a) Kernel video capture (with XPutImage/ShmPut/XvPut/GL/TVout display)
     and/or DMA overlay, [sound controls], [tuning]
b) Kernel video + PCM (tv card)
c) Kernel video + PCM (soundcard) + Mixer sound controls
d) Xvideo overlay, [sound controls], [tuning]
e) Xvideo overlay, [tuning] + Mixer sound controls (+ soundcard PCM?)
f) a) + Xvideo overlay
g) b) + Xvideo overlay
h) c) + Xvideo overlay
i-p) a-h) + Kernel vbi device

* Xv-V4L wrapper (and similar): d-h)
* Video card specific Xv driver d-e),
* Video card Xv with kernel backbone d-h)
* Simultaneous full rate capture & overlay (typ. video card with
   kernel backbone w/o DMA overlay, but Xvideo)

TV array

Tuners connected to same RF source (baseband too?), with separate
video capture units unlike one bt878 w/two tuners.

* View devices: can display, sound routed to master line out.
* Capture devices: can capture, sound routed to an ADC.

a) Multi program recording: 2+ capture devices routed to different ADCs.
   - each tv card w/pcm
   - each tv card with loopback to different soundcard
   - mixed cases.
b) Watch and record: 1+ view device, 0+ record devices
   - using view device's line out, record device(s) as in a)
   - each view device with loopback to different soundcard,
     each soundcard can be shared with one record device.
     Other record devices as in a)
c) Background VBI acquisition (VPS, PDC, XDS, TTX, EPG) from another
   channel, fast channel mosaic, live PIP:
   - same as a) or b)
   - 1+ devices without sound (ev. mutable)

Output devices

* X11 XPutImage (GDK)
* X11 XShmPutImage (GDK)
* X11 XvPutImage, frontend/backend scaler
* OpenGL scaler
* TV output

Output array (capture display, DMA overlay?)

* Multiple local X11 displays / Xinerama
* Multiple TV outputs

------------------------------------------------------------------------------

BKTR IOCTL Notes

#define METEORCAPTUR _IOW('x', 1, int)			 /* capture a frame */

Argument: METEOR_CAP_(SINGLE | CONTINUOUS | STOP_CONT).

#define METEORCAPFRM _IOW('x', 2, struct meteor_capframe)  /* sync capture */

Something I/O.

#define METEORSETGEO _IOW('x', 3, struct meteor_geomet)  /* set geometry */
#define METEORGETGEO _IOR('x', 4, struct meteor_geomet)  /* get geometry */

Image size and pixel format.

#define METEORSTATUS _IOR('x', 5, unsigned short)	/* get status */

Argument is set of METEOR_STATUS_. Bktr supports HCLK, FIDT.

#define METEORSHUE   _IOW('x', 6, signed char)		/* set hue */
#define METEORGHUE   _IOR('x', 6, signed char)		/* get hue */
#define	METEORSBRIG  _IOW('x', 14, unsigned char)	/* set brightness */
#define METEORGBRIG  _IOR('x', 14, unsigned char)	/* get brightness */
#define	METEORSCSAT  _IOW('x', 15, unsigned char)	/* set chroma sat */
#define METEORGCSAT  _IOR('x', 15, unsigned char)	/* get uv saturation */
#define	METEORSCONT  _IOW('x', 16, unsigned char)	/* set contrast */
#define	METEORGCONT  _IOR('x', 16, unsigned char)	/* get contrast */
#define	METEORSCHCV  _IOW('x', 9, unsigned char)	/* set uv gain */
#define	METEORGCHCV  _IOR('x', 9, unsigned char)	/* get uv gain */

Range 0..0xFF.

#define METEORSFMT   _IOW('x', 7, unsigned long)	/* set format */
#define METEORGFMT   _IOR('x', 7, unsigned long)	/* get format */

Video standard: METEOR_FMT_.

#define METEORSINPUT _IOW('x', 8, unsigned long)	/* set input dev */
#define METEORGINPUT _IOR('x', 8, unsigned long)	/* get input dev */

Video input: METEOR_INPUT_.
meteor			bktr
DEV0 (DEV_RCA)		composite cinch
DEV1			tuner
DEV2			composite on s-video
DEV_SVIDEO		y/c on s-video
DEV3			composite

#define	METEORSCOUNT _IOW('x',10, struct meteor_counts)
#define	METEORGCOUNT _IOR('x',10, struct meteor_counts)

Error, frame, field counters.

#define METEORSFPS   _IOW('x',11, unsigned short)	/* set fps */
#define METEORGFPS   _IOR('x',11, unsigned short)	/* get fps */

To reduce capture frame rate below 25/30 Hz. Argument is frames/s.

#define METEORSSIGNAL _IOW('x', 12, unsigned int)	/* set signal */
#define METEORGSIGNAL _IOR('x', 12, unsigned int)	/* get signal */

Something I/O.

#define	METEORSVIDEO _IOW('x', 13, struct meteor_video)	/* set video */
#define	METEORGVIDEO _IOR('x', 13, struct meteor_video)	/* get video */

Frame buffer parameters for overlay.

#define METEORSBT254 _IOW('x', 17, unsigned short)	/* set Bt254 reg */
#define METEORGBT254 _IOR('x', 17, unsigned short)	/* get Bt254 reg */

?

#define METEORSHWS   _IOW('x', 18, unsigned char)	/* set hor start reg */
#define METEORGHWS   _IOR('x', 18, unsigned char)	/* get hor start reg */
#define METEORSVWS   _IOW('x', 19, unsigned char)	/* set vert start reg */
#define METEORGVWS   _IOR('x', 19, unsigned char)	/* get vert start reg */

Cropping?

#define	METEORSTS    _IOW('x', 20, unsigned char)	/* set time stamp */
#define	METEORGTS    _IOR('x', 20, unsigned char)	/* get time stamp */

?

** BT848 extensions **

#define	TVTUNER_SETCHNL    _IOW('x', 32, unsigned int)	/* set channel */
#define	TVTUNER_GETCHNL    _IOR('x', 32, unsigned int)	/* get channel */

Select a channel from the current frequency table

#define	TVTUNER_SETTYPE    _IOW('x', 33, unsigned int)	/* set tuner type */
#define	TVTUNER_GETTYPE    _IOR('x', 33, unsigned int)	/* get tuner type */

Select a frequency table, value from enum CHNLSET_
fxtv: tvcapture.c 638 TVCAPTURESetTunerFreqSet()

#define	TVTUNER_GETSTATUS  _IOR('x', 34, unsigned int)	/* get tuner status */

Get signal strength, returns contents of i2c reg
bktr_tuner.c line 977 get_tuner_status()

#define	TVTUNER_SETFREQ    _IOW('x', 35, unsigned int)	/* set frequency */
#define	TVTUNER_GETFREQ    _IOR('x', 36, unsigned int)	/* get frequency */

Argument is frequency in 62.5 kHz units
NOTE fxtv:
    /*  Driver FIXME: Hack to get around driver unmuting audio across  */
    /*    channel, freq, and input device changes.                     */
    if ( ioctl( c->tfd, BT848_GAUDIO, &old_audio ) < 0 ) {
        DO_IOCTL_GERR( "BT848_GAUDIO" );
        return;
    }
    ioctl( c->tfd, TVTUNER_SETFREQ, &larg );

#define BT848_SHUE	_IOW('x', 37, int)		/* set hue */
#define BT848_GHUE	_IOR('x', 37, int)		/* get hue */
#define	BT848_SBRIG	_IOW('x', 38, int)		/* set brightness */
#define BT848_GBRIG	_IOR('x', 38, int)		/* get brightness */
#define	BT848_SCSAT	_IOW('x', 39, int)		/* set chroma sat */
#define BT848_GCSAT	_IOR('x', 39, int)		/* get UV saturation */
#define	BT848_SCONT	_IOW('x', 40, int)		/* set contrast */
#define	BT848_GCONT	_IOR('x', 40, int)		/* get contrast */
#define	BT848_SVSAT	_IOW('x', 41, int)		/* set chroma V sat */
#define BT848_GVSAT	_IOR('x', 41, int)		/* get V saturation */
#define	BT848_SUSAT	_IOW('x', 42, int)		/* set chroma U sat */
#define BT848_GUSAT	_IOR('x', 42, int)		/* get U saturation */

Should be clear, see also #defines for min/max/center (the hardware
values are used here, not the flpt numbers)

#define	BT848_SCBARS	_IOR('x', 43, int)		/* set colorbar */
#define	BT848_CCBARS	_IOR('x', 44, int)		/* clear colorbar */

Argument is ignored

#define	BT848_SAUDIO	_IOW('x', 46, int)		/* set audio channel */
#define BT848_GAUDIO	_IOR('x', 47, int)		/* get audio channel */

Argument is one of AUDIO_(TUNER, EXTERN, ... MUTE, UNMUTE)

#define	BT848_SBTSC	_IOW('x', 48, int)		/* set audio channel */

Probably intended to enable/disable SAP
bktr_audio.c 314: (control is the argument)
/*
 * setup the dbx chip
 * XXX FIXME: alot of work to be done here, this merely unmutes it.
 */
int
set_BTSC( bktr_ptr_t bktr, int control )
{
	return( i2cWrite( bktr, TDA9850_WADDR, CON3ADDR, control ) );
}

#define	BT848_GSTATUS	_IOR('x', 49, unsigned int)	/* reap status */

BT848 DSTATUS (0x000) and INT_STAT (0x100) reg, bit:
0	- Format change (PAL/NTSC) detected
1	- VSYNC
2	- HSYNC
3	- Luma or chroma overflow
4	- Horizontal lock condition change
5	- Video signal present 
6	- Chroma ADC overflow (from DSTATUS 0x000)
7	- Luma ADC overflow (from DSTATUS)
8	- I2C done
9	- GPINT
10	- reserved
11	- RISC IRQ
12	- PCI FIFO overrun
13	- PCI FIFO overrun
14	- PCI FIFO data resync
15	- PCI parity error
16	- RISC parity error
17	- PCI master or target abort
18	- invalid RISC op
19	- DMA sync error
20-23	- reserved
24	- 1=even field
25	- I2C ACK
26	- reserved
27	- RISC enabled
28-31	- RISC status

#define	BT848_WEEPROM	_IOWR('x', 50, struct eeProm)	/* write to EEProm */
#define	BT848_REEPROM	_IOWR('x', 51, struct eeProm)	/* read from EEProm */
#define	BT848_SIGNATURE	_IOWR('x', 52, struct eeProm)	/* read card sig */

Tinneff

#define	TVTUNER_SETAFC	_IOW('x', 53, int)		/* turn AFC on/off */
#define TVTUNER_GETAFC	_IOR('x', 54, int)		/* query AFC on/off */

Value 0 or 1, enables AFC on frequency change

#define BT848_SLNOTCH	_IOW('x', 55, int)		/* set luma notch */
#define BT848_GLNOTCH	_IOR('x', 56, int)		/* get luma notch */

Enable, bit (bktr_core.c 2089):
0	- 0=luma decimation, useful when scaling to CIF resolutions or lower
1	- 1=Y/C, 0=composite video
2	- 0=luma notch filter

/* Read/Write the BT848's I2C bus directly
 * b7-b0:    data (read/write)
 * b15-b8:   internal peripheral register (write)   
 * b23-b16:  i2c addr (write)
 * b31-b24:  1 = write, 0 = read 
 */
#define BT848_I2CWR     _IOWR('x', 57, u_long)    /* i2c read-write */

struct bktr_msp_control {
	unsigned char function;
	unsigned int  address;
	unsigned int  data;
};
#define BT848_MSP_RESET _IO('x', 76)				/* MSP chip reset */
#define BT848_MSP_READ  _IOWR('x', 77, struct bktr_msp_control)	/* MSP chip read */
#define BT848_MSP_WRITE _IOWR('x', 78, struct bktr_msp_control)	/* MSP chip write */

/* Support for radio tuner */
#define RADIO_SETMODE	 _IOW('x', 58, unsigned int)  /* set radio modes */
#define RADIO_GETMODE	 _IOR('x', 58, unsigned char)  /* get radio modes */
#define RADIO_SETFREQ    _IOW('x', 59, unsigned int)  /* set frequency   */
#define RADIO_GETFREQ    _IOR('x', 59, unsigned int)  /* set frequency   */

/*
 * XXX: more bad magic,
 *      we need to fix the METEORGINPUT to return something public
 *      duplicate them here for now...
 */
#define	METEOR_DEV0		0x00001000
#define	METEOR_DEV1		0x00002000
#define	METEOR_DEV2		0x00004000
#define	METEOR_DEV3		0x00008000
#define	METEOR_DEV_SVIDEO	0x00006000
/*
 * right now I don't know were to put these, but as they are suppose to be
 * a part of a common video capture interface, these should be relocated to
 * another place.  Probably most of the METEOR_xxx defines need to be
 * renamed and moved to a common header
 */

typedef enum { METEOR_PIXTYPE_RGB, METEOR_PIXTYPE_YUV,
	       METEOR_PIXTYPE_YUV_PACKED,
	       METEOR_PIXTYPE_YUV_12 } METEOR_PIXTYPE;

struct meteor_pixfmt {
	u_int          index;         /* Index in supported pixfmt list     */
	METEOR_PIXTYPE type;          /* What's the board gonna feed us     */
	u_int          Bpp;           /* Bytes per pixel                    */
	u_long         masks[3];      /* R,G,B or Y,U,V masks, respectively */
	unsigned       swap_bytes :1; /* Bytes  swapped within shorts       */
	unsigned       swap_shorts:1; /* Shorts swapped within longs        */
};

struct bktr_clip {
    int          x_min;
    int          x_max;
    int          y_min;
    int          y_max;
};

#define BT848_MAX_CLIP_NODE 100
struct _bktr_clip {
    struct bktr_clip x[BT848_MAX_CLIP_NODE];
};

/*
 * I'm using METEOR_xxx just because that will be common to other interface
 * and less of a surprise
 */
#define METEORSACTPIXFMT	_IOW('x', 64, int )
#define METEORGACTPIXFMT	_IOR('x', 64, int )
#define METEORGSUPPIXFMT	_IOWR('x', 65, struct meteor_pixfmt)

#define BT848SCLIP     _IOW('x', 66, struct _bktr_clip )
#define BT848GCLIP     _IOR('x', 66, struct _bktr_clip )

#define BT848SFMT		_IOW('x', 67, unsigned long )
#define BT848GFMT		_IOR('x', 67, unsigned long )

set input format
/*  XXX - Copied from /sys/pci/brktree_reg.h  */
#define BT848_IFORM_FORMAT              (0x7<<0)
# define BT848_IFORM_F_RSVD             (0x7)
# define BT848_IFORM_F_SECAM            (0x6)
# define BT848_IFORM_F_PALN             (0x5)
# define BT848_IFORM_F_PALM             (0x4)
# define BT848_IFORM_F_PALBDGHI         (0x3)
# define BT848_IFORM_F_NTSCJ            (0x2)
# define BT848_IFORM_F_NTSCM            (0x1)
# define BT848_IFORM_F_AUTO             (0x0)

#define BT848SCBUF	_IOW('x', 68, int)
#define BT848GCBUF	_IOR('x', 68, int)

Set clear-buffer-on-start

#define BT848_SCAPAREA   _IOW('x', 69, struct bktr_capture_area)
#define BT848_GCAPAREA   _IOR('x', 69, struct bktr_capture_area)

Cropping

#define	TVTUNER_GETCHNLSET _IOWR('x', 70, struct bktr_chnlset)

#define BT848_MAX_CHNLSET_NAME_LEN 16
struct bktr_chnlset {
       short   index;
       short   max_channel;
       char    name[BT848_MAX_CHNLSET_NAME_LEN];
};

/* Infra Red Remote Control */
struct bktr_remote {
       unsigned char data[3];
};
#define	REMOTE_GETKEY      _IOR('x', 71, struct bktr_remote)/*read the remote */
                                                        /*control receiver*/
                                                        /*returns raw data*/

#define BT848_GPIO_SET_EN      _IOW('x', 72, int)      /* set gpio_out_en */
#define BT848_GPIO_GET_EN      _IOR('x', 73, int)      /* get gpio_out_en */
#define BT848_GPIO_SET_DATA    _IOW('x', 74, int)      /* set gpio_data */
#define BT848_GPIO_GET_DATA    _IOR('x', 75, int)      /* get gpio_data */

 * Direct access to GPIO pins. You must add BKTR_GPIO_ACCESS to your kernel
 * configuration file to use these 

bad ioctl:
    ENOTTY

------------------------------------------------------------------------------

Device configuration dialog

| Table of logical devices (tree?)
| [x] check buttons to connect devices sharing the
| [ ] same RF source (assumed only one)

Video config

(x) Kernel video device
  Name: foo
  Driver: foo
  Video device file: [______][Browse]
  Tuner device file: [______][Browse] (bktr)

  [x] VBI device
      VBI device file: [______][Browse] (v4l/v4l2 0.20/bktr)
{
  (x) Color key overlay
     Color: ... ?
  ( ) Blitter overlay
  ( ) No XVideo hardware scaling
} ...?

{ satellite } ...?

( ) XVideo device (no recording)
  Name: foo
  Port: [___________][v]

Audio config

(x) Kernel audio device (recommended)
  Name: foo
  Driver: foo
  Device file: [______][Browse]
( ) Gnome audio daemon
( ) KDE audio daemon
( ) No audio recording

[x] Control volume with soundcard mixer
  Name: foo
  Driver: foo
  Device file: [______][Browse]

------------------------------------------------------------------------------

Channel configuration dialog

Each channel:
* Channel number
* Channel name
* Logical device
* Video input
  - terr tuner
    * RF channel name
    * frequency
  - sat tuner
    * satellite position
    * transponder pol
    * transponder freq
  - baseband
  - none ...?
* Audio input
  - terr tuner
  - sat tuner
    * audio subcarrier left
    * audio subcarrier right
    XXX languages?
  - input (tv card)
  - none
* Video standard
* Keyboard shortcut

-----

#<property name="icon">zapping-mute</property>
#<property name="stock_pixmap">zapping-mute</property>

-----

Overlay

1) target
  - dma overlay into video memory: get|set_overlay_buffer
  - chroma-key genlock: get|set_chroma_key. Client is
    responsible for painting the screen.
  - X window: get|set_overlay_xwindow
2) windowing and clipping
  - dma overlay: get|set_overlay_window, no clipping
  - dma overlay: get|set_overlay_window, with clip list
  - chroma-key: get|set_overlay_window
  - x window frontend overlay: get|set_overlay_window
  - x window backend overlay: get|set_overlay_window. XVideo
    will paint c-k color (true?), must be another parameter.
3) cropping and scaling
  - get|set_overlay_source (zoom effect etc), where available.
