1 /*
2 * (c) 1999 Gerd Knorr <kraxel@goldbach.in-berlin.de>
3 *
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <errno.h>
11 #include <math.h>
12 #include <pthread.h>
13
14 #include "config.h"
15
16 #ifdef HAVE_LIBXV
17 # include <X11/Xlib.h>
18 # include <X11/extensions/Xv.h>
19 # include <X11/extensions/Xvlib.h>
20 # include "atoms.h"
21 # include "xv.h"
22 #endif
23
24 #include "grab-ng.h"
25 #include "channel.h"
26 #include "frequencies.h"
27 #include "commands.h"
28
29 int have_dga = 0;
30 #ifdef HAVE_LIBXV
31 Display *dpy;
32 #endif
33
34 /*--- main ---------------------------------------------------------------*/
35
36 static void
grabber_init(void)37 grabber_init(void)
38 {
39 drv = ng_vid_open(&ng_dev.video,ng_dev.driver,NULL,0,&h_drv);
40 if (NULL == drv) {
41 fprintf(stderr,"no grabber device available\n");
42 exit(1);
43 }
44 f_drv = drv->capabilities(h_drv);
45 add_attrs(drv->list_attrs(h_drv));
46 }
47
48 static void
usage(void)49 usage(void)
50 {
51 fprintf(stderr,
52 "\n"
53 "usage: v4lctl [ options ] command\n"
54 "options:\n"
55 " -v, --debug=n debug level n, n = [0..2]\n"
56 " -c, --device=file use <file> as video4linux device\n"
57 " -h, --help print this text\n"
58 "\n");
59 }
60
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63 int c;
64 int xvideo = 1;
65
66 ng_init();
67 for (;;) {
68 if (-1 == (c = getopt(argc, argv, "hv:c:D:")))
69 break;
70 switch (c) {
71 case 'v':
72 ng_debug = debug = atoi(optarg);
73 break;
74 case 'c':
75 ng_dev.video = optarg;
76 xvideo = 0;
77 break;
78 case 'D':
79 ng_dev.driver = optarg;
80 xvideo = 0;
81 break;
82 case 'h':
83 default:
84 usage();
85 exit(1);
86 }
87 }
88 if (optind == argc) {
89 usage();
90 exit(1);
91 }
92
93 #ifdef HAVE_LIBXV
94 if (NULL != getenv("DISPLAY"))
95 dpy = XOpenDisplay(NULL);
96 if (dpy) {
97 init_atoms(dpy);
98 if (xvideo)
99 xv_video_init(-1,0);
100 }
101 #endif
102 if (NULL == drv)
103 grabber_init();
104 freq_init();
105 read_config(NULL,NULL,NULL);
106
107 attr_init();
108 audio_init();
109 audio_init();
110
111 parse_config(1);
112
113 do_command(argc-optind,argv+optind);
114 drv->close(h_drv);
115 #ifdef HAVE_LIBXV
116 if (dpy)
117 XCloseDisplay(dpy);
118 #endif
119 return 0;
120 }
121