annotate libmpdemux/tvi_v4l.c @ 6703:feeaffcce1fa

adapting to the 'adding fff prefix to avoid global name conflicts' changes in libavcodec
author rik
date Thu, 11 Jul 2002 13:05:53 +0000
parents d000112bd06e
children 2e5c07262861
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>
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
22 #include <sys/time.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
23 #include <linux/videodev.h>
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
24 #include <linux/soundcard.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
25 #include <unistd.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
26 #include <sys/mman.h>
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
27 #include <stdlib.h>
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
28 #include <string.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
29
2830
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
30 #include "mp_msg.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
31 #include "../libao2/afmt.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
32 #include "../libvo/img_format.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
33 #include "../libvo/fastmemcpy.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
34
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
35 #include "tv.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
36
98769cea155c added tv subsystem
alex
parents:
diff changeset
37 static tvi_info_t info = {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
38 "Video 4 Linux input",
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
39 "v4l",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
40 "Alex Beregszaszi <alex@naxine.org>",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
41 "under development"
09d5c9834580 tv update
alex
parents: 2790
diff changeset
42 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
43
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
44 #define MAX_AUDIO_CHANNELS 10
622a9ade4517 updated
alex
parents: 3711
diff changeset
45
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
46 typedef struct {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
47 /* general */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
48 char *video_device;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
49 int video_fd;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
50 struct video_capability capability;
98769cea155c added tv subsystem
alex
parents:
diff changeset
51 struct video_channel *channels;
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
52 int act_channel;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
53 struct video_tuner tuner;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
54
09d5c9834580 tv update
alex
parents: 2790
diff changeset
55 /* video */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
56 struct video_picture picture;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
57 int format; /* output format */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
58 int width;
98769cea155c added tv subsystem
alex
parents:
diff changeset
59 int height;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
60 int bytesperline;
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
61 int fps;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
62
09d5c9834580 tv update
alex
parents: 2790
diff changeset
63 struct video_mbuf mbuf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
64 unsigned char *mmap;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
65 struct video_mmap *buf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
66 int nbuf;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
67 int queue;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
68
09d5c9834580 tv update
alex
parents: 2790
diff changeset
69 /* audio */
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
70 int audio_id;
622a9ade4517 updated
alex
parents: 3711
diff changeset
71 char *audio_device;
622a9ade4517 updated
alex
parents: 3711
diff changeset
72 struct video_audio audio[MAX_AUDIO_CHANNELS];
622a9ade4517 updated
alex
parents: 3711
diff changeset
73 int audio_fd;
622a9ade4517 updated
alex
parents: 3711
diff changeset
74 int audio_channels[MAX_AUDIO_CHANNELS];
622a9ade4517 updated
alex
parents: 3711
diff changeset
75 int audio_format[MAX_AUDIO_CHANNELS];
622a9ade4517 updated
alex
parents: 3711
diff changeset
76 int audio_samplesize[MAX_AUDIO_CHANNELS];
622a9ade4517 updated
alex
parents: 3711
diff changeset
77 int audio_samplerate[MAX_AUDIO_CHANNELS];
622a9ade4517 updated
alex
parents: 3711
diff changeset
78 int audio_blocksize;
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
79
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
80 /* other */
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
81 double starttime;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
82 } priv_t;
98769cea155c added tv subsystem
alex
parents:
diff changeset
83
98769cea155c added tv subsystem
alex
parents:
diff changeset
84 #include "tvi_def.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
85
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
86 static const char *device_cap2name[] = {
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
87 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
88 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
89 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL
09d5c9834580 tv update
alex
parents: 2790
diff changeset
90 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
91
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
92 static const char *device_palette2name[] = {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
93 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
94 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
95 "yuv420p", "yuv410p", NULL
09d5c9834580 tv update
alex
parents: 2790
diff changeset
96 };
09d5c9834580 tv update
alex
parents: 2790
diff changeset
97 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN")
09d5c9834580 tv update
alex
parents: 2790
diff changeset
98
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
99 static const char *audio_mode2name[] = {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
100 "unknown", "mono", "stereo", "language1", "language2", NULL
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
101 };
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
102
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
103 static int palette2depth(int palette)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
104 {
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
105 switch(palette)
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
106 {
3220
alex
parents: 2937
diff changeset
107 /* component */
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
108 case VIDEO_PALETTE_RGB555:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
109 return(15);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
110 case VIDEO_PALETTE_RGB565:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
111 return(16);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
112 case VIDEO_PALETTE_RGB24:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
113 return(24);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
114 case VIDEO_PALETTE_RGB32:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
115 return(32);
3220
alex
parents: 2937
diff changeset
116 /* planar */
alex
parents: 2937
diff changeset
117 case VIDEO_PALETTE_YUV411P:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
118 case VIDEO_PALETTE_YUV420P:
3220
alex
parents: 2937
diff changeset
119 case VIDEO_PALETTE_YUV410P:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
120 return(12);
3220
alex
parents: 2937
diff changeset
121 /* packed */
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
122 case VIDEO_PALETTE_YUV422P:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
123 case VIDEO_PALETTE_YUV422:
3220
alex
parents: 2937
diff changeset
124 case VIDEO_PALETTE_YUYV:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
125 case VIDEO_PALETTE_UYVY:
3220
alex
parents: 2937
diff changeset
126 case VIDEO_PALETTE_YUV420:
alex
parents: 2937
diff changeset
127 case VIDEO_PALETTE_YUV411:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
128 return(16);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
129 }
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
130 return(-1);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
131 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
132
09d5c9834580 tv update
alex
parents: 2790
diff changeset
133 static int format2palette(int format)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
134 {
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
135 switch(format)
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
136 {
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
137 case IMGFMT_RGB15:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
138 return(VIDEO_PALETTE_RGB555);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
139 case IMGFMT_RGB16:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
140 return(VIDEO_PALETTE_RGB565);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
141 case IMGFMT_RGB24:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
142 return(VIDEO_PALETTE_RGB24);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
143 case IMGFMT_RGB32:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
144 return(VIDEO_PALETTE_RGB32);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
145 case IMGFMT_YV12:
3703
3717145636b5 i420 support
alex
parents: 3611
diff changeset
146 case IMGFMT_I420:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
147 return(VIDEO_PALETTE_YUV420P);
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
148 case IMGFMT_UYVY:
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
149 return(VIDEO_PALETTE_YUV422);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
150 case IMGFMT_YUY2:
622a9ade4517 updated
alex
parents: 3711
diff changeset
151 return(VIDEO_PALETTE_YUYV);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
152 }
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
153 return(-1);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
154 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
155
09d5c9834580 tv update
alex
parents: 2790
diff changeset
156 static int one = 1, zero = 0;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
157
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
158 tvi_handle_t *tvi_init_v4l(char *device)
98769cea155c added tv subsystem
alex
parents:
diff changeset
159 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
160 tvi_handle_t *h;
98769cea155c added tv subsystem
alex
parents:
diff changeset
161 priv_t *priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
162
98769cea155c added tv subsystem
alex
parents:
diff changeset
163 h = new_handle();
98769cea155c added tv subsystem
alex
parents:
diff changeset
164 if (!h)
98769cea155c added tv subsystem
alex
parents:
diff changeset
165 return(NULL);
98769cea155c added tv subsystem
alex
parents:
diff changeset
166
98769cea155c added tv subsystem
alex
parents:
diff changeset
167 priv = h->priv;
98769cea155c added tv subsystem
alex
parents:
diff changeset
168
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
169 /* set video device name */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
170 if (!device)
5088
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
171 priv->video_device = strdup("/dev/video");
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
172 else
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
173 priv->video_device = strdup(device);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
174
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
175 /* allocation failed */
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
176 if (!priv->video_device) {
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
177 free_handle(h);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
178 return(NULL);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
179 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
180
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
181 /* set audio device name */
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
182 priv->audio_device = strdup("/dev/dsp");
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
183
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
184 return(h);
98769cea155c added tv subsystem
alex
parents:
diff changeset
185 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
186
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
187 static int init(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
188 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
189 int i;
98769cea155c added tv subsystem
alex
parents:
diff changeset
190
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
191 priv->video_fd = open(priv->video_device, O_RDWR);
5088
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
192 mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %x\n", priv->video_fd,
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
193 priv->video_device);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
194 if (priv->video_fd == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
195 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
196 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
197 priv->video_device, strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
198 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
199 }
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
200
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
201 priv->fps = 25; /* pal */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
202
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
203 /* get capabilities (priv->capability is needed!) */
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
204 if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
205 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
206 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
207 goto err;
98769cea155c added tv subsystem
alex
parents:
diff changeset
208 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
209
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
210 fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
211
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
212 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
213 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: ");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
214 for (i = 0; device_cap2name[i] != NULL; i++)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
215 if (priv->capability.type & (1 << i))
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
216 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]);
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
217 mp_msg(MSGT_TV, MSGL_INFO, "\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
218 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
219 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n",
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
220 priv->capability.minwidth, priv->capability.minheight,
98769cea155c added tv subsystem
alex
parents:
diff changeset
221 priv->capability.maxwidth, priv->capability.maxheight);
98769cea155c added tv subsystem
alex
parents:
diff changeset
222 priv->width = priv->capability.minwidth;
98769cea155c added tv subsystem
alex
parents:
diff changeset
223 priv->height = priv->capability.minheight;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
224 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
2790
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->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
227 if (!priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
228 goto malloc_failed;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
229 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
98769cea155c added tv subsystem
alex
parents:
diff changeset
230 for (i = 0; i < priv->capability.channels; i++)
98769cea155c added tv subsystem
alex
parents:
diff changeset
231 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
232 priv->channels[i].channel = i;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
233 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
234 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
235 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
236 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
237 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
238 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
239 priv->channels[i].name,
98769cea155c added tv subsystem
alex
parents:
diff changeset
240 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
241 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "",
98769cea155c added tv subsystem
alex
parents:
diff changeset
242 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
243 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "",
09d5c9834580 tv update
alex
parents: 2790
diff changeset
244 priv->channels[i].tuners,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
245 priv->channels[i].norm);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
246 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
247
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
248 /* audio chanlist */
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
249 if (priv->capability.audios)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
250 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
251 mp_msg(MSGT_TV, MSGL_INFO, " Audio devices: %d\n", priv->capability.audios);
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
252
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
253 for (i = 0; i < priv->capability.audios; i++)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
254 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
255 if (i >= MAX_AUDIO_CHANNELS)
622a9ade4517 updated
alex
parents: 3711
diff changeset
256 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
257 mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (incrase in source!) (%d > %d)\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
258 i, MAX_AUDIO_CHANNELS);
622a9ade4517 updated
alex
parents: 3711
diff changeset
259 i = priv->capability.audios;
622a9ade4517 updated
alex
parents: 3711
diff changeset
260 break;
622a9ade4517 updated
alex
parents: 3711
diff changeset
261 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
262
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
263 priv->audio[i].audio = i;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
264 if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
265 {
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
266 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
267 break;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
268 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
269
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
270 if (priv->audio[i].volume <= 0)
622a9ade4517 updated
alex
parents: 3711
diff changeset
271 priv->audio[i].volume = 100;
622a9ade4517 updated
alex
parents: 3711
diff changeset
272 priv->audio[i].flags &= ~VIDEO_AUDIO_MUTE;
622a9ade4517 updated
alex
parents: 3711
diff changeset
273 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]);
622a9ade4517 updated
alex
parents: 3711
diff changeset
274
622a9ade4517 updated
alex
parents: 3711
diff changeset
275 switch(priv->audio[i].mode)
622a9ade4517 updated
alex
parents: 3711
diff changeset
276 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
277 case VIDEO_SOUND_MONO:
622a9ade4517 updated
alex
parents: 3711
diff changeset
278 case VIDEO_SOUND_LANG1:
622a9ade4517 updated
alex
parents: 3711
diff changeset
279 case VIDEO_SOUND_LANG2:
622a9ade4517 updated
alex
parents: 3711
diff changeset
280 priv->audio_channels[i] = 1;
622a9ade4517 updated
alex
parents: 3711
diff changeset
281 break;
622a9ade4517 updated
alex
parents: 3711
diff changeset
282 case VIDEO_SOUND_STEREO:
622a9ade4517 updated
alex
parents: 3711
diff changeset
283 priv->audio_channels[i] = 2;
622a9ade4517 updated
alex
parents: 3711
diff changeset
284 break;
622a9ade4517 updated
alex
parents: 3711
diff changeset
285 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
286
622a9ade4517 updated
alex
parents: 3711
diff changeset
287 priv->audio_format[i] = AFMT_S16_LE;
622a9ade4517 updated
alex
parents: 3711
diff changeset
288 priv->audio_samplerate[i] = 44100;
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
289 priv->audio_samplesize[i] =
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
290 priv->audio_samplerate[i]/8/priv->fps*
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
291 priv->audio_channels[i];
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
292
622a9ade4517 updated
alex
parents: 3711
diff changeset
293 /* display stuff */
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
294 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
295 priv->audio[i].name);
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
296 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE)
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
297 mp_msg(MSGT_TV, MSGL_V, "muted=%s ",
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
298 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no");
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
299 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
300 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble,
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
301 priv->audio[i].balance, audio_mode2name[priv->audio[i].mode]);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
302 mp_msg(MSGT_TV, MSGL_V, " channels: %d, samplerate: %d, samplesize: %d, format: %s\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
303 priv->audio_channels[i], priv->audio_samplerate[i], priv->audio_samplesize[i],
622a9ade4517 updated
alex
parents: 3711
diff changeset
304 audio_out_format_name(priv->audio_format[i]));
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
305 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
306 }
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
307
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
308 if (!(priv->capability.type & VID_TYPE_CAPTURE))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
309 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
310 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
311 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
312 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
313
09d5c9834580 tv update
alex
parents: 2790
diff changeset
314 /* map grab buffer */
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
315 if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
316 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
317 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
318 goto err;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
319 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
320
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
321 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
322 priv->mbuf.size, priv->mbuf.frames);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
323 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
324 MAP_SHARED, priv->video_fd, 0);
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
325 if (priv->mmap == (unsigned char *)-1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
326 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
327 mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
328 goto err;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
329 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
330 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
331
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
332 /* num of buffers */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
333 priv->nbuf = priv->mbuf.frames;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
334
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
335 /* video buffers */
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
336 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
337 if (!priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
338 goto malloc_failed;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
339 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
340
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
341 /* audio init */
5088
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
342 #if 1
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
343 priv->audio_fd = open(priv->audio_device, O_RDONLY);
622a9ade4517 updated
alex
parents: 3711
diff changeset
344 if (priv->audio_fd < 0)
622a9ade4517 updated
alex
parents: 3711
diff changeset
345 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
346 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
347 priv->audio_device, strerror(errno));
622a9ade4517 updated
alex
parents: 3711
diff changeset
348 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
349 else
622a9ade4517 updated
alex
parents: 3711
diff changeset
350 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
351 int ioctl_param;
622a9ade4517 updated
alex
parents: 3711
diff changeset
352
622a9ade4517 updated
alex
parents: 3711
diff changeset
353 fcntl(priv->audio_fd, F_SETFL, O_NONBLOCK);
622a9ade4517 updated
alex
parents: 3711
diff changeset
354
622a9ade4517 updated
alex
parents: 3711
diff changeset
355 #if 0
622a9ade4517 updated
alex
parents: 3711
diff changeset
356 ioctl_param = 0x7fff000d; /* 8k */
622a9ade4517 updated
alex
parents: 3711
diff changeset
357 printf("ioctl dsp setfragment: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
358 ioctl(priv->audio_fd, SNDCTL_DSP_SETFRAGMENT, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
359 #endif
622a9ade4517 updated
alex
parents: 3711
diff changeset
360
622a9ade4517 updated
alex
parents: 3711
diff changeset
361 ioctl_param = 0 ;
622a9ade4517 updated
alex
parents: 3711
diff changeset
362 printf("ioctl dsp getfmt: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
363 ioctl(priv->audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
364
622a9ade4517 updated
alex
parents: 3711
diff changeset
365 printf("Supported formats: %x\n", ioctl_param);
622a9ade4517 updated
alex
parents: 3711
diff changeset
366 if (!(ioctl_param & priv->audio_format[priv->audio_id]))
622a9ade4517 updated
alex
parents: 3711
diff changeset
367 printf("notsupported format\n");
622a9ade4517 updated
alex
parents: 3711
diff changeset
368
622a9ade4517 updated
alex
parents: 3711
diff changeset
369 ioctl_param = priv->audio_format[priv->audio_id];
622a9ade4517 updated
alex
parents: 3711
diff changeset
370 printf("ioctl dsp setfmt: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
371 ioctl(priv->audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
372
622a9ade4517 updated
alex
parents: 3711
diff changeset
373 // ioctl(priv->audio_fd, SNDCTL_DSP_GETISPACE, &ioctl_param);
622a9ade4517 updated
alex
parents: 3711
diff changeset
374 // printf("getispace: %d\n", ioctl_param);
622a9ade4517 updated
alex
parents: 3711
diff changeset
375
622a9ade4517 updated
alex
parents: 3711
diff changeset
376 if (priv->audio_channels[priv->audio_id] > 2)
622a9ade4517 updated
alex
parents: 3711
diff changeset
377 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
378 ioctl_param = priv->audio_channels[priv->audio_id];
622a9ade4517 updated
alex
parents: 3711
diff changeset
379 printf("ioctl dsp channels: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
380 ioctl(priv->audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
381 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
382 else
622a9ade4517 updated
alex
parents: 3711
diff changeset
383 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
384 // if (priv->audio_channels[priv->audio_id] == 2)
622a9ade4517 updated
alex
parents: 3711
diff changeset
385 // ioctl_param = 1;
622a9ade4517 updated
alex
parents: 3711
diff changeset
386 // else
622a9ade4517 updated
alex
parents: 3711
diff changeset
387 // ioctl_param = 0;
622a9ade4517 updated
alex
parents: 3711
diff changeset
388
622a9ade4517 updated
alex
parents: 3711
diff changeset
389 ioctl_param = (priv->audio_channels[priv->audio_id] == 2);
622a9ade4517 updated
alex
parents: 3711
diff changeset
390 printf("ioctl dsp stereo: %d (req: %d)\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
391 ioctl(priv->audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
622a9ade4517 updated
alex
parents: 3711
diff changeset
392 ioctl_param);
622a9ade4517 updated
alex
parents: 3711
diff changeset
393 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
394
622a9ade4517 updated
alex
parents: 3711
diff changeset
395 ioctl_param = priv->audio_samplerate[priv->audio_id];
622a9ade4517 updated
alex
parents: 3711
diff changeset
396 printf("ioctl dsp speed: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
397 ioctl(priv->audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
398
622a9ade4517 updated
alex
parents: 3711
diff changeset
399 #if 0
622a9ade4517 updated
alex
parents: 3711
diff changeset
400 ioctl_param = 0;
622a9ade4517 updated
alex
parents: 3711
diff changeset
401 ioctl_param = ~PCM_ENABLE_INPUT;
622a9ade4517 updated
alex
parents: 3711
diff changeset
402 printf("ioctl dsp trigger: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
403 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
404 ioctl_param = PCM_ENABLE_INPUT;
622a9ade4517 updated
alex
parents: 3711
diff changeset
405 printf("ioctl dsp trigger: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
406 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
407 #endif
622a9ade4517 updated
alex
parents: 3711
diff changeset
408
622a9ade4517 updated
alex
parents: 3711
diff changeset
409 printf("ioctl dsp trigger: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
410 ioctl(priv->audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
411 printf("trigger: %x\n", ioctl_param);
622a9ade4517 updated
alex
parents: 3711
diff changeset
412 ioctl_param = PCM_ENABLE_INPUT;
622a9ade4517 updated
alex
parents: 3711
diff changeset
413 printf("ioctl dsp trigger: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
414 ioctl(priv->audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
622a9ade4517 updated
alex
parents: 3711
diff changeset
415
622a9ade4517 updated
alex
parents: 3711
diff changeset
416 printf("ioctl dsp getblocksize: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
417 ioctl(priv->audio_fd, SNDCTL_DSP_GETBLKSIZE, &priv->audio_blocksize));
622a9ade4517 updated
alex
parents: 3711
diff changeset
418 printf("blocksize: %d\n", priv->audio_blocksize);
622a9ade4517 updated
alex
parents: 3711
diff changeset
419 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
420 #endif
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
421 return(1);
98769cea155c added tv subsystem
alex
parents:
diff changeset
422
3611
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
423
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
424 malloc_failed:
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
425 if (priv->channels)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
426 free(priv->channels);
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
427 if (priv->buf)
178c562948ff checkings for malloc results (potential memleaks)
pl
parents: 3284
diff changeset
428 free(priv->buf);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
429 err:
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
430 if (priv->video_fd != -1)
622a9ade4517 updated
alex
parents: 3711
diff changeset
431 close(priv->video_fd);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
432 return(0);
98769cea155c added tv subsystem
alex
parents:
diff changeset
433 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
434
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
435 static int uninit(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
436 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
437 close(priv->video_fd);
622a9ade4517 updated
alex
parents: 3711
diff changeset
438
622a9ade4517 updated
alex
parents: 3711
diff changeset
439 priv->audio[priv->audio_id].volume = 0;
622a9ade4517 updated
alex
parents: 3711
diff changeset
440 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE;
622a9ade4517 updated
alex
parents: 3711
diff changeset
441 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
622a9ade4517 updated
alex
parents: 3711
diff changeset
442 close(priv->audio_fd);
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
443
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
444 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
445 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
446
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
447 static int start(priv_t *priv)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
448 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
449 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
450
09d5c9834580 tv update
alex
parents: 2790
diff changeset
451
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
452 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
453 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
454 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
455 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
456 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
457
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
458 priv->picture.palette = format2palette(priv->format);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
459 priv->picture.depth = palette2depth(priv->picture.palette);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
460 priv->bytesperline = priv->width * priv->picture.depth / 8;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
461 // if (IMGFMT_IS_BGR(priv->format) || IMGFMT_IS_RGB(priv->format))
622a9ade4517 updated
alex
parents: 3711
diff changeset
462 // priv->bytesperline = priv->width * priv->picture.depth / 8;
622a9ade4517 updated
alex
parents: 3711
diff changeset
463 // if ((priv->format == IMGFMT_YV12) || (priv->format == IMGFMT_I420) || (priv->format == IMGFMT_IYUV))
622a9ade4517 updated
alex
parents: 3711
diff changeset
464 // priv->bytesperline = priv->width * 3 / 2;
622a9ade4517 updated
alex
parents: 3711
diff changeset
465
622a9ade4517 updated
alex
parents: 3711
diff changeset
466 printf("palette: %d, depth: %d, bytesperline: %d\n",
622a9ade4517 updated
alex
parents: 3711
diff changeset
467 priv->picture.palette, priv->picture.depth, priv->bytesperline);
622a9ade4517 updated
alex
parents: 3711
diff changeset
468
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
469 mp_msg(MSGT_TV, MSGL_INFO, "Picture values:\n");
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
470 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
471 priv->picture.palette, vo_format_name(priv->format));
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
472 mp_msg(MSGT_TV, MSGL_INFO, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
473 priv->picture.brightness, priv->picture.hue,
09d5c9834580 tv update
alex
parents: 2790
diff changeset
474 priv->picture.colour, priv->picture.contrast);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
475
09d5c9834580 tv update
alex
parents: 2790
diff changeset
476
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
477 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
478 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
479 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
480 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
481 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
482
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
483 priv->nbuf = priv->mbuf.frames;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
484 for (i=0; i < priv->nbuf; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
485 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
486 priv->buf[i].format = priv->picture.palette;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
487 priv->buf[i].frame = i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
488 priv->buf[i].width = priv->width;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
489 priv->buf[i].height = priv->height;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
490 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
491 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
492
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
493 #if 0
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
494 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
495 struct video_play_mode pmode;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
496
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
497 pmode.mode = VID_PLAY_NORMAL;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
498 pmode.p1 = 1;
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
499 pmode.p2 = 0;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
500 if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1)
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
501 {
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
502 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno));
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
503 // return(0);
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
504 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
505 }
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
506 #endif
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
507
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
508 #if 0
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
509 {
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
510 struct video_window win;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
511
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
512 win.x = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
513 win.y = 0;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
514 win.width = priv->width;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
515 win.height = priv->height;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
516 win.chromakey = -1;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
517 win.flags = 0;
5088
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
518 //win.clipcount = 0;
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
519
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
520 ioctl(priv->video_fd, VIDIOCSWIN, &win);
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
521 }
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
522
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
523 /* start capture */
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
524 if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
525 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
526 mp_msg(MSGT_TV, MSGL_ERR, "ioctl capture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
527 return(0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
528 }
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
529 #endif
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
530
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
531 {
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
532 struct timeval curtime;
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
533 gettimeofday(&curtime, NULL);
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
534 priv->starttime=curtime.tv_sec + curtime.tv_usec*.000001;
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
535 }
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
536
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
537 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
538 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
539
98769cea155c added tv subsystem
alex
parents:
diff changeset
540 static int control(priv_t *priv, int cmd, void *arg)
98769cea155c added tv subsystem
alex
parents:
diff changeset
541 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
542 mp_msg(MSGT_TV, MSGL_DBG2, "debug: control(priv=%p, cmd=%d, arg=%p)\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
543 priv, cmd, arg);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
544 switch(cmd)
98769cea155c added tv subsystem
alex
parents:
diff changeset
545 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
546 /* ========== GENERIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
547 case TVI_CONTROL_IS_VIDEO:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
548 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
549 if (priv->capability.type & VID_TYPE_CAPTURE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
550 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
551 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
552 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
553 case TVI_CONTROL_IS_AUDIO:
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
554 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
555 {
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
556 return(TVI_CONTROL_TRUE);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
557 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
558 return(TVI_CONTROL_TRUE);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
559 case TVI_CONTROL_IS_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
560 {
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
561 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
562 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
563 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
564 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
565 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
566
09d5c9834580 tv update
alex
parents: 2790
diff changeset
567 /* ========== VIDEO controls =========== */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
568 case TVI_CONTROL_VID_GET_FORMAT:
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
569 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
570 int output_fmt = -1;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
571
09d5c9834580 tv update
alex
parents: 2790
diff changeset
572 output_fmt = priv->format;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
573 (int)*(void **)arg = output_fmt;
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
574 mp_msg(MSGT_TV, MSGL_INFO, "Output format: %s\n", vo_format_name(output_fmt));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
575 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
576 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
577 case TVI_CONTROL_VID_SET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
578 priv->format = (int)*(void **)arg;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
579 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
580 case TVI_CONTROL_VID_GET_PLANES:
3220
alex
parents: 2937
diff changeset
581 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
582 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
583 case TVI_CONTROL_VID_GET_BITS:
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
584 (int)*(void **)arg = palette2depth(format2palette(priv->format));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
585 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
586 case TVI_CONTROL_VID_GET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
587 (int)*(void **)arg = priv->width;
98769cea155c added tv subsystem
alex
parents:
diff changeset
588 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
589 case TVI_CONTROL_VID_CHK_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
590 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
591 int req_width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
592
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
593 mp_msg(MSGT_TV, MSGL_INFO, "Requested width: %d\n", req_width);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
594 if ((req_width >= priv->capability.minwidth) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
595 (req_width <= priv->capability.maxwidth))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
596 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
597 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
598 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
599 case TVI_CONTROL_VID_SET_WIDTH:
98769cea155c added tv subsystem
alex
parents:
diff changeset
600 priv->width = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
601 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
602 case TVI_CONTROL_VID_GET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
603 (int)*(void **)arg = priv->height;
98769cea155c added tv subsystem
alex
parents:
diff changeset
604 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
605 case TVI_CONTROL_VID_CHK_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
606 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
607 int req_height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
608
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
609 mp_msg(MSGT_TV, MSGL_INFO, "Requested height: %d\n", req_height);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
610 if ((req_height >= priv->capability.minheight) &&
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
611 (req_height <= priv->capability.maxheight))
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
612 return(TVI_CONTROL_TRUE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
613 return(TVI_CONTROL_FALSE);
98769cea155c added tv subsystem
alex
parents:
diff changeset
614 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
615 case TVI_CONTROL_VID_SET_HEIGHT:
98769cea155c added tv subsystem
alex
parents:
diff changeset
616 priv->height = (int)*(void **)arg;
98769cea155c added tv subsystem
alex
parents:
diff changeset
617 return(TVI_CONTROL_TRUE);
2937
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
618 case TVI_CONTROL_VID_GET_PICTURE:
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
619 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1)
2937
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
620 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
621 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
622 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
623 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
624 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
625 case TVI_CONTROL_VID_SET_PICTURE:
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
626 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
2937
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
627 {
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
628 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
629 return(TVI_CONTROL_FALSE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
630 }
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
631 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
632 case TVI_CONTROL_VID_SET_BRIGHTNESS:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
633 priv->picture.brightness = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
634 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
635 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
636 case TVI_CONTROL_VID_SET_HUE:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
637 priv->picture.hue = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
638 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
639 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
640 case TVI_CONTROL_VID_SET_SATURATION:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
641 priv->picture.colour = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
642 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
643 return(TVI_CONTROL_TRUE);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
644 case TVI_CONTROL_VID_SET_CONTRAST:
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
645 priv->picture.contrast = (int)*(void **)arg;
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
646 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0);
4307478ad922 added support for setting color values
alex
parents: 2931
diff changeset
647 return(TVI_CONTROL_TRUE);
6529
8552767dbb46 tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents: 6305
diff changeset
648 case TVI_CONTROL_VID_GET_FPS:
8552767dbb46 tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents: 6305
diff changeset
649 (int)*(void **)arg=priv->fps;
8552767dbb46 tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents: 6305
diff changeset
650 return(TVI_CONTROL_TRUE);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
651
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
652 /* ========== TUNER controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
653 case TVI_CONTROL_TUN_GET_FREQ:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
654 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
655 unsigned long freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
656
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
657 if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
658 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
659 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
660 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
661 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
662
09d5c9834580 tv update
alex
parents: 2790
diff changeset
663 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
664 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
665 // freq /= 1000;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
666 (unsigned long)*(void **)arg = freq;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
667 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
668 }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
669 case TVI_CONTROL_TUN_SET_FREQ:
98769cea155c added tv subsystem
alex
parents:
diff changeset
670 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
671 /* argument is in MHz ! */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
672 unsigned long freq = (unsigned long)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
673
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
674 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
675
09d5c9834580 tv update
alex
parents: 2790
diff changeset
676 /* tuner uses khz not mhz ! */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
677 // if (priv->tuner.flags & VIDEO_TUNER_LOW)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
678 // freq *= 1000;
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
679 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
680 if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
681 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
682 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
683 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
684 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
685 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
686 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
687 case TVI_CONTROL_TUN_GET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
688 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
689 if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
690 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
691 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
692 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
693 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
694
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
695 mp_msg(MSGT_TV, MSGL_INFO, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name,
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
696 priv->tuner.rangelow, priv->tuner.rangehigh);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
697 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
698 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
699 case TVI_CONTROL_TUN_SET_TUNER:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
700 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
701 if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
702 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
703 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
704 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
705 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
706 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
707 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
708 case TVI_CONTROL_TUN_SET_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
709 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
710 int req_mode = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
711
09d5c9834580 tv update
alex
parents: 2790
diff changeset
712 if ((!(priv->tuner.flags & VIDEO_TUNER_NORM)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
713 ((req_mode == VIDEO_MODE_PAL) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
714 ((req_mode == VIDEO_MODE_NTSC) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) ||
09d5c9834580 tv update
alex
parents: 2790
diff changeset
715 ((req_mode == VIDEO_MODE_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM)))
09d5c9834580 tv update
alex
parents: 2790
diff changeset
716 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
717 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n");
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
718 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
719 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
720
09d5c9834580 tv update
alex
parents: 2790
diff changeset
721 priv->tuner.mode = req_mode;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
722
6305
bd8e39725cfd Fix by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>.
atmos4
parents: 5941
diff changeset
723 if (control(priv, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
724 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
725 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
726 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
727 case TVI_CONTROL_TUN_GET_NORM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
728 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
729 (int)*(void **)arg = priv->tuner.mode;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
730
09d5c9834580 tv update
alex
parents: 2790
diff changeset
731 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
732 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
733
09d5c9834580 tv update
alex
parents: 2790
diff changeset
734 /* ========== AUDIO controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
735 case TVI_CONTROL_AUD_GET_FORMAT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
736 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
737 (int)*(void **)arg = priv->audio_format[priv->audio_id];
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
738 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
739 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
740 case TVI_CONTROL_AUD_GET_CHANNELS:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
741 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
742 (int)*(void **)arg = priv->audio_channels[priv->audio_id];
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
743 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
744 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
745 case TVI_CONTROL_AUD_GET_SAMPLERATE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
746 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
747 (int)*(void **)arg = priv->audio_samplerate[priv->audio_id];
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
748 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
749 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
750 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
751 {
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
752 (int)*(void **)arg = priv->audio_samplesize[priv->audio_id]/8;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
753 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
754 }
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
755 case TVI_CONTROL_AUD_SET_SAMPLERATE:
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
756 {
6529
8552767dbb46 tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents: 6305
diff changeset
757 int tmp = priv->audio_samplerate[priv->audio_id] = (int)*(void **)arg;
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
758
6529
8552767dbb46 tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents: 6305
diff changeset
759 if (ioctl(priv->audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1)
5941
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
760 return(TVI_CONTROL_FALSE);
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
761 priv->audio_samplesize[priv->audio_id] =
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
762 priv->audio_samplerate[priv->audio_id]/8/priv->fps*
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
763 priv->audio_channels[priv->audio_id];
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
764 return(TVI_CONTROL_TRUE);
f2bad7299936 disabled audio
alex
parents: 5572
diff changeset
765 }
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
766 /* ========== SPECIFIC controls =========== */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
767 case TVI_CONTROL_SPC_GET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
768 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
769 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
770 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
771
09d5c9834580 tv update
alex
parents: 2790
diff changeset
772 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
773 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
774 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
775 break;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
776 }
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
777
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
778 priv->act_channel = i;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
779
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
780 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
781 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
782 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
783 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
784 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
785 return(TVI_CONTROL_TRUE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
786 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
787
09d5c9834580 tv update
alex
parents: 2790
diff changeset
788 case TVI_CONTROL_SPC_SET_INPUT:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
789 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
790 struct video_channel chan;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
791 int req_chan = (int)*(void **)arg;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
792 int i;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
793
09d5c9834580 tv update
alex
parents: 2790
diff changeset
794 if (req_chan >= priv->capability.channels)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
795 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
796 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
797 req_chan, priv->capability.channels);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
798 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
799 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
800
09d5c9834580 tv update
alex
parents: 2790
diff changeset
801 for (i = 0; i < priv->capability.channels; i++)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
802 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
803 if (priv->channels[i].channel == req_chan)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
804 chan = priv->channels[i];
09d5c9834580 tv update
alex
parents: 2790
diff changeset
805 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
806
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
807 if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
808 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
809 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
810 return(TVI_CONTROL_FALSE);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
811 }
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
812 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
813
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
814 priv->act_channel = i;
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
815
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
816 /* update tuner state */
2841
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
817 // if (priv->capability.type & VID_TYPE_TUNER)
7ff47d6ae6e9 updated audio and tuner checking
alex
parents: 2837
diff changeset
818 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER)
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
819 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
820
09d5c9834580 tv update
alex
parents: 2790
diff changeset
821 /* update local channel list */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
822 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
823 return(TVI_CONTROL_TRUE);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
824 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
825 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
826
98769cea155c added tv subsystem
alex
parents:
diff changeset
827 return(TVI_CONTROL_UNKNOWN);
98769cea155c added tv subsystem
alex
parents:
diff changeset
828 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
829
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5088
diff changeset
830 static double grab_video_frame(priv_t *priv, char *buffer, int len)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
831 {
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
832 struct timeval curtime;
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
833 double timestamp;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
834 int frame = priv->queue % priv->nbuf;
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
835 int nextframe = (priv->queue+1) % priv->nbuf;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
836
3284
702e399a4b3e update (audio support is coming:)
alex
parents: 3243
diff changeset
837 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
838 priv, buffer, len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
839
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
840 mp_dbg(MSGT_TV, MSGL_DBG3, "buf: %p + frame: %d => %p\n",
2814
37fc45a05082 doublebuffeing SYNC fixed
arpi
parents: 2810
diff changeset
841 priv->buf, nextframe, &priv->buf[nextframe]);
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
842 if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[nextframe]) == -1)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
843 {
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2814
diff changeset
844 mp_msg(MSGT_TV, MSGL_ERR, "ioctl mcapture failed: %s\n", strerror(errno));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
845 return(0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
846 }
3711
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
847
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
848 while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
3711
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
849 (errno == EAGAIN || errno == EINTR));
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
850 mp_dbg(MSGT_TV, MSGL_DBG3, "picture sync failed\n");
5fa7eb90e2ec fixed video syncing
alex
parents: 3703
diff changeset
851
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
852 priv->queue++;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
853
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
854 gettimeofday(&curtime, NULL);
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
855 timestamp=curtime.tv_sec + curtime.tv_usec*.000001;
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
856
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
857 mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n",
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
858 priv->mmap, priv->mbuf.offsets[frame],
09d5c9834580 tv update
alex
parents: 2790
diff changeset
859 priv->mmap+priv->mbuf.offsets[frame]);
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
860
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
861 /* XXX also directrendering would be nicer! */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
862 /* 3 times copying the same picture to other buffer :( */
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
863
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
864 /* copy the actual frame */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
865 memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
866
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
867 return(timestamp-priv->starttime);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
868 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
869
98769cea155c added tv subsystem
alex
parents:
diff changeset
870 static int get_video_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
871 {
2931
bce9c945b29c tv interface update
alex
parents: 2841
diff changeset
872 return(priv->bytesperline * priv->height);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
873 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
874
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5088
diff changeset
875 static double grab_audio_frame(priv_t *priv, char *buffer, int len)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
876 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
877 int in_len = 0;
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
878 int max_tries = 2;
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
879
5088
942d497875b4 update by Charles Henrich
alex
parents: 3815
diff changeset
880 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n",
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
881 priv, buffer, len);
622a9ade4517 updated
alex
parents: 3711
diff changeset
882
6553
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
883 while (--max_tries > 0)
d000112bd06e Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents: 6529
diff changeset
884 // for (;;)
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
885 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
886 in_len = read(priv->audio_fd, buffer, len);
622a9ade4517 updated
alex
parents: 3711
diff changeset
887 // printf("in_len: %d\n", in_len);
622a9ade4517 updated
alex
parents: 3711
diff changeset
888 // fflush(NULL);
622a9ade4517 updated
alex
parents: 3711
diff changeset
889
622a9ade4517 updated
alex
parents: 3711
diff changeset
890 if (in_len > 0)
622a9ade4517 updated
alex
parents: 3711
diff changeset
891 break;
622a9ade4517 updated
alex
parents: 3711
diff changeset
892 if (!((in_len == 0) || (in_len == -1 && (errno == EAGAIN || errno == EINTR))))
622a9ade4517 updated
alex
parents: 3711
diff changeset
893 {
622a9ade4517 updated
alex
parents: 3711
diff changeset
894 in_len = 0; /* -EIO */
622a9ade4517 updated
alex
parents: 3711
diff changeset
895 break;
622a9ade4517 updated
alex
parents: 3711
diff changeset
896 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
897 }
622a9ade4517 updated
alex
parents: 3711
diff changeset
898
5572
8cd761968f35 BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents: 5088
diff changeset
899 return 0; //(in_len); // FIXME!
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
900 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
901
98769cea155c added tv subsystem
alex
parents:
diff changeset
902 static int get_audio_framesize(priv_t *priv)
98769cea155c added tv subsystem
alex
parents:
diff changeset
903 {
3815
622a9ade4517 updated
alex
parents: 3711
diff changeset
904 return(priv->audio_blocksize);
622a9ade4517 updated
alex
parents: 3711
diff changeset
905 // return(priv->audio_samplesize[priv->audio_id]);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
906 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
907
98769cea155c added tv subsystem
alex
parents:
diff changeset
908 #endif /* USE_TV */