annotate libmpdemux/tvi_v4l.c @ 3690:c42f1e391c5f

10l? streaming must be yes, auto is not enough because of Makefile
author arpi
date Sun, 23 Dec 2001 23:20:49 +0000
parents 178c562948ff
children 3717145636b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
1 /*
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
2 Video 4 Linux input
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
3
09d5c9834580 tv update
alex
parents: 2790
diff changeset
4 (C) Alex Beregszaszi <alex@naxine.org>
09d5c9834580 tv update
alex
parents: 2790
diff changeset
5
09d5c9834580 tv update
alex
parents: 2790
diff changeset
6 Some ideas are based on xawtv/libng's grab-v4l.c written by
09d5c9834580 tv update
alex
parents: 2790
diff changeset
7 Gerd Knorr <kraxel@bytesex.org>
09d5c9834580 tv update
alex
parents: 2790
diff changeset
8
09d5c9834580 tv update
alex
parents: 2790
diff changeset
9 CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE!
09d5c9834580 tv update
alex
parents: 2790
diff changeset
10 */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
11
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
12 #include "config.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
13
3243
3bd16d4a94e2 updated for support detection by configure
alex
parents: 3220
diff changeset
14 #if defined(USE_TV) && defined(HAVE_TV_V4L)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
15
98769cea155c added tv subsystem
alex
parents:
diff changeset
16 #include <stdio.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
17 #include <errno.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
18 #include <fcntl.h>
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
19 #include <signal.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
20 #include <sys/ioctl.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
21 #include <sys/types.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
22 #include <linux/videodev.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
23 #include <unistd.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
24 #include <sys/mman.h>
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
25 #include <stdlib.h>
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
26 #include <string.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
27
2830
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
28 #include "mp_msg.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
29 #include "../libao2/afmt.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
30 #include "../libvo/img_format.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
31 #include "../libvo/fastmemcpy.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
32
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
33 #include "tv.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
34
98769cea155c added tv subsystem
alex
parents:
diff changeset
35 static tvi_info_t info = {
98769cea155c added tv subsystem
alex
parents:
diff changeset
36 "Video for Linux TV Input",
98769cea155c added tv subsystem
alex
parents:
diff changeset
37 "v4l",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
38 "Alex Beregszaszi <alex@naxine.org>",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
39 "under development"
09d5c9834580 tv update
alex
parents: 2790
diff changeset
40 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
41
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
42 typedef struct {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
43 /* general */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
44 char *video_device;
98769cea155c added tv subsystem
alex
parents:
diff changeset
45 int fd;
98769cea155c added tv subsystem
alex
parents:
diff changeset
46 struct video_capability capability;
98769cea155c added tv subsystem
alex
parents:
diff changeset
47 struct video_channel *channels;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
48 int act_channel;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
49 struct video_tuner tuner;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
50
09d5c9834580 tv update
alex
parents: 2790
diff changeset
51 /* video */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
52 struct video_picture picture;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
53 int format; /* output format */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
54 int width;
98769cea155c added tv subsystem
alex
parents:
diff changeset
55 int height;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
56 int bytesperline;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
57
09d5c9834580 tv update
alex
parents: 2790
diff changeset
58 struct video_mbuf mbuf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
59 unsigned char *mmap;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
60 struct video_mmap *buf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
61 int nbuf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
62 int queue;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
63
09d5c9834580 tv update
alex
parents: 2790
diff changeset
64 /* audio */
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
65 struct video_audio *audio;
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
66 int act_audio;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
67 } priv_t;
98769cea155c added tv subsystem
alex
parents:
diff changeset
68
98769cea155c added tv subsystem
alex
parents:
diff changeset
69 #include "tvi_def.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
70
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
71 static const char *device_cap2name[] = {
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
72 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
73 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
74 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL
09d5c9834580 tv update
alex
parents: 2790
diff changeset
75 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
76
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
77 static const char *device_palette2name[] = {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
78 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
79 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
80 "yuv420p", "yuv410p", NULL
09d5c9834580 tv update
alex
parents: 2790
diff changeset
81 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
82 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN")
09d5c9834580 tv update
alex
parents: 2790
diff changeset
83
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
84 static const char *audio_mode2name[] = {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
85 "unknown", "mono", "stereo", "language1", "language2", NULL
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
86 };
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
87
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
88 static int palette2depth(int palette)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
89 {
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
90 switch(palette)
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
91 {
3220
alex
parents: 2937
diff changeset
92 /* component */
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
93 case VIDEO_PALETTE_RGB555:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
94 return(15);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
95 case VIDEO_PALETTE_RGB565:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
96 return(16);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
97 case VIDEO_PALETTE_RGB24:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
98 return(24);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
99 case VIDEO_PALETTE_RGB32:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
100 return(32);
3220
alex
parents: 2937
diff changeset
101 /* planar */
alex
parents: 2937
diff changeset
102 case VIDEO_PALETTE_YUV422P:
alex
parents: 2937
diff changeset
103 case VIDEO_PALETTE_YUV411P:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
104 case VIDEO_PALETTE_YUV420P:
3220
alex
parents: 2937
diff changeset
105 case VIDEO_PALETTE_YUV410P:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
106 return(12);
3220
alex
parents: 2937
diff changeset
107 /* packed */
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
108 case VIDEO_PALETTE_YUV422:
3220
alex
parents: 2937
diff changeset
109 case VIDEO_PALETTE_YUYV:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
110 case VIDEO_PALETTE_UYVY:
3220
alex
parents: 2937
diff changeset
111 case VIDEO_PALETTE_YUV420:
alex
parents: 2937
diff changeset
112 case VIDEO_PALETTE_YUV411:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
113 return(16);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
114 }
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
115 return(-1);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
116 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
117
09d5c9834580 tv update
alex
parents: 2790
diff changeset
118 static int format2palette(int format)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
119 {
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
120 switch(format)
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
121 {
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
122 case IMGFMT_RGB15:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
123 return(VIDEO_PALETTE_RGB555);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
124 case IMGFMT_RGB16:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
125 return(VIDEO_PALETTE_RGB565);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
126 case IMGFMT_RGB24:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
127 return(VIDEO_PALETTE_RGB24);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
128 case IMGFMT_RGB32:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
129 return(VIDEO_PALETTE_RGB32);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
130 case IMGFMT_YV12:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
131 return(VIDEO_PALETTE_YUV420P);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
132 case IMGFMT_UYVY:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
133 return(VIDEO_PALETTE_YUV422);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
134 }
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
135 return(-1);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
136 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
137
09d5c9834580 tv update
alex
parents: 2790
diff changeset
138 #if 0
09d5c9834580 tv update
alex
parents: 2790
diff changeset
139 struct STRTAB {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
140 long nr;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
141 const char *str;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
142 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
143
09d5c9834580 tv update
alex
parents: 2790
diff changeset
144 static struct STRTAB stereo[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
145 { 0, "auto" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
146 { VIDEO_SOUND_MONO, "mono" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
147 { VIDEO_SOUND_STEREO, "stereo" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
148 { VIDEO_SOUND_LANG1, "lang1" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
149 { VIDEO_SOUND_LANG2, "lang1" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
150 { -1, NULL }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
151 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
152
09d5c9834580 tv update
alex
parents: 2790
diff changeset
153 static struct STRTAB norms_v4l[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
154 { VIDEO_MODE_PAL, "PAL" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
155 { VIDEO_MODE_NTSC, "NTSC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
156 { VIDEO_MODE_SECAM, "SECAM" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
157 { VIDEO_MODE_AUTO, "AUTO" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
158 { -1, NULL }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
159 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
160
09d5c9834580 tv update
alex
parents: 2790
diff changeset
161 static struct STRTAB norms_bttv[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
162 { VIDEO_MODE_PAL, "PAL" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
163 { VIDEO_MODE_NTSC, "NTSC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
164 { VIDEO_MODE_SECAM, "SECAM" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
165 { 3, "PAL-NC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
166 { 4, "PAL-M" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
167 { 5, "PAL-N" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
168 { 6, "NTSC-JP" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
169 { -1, NULL }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
170 };
98769cea155c added tv subsystem
alex
parents:
diff changeset
171
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
172 static unsigned short _format2palette[VIDEO_FMT_COUNT] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
173 0, /* unused */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
174 VIDEO_PALETTE_HI240, /* RGB8 */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
175 VIDEO_PALETTE_GREY,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
176 VIDEO_PALETTE_RGB555,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
177 VIDEO_PALETTE_RGB565,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
178 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
179 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
180 VIDEO_PALETTE_RGB24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
181 VIDEO_PALETTE_RGB32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
182 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
183 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
184 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
185 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
186 VIDEO_PALETTE_YUV422,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
187 VIDEO_PALETTE_YUV422P,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
188 VIDEO_PALETTE_YUV420P,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
189 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
190 #define FMT2PAL(fmt) ((fmt < sizeof(format2palette)/sizeof(unsigned short)) ? \
09d5c9834580 tv update
alex
parents: 2790
diff changeset
191 format2palette[fmt] : 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
192
09d5c9834580 tv update
alex
parents: 2790
diff changeset
193 const unsigned int vfmt_to_depth[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
194 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
195 8,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
196 8,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
197 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
198 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
199 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
200 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
201 24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
202 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
203 24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
204 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
205 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
206 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
207 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
208 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
209 12,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
210 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
211 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
212 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
213 #endif
09d5c9834580 tv update
alex
parents: 2790
diff changeset
214
09d5c9834580 tv update
alex
parents: 2790
diff changeset
215 static int one = 1, zero = 0;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
216
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
217 tvi_handle_t *tvi_init_v4l(char *device)
98769cea155c added tv subsystem
alex
parents:
diff changeset
218 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
219 tvi_handle_t *h;
98769cea155c added tv subsystem
alex
parents:
diff changeset
220 priv_t *priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
221
98769cea155c added tv subsystem
alex
parents:
diff changeset
222 h = new_handle();
98769cea155c added tv subsystem
alex
parents:
diff changeset
223 if (!h)
98769cea155c added tv subsystem
alex
parents:
diff changeset
224 return(NULL);
98769cea155c added tv subsystem
alex
parents:
diff changeset
225
98769cea155c added tv subsystem
alex
parents:
diff changeset
226 priv = h->priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
227
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
228 /* set video device name */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
229 if (!device)
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
230 priv->video_device = strdup("/dev/video0");
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
231 else
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
232 priv->video_device = strdup(device);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
233
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
234 /* allocation failed */
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
235 if (!priv->video_device) {
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
236 free_handle(h);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
237 return(NULL);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
238 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
239
98769cea155c added tv subsystem
alex
parents:
diff changeset
240 return(h);
98769cea155c added tv subsystem
alex
parents:
diff changeset
241 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
242
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
243 static int init(priv_t *priv, tvi_param_t *params)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
244 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
245 int i;
98769cea155c added tv subsystem
alex
parents:
diff changeset
246
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
247 priv->fd = open(priv->video_device, O_RDWR);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
248 if (priv->fd == -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
249 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
250 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
251 priv->video_device, strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
252 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
253 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
254
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
255 mp_msg(MSGT_TV, MSGL_V, "Video fd: %d\n", priv->fd);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
256
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
257 /* get capabilities (priv->capability is needed!) */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
258 if (ioctl(priv->fd, VIDIOCGCAP, &priv->capability) == -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
259 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
260 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
261 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
262 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
263
98769cea155c added tv subsystem
alex
parents:
diff changeset
264 fcntl(priv->fd, F_SETFD, FD_CLOEXEC);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
265
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
266 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name);
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
267 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: ");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
268 for (i = 0; device_cap2name[i] != NULL; i++)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
269 if (priv->capability.type & (1 << i))
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
270 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]);
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
271 mp_msg(MSGT_TV, MSGL_INFO, "\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
272 mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type);
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
273 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n",
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
274 priv->capability.minwidth, priv->capability.minheight,
98769cea155c added tv subsystem
alex
parents:
diff changeset
275 priv->capability.maxwidth, priv->capability.maxheight);
98769cea155c added tv subsystem
alex
parents:
diff changeset
276 priv->width = priv->capability.minwidth;
98769cea155c added tv subsystem
alex
parents:
diff changeset
277 priv->height = priv->capability.minheight;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
278 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
279
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
280 priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels);
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
281 if (!priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
282 goto malloc_failed;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
283 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
98769cea155c added tv subsystem
alex
parents:
diff changeset
284 for (i = 0; i < priv->capability.channels; i++)
98769cea155c added tv subsystem
alex
parents:
diff changeset
285 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
286 priv->channels[i].channel = i;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
287 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
288 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
289 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
290 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
291 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
292 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%d)\n", i,
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
293 priv->channels[i].name,
98769cea155c added tv subsystem
alex
parents:
diff changeset
294 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
295 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
296 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
297 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
298 priv->channels[i].tuners,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
299 priv->channels[i].norm);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
300 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
301
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
302 if (priv->capability.audios)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
303 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
304 mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios);
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
305
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
306 priv->act_audio = 0;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
307
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
308 for (i = 0; i < priv->capability.audios; i++)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
309 {
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
310 priv->audio = realloc(priv->audio, sizeof(struct video_audio)*(i+1));
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
311 priv->audio[i].audio = i;
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
312 if (ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
313 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
314 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno));
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
315 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
316 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
317
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
318 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
319 priv->audio[i].name);
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
320 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
321 mp_msg(MSGT_TV, MSGL_V, "muted=%s ",
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
322 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
323 mp_msg(MSGT_TV, MSGL_V, "volume=%d bass=%d treble=%d balance=%d mode=%s\n",
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
324 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
325 priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]);
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
326
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
327 /* un-mute channels */
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
328 priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE;
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
329 ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]);
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
330 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
331 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
332
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
333 if (!(priv->capability.type & VID_TYPE_CAPTURE))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
334 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
335 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
336 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
337 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
338
09d5c9834580 tv update
alex
parents: 2790
diff changeset
339 /* map grab buffer */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
340 if (ioctl(priv->fd, VIDIOCGMBUF, &priv->mbuf) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
341 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
342 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
343 goto err;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
344 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
345
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
346 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
347 priv->mbuf.size, priv->mbuf.frames);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
348 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
349 MAP_SHARED, priv->fd, 0);
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
350 if (priv->mmap == (unsigned char *)-1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
351 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
352 mp_msg(MSGT_TV, MSGL_ERR, "Unabel to map memory for buffers: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
353 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
354 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
355 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
356
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
357 /* num of buffers */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
358 priv->nbuf = priv->mbuf.frames;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
359
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
360 /* video buffers */
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
361 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap));
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
362 if (!priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
363 goto malloc_failed;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
364 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
365
98769cea155c added tv subsystem
alex
parents:
diff changeset
366 return(1);
98769cea155c added tv subsystem
alex
parents:
diff changeset
367
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
368
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
369 malloc_failed:
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
370 if (priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
371 free(priv->channels);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
372 if (priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
373 free(priv->buf);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
374 err:
98769cea155c added tv subsystem
alex
parents:
diff changeset
375 if (priv->fd != -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
376 close(priv->fd);
98769cea155c added tv subsystem
alex
parents:
diff changeset
377 return(0);
98769cea155c added tv subsystem
alex
parents:
diff changeset
378 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
379
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
380 static int uninit(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
381 {
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
382 close(priv->fd);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
383 #warning "Implement uninit!"
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
384
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
385 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
386 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
387
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
388 static int start(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
389 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
390 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
391
09d5c9834580 tv update
alex
parents: 2790
diff changeset
392
09d5c9834580 tv update
alex
parents: 2790
diff changeset
393 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
394 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
395 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
396 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
397 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
398
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
399 priv->picture.palette = format2palette(priv->format);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
400 priv->picture.depth = palette2depth(priv->picture.palette);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
401 priv->bytesperline = priv->width * priv->picture.depth / 8;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
402
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
403 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
404 mp_msg(MSGT_TV, MSGL_INFO, " Depth: %d, Palette: %d (Format: %s)\n", priv->picture.depth,
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
405 priv->picture.palette, vo_format_name(priv->format));
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
406 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
407 priv->picture.brightness, priv->picture.hue,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
408 priv->picture.colour, priv->picture.contrast);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
409
09d5c9834580 tv update
alex
parents: 2790
diff changeset
410
09d5c9834580 tv update
alex
parents: 2790
diff changeset
411 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
412 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
413 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
414 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
415 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
416
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
417 priv->nbuf = priv->mbuf.frames;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
418 for (i=0; i < priv->nbuf; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
419 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
420 priv->buf[i].format = priv->picture.palette;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
421 priv->buf[i].frame = i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
422 priv->buf[i].width = priv->width;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
423 priv->buf[i].height = priv->height;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
424 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
425 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
426
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
427 #if 0
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
428 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
429 struct video_play_mode pmode;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
430
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
431 pmode.mode = VID_PLAY_NORMAL;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
432 pmode.p1 = 1;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
433 pmode.p2 = 0;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
434 if (ioctl(priv->fd, VIDIOCSPLAYMODE, &pmode) == -1)
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
435 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
436 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
437 // return(0);
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
438 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
439 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
440 #endif
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
441
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
442 #if 0
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
443 {
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
444 struct video_window win;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
445
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
446 win.x = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
447 win.y = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
448 win.width = priv->width;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
449 win.height = priv->height;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
450 win.chromakey = -1;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
451 win.flags = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
452
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
453 ioctl(priv->fd, VIDIOCSWIN, &win);
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
454 }
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
455
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
456 /* start capture */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
457 if (ioctl(priv->fd, VIDIOCCAPTURE, &one) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
458 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
459 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
460 return(0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
461 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
462 #endif
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
463
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
464 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
465 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
466
98769cea155c added tv subsystem
alex
parents:
diff changeset
467 static int control(priv_t *priv, int cmd, void *arg)
98769cea155c added tv subsystem
alex
parents:
diff changeset
468 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
469 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
470 priv, cmd, arg);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
471 switch(cmd)
98769cea155c added tv subsystem
alex
parents:
diff changeset
472 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
473 /* ========== GENERIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
474 case TVI_CONTROL_IS_VIDEO:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
475 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
476 if (priv->capability.type & VID_TYPE_CAPTURE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
477 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
478 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
479 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
480 case TVI_CONTROL_IS_AUDIO:
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
481 #if 0 /* also disable audio for as it's not working! */
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
482 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
483 return(TVI_CONTROL_TRUE);
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
484 #endif
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
485 return(TVI_CONTROL_FALSE);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
486 case TVI_CONTROL_IS_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
487 {
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
488 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
489 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
490 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
491 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
492 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
493
09d5c9834580 tv update
alex
parents: 2790
diff changeset
494 /* ========== VIDEO controls =========== */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
495 case TVI_CONTROL_VID_GET_FORMAT:
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
496 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
497 int output_fmt = -1;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
498
09d5c9834580 tv update
alex
parents: 2790
diff changeset
499 output_fmt = priv->format;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
500 (int)*(void **)arg = output_fmt;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
501 mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
502 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
503 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
504 case TVI_CONTROL_VID_SET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
505 priv->format = (int)*(void **)arg;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
506 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
507 case TVI_CONTROL_VID_GET_PLANES:
3220
alex
parents: 2937
diff changeset
508 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
509 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
510 case TVI_CONTROL_VID_GET_BITS:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
511 (int)*(void **)arg = palette2depth(format2palette(priv->format));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
512 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
513 case TVI_CONTROL_VID_GET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
514 (int)*(void **)arg = priv->width;
98769cea155c added tv subsystem
alex
parents:
diff changeset
515 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
516 case TVI_CONTROL_VID_CHK_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
517 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
518 int req_width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
519
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
520 mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
521 if ((req_width >= priv->capability.minwidth) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
522 (req_width <= priv->capability.maxwidth))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
523 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
524 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
525 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
526 case TVI_CONTROL_VID_SET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
527 priv->width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
528 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
529 case TVI_CONTROL_VID_GET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
530 (int)*(void **)arg = priv->height;
98769cea155c added tv subsystem
alex
parents:
diff changeset
531 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
532 case TVI_CONTROL_VID_CHK_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
533 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
534 int req_height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
535
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
536 mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
537 if ((req_height >= priv->capability.minheight) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
538 (req_height <= priv->capability.maxheight))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
539 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
540 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
541 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
542 case TVI_CONTROL_VID_SET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
543 priv->height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
544 return(TVI_CONTROL_TRUE);
2937
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
545 case TVI_CONTROL_VID_GET_PICTURE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
546 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1)
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
547 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
548 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
549 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
550 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
551 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
552 case TVI_CONTROL_VID_SET_PICTURE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
553 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1)
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
554 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
555 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
556 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
557 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
558 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
559 case TVI_CONTROL_VID_SET_BRIGHTNESS:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
560 priv->picture.brightness = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
561 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
562 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
563 case TVI_CONTROL_VID_SET_HUE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
564 priv->picture.hue = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
565 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
566 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
567 case TVI_CONTROL_VID_SET_SATURATION:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
568 priv->picture.colour = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
569 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
570 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
571 case TVI_CONTROL_VID_SET_CONTRAST:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
572 priv->picture.contrast = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
573 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
574 return(TVI_CONTROL_TRUE);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
575
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
576 /* ========== TUNER controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
577 case TVI_CONTROL_TUN_GET_FREQ:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
578 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
579 unsigned long freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
580
09d5c9834580 tv update
alex
parents: 2790
diff changeset
581 if (ioctl(priv->fd, VIDIOCGFREQ, &freq) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
582 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
583 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
584 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
585 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
586
09d5c9834580 tv update
alex
parents: 2790
diff changeset
587 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
588 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
589 // freq /= 1000;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
590 (unsigned long)*(void **)arg = freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
591 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
592 }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
593 case TVI_CONTROL_TUN_SET_FREQ:
98769cea155c added tv subsystem
alex
parents:
diff changeset
594 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
595 /* argument is in MHz ! */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
596 unsigned long freq = (unsigned long)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
597
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
598 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
599
09d5c9834580 tv update
alex
parents: 2790
diff changeset
600 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
601 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
602 // freq *= 1000;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
603 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
604 if (ioctl(priv->fd, VIDIOCSFREQ, &freq) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
605 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
606 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
607 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
608 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
609 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
610 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
611 case TVI_CONTROL_TUN_GET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
612 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
613 if (ioctl(priv->fd, VIDIOCGTUNER, &priv->tuner) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
614 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
615 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
616 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
617 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
618
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
619 mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
620 priv->tuner.rangelow, priv->tuner.rangehigh);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
621 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
622 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
623 case TVI_CONTROL_TUN_SET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
624 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
625 if (ioctl(priv->fd, VIDIOCSTUNER, &priv->tuner) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
626 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
627 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
628 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
629 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
630 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
631 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
632 case TVI_CONTROL_TUN_SET_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
633 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
634 int req_mode = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
635
09d5c9834580 tv update
alex
parents: 2790
diff changeset
636 if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
637 ((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
638 ((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
639 ((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM)))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
640 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
641 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
642 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
643 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
644
09d5c9834580 tv update
alex
parents: 2790
diff changeset
645 priv->tuner.mode = req_mode;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
646
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
647 if (control(priv->fd, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
648 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
649 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
650 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
651 case TVI_CONTROL_TUN_GET_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
652 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
653 (int)*(void **)arg = priv->tuner.mode;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
654
09d5c9834580 tv update
alex
parents: 2790
diff changeset
655 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
656 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
657
09d5c9834580 tv update
alex
parents: 2790
diff changeset
658 /* ========== AUDIO controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
659 case TVI_CONTROL_AUD_GET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
660 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
661 (int)*(void **)arg = AFMT_S16_LE;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
662 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
663 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
664 case TVI_CONTROL_AUD_GET_CHANNELS:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
665 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
666 (int)*(void **)arg = 2;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
667 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
668 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
669 case TVI_CONTROL_AUD_GET_SAMPLERATE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
670 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
671 (int)*(void **)arg = 44100;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
672 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
673 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
674 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
675 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
676 (int)*(void **)arg = 76000;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
677 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
678 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
679
09d5c9834580 tv update
alex
parents: 2790
diff changeset
680 /* ========== SPECIFIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
681 case TVI_CONTROL_SPC_GET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
682 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
683 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
684 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
685
09d5c9834580 tv update
alex
parents: 2790
diff changeset
686 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
687 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
688 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
689 break;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
690 }
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
691
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
692 priv->act_channel = i;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
693
09d5c9834580 tv update
alex
parents: 2790
diff changeset
694 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
695 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
696 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
697 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
698 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
699 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
700 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
701
09d5c9834580 tv update
alex
parents: 2790
diff changeset
702 case TVI_CONTROL_SPC_SET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
703 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
704 struct video_channel chan;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
705 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
706 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
707
09d5c9834580 tv update
alex
parents: 2790
diff changeset
708 if (req_chan >= priv->capability.channels)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
709 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
710 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
711 req_chan, priv->capability.channels);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
712 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
713 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
714
09d5c9834580 tv update
alex
parents: 2790
diff changeset
715 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
716 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
717 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
718 chan = priv->channels[i];
09d5c9834580 tv update
alex
parents: 2790
diff changeset
719 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
720
09d5c9834580 tv update
alex
parents: 2790
diff changeset
721 if (ioctl(priv->fd, VIDIOCSCHAN, &chan) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
722 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
723 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
724 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
725 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
726 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
727
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
728 priv->act_channel = i;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
729
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
730 /* update tuner state */
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
731 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
732 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
733 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
734
09d5c9834580 tv update
alex
parents: 2790
diff changeset
735 /* update local channel list */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
736 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
737 return(TVI_CONTROL_TRUE);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
738 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
739 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
740
98769cea155c added tv subsystem
alex
parents:
diff changeset
741 return(TVI_CONTROL_UNKNOWN);
98769cea155c added tv subsystem
alex
parents:
diff changeset
742 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
743
98769cea155c added tv subsystem
alex
parents:
diff changeset
744 static int grab_video_frame(priv_t *priv, char *buffer, int len)
98769cea155c added tv subsystem
alex
parents:
diff changeset
745 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
746 int frame = priv->queue % priv->nbuf;
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
747 int nextframe = (priv->queue+1) % priv->nbuf;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
748
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
749 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d)\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
750 priv, buffer, len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
751
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
752 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n",
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
753 priv->buf, nextframe, &priv->buf[nextframe]);
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
754 if (ioctl(priv->fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
755 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
756 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
757 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
758 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
759
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
760 if (ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame].frame) == -1)
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
761 mp_msg(MSGT_TV, MSGL_ERR, "ioctl sync failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
762 priv->queue++;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
763
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
764 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
765 priv->mmap, priv->mbuf.offsets[frame],
09d5c9834580 tv update
alex
parents: 2790
diff changeset
766 priv->mmap+priv->mbuf.offsets[frame]);
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
767
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
768 /* XXX also directrendering would be nicer! */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
769 /* 3 times copying the same picture to other buffer :( */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
770
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
771 /* copy the actual frame */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
772 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
773
09d5c9834580 tv update
alex
parents: 2790
diff changeset
774 return(len);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
775 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
776
98769cea155c added tv subsystem
alex
parents:
diff changeset
777 static int get_video_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
778 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
779 return(priv->bytesperline * priv->height);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
780 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
781
98769cea155c added tv subsystem
alex
parents:
diff changeset
782 static int grab_audio_frame(priv_t *priv, char *buffer, int len)
98769cea155c added tv subsystem
alex
parents:
diff changeset
783 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
784 return(65536);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
785 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
786
98769cea155c added tv subsystem
alex
parents:
diff changeset
787 static int get_audio_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
788 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
789 return(65536);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
790 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
791
98769cea155c added tv subsystem
alex
parents:
diff changeset
792 #endif /* USE_TV */