annotate libmpdemux/tvi_v4l.c @ 3099:897d46457708

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