annotate libmpdemux/tvi_v4l.c @ 3766:771cb762cacc

authors updated. TODO: mms/rtp streaming authors, dvd subtitles author, etc (see whatsnew)
author arpi
date Wed, 26 Dec 2001 14:22:42 +0000
parents 5fa7eb90e2ec
children 622a9ade4517
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:
3703
3717145636b5 i420 support
alex
parents: 3611
diff changeset
131 case IMGFMT_I420:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
132 return(VIDEO_PALETTE_YUV420P);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
133 case IMGFMT_UYVY:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
134 return(VIDEO_PALETTE_YUV422);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
135 }
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
136 return(-1);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
137 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
138
09d5c9834580 tv update
alex
parents: 2790
diff changeset
139 #if 0
09d5c9834580 tv update
alex
parents: 2790
diff changeset
140 struct STRTAB {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
141 long nr;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
142 const char *str;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
143 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
144
09d5c9834580 tv update
alex
parents: 2790
diff changeset
145 static struct STRTAB stereo[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
146 { 0, "auto" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
147 { VIDEO_SOUND_MONO, "mono" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
148 { VIDEO_SOUND_STEREO, "stereo" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
149 { VIDEO_SOUND_LANG1, "lang1" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
150 { VIDEO_SOUND_LANG2, "lang1" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
151 { -1, NULL }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
152 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
153
09d5c9834580 tv update
alex
parents: 2790
diff changeset
154 static struct STRTAB norms_v4l[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
155 { VIDEO_MODE_PAL, "PAL" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
156 { VIDEO_MODE_NTSC, "NTSC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
157 { VIDEO_MODE_SECAM, "SECAM" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
158 { VIDEO_MODE_AUTO, "AUTO" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
159 { -1, NULL }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
160 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
161
09d5c9834580 tv update
alex
parents: 2790
diff changeset
162 static struct STRTAB norms_bttv[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
163 { VIDEO_MODE_PAL, "PAL" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
164 { VIDEO_MODE_NTSC, "NTSC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
165 { VIDEO_MODE_SECAM, "SECAM" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
166 { 3, "PAL-NC" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
167 { 4, "PAL-M" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
168 { 5, "PAL-N" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
169 { 6, "NTSC-JP" },
09d5c9834580 tv update
alex
parents: 2790
diff changeset
170 { -1, NULL }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
171 };
98769cea155c added tv subsystem
alex
parents:
diff changeset
172
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
173 static unsigned short _format2palette[VIDEO_FMT_COUNT] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
174 0, /* unused */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
175 VIDEO_PALETTE_HI240, /* RGB8 */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
176 VIDEO_PALETTE_GREY,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
177 VIDEO_PALETTE_RGB555,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
178 VIDEO_PALETTE_RGB565,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
179 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
180 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
181 VIDEO_PALETTE_RGB24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
182 VIDEO_PALETTE_RGB32,
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 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
187 VIDEO_PALETTE_YUV422,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
188 VIDEO_PALETTE_YUV422P,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
189 VIDEO_PALETTE_YUV420P,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
190 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
191 #define FMT2PAL(fmt) ((fmt < sizeof(format2palette)/sizeof(unsigned short)) ? \
09d5c9834580 tv update
alex
parents: 2790
diff changeset
192 format2palette[fmt] : 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
193
09d5c9834580 tv update
alex
parents: 2790
diff changeset
194 const unsigned int vfmt_to_depth[] = {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
195 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
196 8,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
197 8,
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 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
202 24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
203 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
204 24,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
205 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
206 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
207 32,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
208 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
209 16,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
210 12,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
211 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
212 0,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
213 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
214 #endif
09d5c9834580 tv update
alex
parents: 2790
diff changeset
215
09d5c9834580 tv update
alex
parents: 2790
diff changeset
216 static int one = 1, zero = 0;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
217
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
218 tvi_handle_t *tvi_init_v4l(char *device)
98769cea155c added tv subsystem
alex
parents:
diff changeset
219 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
220 tvi_handle_t *h;
98769cea155c added tv subsystem
alex
parents:
diff changeset
221 priv_t *priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
222
98769cea155c added tv subsystem
alex
parents:
diff changeset
223 h = new_handle();
98769cea155c added tv subsystem
alex
parents:
diff changeset
224 if (!h)
98769cea155c added tv subsystem
alex
parents:
diff changeset
225 return(NULL);
98769cea155c added tv subsystem
alex
parents:
diff changeset
226
98769cea155c added tv subsystem
alex
parents:
diff changeset
227 priv = h->priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
228
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
229 /* set video device name */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
230 if (!device)
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
231 priv->video_device = strdup("/dev/video0");
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
232 else
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
233 priv->video_device = strdup(device);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
234
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
235 /* allocation failed */
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
236 if (!priv->video_device) {
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
237 free_handle(h);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
238 return(NULL);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
239 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
240
98769cea155c added tv subsystem
alex
parents:
diff changeset
241 return(h);
98769cea155c added tv subsystem
alex
parents:
diff changeset
242 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
243
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
244 static int init(priv_t *priv, tvi_param_t *params)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
245 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
246 int i;
98769cea155c added tv subsystem
alex
parents:
diff changeset
247
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
248 priv->fd = open(priv->video_device, O_RDWR);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
249 if (priv->fd == -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
250 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
251 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
252 priv->video_device, strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
253 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
254 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
255
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
256 mp_msg(MSGT_TV, MSGL_V, "Video fd: %d\n", priv->fd);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
257
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
258 /* get capabilities (priv->capability is needed!) */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
259 if (ioctl(priv->fd, VIDIOCGCAP, &priv->capability) == -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
260 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
261 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
262 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
263 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
264
98769cea155c added tv subsystem
alex
parents:
diff changeset
265 fcntl(priv->fd, F_SETFD, FD_CLOEXEC);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
266
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
267 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
268 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: ");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
269 for (i = 0; device_cap2name[i] != NULL; i++)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
270 if (priv->capability.type & (1 << i))
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
271 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]);
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
272 mp_msg(MSGT_TV, MSGL_INFO, "\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
273 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
274 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n",
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
275 priv->capability.minwidth, priv->capability.minheight,
98769cea155c added tv subsystem
alex
parents:
diff changeset
276 priv->capability.maxwidth, priv->capability.maxheight);
98769cea155c added tv subsystem
alex
parents:
diff changeset
277 priv->width = priv->capability.minwidth;
98769cea155c added tv subsystem
alex
parents:
diff changeset
278 priv->height = priv->capability.minheight;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
279 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
280
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
281 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
282 if (!priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
283 goto malloc_failed;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
284 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
98769cea155c added tv subsystem
alex
parents:
diff changeset
285 for (i = 0; i < priv->capability.channels; i++)
98769cea155c added tv subsystem
alex
parents:
diff changeset
286 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
287 priv->channels[i].channel = i;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
288 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
289 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
290 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
291 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
292 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
293 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
294 priv->channels[i].name,
98769cea155c added tv subsystem
alex
parents:
diff changeset
295 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
296 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
297 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
298 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
299 priv->channels[i].tuners,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
300 priv->channels[i].norm);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
301 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
302
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
303 if (priv->capability.audios)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
304 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
305 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
306
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
307 priv->act_audio = 0;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
308
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
309 for (i = 0; i < priv->capability.audios; i++)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
310 {
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
311 priv->audio = realloc(priv->audio, sizeof(struct video_audio)*(i+1));
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
312 priv->audio[i].audio = i;
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
313 if (ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
314 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
315 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
316 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
317 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
318
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
319 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
320 priv->audio[i].name);
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
321 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
322 mp_msg(MSGT_TV, MSGL_V, "muted=%s ",
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
323 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
324 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
325 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
326 priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]);
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
327
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
328 /* un-mute channels */
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
329 priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE;
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
330 ioctl(priv->fd, VIDIOCGAUDIO, &priv->audio[i]);
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
331 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
332 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
333
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
334 if (!(priv->capability.type & VID_TYPE_CAPTURE))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
335 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
336 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
337 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
338 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
339
09d5c9834580 tv update
alex
parents: 2790
diff changeset
340 /* map grab buffer */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
341 if (ioctl(priv->fd, VIDIOCGMBUF, &priv->mbuf) == -1)
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, "ioctl get mbuf failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
344 goto err;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
345 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
346
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
347 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
348 priv->mbuf.size, priv->mbuf.frames);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
349 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
350 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
351 if (priv->mmap == (unsigned char *)-1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
352 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
353 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
354 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
355 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
356 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
357
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
358 /* num of buffers */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
359 priv->nbuf = priv->mbuf.frames;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
360
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
361 /* video buffers */
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
362 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
363 if (!priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
364 goto malloc_failed;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
365 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
366
98769cea155c added tv subsystem
alex
parents:
diff changeset
367 return(1);
98769cea155c added tv subsystem
alex
parents:
diff changeset
368
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
369
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
370 malloc_failed:
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
371 if (priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
372 free(priv->channels);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
373 if (priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
374 free(priv->buf);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
375 err:
98769cea155c added tv subsystem
alex
parents:
diff changeset
376 if (priv->fd != -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
377 close(priv->fd);
98769cea155c added tv subsystem
alex
parents:
diff changeset
378 return(0);
98769cea155c added tv subsystem
alex
parents:
diff changeset
379 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
380
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
381 static int uninit(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
382 {
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
383 close(priv->fd);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
384 #warning "Implement uninit!"
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
385
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
386 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
387 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
388
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
389 static int start(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
390 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
391 int i;
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, VIDIOCGPICT, &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 get 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->picture.palette = format2palette(priv->format);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
401 priv->picture.depth = palette2depth(priv->picture.palette);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
402 priv->bytesperline = priv->width * priv->picture.depth / 8;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
403
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
404 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
405 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
406 priv->picture.palette, vo_format_name(priv->format));
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
407 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
408 priv->picture.brightness, priv->picture.hue,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
409 priv->picture.colour, priv->picture.contrast);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
410
09d5c9834580 tv update
alex
parents: 2790
diff changeset
411
09d5c9834580 tv update
alex
parents: 2790
diff changeset
412 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
413 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
414 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
415 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
416 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
417
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
418 priv->nbuf = priv->mbuf.frames;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
419 for (i=0; i < priv->nbuf; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
420 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
421 priv->buf[i].format = priv->picture.palette;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
422 priv->buf[i].frame = i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
423 priv->buf[i].width = priv->width;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
424 priv->buf[i].height = priv->height;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
425 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
426 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
427
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
428 #if 0
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
429 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
430 struct video_play_mode pmode;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
431
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
432 pmode.mode = VID_PLAY_NORMAL;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
433 pmode.p1 = 1;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
434 pmode.p2 = 0;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
435 if (ioctl(priv->fd, VIDIOCSPLAYMODE, &pmode) == -1)
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
436 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
437 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
438 // return(0);
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
439 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
440 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
441 #endif
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
442
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
443 #if 0
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
444 {
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
445 struct video_window win;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
446
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
447 win.x = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
448 win.y = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
449 win.width = priv->width;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
450 win.height = priv->height;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
451 win.chromakey = -1;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
452 win.flags = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
453
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
454 ioctl(priv->fd, VIDIOCSWIN, &win);
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
455 }
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
456
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
457 /* start capture */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
458 if (ioctl(priv->fd, VIDIOCCAPTURE, &one) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
459 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
460 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
461 return(0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
462 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
463 #endif
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
464
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
465 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
466 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
467
98769cea155c added tv subsystem
alex
parents:
diff changeset
468 static int control(priv_t *priv, int cmd, void *arg)
98769cea155c added tv subsystem
alex
parents:
diff changeset
469 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
470 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
471 priv, cmd, arg);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
472 switch(cmd)
98769cea155c added tv subsystem
alex
parents:
diff changeset
473 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
474 /* ========== GENERIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
475 case TVI_CONTROL_IS_VIDEO:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
476 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
477 if (priv->capability.type & VID_TYPE_CAPTURE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
478 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
479 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
480 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
481 case TVI_CONTROL_IS_AUDIO:
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
482 #if 0 /* also disable audio for as it's not working! */
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
483 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
484 return(TVI_CONTROL_TRUE);
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
485 #endif
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
486 return(TVI_CONTROL_FALSE);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
487 case TVI_CONTROL_IS_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
488 {
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
489 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
490 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
491 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
492 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
493 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
494
09d5c9834580 tv update
alex
parents: 2790
diff changeset
495 /* ========== VIDEO controls =========== */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
496 case TVI_CONTROL_VID_GET_FORMAT:
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
497 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
498 int output_fmt = -1;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
499
09d5c9834580 tv update
alex
parents: 2790
diff changeset
500 output_fmt = priv->format;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
501 (int)*(void **)arg = output_fmt;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
502 mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
503 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
504 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
505 case TVI_CONTROL_VID_SET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
506 priv->format = (int)*(void **)arg;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
507 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
508 case TVI_CONTROL_VID_GET_PLANES:
3220
alex
parents: 2937
diff changeset
509 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
510 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
511 case TVI_CONTROL_VID_GET_BITS:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
512 (int)*(void **)arg = palette2depth(format2palette(priv->format));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
513 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
514 case TVI_CONTROL_VID_GET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
515 (int)*(void **)arg = priv->width;
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_CHK_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
518 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
519 int req_width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
520
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
521 mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
522 if ((req_width >= priv->capability.minwidth) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
523 (req_width <= priv->capability.maxwidth))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
524 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
525 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
526 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
527 case TVI_CONTROL_VID_SET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
528 priv->width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
529 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
530 case TVI_CONTROL_VID_GET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
531 (int)*(void **)arg = priv->height;
98769cea155c added tv subsystem
alex
parents:
diff changeset
532 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
533 case TVI_CONTROL_VID_CHK_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
534 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
535 int req_height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
536
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
537 mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
538 if ((req_height >= priv->capability.minheight) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
539 (req_height <= priv->capability.maxheight))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
540 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
541 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
542 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
543 case TVI_CONTROL_VID_SET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
544 priv->height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
545 return(TVI_CONTROL_TRUE);
2937
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
546 case TVI_CONTROL_VID_GET_PICTURE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
547 if (ioctl(priv->fd, VIDIOCGPICT, &priv->picture) == -1)
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
548 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
549 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
550 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
551 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
552 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
553 case TVI_CONTROL_VID_SET_PICTURE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
554 if (ioctl(priv->fd, VIDIOCSPICT, &priv->picture) == -1)
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
555 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
556 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
557 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
558 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
559 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
560 case TVI_CONTROL_VID_SET_BRIGHTNESS:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
561 priv->picture.brightness = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
562 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
563 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
564 case TVI_CONTROL_VID_SET_HUE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
565 priv->picture.hue = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
566 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
567 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
568 case TVI_CONTROL_VID_SET_SATURATION:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
569 priv->picture.colour = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
570 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
571 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
572 case TVI_CONTROL_VID_SET_CONTRAST:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
573 priv->picture.contrast = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
574 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
575 return(TVI_CONTROL_TRUE);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
576
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
577 /* ========== TUNER controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
578 case TVI_CONTROL_TUN_GET_FREQ:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
579 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
580 unsigned long freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
581
09d5c9834580 tv update
alex
parents: 2790
diff changeset
582 if (ioctl(priv->fd, VIDIOCGFREQ, &freq) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
583 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
584 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
585 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
586 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
587
09d5c9834580 tv update
alex
parents: 2790
diff changeset
588 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
589 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
590 // freq /= 1000;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
591 (unsigned long)*(void **)arg = freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
592 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
593 }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
594 case TVI_CONTROL_TUN_SET_FREQ:
98769cea155c added tv subsystem
alex
parents:
diff changeset
595 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
596 /* argument is in MHz ! */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
597 unsigned long freq = (unsigned long)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
598
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
599 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
600
09d5c9834580 tv update
alex
parents: 2790
diff changeset
601 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
602 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
603 // freq *= 1000;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
604 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
605 if (ioctl(priv->fd, VIDIOCSFREQ, &freq) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
606 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
607 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
608 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
609 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
610 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
611 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
612 case TVI_CONTROL_TUN_GET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
613 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
614 if (ioctl(priv->fd, VIDIOCGTUNER, &priv->tuner) == -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 get tuner 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
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
620 mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
621 priv->tuner.rangelow, priv->tuner.rangehigh);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
622 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
623 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
624 case TVI_CONTROL_TUN_SET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
625 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
626 if (ioctl(priv->fd, VIDIOCSTUNER, &priv->tuner) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
627 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
628 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
629 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
630 }
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_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
634 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
635 int req_mode = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
636
09d5c9834580 tv update
alex
parents: 2790
diff changeset
637 if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
638 ((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
639 ((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
640 ((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM)))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
641 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
642 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
643 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
644 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
645
09d5c9834580 tv update
alex
parents: 2790
diff changeset
646 priv->tuner.mode = req_mode;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
647
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
648 if (control(priv->fd, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
649 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
650 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
651 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
652 case TVI_CONTROL_TUN_GET_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
653 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
654 (int)*(void **)arg = priv->tuner.mode;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
655
09d5c9834580 tv update
alex
parents: 2790
diff changeset
656 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
657 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
658
09d5c9834580 tv update
alex
parents: 2790
diff changeset
659 /* ========== AUDIO controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
660 case TVI_CONTROL_AUD_GET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
661 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
662 (int)*(void **)arg = AFMT_S16_LE;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
663 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
664 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
665 case TVI_CONTROL_AUD_GET_CHANNELS:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
666 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
667 (int)*(void **)arg = 2;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
668 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
669 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
670 case TVI_CONTROL_AUD_GET_SAMPLERATE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
671 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
672 (int)*(void **)arg = 44100;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
673 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
674 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
675 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
676 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
677 (int)*(void **)arg = 76000;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
678 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
679 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
680
09d5c9834580 tv update
alex
parents: 2790
diff changeset
681 /* ========== SPECIFIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
682 case TVI_CONTROL_SPC_GET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
683 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
684 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
685 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
686
09d5c9834580 tv update
alex
parents: 2790
diff changeset
687 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
688 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
689 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
690 break;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
691 }
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
692
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
693 priv->act_channel = i;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
694
09d5c9834580 tv update
alex
parents: 2790
diff changeset
695 if (ioctl(priv->fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
696 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
697 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
698 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
699 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
700 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
701 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
702
09d5c9834580 tv update
alex
parents: 2790
diff changeset
703 case TVI_CONTROL_SPC_SET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
704 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
705 struct video_channel chan;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
706 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
707 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
708
09d5c9834580 tv update
alex
parents: 2790
diff changeset
709 if (req_chan >= priv->capability.channels)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
710 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
711 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
712 req_chan, priv->capability.channels);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
713 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
714 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
715
09d5c9834580 tv update
alex
parents: 2790
diff changeset
716 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
717 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
718 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
719 chan = priv->channels[i];
09d5c9834580 tv update
alex
parents: 2790
diff changeset
720 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
721
09d5c9834580 tv update
alex
parents: 2790
diff changeset
722 if (ioctl(priv->fd, VIDIOCSCHAN, &chan) == -1)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
723 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
724 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
725 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
726 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
727 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
728
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
729 priv->act_channel = i;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
730
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
731 /* update tuner state */
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
732 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
733 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
734 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
735
09d5c9834580 tv update
alex
parents: 2790
diff changeset
736 /* update local channel list */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
737 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
738 return(TVI_CONTROL_TRUE);
2790
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
98769cea155c added tv subsystem
alex
parents:
diff changeset
742 return(TVI_CONTROL_UNKNOWN);
98769cea155c added tv subsystem
alex
parents:
diff changeset
743 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
744
98769cea155c added tv subsystem
alex
parents:
diff changeset
745 static int grab_video_frame(priv_t *priv, char *buffer, int len)
98769cea155c added tv subsystem
alex
parents:
diff changeset
746 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
747 int frame = priv->queue % priv->nbuf;
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
748 int nextframe = (priv->queue+1) % priv->nbuf;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
749
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
750 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
751 priv, buffer, len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
752
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
753 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n",
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
754 priv->buf, nextframe, &priv->buf[nextframe]);
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
755 if (ioctl(priv->fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
756 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
757 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
758 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
759 }
3711
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
760
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
761 while (ioctl(priv->fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
762 (errno == EAGAIN || errno == EINTR));
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
763 mp_dbg(MSGT_TV, MSGL_DBG3, "picture sync failed\n");
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
764
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
765 priv->queue++;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
766
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
767 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
768 priv->mmap, priv->mbuf.offsets[frame],
09d5c9834580 tv update
alex
parents: 2790
diff changeset
769 priv->mmap+priv->mbuf.offsets[frame]);
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
770
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
771 /* XXX also directrendering would be nicer! */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
772 /* 3 times copying the same picture to other buffer :( */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
773
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
774 /* copy the actual frame */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
775 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
776
09d5c9834580 tv update
alex
parents: 2790
diff changeset
777 return(len);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
778 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
779
98769cea155c added tv subsystem
alex
parents:
diff changeset
780 static int get_video_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
781 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
782 return(priv->bytesperline * priv->height);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
783 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
784
98769cea155c added tv subsystem
alex
parents:
diff changeset
785 static int grab_audio_frame(priv_t *priv, char *buffer, int len)
98769cea155c added tv subsystem
alex
parents:
diff changeset
786 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
787 return(65536);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
788 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
789
98769cea155c added tv subsystem
alex
parents:
diff changeset
790 static int get_audio_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
791 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
792 return(65536);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
793 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
794
98769cea155c added tv subsystem
alex
parents:
diff changeset
795 #endif /* USE_TV */