Mercurial > mplayer.hg
annotate libmpdemux/tvi_v4l.c @ 8860:778989dba3a2
cpu cache line length detection
from mplayerxp (Nick Kurshev <nickols_k@mail.ru>)
author | arpi |
---|---|
date | Thu, 09 Jan 2003 18:39:09 +0000 |
parents | dbe99860575d |
children | 1ebf4c3ab032 |
rev | line source |
---|---|
2802 | 1 /* |
3284 | 2 Video 4 Linux input |
2802 | 3 |
4 (C) Alex Beregszaszi <alex@naxine.org> | |
5 | |
6 Some ideas are based on xawtv/libng's grab-v4l.c written by | |
7 Gerd Knorr <kraxel@bytesex.org> | |
8 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
9 Multithreading, a/v sync and native ALSA support by |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
10 Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz> |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
11 |
2802 | 12 CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE! |
13 */ | |
14 | |
2790 | 15 #include "config.h" |
16 | |
3243 | 17 #if defined(USE_TV) && defined(HAVE_TV_V4L) |
2790 | 18 |
19 #include <stdio.h> | |
20 #include <errno.h> | |
21 #include <fcntl.h> | |
2802 | 22 #include <signal.h> |
2790 | 23 #include <sys/ioctl.h> |
24 #include <sys/types.h> | |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
25 #include <sys/time.h> |
2790 | 26 #include <linux/videodev.h> |
27 #include <unistd.h> | |
28 #include <sys/mman.h> | |
2931 | 29 #include <stdlib.h> |
30 #include <string.h> | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
31 #include <pthread.h> |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
32 #ifdef HAVE_SYS_SYSINFO_H |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
33 #include <sys/sysinfo.h> |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
34 #endif |
2790 | 35 |
2830 | 36 #include "mp_msg.h" |
37 #include "../libao2/afmt.h" | |
38 #include "../libvo/img_format.h" | |
39 #include "../libvo/fastmemcpy.h" | |
40 | |
2790 | 41 #include "tv.h" |
42 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
43 #include "audio_in.h" |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
44 |
2790 | 45 static tvi_info_t info = { |
3815 | 46 "Video 4 Linux input", |
2790 | 47 "v4l", |
2802 | 48 "Alex Beregszaszi <alex@naxine.org>", |
49 "under development" | |
50 }; | |
51 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
52 #define PAL_WIDTH 768 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
53 #define PAL_HEIGHT 576 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
54 #define PAL_FPS 25 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
55 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
56 #define NTSC_WIDTH 640 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
57 #define NTSC_HEIGHT 480 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
58 #define NTSC_FPS 30 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
59 |
3815 | 60 #define MAX_AUDIO_CHANNELS 10 |
61 | |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
62 #define VID_BUF_SIZE_IMMEDIATE 2 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
63 |
2790 | 64 typedef struct { |
2802 | 65 /* general */ |
2790 | 66 char *video_device; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
67 int video_fd; |
2790 | 68 struct video_capability capability; |
69 struct video_channel *channels; | |
2841 | 70 int act_channel; |
2790 | 71 struct video_tuner tuner; |
2802 | 72 |
73 /* video */ | |
2790 | 74 struct video_picture picture; |
2802 | 75 int format; /* output format */ |
2790 | 76 int width; |
77 int height; | |
2802 | 78 int bytesperline; |
5941 | 79 int fps; |
2802 | 80 |
81 struct video_mbuf mbuf; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
82 unsigned char *mmap; |
2802 | 83 struct video_mmap *buf; |
84 int nbuf; | |
85 | |
86 /* audio */ | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
87 char *audio_device; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
88 audio_in_t audio_in; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
89 |
3815 | 90 int audio_id; |
91 struct video_audio audio[MAX_AUDIO_CHANNELS]; | |
92 int audio_channels[MAX_AUDIO_CHANNELS]; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
93 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
94 /* buffering stuff */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
95 int immediate_mode; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
96 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
97 int audio_buffer_size; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
98 int aud_skew_cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
99 unsigned char *audio_ringbuffer; |
8131 | 100 long long *audio_skew_buffer; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
101 volatile int audio_head; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
102 volatile int audio_tail; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
103 volatile int audio_cnt; |
8131 | 104 volatile long long audio_skew; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
105 volatile double audio_skew_factor; |
8131 | 106 volatile long long audio_skew_measure_time; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
107 volatile int audio_drop; |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
108 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
109 int first; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
110 int video_buffer_size_max; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
111 volatile int video_buffer_size_current; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
112 unsigned char **video_ringbuffer; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
113 long long *video_timebuffer; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
114 volatile int video_head; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
115 volatile int video_tail; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
116 volatile int video_cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
117 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
118 volatile int shutdown; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
119 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
120 pthread_t audio_grabber_thread; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
121 pthread_t video_grabber_thread; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
122 pthread_mutex_t audio_starter; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
123 pthread_mutex_t skew_mutex; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
124 pthread_mutex_t video_buffer_mutex; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
125 |
8131 | 126 long long starttime; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
127 double audio_secs_per_block; |
8131 | 128 long long audio_skew_total; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
129 long audio_recv_blocks_total; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
130 long audio_sent_blocks_total; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
131 |
2790 | 132 } priv_t; |
133 | |
134 #include "tvi_def.h" | |
135 | |
2841 | 136 static const char *device_cap2name[] = { |
2790 | 137 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping", |
2802 | 138 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder", |
139 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL | |
140 }; | |
141 | |
2841 | 142 static const char *device_palette2name[] = { |
2802 | 143 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422", |
144 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p", | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
145 "yuv420p", "yuv410p" |
2802 | 146 }; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
147 #define PALETTE(x) ((x < sizeof(device_palette2name)/sizeof(char*)) ? device_palette2name[x] : "UNKNOWN") |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
148 |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
149 static const char *norm2name(int mode) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
150 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
151 switch (mode) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
152 case VIDEO_MODE_PAL: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
153 return "pal"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
154 case VIDEO_MODE_SECAM: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
155 return "secam"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
156 case VIDEO_MODE_NTSC: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
157 return "ntsc"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
158 case VIDEO_MODE_AUTO: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
159 return "auto"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
160 default: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
161 return "unknown"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
162 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
163 }; |
2802 | 164 |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
165 static const char *audio_mode2name(int mode) |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
166 { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
167 switch (mode) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
168 case VIDEO_SOUND_MONO: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
169 return "mono"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
170 case VIDEO_SOUND_STEREO: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
171 return "stereo"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
172 case VIDEO_SOUND_LANG1: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
173 return "language1"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
174 case VIDEO_SOUND_LANG2: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
175 return "language2"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
176 default: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
177 return "unknown"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
178 } |
2841 | 179 }; |
180 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
181 static void *audio_grabber(void *data); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
182 static void *video_grabber(void *data); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
183 |
2802 | 184 static int palette2depth(int palette) |
185 { | |
2810 | 186 switch(palette) |
187 { | |
3220 | 188 /* component */ |
2810 | 189 case VIDEO_PALETTE_RGB555: |
190 return(15); | |
191 case VIDEO_PALETTE_RGB565: | |
192 return(16); | |
193 case VIDEO_PALETTE_RGB24: | |
194 return(24); | |
195 case VIDEO_PALETTE_RGB32: | |
196 return(32); | |
3220 | 197 /* planar */ |
198 case VIDEO_PALETTE_YUV411P: | |
2810 | 199 case VIDEO_PALETTE_YUV420P: |
3220 | 200 case VIDEO_PALETTE_YUV410P: |
2810 | 201 return(12); |
3220 | 202 /* packed */ |
3815 | 203 case VIDEO_PALETTE_YUV422P: |
2810 | 204 case VIDEO_PALETTE_YUV422: |
3220 | 205 case VIDEO_PALETTE_YUYV: |
2810 | 206 case VIDEO_PALETTE_UYVY: |
3220 | 207 case VIDEO_PALETTE_YUV420: |
208 case VIDEO_PALETTE_YUV411: | |
2810 | 209 return(16); |
210 } | |
211 return(-1); | |
2802 | 212 } |
213 | |
214 static int format2palette(int format) | |
215 { | |
2810 | 216 switch(format) |
217 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
218 case IMGFMT_BGR15: |
2810 | 219 return(VIDEO_PALETTE_RGB555); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
220 case IMGFMT_BGR16: |
2810 | 221 return(VIDEO_PALETTE_RGB565); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
222 case IMGFMT_BGR24: |
2810 | 223 return(VIDEO_PALETTE_RGB24); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
224 case IMGFMT_BGR32: |
2810 | 225 return(VIDEO_PALETTE_RGB32); |
226 case IMGFMT_YV12: | |
3703 | 227 case IMGFMT_I420: |
2810 | 228 return(VIDEO_PALETTE_YUV420P); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
229 case IMGFMT_YUY2: |
2810 | 230 return(VIDEO_PALETTE_YUV422); |
231 } | |
232 return(-1); | |
2802 | 233 } |
234 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
235 // sets and sanitizes audio buffer/block sizes |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
236 static void setup_audio_buffer_sizes(priv_t *priv) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
237 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
238 int bytes_per_sample = priv->audio_in.bytes_per_sample; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
239 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
240 // make the audio buffer at least 5 seconds long |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
241 priv->audio_buffer_size = 1 + 5*priv->audio_in.samplerate |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
242 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
243 *bytes_per_sample/priv->audio_in.blocksize; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
244 if (priv->audio_buffer_size < 256) priv->audio_buffer_size = 256; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
245 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
246 // make the skew buffer at least 1 second long |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
247 priv->aud_skew_cnt = 1 + 1*priv->audio_in.samplerate |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
248 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
249 *bytes_per_sample/priv->audio_in.blocksize; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
250 if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
251 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
252 mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n", |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
253 priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
254 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
255 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
256 tvi_handle_t *tvi_init_v4l(char *device, char *adevice) |
2790 | 257 { |
258 tvi_handle_t *h; | |
259 priv_t *priv; | |
260 | |
261 h = new_handle(); | |
262 if (!h) | |
263 return(NULL); | |
264 | |
265 priv = h->priv; | |
266 | |
2802 | 267 /* set video device name */ |
2790 | 268 if (!device) |
5088 | 269 priv->video_device = strdup("/dev/video"); |
2790 | 270 else |
3611 | 271 priv->video_device = strdup(device); |
272 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
273 /* set video device name */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
274 if (!adevice) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
275 priv->audio_device = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
276 else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
277 priv->audio_device = strdup(adevice); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
278 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
279 |
3611 | 280 /* allocation failed */ |
281 if (!priv->video_device) { | |
282 free_handle(h); | |
283 return(NULL); | |
2790 | 284 } |
285 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
286 return(h); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
287 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
288 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
289 /* retrieves info about audio channels from the BTTV */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
290 static void init_v4l_audio(priv_t *priv) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
291 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
292 int i; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
293 int reqmode; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
294 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
295 if (!priv->capability.audios) return; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
296 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
297 /* audio chanlist */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
298 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
299 mp_msg(MSGT_TV, MSGL_V, " Audio devices: %d\n", priv->capability.audios); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
300 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
301 mp_msg(MSGT_TV, MSGL_V, "Video capture card reports the audio setup as follows:\n"); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
302 for (i = 0; i < priv->capability.audios; i++) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
303 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
304 if (i >= MAX_AUDIO_CHANNELS) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
305 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
306 mp_msg(MSGT_TV, MSGL_ERR, "no space for more audio channels (increase in source!) (%d > %d)\n", |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
307 i, MAX_AUDIO_CHANNELS); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
308 i = priv->capability.audios; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
309 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
310 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
311 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
312 priv->audio[i].audio = i; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
313 if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
314 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
315 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
316 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
317 } |
3815 | 318 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
319 /* mute all channels */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
320 priv->audio[i].volume = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
321 priv->audio[i].flags |= VIDEO_AUDIO_MUTE; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
322 reqmode = -1; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
323 if (tv_param_amode >= 0) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
324 switch (tv_param_amode) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
325 case 0: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
326 reqmode = VIDEO_SOUND_MONO; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
327 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
328 case 1: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
329 reqmode = VIDEO_SOUND_STEREO; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
330 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
331 case 2: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
332 reqmode = VIDEO_SOUND_LANG1; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
333 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
334 case 3: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
335 reqmode = VIDEO_SOUND_LANG2; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
336 break; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
337 default: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
338 mp_msg(MSGT_TV, MSGL_ERR, "Unknown audio mode requested.\n"); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
339 break; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
340 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
341 if (reqmode >= 0) priv->audio[i].mode = reqmode; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
342 } |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
343 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[i]); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
344 |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
345 // get the parameters back |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
346 if (ioctl(priv->video_fd, VIDIOCGAUDIO, &priv->audio[i]) == -1) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
347 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
348 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get audio failed: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
349 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
350 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
351 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
352 switch(priv->audio[i].mode) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
353 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
354 case VIDEO_SOUND_MONO: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
355 case VIDEO_SOUND_LANG1: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
356 case VIDEO_SOUND_LANG2: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
357 priv->audio_channels[i] = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
358 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
359 case VIDEO_SOUND_STEREO: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
360 priv->audio_channels[i] = 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
361 break; |
8335
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
362 default: |
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
363 mp_msg(MSGT_TV, MSGL_ERR, "Card reports an unknown audio mode !\n"); |
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
364 mp_msg(MSGT_TV, MSGL_ERR, "Trying two channel audio. Use forcechan to override.\n"); |
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
365 priv->audio_channels[i] = 2; |
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
366 break; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
367 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
368 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
369 if (reqmode >= 0 && priv->audio[i].mode != reqmode) { |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
370 mp_msg(MSGT_TV, MSGL_ERR, "Audio mode setup warning!\n"); |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
371 mp_msg(MSGT_TV, MSGL_ERR, "Requested mode was %s, but v4l still reports %s.\n", |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
372 audio_mode2name(reqmode), audio_mode2name(priv->audio[i].mode)); |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
373 mp_msg(MSGT_TV, MSGL_ERR, "You may need \"forcechan\" option to force stereo/mono audio recording.\n"); |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
374 } |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
375 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
376 /* display stuff */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
377 mp_msg(MSGT_TV, MSGL_V, " %d: %s: ", priv->audio[i].audio, |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
378 priv->audio[i].name); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
379 if (priv->audio[i].flags & VIDEO_AUDIO_MUTABLE) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
380 mp_msg(MSGT_TV, MSGL_V, "muted=%s ", |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
381 (priv->audio[i].flags & VIDEO_AUDIO_MUTE) ? "yes" : "no"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
382 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
383 mp_msg(MSGT_TV, MSGL_V, "vol=%d bass=%d treble=%d balance=%d mode=%s", |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
384 priv->audio[i].volume, priv->audio[i].bass, priv->audio[i].treble, |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
385 priv->audio[i].balance, audio_mode2name(priv->audio[i].mode)); |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
386 mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[i]); |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
387 |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
388 if (tv_param_forcechan >= 0) |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
389 priv->audio_channels[i] = tv_param_forcechan; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
390 |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
391 // we'll call VIDIOCSAUDIO again when starting capture |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
392 // let's set audio mode to requested mode again for the case |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
393 // when VIDIOCGAUDIO just cannot report the mode correctly |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
394 if (reqmode >= 0) priv->audio[i].mode = reqmode; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
395 } |
2790 | 396 } |
397 | |
3815 | 398 static int init(priv_t *priv) |
2790 | 399 { |
400 int i; | |
401 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
402 if (tv_param_immediate == 1) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
403 tv_param_noaudio = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
404 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
405 priv->video_ringbuffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
406 priv->video_timebuffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
407 priv->audio_ringbuffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
408 priv->audio_skew_buffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
409 |
3815 | 410 priv->video_fd = open(priv->video_device, O_RDWR); |
5088 | 411 mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %x\n", priv->video_fd, |
412 priv->video_device); | |
3815 | 413 if (priv->video_fd == -1) |
2790 | 414 { |
2818 | 415 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", |
2802 | 416 priv->video_device, strerror(errno)); |
2790 | 417 goto err; |
418 } | |
5941 | 419 |
2802 | 420 /* get capabilities (priv->capability is needed!) */ |
3815 | 421 if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) |
2790 | 422 { |
2818 | 423 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2790 | 424 goto err; |
425 } | |
426 | |
3815 | 427 fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC); |
2802 | 428 |
2818 | 429 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name); |
430 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: "); | |
2841 | 431 for (i = 0; device_cap2name[i] != NULL; i++) |
2790 | 432 if (priv->capability.type & (1 << i)) |
2841 | 433 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]); |
2818 | 434 mp_msg(MSGT_TV, MSGL_INFO, "\n"); |
435 mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type); | |
436 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n", | |
2790 | 437 priv->capability.minwidth, priv->capability.minheight, |
438 priv->capability.maxwidth, priv->capability.maxheight); | |
439 priv->width = priv->capability.minwidth; | |
440 priv->height = priv->capability.minheight; | |
2818 | 441 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels); |
2790 | 442 |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
443 priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels); |
3611 | 444 if (!priv->channels) |
445 goto malloc_failed; | |
2790 | 446 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels); |
447 for (i = 0; i < priv->capability.channels; i++) | |
448 { | |
449 priv->channels[i].channel = i; | |
3815 | 450 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2841 | 451 { |
452 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); | |
453 break; | |
454 } | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
455 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%s)\n", i, |
2790 | 456 priv->channels[i].name, |
457 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "", | |
458 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "", | |
459 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "", | |
2802 | 460 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "", |
461 priv->channels[i].tuners, | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
462 norm2name(priv->channels[i].norm)); |
2802 | 463 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
464 priv->act_channel = 0; |
2802 | 465 |
466 if (!(priv->capability.type & VID_TYPE_CAPTURE)) | |
467 { | |
2818 | 468 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n"); |
2802 | 469 goto err; |
470 } | |
471 | |
472 /* map grab buffer */ | |
3815 | 473 if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1) |
2802 | 474 { |
2818 | 475 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno)); |
2802 | 476 goto err; |
2790 | 477 } |
478 | |
2818 | 479 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n", |
2802 | 480 priv->mbuf.size, priv->mbuf.frames); |
481 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | |
3815 | 482 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
|
483 if (priv->mmap == (unsigned char *)-1) |
2802 | 484 { |
3815 | 485 mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno)); |
2802 | 486 goto err; |
487 } | |
2818 | 488 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap); |
2790 | 489 |
2802 | 490 /* num of buffers */ |
491 priv->nbuf = priv->mbuf.frames; | |
2790 | 492 |
2802 | 493 /* video buffers */ |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
494 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap)); |
3611 | 495 if (!priv->buf) |
496 goto malloc_failed; | |
2802 | 497 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap)); |
2790 | 498 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
499 /* init v4l audio even when we don't capture */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
500 init_v4l_audio(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
501 |
7835
d489890c59d3
add an option to force audio recording when a tv card reports no audio sources
henry
parents:
7834
diff
changeset
|
502 if (!priv->capability.audios && !tv_param_force_audio) tv_param_noaudio = 1; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
503 |
3815 | 504 /* audio init */ |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
505 if (!tv_param_noaudio) { |
3815 | 506 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
507 #ifdef HAVE_ALSA9 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
508 if (tv_param_alsa) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
509 audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
510 else |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
511 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
512 #else |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
513 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); |
3815 | 514 #endif |
515 | |
7070
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
516 if (priv->audio_device) { |
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
517 audio_in_set_device(&priv->audio_in, priv->audio_device); |
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
518 } |
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
519 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
520 if (tv_param_audio_id < priv->capability.audios) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
521 priv->audio_id = tv_param_audio_id; |
3815 | 522 else |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
523 priv->audio_id = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
524 audio_in_set_samplerate(&priv->audio_in, 44100); |
7844 | 525 if (priv->capability.audios) { |
526 audio_in_set_channels(&priv->audio_in, priv->audio_channels[priv->audio_id]); | |
527 } else { | |
528 if (tv_param_forcechan >= 0) { | |
529 audio_in_set_channels(&priv->audio_in, tv_param_forcechan); | |
530 } else { | |
531 audio_in_set_channels(&priv->audio_in, 2); | |
532 } | |
533 } | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
534 if (audio_in_setup(&priv->audio_in) < 0) return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
535 setup_audio_buffer_sizes(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
536 } |
3815 | 537 |
2790 | 538 return(1); |
539 | |
3611 | 540 malloc_failed: |
541 if (priv->channels) | |
542 free(priv->channels); | |
543 if (priv->buf) | |
544 free(priv->buf); | |
2790 | 545 err: |
3815 | 546 if (priv->video_fd != -1) |
547 close(priv->video_fd); | |
2790 | 548 return(0); |
549 } | |
550 | |
2802 | 551 static int uninit(priv_t *priv) |
2790 | 552 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
553 priv->shutdown = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
554 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
555 mp_msg(MSGT_TV, MSGL_V, "Waiting for threads to finish... "); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
556 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
557 pthread_join(priv->audio_grabber_thread, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
558 pthread_mutex_destroy(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
559 pthread_mutex_destroy(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
560 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
561 pthread_mutex_destroy(&priv->video_buffer_mutex); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
562 pthread_join(priv->video_grabber_thread, NULL); |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
563 mp_msg(MSGT_TV, MSGL_V, "done\n"); |
3815 | 564 |
8703 | 565 if (priv->capability.audios) { |
566 priv->audio[priv->audio_id].volume = 0; | |
567 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE; | |
568 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
569 } | |
570 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
571 close(priv->video_fd); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
572 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
573 audio_in_uninit(&priv->audio_in); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
574 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
575 if (priv->video_ringbuffer) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
576 int i; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
577 for (i = 0; i < priv->video_buffer_size_current; i++) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
578 free(priv->video_ringbuffer[i]); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
579 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
580 free(priv->video_ringbuffer); |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
581 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
582 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
583 if (priv->video_timebuffer) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
584 free(priv->video_timebuffer); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
585 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
586 if (priv->audio_ringbuffer) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
587 free(priv->audio_ringbuffer); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
588 if (priv->audio_skew_buffer) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
589 free(priv->audio_skew_buffer); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
590 } |
2931 | 591 |
592 return(1); | |
2790 | 593 } |
594 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
595 static int get_capture_buffer_size(priv_t *priv) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
596 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
597 int bufsize, cnt; |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
598 |
7954 | 599 if (tv_param_buffer_size >= 0) { |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
600 bufsize = tv_param_buffer_size*1024*1024; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
601 } else { |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
602 #ifdef HAVE_SYS_SYSINFO_H |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
603 struct sysinfo si; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
604 |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
605 sysinfo(&si); |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
606 if (si.totalram<2*1024*1024) { |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
607 bufsize = 1024*1024; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
608 } else { |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
609 bufsize = si.totalram/2; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
610 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
611 #else |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
612 bufsize = 16*1024*1024; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
613 #endif |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
614 } |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
615 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
616 cnt = bufsize/(priv->height*priv->bytesperline); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
617 if (cnt < 2) cnt = 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
618 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
619 return cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
620 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
621 |
2802 | 622 static int start(priv_t *priv) |
2790 | 623 { |
2802 | 624 int i; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
625 int bytes_per_sample; |
2802 | 626 |
3815 | 627 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1) |
2790 | 628 { |
2818 | 629 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); |
2802 | 630 return(0); |
2790 | 631 } |
632 | |
2802 | 633 priv->picture.palette = format2palette(priv->format); |
634 priv->picture.depth = palette2depth(priv->picture.palette); | |
3815 | 635 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
636 if (priv->format != IMGFMT_BGR15) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
637 priv->bytesperline = priv->width * priv->picture.depth / 8; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
638 } else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
639 priv->bytesperline = priv->width * 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
640 } |
3815 | 641 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
642 mp_msg(MSGT_TV, MSGL_V, "Picture values:\n"); |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
643 mp_msg(MSGT_TV, MSGL_V, " Depth: %d, Palette: %s (Format: %s)\n", priv->picture.depth, |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
644 PALETTE(priv->picture.palette), vo_format_name(priv->format)); |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
645 mp_msg(MSGT_TV, MSGL_V, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n", |
2802 | 646 priv->picture.brightness, priv->picture.hue, |
647 priv->picture.colour, priv->picture.contrast); | |
648 | |
649 | |
3815 | 650 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1) |
2790 | 651 { |
2818 | 652 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno)); |
2802 | 653 return(0); |
2790 | 654 } |
655 | |
2802 | 656 priv->nbuf = priv->mbuf.frames; |
657 for (i=0; i < priv->nbuf; i++) | |
658 { | |
659 priv->buf[i].format = priv->picture.palette; | |
660 priv->buf[i].frame = i; | |
661 priv->buf[i].width = priv->width; | |
662 priv->buf[i].height = priv->height; | |
2818 | 663 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]); |
2802 | 664 } |
2837 | 665 |
2931 | 666 #if 0 |
667 { | |
668 struct video_play_mode pmode; | |
669 | |
670 pmode.mode = VID_PLAY_NORMAL; | |
671 pmode.p1 = 1; | |
672 pmode.p2 = 0; | |
3815 | 673 if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1) |
2931 | 674 { |
675 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno)); | |
676 // return(0); | |
677 } | |
678 } | |
679 #endif | |
2837 | 680 |
681 #if 0 | |
682 { | |
683 struct video_window win; | |
684 | |
685 win.x = 0; | |
686 win.y = 0; | |
687 win.width = priv->width; | |
688 win.height = priv->height; | |
689 win.chromakey = -1; | |
690 win.flags = 0; | |
5088 | 691 //win.clipcount = 0; |
2837 | 692 |
3815 | 693 ioctl(priv->video_fd, VIDIOCSWIN, &win); |
2837 | 694 } |
695 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
696 // initialize video capture |
3815 | 697 if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1) |
2802 | 698 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
699 mp_msg(MSGT_TV, MSGL_ERR, "FATAL: ioctl ccapture failed: %s\n", strerror(errno)); |
2802 | 700 return(0); |
701 } | |
2837 | 702 #endif |
703 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
704 /* setup audio parameters */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
705 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
706 setup_audio_buffer_sizes(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
707 bytes_per_sample = priv->audio_in.bytes_per_sample; |
8131 | 708 priv->audio_skew_buffer = (long long*)malloc(sizeof(long long)*priv->aud_skew_cnt); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
709 if (!priv->audio_skew_buffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
710 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
711 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
712 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
713 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
714 priv->audio_ringbuffer = (unsigned char*)malloc(priv->audio_in.blocksize*priv->audio_buffer_size); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
715 if (!priv->audio_ringbuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
716 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate audio buffer: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
717 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
718 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
719 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
720 priv->audio_secs_per_block = (double)priv->audio_in.blocksize/(priv->audio_in.samplerate |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
721 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
722 *bytes_per_sample); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
723 priv->audio_head = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
724 priv->audio_tail = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
725 priv->audio_cnt = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
726 priv->audio_drop = 0; |
8131 | 727 priv->audio_skew = 0; |
728 priv->audio_skew_total = 0; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
729 priv->audio_recv_blocks_total = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
730 priv->audio_sent_blocks_total = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
731 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
732 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
733 /* setup video parameters */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
734 if (priv->immediate_mode) { |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
735 priv->video_buffer_size_max = VID_BUF_SIZE_IMMEDIATE; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
736 } else { |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
737 priv->video_buffer_size_max = get_capture_buffer_size(priv); |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
738 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
739 priv->video_buffer_size_current = 0; |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
740 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
741 if (!tv_param_noaudio) { |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
742 if (priv->video_buffer_size_max < 3.0*priv->fps*priv->audio_secs_per_block) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
743 mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n" |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
744 "You will probably experience heavy framedrops.\n"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
745 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
746 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
747 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
748 mp_msg(MSGT_TV, MSGL_V, "Using a ring buffer for maximum %d frames, %d MB total size.\n", |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
749 priv->video_buffer_size_max, |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
750 priv->video_buffer_size_max*priv->height*priv->bytesperline/(1024*1024)); |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
751 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
752 priv->video_ringbuffer = (unsigned char**)malloc(priv->video_buffer_size_max*sizeof(unsigned char*)); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
753 if (!priv->video_ringbuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
754 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate video buffer: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
755 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
756 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
757 for (i = 0; i < priv->video_buffer_size_max; i++) |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
758 priv->video_ringbuffer[i] = NULL; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
759 |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
760 priv->video_timebuffer = (long long*)malloc(sizeof(long long) * priv->video_buffer_size_max); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
761 if (!priv->video_timebuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
762 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate time buffer: %s\n", strerror(errno)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
763 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
764 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
765 priv->video_head = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
766 priv->video_tail = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
767 priv->video_cnt = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
768 priv->first = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
769 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
770 if (priv->capability.audios) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
771 /* enable audio */ |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
772 if (tv_param_volume >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
773 priv->audio[priv->audio_id].volume = tv_param_volume; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
774 if (tv_param_bass >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
775 priv->audio[priv->audio_id].bass = tv_param_bass; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
776 if (tv_param_treble >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
777 priv->audio[priv->audio_id].treble = tv_param_treble; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
778 if (tv_param_balance >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
779 priv->audio[priv->audio_id].balance = tv_param_balance; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
780 priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
781 mp_msg(MSGT_TV, MSGL_V, "Enabling tv audio. Requested setup is:\n"); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
782 mp_msg(MSGT_TV, MSGL_V, "id=%d vol=%d bass=%d treble=%d balance=%d mode=%s", |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
783 priv->audio_id, |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
784 priv->audio[priv->audio_id].volume, priv->audio[priv->audio_id].bass, priv->audio[priv->audio_id].treble, |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
785 priv->audio[priv->audio_id].balance, audio_mode2name(priv->audio[priv->audio_id].mode)); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
786 mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[priv->audio_id]); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
787 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
788 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
789 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
790 /* launch capture threads */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
791 priv->shutdown = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
792 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
793 pthread_mutex_init(&priv->audio_starter, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
794 pthread_mutex_init(&priv->skew_mutex, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
795 pthread_mutex_lock(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
796 pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
797 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
798 pthread_mutex_init(&priv->video_buffer_mutex, NULL); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
799 /* we'll launch the video capture later, when a first request for a frame arrives */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
800 |
2837 | 801 return(1); |
2790 | 802 } |
803 | |
804 static int control(priv_t *priv, int cmd, void *arg) | |
805 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
806 mp_msg(MSGT_TV, MSGL_DBG2, "\ndebug: control(priv=%p, cmd=%d, arg=%p)\n", |
2802 | 807 priv, cmd, arg); |
2790 | 808 switch(cmd) |
809 { | |
2802 | 810 /* ========== GENERIC controls =========== */ |
811 case TVI_CONTROL_IS_VIDEO: | |
812 { | |
813 if (priv->capability.type & VID_TYPE_CAPTURE) | |
814 return(TVI_CONTROL_TRUE); | |
815 return(TVI_CONTROL_FALSE); | |
816 } | |
817 case TVI_CONTROL_IS_AUDIO: | |
2841 | 818 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO) |
3815 | 819 { |
2841 | 820 return(TVI_CONTROL_TRUE); |
3815 | 821 } |
8774 | 822 return(TVI_CONTROL_FALSE); |
2802 | 823 case TVI_CONTROL_IS_TUNER: |
824 { | |
2841 | 825 // if (priv->capability.type & VID_TYPE_TUNER) |
826 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 827 return(TVI_CONTROL_TRUE); |
828 return(TVI_CONTROL_FALSE); | |
829 } | |
830 | |
831 /* ========== VIDEO controls =========== */ | |
2790 | 832 case TVI_CONTROL_VID_GET_FORMAT: |
2802 | 833 { |
834 int output_fmt = -1; | |
835 | |
836 output_fmt = priv->format; | |
837 (int)*(void **)arg = output_fmt; | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
838 mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt)); |
2802 | 839 return(TVI_CONTROL_TRUE); |
840 } | |
841 case TVI_CONTROL_VID_SET_FORMAT: | |
842 priv->format = (int)*(void **)arg; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
843 // !HACK! v4l uses BGR format instead of RGB |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
844 // and we have to correct this. Fortunately, |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
845 // tv.c reads later the format back so we |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
846 // can persuade it to use what we want. |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
847 if (IMGFMT_IS_RGB(priv->format)) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
848 priv->format &= ~IMGFMT_RGB_MASK; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
849 priv->format |= IMGFMT_BGR; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
850 } |
2790 | 851 return(TVI_CONTROL_TRUE); |
852 case TVI_CONTROL_VID_GET_PLANES: | |
3220 | 853 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */ |
2790 | 854 return(TVI_CONTROL_TRUE); |
855 case TVI_CONTROL_VID_GET_BITS: | |
2810 | 856 (int)*(void **)arg = palette2depth(format2palette(priv->format)); |
2790 | 857 return(TVI_CONTROL_TRUE); |
858 case TVI_CONTROL_VID_GET_WIDTH: | |
859 (int)*(void **)arg = priv->width; | |
860 return(TVI_CONTROL_TRUE); | |
861 case TVI_CONTROL_VID_CHK_WIDTH: | |
862 { | |
863 int req_width = (int)*(void **)arg; | |
864 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
865 mp_msg(MSGT_TV, MSGL_V, "Requested width: %d\n", req_width); |
2810 | 866 if ((req_width >= priv->capability.minwidth) && |
867 (req_width <= priv->capability.maxwidth)) | |
2790 | 868 return(TVI_CONTROL_TRUE); |
869 return(TVI_CONTROL_FALSE); | |
870 } | |
871 case TVI_CONTROL_VID_SET_WIDTH: | |
872 priv->width = (int)*(void **)arg; | |
873 return(TVI_CONTROL_TRUE); | |
874 case TVI_CONTROL_VID_GET_HEIGHT: | |
875 (int)*(void **)arg = priv->height; | |
876 return(TVI_CONTROL_TRUE); | |
877 case TVI_CONTROL_VID_CHK_HEIGHT: | |
878 { | |
879 int req_height = (int)*(void **)arg; | |
880 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
881 mp_msg(MSGT_TV, MSGL_V, "Requested height: %d\n", req_height); |
2810 | 882 if ((req_height >= priv->capability.minheight) && |
883 (req_height <= priv->capability.maxheight)) | |
2790 | 884 return(TVI_CONTROL_TRUE); |
885 return(TVI_CONTROL_FALSE); | |
886 } | |
887 case TVI_CONTROL_VID_SET_HEIGHT: | |
888 priv->height = (int)*(void **)arg; | |
889 return(TVI_CONTROL_TRUE); | |
2937 | 890 case TVI_CONTROL_VID_GET_PICTURE: |
3815 | 891 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1) |
2937 | 892 { |
893 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
894 return(TVI_CONTROL_FALSE); | |
895 } | |
896 return(TVI_CONTROL_TRUE); | |
897 case TVI_CONTROL_VID_SET_PICTURE: | |
3815 | 898 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1) |
2937 | 899 { |
900 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
901 return(TVI_CONTROL_FALSE); | |
902 } | |
903 return(TVI_CONTROL_TRUE); | |
904 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
905 priv->picture.brightness = (int)*(void **)arg; | |
906 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
907 return(TVI_CONTROL_TRUE); | |
908 case TVI_CONTROL_VID_SET_HUE: | |
909 priv->picture.hue = (int)*(void **)arg; | |
910 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
911 return(TVI_CONTROL_TRUE); | |
912 case TVI_CONTROL_VID_SET_SATURATION: | |
913 priv->picture.colour = (int)*(void **)arg; | |
914 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
915 return(TVI_CONTROL_TRUE); | |
916 case TVI_CONTROL_VID_SET_CONTRAST: | |
917 priv->picture.contrast = (int)*(void **)arg; | |
918 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); | |
919 return(TVI_CONTROL_TRUE); | |
6529
8552767dbb46
tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents:
6305
diff
changeset
|
920 case TVI_CONTROL_VID_GET_FPS: |
8552767dbb46
tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents:
6305
diff
changeset
|
921 (int)*(void **)arg=priv->fps; |
8552767dbb46
tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents:
6305
diff
changeset
|
922 return(TVI_CONTROL_TRUE); |
2790 | 923 |
2802 | 924 /* ========== TUNER controls =========== */ |
925 case TVI_CONTROL_TUN_GET_FREQ: | |
926 { | |
927 unsigned long freq; | |
928 | |
3815 | 929 if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1) |
2802 | 930 { |
2818 | 931 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno)); |
2802 | 932 return(TVI_CONTROL_FALSE); |
933 } | |
934 | |
935 /* tuner uses khz not mhz ! */ | |
2837 | 936 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
937 // freq /= 1000; | |
2802 | 938 (unsigned long)*(void **)arg = freq; |
939 return(TVI_CONTROL_TRUE); | |
940 } | |
2790 | 941 case TVI_CONTROL_TUN_SET_FREQ: |
942 { | |
2802 | 943 /* argument is in MHz ! */ |
944 unsigned long freq = (unsigned long)*(void **)arg; | |
945 | |
8703 | 946 if (priv->capability.audios) { |
947 priv->audio[priv->audio_id].volume = 0; | |
948 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE; | |
949 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
950 } | |
951 | |
2837 | 952 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16); |
2802 | 953 |
954 /* tuner uses khz not mhz ! */ | |
2837 | 955 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
956 // freq *= 1000; | |
957 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16); | |
3815 | 958 if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1) |
2802 | 959 { |
2818 | 960 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno)); |
2802 | 961 return(TVI_CONTROL_FALSE); |
962 } | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
963 usleep(100000); // wait to supress noise during switching |
8703 | 964 |
965 if (priv->capability.audios) { | |
966 priv->audio[priv->audio_id].volume = tv_param_volume; | |
967 priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE; | |
968 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
969 } | |
970 | |
2802 | 971 return(TVI_CONTROL_TRUE); |
972 } | |
973 case TVI_CONTROL_TUN_GET_TUNER: | |
974 { | |
3815 | 975 if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1) |
2802 | 976 { |
2818 | 977 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 978 return(TVI_CONTROL_FALSE); |
979 } | |
980 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
981 mp_msg(MSGT_TV, MSGL_V, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name, |
2802 | 982 priv->tuner.rangelow, priv->tuner.rangehigh); |
983 return(TVI_CONTROL_TRUE); | |
984 } | |
985 case TVI_CONTROL_TUN_SET_TUNER: | |
986 { | |
3815 | 987 if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1) |
2802 | 988 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
989 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set tuner failed: %s\n", strerror(errno)); |
2802 | 990 return(TVI_CONTROL_FALSE); |
991 } | |
992 return(TVI_CONTROL_TRUE); | |
993 } | |
994 case TVI_CONTROL_TUN_SET_NORM: | |
995 { | |
996 int req_mode = (int)*(void **)arg; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
997 |
8477 | 998 if ((req_mode != TV_NORM_PAL) && (req_mode != TV_NORM_NTSC) && (req_mode != TV_NORM_SECAM) |
999 && (req_mode != TV_NORM_PALNC) && (req_mode != TV_NORM_PALM) && (req_mode != TV_NORM_PALN) | |
1000 && (req_mode != TV_NORM_NTSCJP)) { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1001 mp_msg(MSGT_TV, MSGL_ERR, "Unknown norm!\n"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1002 return(TVI_CONTROL_FALSE); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1003 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1004 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1005 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) { |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1006 int prev_mode; |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1007 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1008 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
8477 | 1009 if (((req_mode == TV_NORM_PAL |
1010 || req_mode == TV_NORM_PALNC | |
1011 || req_mode == TV_NORM_PALN) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) || | |
1012 ((req_mode == TV_NORM_NTSC | |
1013 || req_mode == TV_NORM_NTSCJP | |
1014 || req_mode == TV_NORM_PALM) && !(priv->tuner.flags & VIDEO_TUNER_NTSC)) || | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1015 ((req_mode == TV_NORM_SECAM) && !(priv->tuner.flags & VIDEO_TUNER_SECAM))) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1016 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1017 mp_msg(MSGT_TV, MSGL_ERR, "Tuner isn't capable to set norm!\n"); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1018 return(TVI_CONTROL_FALSE); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1019 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1020 |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1021 prev_mode = priv->tuner.mode; |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1022 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1023 switch(req_mode) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1024 case TV_NORM_PAL: |
8477 | 1025 case TV_NORM_PALNC: |
1026 case TV_NORM_PALN: | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1027 priv->tuner.mode = VIDEO_MODE_PAL; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1028 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1029 case TV_NORM_NTSC: |
8477 | 1030 case TV_NORM_NTSCJP: |
1031 case TV_NORM_PALM: | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1032 priv->tuner.mode = VIDEO_MODE_NTSC; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1033 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1034 case TV_NORM_SECAM: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1035 priv->tuner.mode = VIDEO_MODE_SECAM; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1036 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1037 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1038 |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1039 if (control(priv, TVI_CONTROL_TUN_SET_TUNER, &priv->tuner) != TVI_CONTROL_TRUE) { |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1040 // norm setting failed, but maybe it's only because it's fixed |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1041 if (priv->tuner.mode != prev_mode) return(TVI_CONTROL_FALSE); // no it really failed |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1042 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1043 |
2802 | 1044 } |
1045 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1046 switch(req_mode) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1047 case TV_NORM_PAL: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1048 priv->channels[priv->act_channel].norm = VIDEO_MODE_PAL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1049 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1050 case TV_NORM_NTSC: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1051 priv->channels[priv->act_channel].norm = VIDEO_MODE_NTSC; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1052 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1053 case TV_NORM_SECAM: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1054 priv->channels[priv->act_channel].norm = VIDEO_MODE_SECAM; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1055 break; |
8477 | 1056 case TV_NORM_PALNC: |
1057 priv->channels[priv->act_channel].norm = 3; | |
1058 break; | |
1059 case TV_NORM_PALM: | |
1060 priv->channels[priv->act_channel].norm = 4; | |
1061 break; | |
1062 case TV_NORM_PALN: | |
1063 priv->channels[priv->act_channel].norm = 5; | |
1064 break; | |
1065 case TV_NORM_NTSCJP: | |
1066 priv->channels[priv->act_channel].norm = 6; | |
1067 break; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1068 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1069 if (ioctl(priv->video_fd, VIDIOCSCHAN, &priv->channels[priv->act_channel]) == -1) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1070 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1071 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1072 return(TVI_CONTROL_FALSE); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1073 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1074 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1075 if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1076 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2802 | 1077 return(TVI_CONTROL_FALSE); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1078 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1079 |
8477 | 1080 if(req_mode == TV_NORM_PAL || req_mode == TV_NORM_SECAM || req_mode == TV_NORM_PALN || req_mode == TV_NORM_PALNC) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1081 priv->fps = PAL_FPS; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1082 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1083 |
8477 | 1084 if(req_mode == TV_NORM_NTSC || req_mode == TV_NORM_NTSCJP || req_mode == TV_NORM_PALM) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1085 priv->fps = NTSC_FPS; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1086 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1087 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1088 if(priv->height > priv->capability.maxheight) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1089 priv->height = priv->capability.maxheight; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1090 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1091 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1092 if(priv->width > priv->capability.maxwidth) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1093 priv->width = priv->capability.maxwidth; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1094 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1095 |
2802 | 1096 return(TVI_CONTROL_TRUE); |
1097 } | |
1098 case TVI_CONTROL_TUN_GET_NORM: | |
1099 { | |
1100 (int)*(void **)arg = priv->tuner.mode; | |
1101 | |
1102 return(TVI_CONTROL_TRUE); | |
1103 } | |
1104 | |
1105 /* ========== AUDIO controls =========== */ | |
1106 case TVI_CONTROL_AUD_GET_FORMAT: | |
1107 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1108 (int)*(void **)arg = AFMT_S16_LE; |
2802 | 1109 return(TVI_CONTROL_TRUE); |
1110 } | |
1111 case TVI_CONTROL_AUD_GET_CHANNELS: | |
1112 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1113 (int)*(void **)arg = priv->audio_in.channels; |
2802 | 1114 return(TVI_CONTROL_TRUE); |
1115 } | |
1116 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
1117 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1118 (int)*(void **)arg = priv->audio_in.samplerate; |
2802 | 1119 return(TVI_CONTROL_TRUE); |
1120 } | |
1121 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
1122 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1123 (int)*(void **)arg = priv->audio_in.bytes_per_sample; |
2802 | 1124 return(TVI_CONTROL_TRUE); |
1125 } | |
5941 | 1126 case TVI_CONTROL_AUD_SET_SAMPLERATE: |
1127 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1128 if (audio_in_set_samplerate(&priv->audio_in, (int)*(void **)arg) < 0) return TVI_CONTROL_FALSE; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1129 setup_audio_buffer_sizes(priv); |
5941 | 1130 return(TVI_CONTROL_TRUE); |
1131 } | |
2802 | 1132 /* ========== SPECIFIC controls =========== */ |
1133 case TVI_CONTROL_SPC_GET_INPUT: | |
1134 { | |
1135 int req_chan = (int)*(void **)arg; | |
1136 int i; | |
1137 | |
1138 for (i = 0; i < priv->capability.channels; i++) | |
1139 { | |
1140 if (priv->channels[i].channel == req_chan) | |
1141 break; | |
1142 } | |
2841 | 1143 |
1144 priv->act_channel = i; | |
2802 | 1145 |
3815 | 1146 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2802 | 1147 { |
2818 | 1148 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); |
2802 | 1149 return(TVI_CONTROL_FALSE); |
1150 } | |
1151 return(TVI_CONTROL_TRUE); | |
1152 } | |
1153 | |
1154 case TVI_CONTROL_SPC_SET_INPUT: | |
1155 { | |
1156 struct video_channel chan; | |
1157 int req_chan = (int)*(void **)arg; | |
1158 int i; | |
1159 | |
1160 if (req_chan >= priv->capability.channels) | |
1161 { | |
2818 | 1162 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n", |
2802 | 1163 req_chan, priv->capability.channels); |
1164 return(TVI_CONTROL_FALSE); | |
1165 } | |
1166 | |
1167 for (i = 0; i < priv->capability.channels; i++) | |
1168 { | |
1169 if (priv->channels[i].channel == req_chan) | |
1170 chan = priv->channels[i]; | |
1171 } | |
1172 | |
3815 | 1173 if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1) |
2802 | 1174 { |
2818 | 1175 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
2802 | 1176 return(TVI_CONTROL_FALSE); |
1177 } | |
2818 | 1178 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name); |
2802 | 1179 |
2841 | 1180 priv->act_channel = i; |
1181 | |
2802 | 1182 /* update tuner state */ |
2841 | 1183 // if (priv->capability.type & VID_TYPE_TUNER) |
1184 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 1185 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
1186 | |
1187 /* update local channel list */ | |
1188 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan); | |
1189 return(TVI_CONTROL_TRUE); | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1190 case TVI_CONTROL_IMMEDIATE: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1191 priv->immediate_mode = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1192 return(TVI_CONTROL_TRUE); |
2790 | 1193 } |
1194 } | |
1195 | |
1196 return(TVI_CONTROL_UNKNOWN); | |
1197 } | |
1198 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1199 // copies a video frame |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1200 // for RGB (i.e. BGR in mplayer) flips the image upside down |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1201 // for YV12 swaps the 2nd and 3rd plane |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1202 static inline void copy_frame(priv_t *priv, unsigned char *dest, unsigned char *source) |
2790 | 1203 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1204 int i; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1205 unsigned char *sptr; |
2802 | 1206 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1207 // YV12 uses VIDEO_PALETTE_YUV420P, but the planes are swapped |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1208 if (priv->format == IMGFMT_YV12) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1209 memcpy(dest, source, priv->width * priv->height); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1210 memcpy(dest+priv->width * priv->height*5/4, source+priv->width * priv->height, priv->width * priv->height/4); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1211 memcpy(dest+priv->width * priv->height, source+priv->width * priv->height*5/4, priv->width * priv->height/4); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1212 return; |
2790 | 1213 } |
3711 | 1214 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1215 switch (priv->picture.palette) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1216 case VIDEO_PALETTE_RGB24: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1217 case VIDEO_PALETTE_RGB32: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1218 case VIDEO_PALETTE_RGB555: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1219 case VIDEO_PALETTE_RGB565: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1220 sptr = source + (priv->height-1)*priv->bytesperline; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1221 for (i = 0; i < priv->height; i++) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1222 memcpy(dest, sptr, priv->bytesperline); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1223 dest += priv->bytesperline; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1224 sptr -= priv->bytesperline; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1225 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1226 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1227 case VIDEO_PALETTE_UYVY: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1228 case VIDEO_PALETTE_YUV420P: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1229 default: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1230 memcpy(dest, source, priv->bytesperline * priv->height); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1231 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1232 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1233 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1234 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1235 // maximum skew change, in frames |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1236 #define MAX_SKEW_DELTA 0.6 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1237 static void *video_grabber(void *data) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1238 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1239 priv_t *priv = (priv_t*)data; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1240 struct timeval curtime; |
8131 | 1241 long long skew, prev_skew, xskew, interval, prev_interval; |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1242 int frame; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1243 int i; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1244 int first = 1; |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1245 int framecount; |
3711 | 1246 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1247 /* start the capture process */ |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1248 |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1249 for (i=0; i < priv->nbuf; i++) { |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1250 if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[i]) == -1) |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1251 { |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1252 mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno)); |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1253 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1254 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1255 |
8131 | 1256 prev_interval = 0; |
1257 prev_skew = 0; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1258 |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1259 for (framecount = 0; !priv->shutdown;) |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1260 { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1261 for (i = 0; i < priv->nbuf && !priv->shutdown; i++, framecount++) { |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1262 |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1263 if (priv->immediate_mode) { |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1264 while (priv->video_cnt == priv->video_buffer_size_max) { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1265 usleep(10000); |
7834 | 1266 if (priv->shutdown) { |
1267 return NULL; | |
1268 } | |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1269 } |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1270 } |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1271 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1272 frame = i; |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1273 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1274 while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 && |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1275 (errno == EAGAIN || errno == EINTR)); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1276 mp_dbg(MSGT_TV, MSGL_DBG3, "\npicture sync failed\n"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1277 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1278 gettimeofday(&curtime, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1279 if (first) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1280 // this was a first frame - let's launch the audio capture thread immediately |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1281 // before that, just initialize some variables |
8131 | 1282 priv->starttime = (long long)1e6*curtime.tv_sec + curtime.tv_usec; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1283 priv->audio_skew_measure_time = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1284 pthread_mutex_unlock(&priv->audio_starter); |
7585
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1285 // first frame must always have timestamp of zero |
8131 | 1286 xskew = 0; |
1287 skew = 0; | |
1288 interval = 0; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1289 first = 0; |
7585
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1290 } else { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1291 if (!priv->immediate_mode) { |
8131 | 1292 interval = (long long)1e6*curtime.tv_sec + curtime.tv_usec - priv->starttime; |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1293 } else { |
8627
14ab71b47a58
user friendly channel tuning + 10L fix in tvi_v4l (by Stephane Jourdois)
henry
parents:
8485
diff
changeset
|
1294 interval = (long long)1e6*framecount/priv->fps; |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1295 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1296 |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1297 if (!priv->immediate_mode) { |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1298 if (interval - prev_interval == 0) { |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1299 mp_msg(MSGT_TV, MSGL_V, "\nvideo capture thread: frame delta = 0\n"); |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1300 } else if ((interval - prev_interval < (long long)0.85e6/priv->fps) |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1301 || (interval - prev_interval > (long long)1.15e6/priv->fps) ) { |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1302 mp_msg(MSGT_TV, MSGL_V, "\nvideo capture thread: frame delta ~ %.1lf fps\n", |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1303 (double)1e6/(interval - prev_interval)); |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1304 } |
7585
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1305 } |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1306 |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1307 // interpolate the skew in time |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1308 pthread_mutex_lock(&priv->skew_mutex); |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1309 xskew = priv->audio_skew + (interval - priv->audio_skew_measure_time)*priv->audio_skew_factor; |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1310 pthread_mutex_unlock(&priv->skew_mutex); |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1311 // correct extreme skew changes to avoid (especially) moving backwards in time |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1312 if (xskew - prev_skew > (interval - prev_interval)*MAX_SKEW_DELTA) { |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1313 skew = prev_skew + (interval - prev_interval)*MAX_SKEW_DELTA; |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1314 } else if (xskew - prev_skew < -(interval - prev_interval)*MAX_SKEW_DELTA) { |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1315 skew = prev_skew - (interval - prev_interval)*MAX_SKEW_DELTA; |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1316 } else { |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1317 skew = xskew; |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1318 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1319 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1320 |
8131 | 1321 mp_msg(MSGT_TV, MSGL_DBG3, "\nfps = %lf, interval = %lf, a_skew = %f, corr_skew = %f\n", |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1322 (interval != prev_interval) ? (double)1e6/(interval - prev_interval) : -1, |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1323 (double)1e-6*interval, (double)1e-6*xskew, (double)1e-6*skew); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1324 mp_msg(MSGT_TV, MSGL_DBG3, "vcnt = %d, acnt = %d\n", priv->video_cnt, priv->audio_cnt); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1325 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1326 prev_skew = skew; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1327 prev_interval = interval; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1328 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1329 /* allocate a new buffer, if needed */ |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1330 pthread_mutex_lock(&priv->video_buffer_mutex); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1331 if (priv->video_buffer_size_current < priv->video_buffer_size_max) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1332 if (priv->video_cnt == priv->video_buffer_size_current) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1333 unsigned char *newbuf = (unsigned char*)malloc(priv->bytesperline * priv->height); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1334 if (newbuf) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1335 memmove(priv->video_ringbuffer+priv->video_tail+1, priv->video_ringbuffer+priv->video_tail, |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1336 (priv->video_buffer_size_current-priv->video_tail)*sizeof(unsigned char *)); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1337 memmove(priv->video_timebuffer+priv->video_tail+1, priv->video_timebuffer+priv->video_tail, |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1338 (priv->video_buffer_size_current-priv->video_tail)*sizeof(long long)); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1339 priv->video_ringbuffer[priv->video_tail] = newbuf; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1340 if ((priv->video_head >= priv->video_tail) && (priv->video_cnt > 0)) priv->video_head++; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1341 priv->video_buffer_size_current++; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1342 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1343 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1344 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1345 pthread_mutex_unlock(&priv->video_buffer_mutex); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1346 |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1347 if (priv->video_cnt == priv->video_buffer_size_current) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1348 if (!priv->immediate_mode) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1349 mp_msg(MSGT_TV, MSGL_ERR, "\nvideo buffer full - dropping frame\n"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1350 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1351 } else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1352 if (priv->immediate_mode) { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1353 priv->video_timebuffer[priv->video_tail] = interval; |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1354 } else { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1355 // compensate for audio skew |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1356 // negative skew => there are more audio samples, increase interval |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1357 // positive skew => less samples, shorten the interval |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1358 priv->video_timebuffer[priv->video_tail] = interval - skew; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1359 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1360 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1361 copy_frame(priv, priv->video_ringbuffer[priv->video_tail], priv->mmap+priv->mbuf.offsets[frame]); |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1362 priv->video_tail = (priv->video_tail+1)%priv->video_buffer_size_current; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1363 priv->video_cnt++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1364 } |
2931 | 1365 |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1366 if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[frame]) == -1) |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1367 { |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1368 mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno)); |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1369 continue; |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1370 } |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1371 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1372 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1373 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1374 } |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7318
diff
changeset
|
1375 return NULL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1376 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1377 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1378 static double grab_video_frame(priv_t *priv, char *buffer, int len) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1379 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1380 double interval; |
2802 | 1381 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1382 if (priv->first) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1383 pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1384 priv->first = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1385 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1386 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1387 while (priv->video_cnt == 0) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1388 usleep(10000); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1389 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1390 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1391 pthread_mutex_lock(&priv->video_buffer_mutex); |
8131 | 1392 interval = (double)priv->video_timebuffer[priv->video_head]*1e-6; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1393 memcpy(buffer, priv->video_ringbuffer[priv->video_head], len); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1394 priv->video_cnt--; |
8671
e1337452fe62
Obvious patch to avoid undefined behaviour of multiple side effects in
arpi
parents:
8650
diff
changeset
|
1395 priv->video_head = (priv->video_head+1)%priv->video_buffer_size_current; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1396 pthread_mutex_unlock(&priv->video_buffer_mutex); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1397 return interval; |
2790 | 1398 } |
1399 | |
1400 static int get_video_framesize(priv_t *priv) | |
1401 { | |
2931 | 1402 return(priv->bytesperline * priv->height); |
2790 | 1403 } |
1404 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1405 static void *audio_grabber(void *data) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1406 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1407 priv_t *priv = (priv_t*)data; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1408 struct timeval tv; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1409 int i, audio_skew_ptr = 0; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1410 long long current_time, prev_skew = 0; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1411 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1412 pthread_mutex_lock(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1413 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1414 audio_in_start_capture(&priv->audio_in); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1415 for (i = 0; i < priv->aud_skew_cnt; i++) |
8131 | 1416 priv->audio_skew_buffer[i] = 0; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1417 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1418 for (; !priv->shutdown;) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1419 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1420 if (audio_in_read_chunk(&priv->audio_in, priv->audio_ringbuffer+priv->audio_tail*priv->audio_in.blocksize) < 0) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1421 continue; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1422 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1423 gettimeofday(&tv, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1424 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1425 priv->audio_recv_blocks_total++; |
8131 | 1426 current_time = (long long)1e6*tv.tv_sec + tv.tv_usec - priv->starttime; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1427 |
8131 | 1428 priv->audio_skew_total -= priv->audio_skew_buffer[audio_skew_ptr]; |
1429 priv->audio_skew_buffer[audio_skew_ptr] = current_time | |
1430 - 1e6*priv->audio_secs_per_block*priv->audio_recv_blocks_total; | |
1431 priv->audio_skew_total += priv->audio_skew_buffer[audio_skew_ptr]; | |
1432 audio_skew_ptr = (audio_skew_ptr+1) % priv->aud_skew_cnt; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1433 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1434 pthread_mutex_lock(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1435 // linear interpolation - here we interpolate current skew value |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1436 // from the moving average, which we expect to be in the middle |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1437 // of the interval |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1438 if (priv->audio_recv_blocks_total > priv->aud_skew_cnt) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1439 priv->audio_skew = priv->audio_skew_total/priv->aud_skew_cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1440 priv->audio_skew += (priv->audio_skew*priv->aud_skew_cnt)/(2*priv->audio_recv_blocks_total-priv->aud_skew_cnt); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1441 } else { |
8131 | 1442 // this smoothes the evolution of audio_skew at startup a bit |
1443 priv->audio_skew = ((priv->aud_skew_cnt+priv->audio_recv_blocks_total)*priv->audio_skew_total)/(priv->aud_skew_cnt*priv->audio_recv_blocks_total); | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1444 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1445 // current skew factor (assuming linearity) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1446 // used for further interpolation in video_grabber |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1447 // probably overkill but seems to be necessary for |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1448 // stress testing by dropping half of the audio frames ;) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1449 // especially when using ALSA with large block sizes |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1450 // where audio_skew remains a long while behind |
8444 | 1451 if ((priv->audio_skew_measure_time != 0) && (current_time - priv->audio_skew_measure_time != 0)) { |
1452 priv->audio_skew_factor = (double)(priv->audio_skew-prev_skew)/(current_time - priv->audio_skew_measure_time); | |
1453 } else { | |
1454 priv->audio_skew_factor = 0.0; | |
1455 } | |
1456 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1457 priv->audio_skew_measure_time = current_time; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1458 prev_skew = priv->audio_skew; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1459 pthread_mutex_unlock(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1460 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1461 if ((priv->audio_tail+1) % priv->audio_buffer_size == priv->audio_head) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1462 mp_msg(MSGT_TV, MSGL_ERR, "\ntoo bad - dropping audio frame !\n"); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1463 priv->audio_drop++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1464 } else { |
8671
e1337452fe62
Obvious patch to avoid undefined behaviour of multiple side effects in
arpi
parents:
8650
diff
changeset
|
1465 priv->audio_tail = (priv->audio_tail+1) % priv->audio_buffer_size; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1466 priv->audio_cnt++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1467 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1468 } |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7318
diff
changeset
|
1469 return NULL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1470 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1471 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
1472 static double grab_audio_frame(priv_t *priv, char *buffer, int len) |
2790 | 1473 { |
5088 | 1474 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n", |
3815 | 1475 priv, buffer, len); |
1476 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1477 // compensate for dropped audio frames |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1478 if (priv->audio_drop && (priv->audio_head == priv->audio_tail)) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1479 priv->audio_drop--; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1480 priv->audio_sent_blocks_total++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1481 memset(buffer, 0, len); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1482 return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block; |
3815 | 1483 } |
1484 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1485 while (priv->audio_head == priv->audio_tail) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1486 usleep(10000); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1487 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1488 memcpy(buffer, priv->audio_ringbuffer+priv->audio_head*priv->audio_in.blocksize, len); |
8671
e1337452fe62
Obvious patch to avoid undefined behaviour of multiple side effects in
arpi
parents:
8650
diff
changeset
|
1489 priv->audio_head = (priv->audio_head+1) % priv->audio_buffer_size; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1490 priv->audio_cnt--; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1491 priv->audio_sent_blocks_total++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1492 return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block; |
2790 | 1493 } |
1494 | |
1495 static int get_audio_framesize(priv_t *priv) | |
1496 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1497 return(priv->audio_in.blocksize); |
2790 | 1498 } |
1499 | |
1500 #endif /* USE_TV */ |