aboutsummaryrefslogtreecommitdiffstats
path: root/x11/v4lctl.c
blob: 4a7bece6aea4790c992f15cf38f7ffef39ab41b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 *  (c) 1999 Gerd Knorr <kraxel@goldbach.in-berlin.de>
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>

#include "config.h"

#ifdef HAVE_LIBXV
# include <X11/Xlib.h>
# include <X11/extensions/Xv.h>
# include <X11/extensions/Xvlib.h>
#endif

#include "grab-ng.h"
#include "channel.h"
#include "frequencies.h"
#include "commands.h"
#include "atoms.h"
#include "xv.h"

int debug = 0;
int have_dga = 0;
#ifdef HAVE_LIBXV
Display *dpy;
#endif

/*--- main ---------------------------------------------------------------*/

static void
grabber_init(void)
{
    drv = ng_vid_open(ng_dev.video,NULL,0,&h_drv);
    if (NULL == drv) {
	fprintf(stderr,"no grabber device available\n");
	exit(1);
    }
    f_drv = drv->capabilities(h_drv);
    add_attrs(drv->list_attrs(h_drv));
}

static void
usage(void)
{
    fprintf(stderr,
	    "\n"
	    "usage: v4lctl [ options ] command\n"
	    "options:\n"
	    "  -v, --debug=n      debug level n, n = [0..2]\n"
	    "  -c, --device=file  use <file> as video4linux device\n"
	    "  -h, --help         print this text\n"
	    "\n");
}

int main(int argc, char *argv[])
{
    int c;
    int xvideo = 1;

    ng_init();
    for (;;) {
	if (-1 == (c = getopt(argc, argv, "hv:c:")))
	    break;
	switch (c) {
	case 'v':
	    ng_debug = debug = atoi(optarg);
	    break;
	case 'c':
	    ng_dev.video = optarg;
	    xvideo = 0;
	    break;
	case 'h':
	default:
	    usage();
	    exit(1);
	}
    }
    if (optind == argc) {
	usage();
	exit(1);
    }

#ifdef HAVE_LIBXV
    if (NULL != getenv("DISPLAY"))
	dpy = XOpenDisplay(NULL);
    if (dpy) {
	init_atoms(dpy);
	if (xvideo)
	    xv_video_init(-1,0);
    }
#endif
    if (NULL == drv)
	grabber_init();
    freq_init();
    read_config(NULL,NULL,NULL);

    attr_init();
    audio_init();
    audio_init();

    parse_config();

    do_command(argc-optind,argv+optind);
    drv->close(h_drv);
#ifdef HAVE_LIBXV
    if (dpy)
	XCloseDisplay(dpy);
#endif
    return 0;
}

Privacy Policy