Mercurial > mplayer.hg
annotate libmpdemux/tvi_v4l.c @ 10448:091fc3a26c00
Small correction and port to XML.
author | diego |
---|---|
date | Sun, 20 Jul 2003 14:50:31 +0000 |
parents | 6fb8a6a4a071 |
children | 27711ab2889f |
rev | line source |
---|---|
2802 | 1 /* |
3284 | 2 Video 4 Linux input |
2802 | 3 |
10368 | 4 (C) Alex Beregszaszi |
2802 | 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 |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
12 Mjpeg hardware encoding support by |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
13 Iván Szántó <szivan@freemail.hu> |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
14 |
2802 | 15 CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE! |
16 */ | |
17 | |
2790 | 18 #include "config.h" |
19 | |
3243 | 20 #if defined(USE_TV) && defined(HAVE_TV_V4L) |
2790 | 21 |
22 #include <stdio.h> | |
23 #include <errno.h> | |
24 #include <fcntl.h> | |
2802 | 25 #include <signal.h> |
2790 | 26 #include <sys/ioctl.h> |
27 #include <sys/types.h> | |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
28 #include <sys/time.h> |
2790 | 29 #include <linux/videodev.h> |
30 #include <unistd.h> | |
31 #include <sys/mman.h> | |
2931 | 32 #include <stdlib.h> |
33 #include <string.h> | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
34 #include <pthread.h> |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
35 #ifdef HAVE_SYS_SYSINFO_H |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
36 #include <sys/sysinfo.h> |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
37 #endif |
2790 | 38 |
2830 | 39 #include "mp_msg.h" |
40 #include "../libao2/afmt.h" | |
41 #include "../libvo/img_format.h" | |
42 #include "../libvo/fastmemcpy.h" | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
43 #include "../libvo/videodev_mjpeg.h" |
2830 | 44 |
2790 | 45 #include "tv.h" |
46 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
47 #include "audio_in.h" |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
48 |
2790 | 49 static tvi_info_t info = { |
3815 | 50 "Video 4 Linux input", |
2790 | 51 "v4l", |
10368 | 52 "Alex Beregszaszi", |
2802 | 53 "under development" |
54 }; | |
55 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
56 #define PAL_WIDTH 768 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
57 #define PAL_HEIGHT 576 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
58 #define PAL_FPS 25 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
59 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
60 #define NTSC_WIDTH 640 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
61 #define NTSC_HEIGHT 480 |
8953
1ebf4c3ab032
NTSC is 29.97 fps, not 30. wrong values here are likely to cause
rfelker
parents:
8774
diff
changeset
|
62 #define NTSC_FPS 29.97 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
63 |
3815 | 64 #define MAX_AUDIO_CHANNELS 10 |
65 | |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
66 #define VID_BUF_SIZE_IMMEDIATE 2 |
9608 | 67 #define VIDEO_AVG_BUFFER_SIZE 600 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
68 |
2790 | 69 typedef struct { |
2802 | 70 /* general */ |
2790 | 71 char *video_device; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
72 int video_fd; |
2790 | 73 struct video_capability capability; |
74 struct video_channel *channels; | |
2841 | 75 int act_channel; |
2790 | 76 struct video_tuner tuner; |
2802 | 77 |
78 /* video */ | |
2790 | 79 struct video_picture picture; |
2802 | 80 int format; /* output format */ |
2790 | 81 int width; |
82 int height; | |
2802 | 83 int bytesperline; |
10019 | 84 float fps; |
2802 | 85 |
86 struct video_mbuf mbuf; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
87 unsigned char *mmap; |
2802 | 88 struct video_mmap *buf; |
89 int nbuf; | |
90 | |
91 /* audio */ | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
92 char *audio_device; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
93 audio_in_t audio_in; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
94 |
3815 | 95 int audio_id; |
96 struct video_audio audio[MAX_AUDIO_CHANNELS]; | |
97 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
|
98 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
99 /* buffering stuff */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
100 int immediate_mode; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
101 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
102 int audio_buffer_size; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
103 int aud_skew_cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
104 unsigned char *audio_ringbuffer; |
8131 | 105 long long *audio_skew_buffer; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
106 volatile int audio_head; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
107 volatile int audio_tail; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
108 volatile int audio_cnt; |
8131 | 109 volatile long long audio_skew; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
110 volatile double audio_skew_factor; |
8131 | 111 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
|
112 volatile int audio_drop; |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
113 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
114 int first; |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
115 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
|
116 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
|
117 unsigned char **video_ringbuffer; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
118 long long *video_timebuffer; |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
119 long long *video_avg_buffer; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
120 int video_avg_ptr; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
121 int video_interval_sum; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
122 volatile int video_head; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
123 volatile int video_tail; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
124 volatile int video_cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
125 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
126 volatile int shutdown; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
127 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
128 pthread_t audio_grabber_thread; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
129 pthread_t video_grabber_thread; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
130 pthread_mutex_t audio_starter; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
131 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
|
132 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
|
133 |
8131 | 134 long long starttime; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
135 double audio_secs_per_block; |
8131 | 136 long long audio_skew_total; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
137 long audio_recv_blocks_total; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
138 long audio_sent_blocks_total; |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
139 long mjpeg_bufsize; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
140 |
2790 | 141 } priv_t; |
142 | |
143 #include "tvi_def.h" | |
144 | |
2841 | 145 static const char *device_cap2name[] = { |
2790 | 146 "capture", "tuner", "teletext", "overlay", "chromakey", "clipping", |
2802 | 147 "frameram", "scales", "monochrome", "subcapture", "mpeg-decoder", |
148 "mpeg-encoder", "mjpeg-decoder", "mjpeg-encoder", NULL | |
149 }; | |
150 | |
2841 | 151 static const char *device_palette2name[] = { |
2802 | 152 "-", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", "yuv422", |
153 "yuyv", "uyvy", "yuv420", "yuv411", "raw", "yuv422p", "yuv411p", | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
154 "yuv420p", "yuv410p" |
2802 | 155 }; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
156 #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
|
157 |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
158 static const char *norm2name(int mode) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
159 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
160 switch (mode) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
161 case VIDEO_MODE_PAL: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
162 return "pal"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
163 case VIDEO_MODE_SECAM: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
164 return "secam"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
165 case VIDEO_MODE_NTSC: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
166 return "ntsc"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
167 case VIDEO_MODE_AUTO: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
168 return "auto"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
169 default: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
170 return "unknown"; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
171 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
172 }; |
2802 | 173 |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
174 static const char *audio_mode2name(int mode) |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
175 { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
176 switch (mode) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
177 case VIDEO_SOUND_MONO: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
178 return "mono"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
179 case VIDEO_SOUND_STEREO: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
180 return "stereo"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
181 case VIDEO_SOUND_LANG1: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
182 return "language1"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
183 case VIDEO_SOUND_LANG2: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
184 return "language2"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
185 default: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
186 return "unknown"; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
187 } |
2841 | 188 }; |
189 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
190 static void *audio_grabber(void *data); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
191 static void *video_grabber(void *data); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
192 |
2802 | 193 static int palette2depth(int palette) |
194 { | |
2810 | 195 switch(palette) |
196 { | |
3220 | 197 /* component */ |
2810 | 198 case VIDEO_PALETTE_RGB555: |
199 return(15); | |
200 case VIDEO_PALETTE_RGB565: | |
201 return(16); | |
202 case VIDEO_PALETTE_RGB24: | |
203 return(24); | |
204 case VIDEO_PALETTE_RGB32: | |
205 return(32); | |
3220 | 206 /* planar */ |
207 case VIDEO_PALETTE_YUV411P: | |
2810 | 208 case VIDEO_PALETTE_YUV420P: |
3220 | 209 case VIDEO_PALETTE_YUV410P: |
2810 | 210 return(12); |
3220 | 211 /* packed */ |
3815 | 212 case VIDEO_PALETTE_YUV422P: |
2810 | 213 case VIDEO_PALETTE_YUV422: |
3220 | 214 case VIDEO_PALETTE_YUYV: |
2810 | 215 case VIDEO_PALETTE_UYVY: |
3220 | 216 case VIDEO_PALETTE_YUV420: |
217 case VIDEO_PALETTE_YUV411: | |
2810 | 218 return(16); |
219 } | |
220 return(-1); | |
2802 | 221 } |
222 | |
223 static int format2palette(int format) | |
224 { | |
2810 | 225 switch(format) |
226 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
227 case IMGFMT_BGR15: |
2810 | 228 return(VIDEO_PALETTE_RGB555); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
229 case IMGFMT_BGR16: |
2810 | 230 return(VIDEO_PALETTE_RGB565); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
231 case IMGFMT_BGR24: |
2810 | 232 return(VIDEO_PALETTE_RGB24); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
233 case IMGFMT_BGR32: |
2810 | 234 return(VIDEO_PALETTE_RGB32); |
235 case IMGFMT_YV12: | |
3703 | 236 case IMGFMT_I420: |
2810 | 237 return(VIDEO_PALETTE_YUV420P); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
238 case IMGFMT_YUY2: |
2810 | 239 return(VIDEO_PALETTE_YUV422); |
240 } | |
241 return(-1); | |
2802 | 242 } |
243 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
244 // 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
|
245 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
|
246 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
247 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
|
248 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
249 // 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
|
250 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
|
251 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
252 *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
|
253 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
|
254 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
255 // 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
|
256 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
|
257 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
258 *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
|
259 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
|
260 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
261 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
|
262 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
|
263 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
264 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
265 tvi_handle_t *tvi_init_v4l(char *device, char *adevice) |
2790 | 266 { |
267 tvi_handle_t *h; | |
268 priv_t *priv; | |
269 | |
270 h = new_handle(); | |
271 if (!h) | |
272 return(NULL); | |
273 | |
274 priv = h->priv; | |
275 | |
2802 | 276 /* set video device name */ |
2790 | 277 if (!device) |
9216
7c536a513ce9
fix default device (manpage says /dev/video0, /dev/video often is a directory)
colin
parents:
9215
diff
changeset
|
278 priv->video_device = strdup("/dev/video0"); |
2790 | 279 else |
3611 | 280 priv->video_device = strdup(device); |
281 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
282 /* set video device name */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
283 if (!adevice) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
284 priv->audio_device = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
285 else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
286 priv->audio_device = strdup(adevice); |
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 |
3611 | 289 /* allocation failed */ |
290 if (!priv->video_device) { | |
291 free_handle(h); | |
292 return(NULL); | |
2790 | 293 } |
294 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
295 return(h); |
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 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
298 /* 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
|
299 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
|
300 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
301 int i; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
302 int reqmode; |
7058
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 (!priv->capability.audios) return; |
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 /* audio chanlist */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
307 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
308 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
|
309 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
310 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
|
311 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
|
312 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
313 if (i >= MAX_AUDIO_CHANNELS) |
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, "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
|
316 i, MAX_AUDIO_CHANNELS); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
317 i = priv->capability.audios; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
318 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
319 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
320 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
321 priv->audio[i].audio = i; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
322 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
|
323 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
324 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
|
325 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
326 } |
3815 | 327 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
328 /* mute all channels */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
329 priv->audio[i].volume = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
330 priv->audio[i].flags |= VIDEO_AUDIO_MUTE; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
331 reqmode = -1; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
332 if (tv_param_amode >= 0) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
333 switch (tv_param_amode) { |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
334 case 0: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
335 reqmode = VIDEO_SOUND_MONO; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
336 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
337 case 1: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
338 reqmode = VIDEO_SOUND_STEREO; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
339 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
340 case 2: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
341 reqmode = VIDEO_SOUND_LANG1; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
342 break; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
343 case 3: |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
344 reqmode = VIDEO_SOUND_LANG2; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
345 break; |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
346 default: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
347 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
|
348 break; |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
349 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
350 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
|
351 } |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
352 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
|
353 |
7163
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
354 // get the parameters back |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
355 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
|
356 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
357 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
|
358 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
359 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
360 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
361 switch(priv->audio[i].mode) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
362 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
363 case VIDEO_SOUND_MONO: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
364 case VIDEO_SOUND_LANG1: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
365 case VIDEO_SOUND_LANG2: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
366 priv->audio_channels[i] = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
367 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
368 case VIDEO_SOUND_STEREO: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
369 priv->audio_channels[i] = 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
370 break; |
8335
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
371 default: |
0e1d45e44813
set channel count to a saner value if the card reports an unknown audio mode
henry
parents:
8254
diff
changeset
|
372 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
|
373 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
|
374 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
|
375 break; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
376 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
377 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 } |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
384 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
385 /* display stuff */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
386 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
|
387 priv->audio[i].name); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
388 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
|
389 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
|
390 (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
|
391 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 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
|
396 |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
397 if (tv_param_forcechan >= 0) |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
398 priv->audio_channels[i] = tv_param_forcechan; |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
399 |
a193df8b275b
v4l audio fixes by Jindrich Makovicka <makovick@KMLinux.fjfi.cvut.cz>
alex
parents:
7070
diff
changeset
|
400 // 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
|
401 // 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
|
402 // 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
|
403 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
|
404 } |
2790 | 405 } |
406 | |
3815 | 407 static int init(priv_t *priv) |
2790 | 408 { |
409 int i; | |
410 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
411 if (tv_param_immediate == 1) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
412 tv_param_noaudio = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
413 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
414 priv->video_ringbuffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
415 priv->video_timebuffer = NULL; |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
416 priv->video_avg_buffer = NULL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
417 priv->audio_ringbuffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
418 priv->audio_skew_buffer = NULL; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
419 |
3815 | 420 priv->video_fd = open(priv->video_device, O_RDWR); |
5088 | 421 mp_msg(MSGT_TV, MSGL_DBG2, "Video fd: %d, %x\n", priv->video_fd, |
422 priv->video_device); | |
3815 | 423 if (priv->video_fd == -1) |
2790 | 424 { |
2818 | 425 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", |
2802 | 426 priv->video_device, strerror(errno)); |
2790 | 427 goto err; |
428 } | |
5941 | 429 |
2802 | 430 /* get capabilities (priv->capability is needed!) */ |
3815 | 431 if (ioctl(priv->video_fd, VIDIOCGCAP, &priv->capability) == -1) |
2790 | 432 { |
2818 | 433 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2790 | 434 goto err; |
435 } | |
436 | |
3815 | 437 fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC); |
2802 | 438 |
2818 | 439 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.name); |
440 mp_msg(MSGT_TV, MSGL_INFO, " Capabilites: "); | |
2841 | 441 for (i = 0; device_cap2name[i] != NULL; i++) |
2790 | 442 if (priv->capability.type & (1 << i)) |
2841 | 443 mp_msg(MSGT_TV, MSGL_INFO, "%s ", device_cap2name[i]); |
2818 | 444 mp_msg(MSGT_TV, MSGL_INFO, "\n"); |
445 mp_msg(MSGT_TV, MSGL_INFO, " Device type: %d\n", priv->capability.type); | |
446 mp_msg(MSGT_TV, MSGL_INFO, " Supported sizes: %dx%d => %dx%d\n", | |
2790 | 447 priv->capability.minwidth, priv->capability.minheight, |
448 priv->capability.maxwidth, priv->capability.maxheight); | |
449 priv->width = priv->capability.minwidth; | |
450 priv->height = priv->capability.minheight; | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
451 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
452 /* somewhere here could disable tv_param_mjpeg, if it is not a capability */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
453 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
454 /* initialize if necessary */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
455 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
456 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
457 struct mjpeg_params bparm; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
458 struct mjpeg_requestbuffers breq; /* buffer requests */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
459 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
460 if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
461 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
462 mp_msg(MSGT_TV, MSGL_ERR, |
9624 | 463 " MJP: Error getting video parameters: %s\n", strerror(errno)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
464 goto err; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
465 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
466 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
467 mp_msg(MSGT_TV, MSGL_INFO, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
468 " MJP: previous params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
469 bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
470 bparm.decimation, bparm.field_per_buff); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
471 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
472 mp_msg(MSGT_TV, MSGL_INFO, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
473 " MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
474 bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
475 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
476 bparm.input = tv_param_input; /* tv */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
477 if (!strcasecmp(tv_param_norm, "pal")) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
478 bparm.norm = 0; /* PAL */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
479 else if (!strcasecmp(tv_param_norm, "ntsc")) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
480 bparm.norm = 1; /* NTSC */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
481 else if (!strcasecmp(tv_param_norm, "secam")) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
482 bparm.norm = 2; /* SECAM */ |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
483 bparm.quality = tv_param_quality; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
484 bparm.decimation = tv_param_decimation; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
485 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
486 mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting params to decimation: %d, quality: %d\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
487 bparm.decimation, bparm.quality); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
488 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
489 if (ioctl(priv->video_fd, MJPIOC_S_PARAMS, &bparm) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
490 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
491 mp_msg(MSGT_TV, MSGL_ERR, |
9624 | 492 " MJP: Error setting video parameters: %s\n", strerror(errno)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
493 goto err; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
494 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
495 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
496 if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
497 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
498 mp_msg(MSGT_TV, MSGL_ERR, |
9624 | 499 " MJP: Error getting video parameters: %s\n", strerror(errno)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
500 goto err; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
501 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
502 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
503 mp_msg(MSGT_TV, MSGL_INFO, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
504 " MJP: current params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
505 bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
506 bparm.decimation, bparm.field_per_buff); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
507 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
508 mp_msg(MSGT_TV, MSGL_INFO, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
509 " MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
510 bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
511 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
512 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
513 breq.count = 64; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
514 priv -> nbuf = breq.count; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
515 priv->mbuf.frames = priv -> nbuf; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
516 priv->mjpeg_bufsize = 256*1024; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
517 if (tv_param_buffer_size >= 0) { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
518 priv->mjpeg_bufsize = tv_param_buffer_size*1024; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
519 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
520 breq.size = priv -> mjpeg_bufsize; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
521 if (ioctl(priv->video_fd, MJPIOC_REQBUFS,&(breq)) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
522 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
523 mp_msg (MSGT_TV, MSGL_ERR, |
9624 | 524 " MJP: Error requesting video buffers: %s\n", strerror(errno)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
525 goto err; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
526 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
527 mp_msg(MSGT_TV, MSGL_INFO, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
528 " MJP: Got %ld buffers of size %ld KB\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
529 breq.count, breq.size/1024); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
530 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
531 priv -> mmap = mmap(0, breq.count * breq.size, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
532 PROT_READ|PROT_WRITE, MAP_SHARED, priv->video_fd, 0); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
533 if (priv -> mmap == MAP_FAILED) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
534 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
535 mp_msg(MSGT_TV, MSGL_INFO, |
9624 | 536 " MJP: Error mapping video buffers: %s\n", strerror(errno)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
537 goto err; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
538 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
539 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
540 |
2818 | 541 mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels); |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
542 priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels); |
3611 | 543 if (!priv->channels) |
544 goto malloc_failed; | |
2790 | 545 memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels); |
546 for (i = 0; i < priv->capability.channels; i++) | |
547 { | |
548 priv->channels[i].channel = i; | |
3815 | 549 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2841 | 550 { |
551 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); | |
552 break; | |
553 } | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
554 mp_msg(MSGT_TV, MSGL_INFO, " %d: %s: %s%s%s%s (tuner:%d, norm:%s)\n", i, |
2790 | 555 priv->channels[i].name, |
556 (priv->channels[i].flags & VIDEO_VC_TUNER) ? "tuner " : "", | |
557 (priv->channels[i].flags & VIDEO_VC_AUDIO) ? "audio " : "", | |
558 (priv->channels[i].flags & VIDEO_TYPE_TV) ? "tv " : "", | |
2802 | 559 (priv->channels[i].flags & VIDEO_TYPE_CAMERA) ? "camera " : "", |
560 priv->channels[i].tuners, | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
561 norm2name(priv->channels[i].norm)); |
2802 | 562 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
563 priv->act_channel = 0; |
2802 | 564 |
565 if (!(priv->capability.type & VID_TYPE_CAPTURE)) | |
566 { | |
2818 | 567 mp_msg(MSGT_TV, MSGL_ERR, "Only grabbing supported (for overlay use another program)\n"); |
2802 | 568 goto err; |
569 } | |
570 | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
571 if ( !tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
572 { |
2802 | 573 /* map grab buffer */ |
3815 | 574 if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1) |
2802 | 575 { |
2818 | 576 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno)); |
2802 | 577 goto err; |
2790 | 578 } |
579 | |
2818 | 580 mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n", |
2802 | 581 priv->mbuf.size, priv->mbuf.frames); |
582 priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE, | |
3815 | 583 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
|
584 if (priv->mmap == (unsigned char *)-1) |
2802 | 585 { |
3815 | 586 mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno)); |
2802 | 587 goto err; |
588 } | |
2818 | 589 mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap); |
2790 | 590 |
2802 | 591 /* num of buffers */ |
592 priv->nbuf = priv->mbuf.frames; | |
2790 | 593 |
2802 | 594 /* video buffers */ |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
595 priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap)); |
3611 | 596 if (!priv->buf) |
597 goto malloc_failed; | |
2802 | 598 memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
599 } |
2790 | 600 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
601 /* 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
|
602 init_v4l_audio(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
603 |
7835
d489890c59d3
add an option to force audio recording when a tv card reports no audio sources
henry
parents:
7834
diff
changeset
|
604 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
|
605 |
3815 | 606 /* audio init */ |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
607 if (!tv_param_noaudio) { |
3815 | 608 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
609 #ifdef HAVE_ALSA9 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
610 if (tv_param_alsa) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
611 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
|
612 else |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
613 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
|
614 #else |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
615 audio_in_init(&priv->audio_in, AUDIO_IN_OSS); |
3815 | 616 #endif |
617 | |
7070
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
618 if (priv->audio_device) { |
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
619 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
|
620 } |
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7058
diff
changeset
|
621 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
622 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
|
623 priv->audio_id = tv_param_audio_id; |
3815 | 624 else |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
625 priv->audio_id = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
626 audio_in_set_samplerate(&priv->audio_in, 44100); |
7844 | 627 if (priv->capability.audios) { |
628 audio_in_set_channels(&priv->audio_in, priv->audio_channels[priv->audio_id]); | |
629 } else { | |
630 if (tv_param_forcechan >= 0) { | |
631 audio_in_set_channels(&priv->audio_in, tv_param_forcechan); | |
632 } else { | |
633 audio_in_set_channels(&priv->audio_in, 2); | |
634 } | |
635 } | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
636 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
|
637 setup_audio_buffer_sizes(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
638 } |
3815 | 639 |
2790 | 640 return(1); |
641 | |
3611 | 642 malloc_failed: |
643 if (priv->channels) | |
644 free(priv->channels); | |
645 if (priv->buf) | |
646 free(priv->buf); | |
2790 | 647 err: |
3815 | 648 if (priv->video_fd != -1) |
649 close(priv->video_fd); | |
2790 | 650 return(0); |
651 } | |
652 | |
2802 | 653 static int uninit(priv_t *priv) |
2790 | 654 { |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
655 unsigned long num; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
656 priv->shutdown = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
657 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
658 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
|
659 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
660 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
|
661 pthread_mutex_destroy(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
662 pthread_mutex_destroy(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
663 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
664 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
|
665 pthread_join(priv->video_grabber_thread, NULL); |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
666 mp_msg(MSGT_TV, MSGL_V, "done\n"); |
3815 | 667 |
8703 | 668 if (priv->capability.audios) { |
669 priv->audio[priv->audio_id].volume = 0; | |
670 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE; | |
671 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
672 } | |
673 | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
674 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
675 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
676 num = -1; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
677 if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
678 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
679 mp_msg(MSGT_TV, MSGL_ERR, "\n MJP: ioctl MJPIOC_QBUF_CAPT failed: %s\n", strerror(errno)); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
680 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
681 } |
9745 | 682 else |
683 { | |
684 // We need to munmap as close don't close mem mappings | |
685 if(munmap(priv->mmap,priv->mbuf.size)) | |
686 mp_msg(MSGT_TV, MSGL_ERR, "Munmap failed: %s\n",strerror(errno)); | |
687 } | |
688 | |
689 if(close(priv->video_fd)) | |
690 mp_msg(MSGT_TV, MSGL_ERR, "Close tv failed: %s\n",strerror(errno)); | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
691 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
692 audio_in_uninit(&priv->audio_in); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
693 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
694 if (priv->video_ringbuffer) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
695 int i; |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
696 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
|
697 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
|
698 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
699 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
|
700 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
701 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
702 if (priv->video_timebuffer) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
703 free(priv->video_timebuffer); |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
704 if (priv->video_avg_buffer) |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
705 free(priv->video_avg_buffer); |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
706 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
707 if (priv->audio_ringbuffer) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
708 free(priv->audio_ringbuffer); |
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 free(priv->audio_skew_buffer); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
711 } |
2931 | 712 |
713 return(1); | |
2790 | 714 } |
715 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
716 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
|
717 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
718 int bufsize, cnt; |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
719 |
7954 | 720 if (tv_param_buffer_size >= 0) { |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
721 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
|
722 } else { |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
723 #ifdef HAVE_SYS_SYSINFO_H |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
724 struct sysinfo si; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
725 |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
726 sysinfo(&si); |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
727 if (si.totalram<2*1024*1024) { |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
728 bufsize = 1024*1024; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
729 } else { |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
730 bufsize = si.totalram/2; |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
731 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
732 #else |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
733 bufsize = 16*1024*1024; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
734 #endif |
7905
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
735 } |
b062996d9794
added an option for specifying the size of capture buffer
henry
parents:
7844
diff
changeset
|
736 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
737 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
|
738 if (cnt < 2) cnt = 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
739 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
740 return cnt; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
741 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
742 |
2802 | 743 static int start(priv_t *priv) |
2790 | 744 { |
2802 | 745 int i; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
746 int bytes_per_sample; |
2802 | 747 |
3815 | 748 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1) |
2790 | 749 { |
2818 | 750 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); |
2802 | 751 return(0); |
2790 | 752 } |
753 | |
2802 | 754 priv->picture.palette = format2palette(priv->format); |
755 priv->picture.depth = palette2depth(priv->picture.palette); | |
3815 | 756 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
757 if (priv->format != IMGFMT_BGR15) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
758 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
|
759 } else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
760 priv->bytesperline = priv->width * 2; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
761 } |
3815 | 762 |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
763 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
|
764 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
|
765 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
|
766 mp_msg(MSGT_TV, MSGL_V, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n", |
2802 | 767 priv->picture.brightness, priv->picture.hue, |
768 priv->picture.colour, priv->picture.contrast); | |
769 | |
770 | |
3815 | 771 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1) |
2790 | 772 { |
2818 | 773 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set picture failed: %s\n", strerror(errno)); |
2802 | 774 return(0); |
2790 | 775 } |
776 | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
777 if ( !tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
778 { |
2802 | 779 priv->nbuf = priv->mbuf.frames; |
780 for (i=0; i < priv->nbuf; i++) | |
781 { | |
782 priv->buf[i].format = priv->picture.palette; | |
783 priv->buf[i].frame = i; | |
784 priv->buf[i].width = priv->width; | |
785 priv->buf[i].height = priv->height; | |
2818 | 786 mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]); |
2802 | 787 } |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
788 } |
2837 | 789 |
2931 | 790 #if 0 |
791 { | |
792 struct video_play_mode pmode; | |
793 | |
794 pmode.mode = VID_PLAY_NORMAL; | |
795 pmode.p1 = 1; | |
796 pmode.p2 = 0; | |
3815 | 797 if (ioctl(priv->video_fd, VIDIOCSPLAYMODE, &pmode) == -1) |
2931 | 798 { |
799 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set play mode failed: %s\n", strerror(errno)); | |
800 // return(0); | |
801 } | |
802 } | |
803 #endif | |
2837 | 804 |
805 #if 0 | |
806 { | |
807 struct video_window win; | |
808 | |
809 win.x = 0; | |
810 win.y = 0; | |
811 win.width = priv->width; | |
812 win.height = priv->height; | |
813 win.chromakey = -1; | |
814 win.flags = 0; | |
5088 | 815 //win.clipcount = 0; |
2837 | 816 |
3815 | 817 ioctl(priv->video_fd, VIDIOCSWIN, &win); |
2837 | 818 } |
819 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
820 // initialize video capture |
3815 | 821 if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1) |
2802 | 822 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
823 mp_msg(MSGT_TV, MSGL_ERR, "FATAL: ioctl ccapture failed: %s\n", strerror(errno)); |
2802 | 824 return(0); |
825 } | |
2837 | 826 #endif |
827 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
828 /* setup audio parameters */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
829 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
830 setup_audio_buffer_sizes(priv); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
831 bytes_per_sample = priv->audio_in.bytes_per_sample; |
8131 | 832 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
|
833 if (!priv->audio_skew_buffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
834 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
|
835 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
836 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
837 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
838 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
|
839 if (!priv->audio_ringbuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
840 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
|
841 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
842 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
843 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
844 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
|
845 *priv->audio_in.channels |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
846 *bytes_per_sample); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
847 priv->audio_head = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
848 priv->audio_tail = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
849 priv->audio_cnt = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
850 priv->audio_drop = 0; |
8131 | 851 priv->audio_skew = 0; |
852 priv->audio_skew_total = 0; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
853 priv->audio_recv_blocks_total = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
854 priv->audio_sent_blocks_total = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
855 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
856 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
857 /* setup video parameters */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
858 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
|
859 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
|
860 } else { |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
861 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
|
862 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
863 priv->video_buffer_size_current = 0; |
6553
d000112bd06e
Paul Ortyl's patch - tv4l timestamps (not so precise :()
alex
parents:
6529
diff
changeset
|
864 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
865 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
|
866 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
|
867 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
|
868 "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
|
869 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
870 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
871 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
872 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
|
873 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
|
874 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
|
875 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
876 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
|
877 if (!priv->video_ringbuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
878 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
|
879 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
880 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
881 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
|
882 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
|
883 |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
884 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
|
885 if (!priv->video_timebuffer) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
886 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
|
887 return 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
888 } |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
889 priv->video_avg_buffer = (long long*)malloc(sizeof(long long) * VIDEO_AVG_BUFFER_SIZE); |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
890 if (!priv->video_avg_buffer) { |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
891 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate period buffer: %s\n", strerror(errno)); |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
892 return 0; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
893 } |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
894 priv->video_interval_sum = (1e6/priv->fps)*VIDEO_AVG_BUFFER_SIZE; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
895 for (i = 0; i < VIDEO_AVG_BUFFER_SIZE; i++) { |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
896 priv->video_avg_buffer[i] = 1e6/priv->fps; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
897 } |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
898 |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
899 priv->video_avg_ptr = 0; |
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
900 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
901 priv->video_head = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
902 priv->video_tail = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
903 priv->video_cnt = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
904 priv->first = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
905 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
906 if (priv->capability.audios) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
907 /* enable audio */ |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
908 if (tv_param_volume >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
909 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
|
910 if (tv_param_bass >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
911 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
|
912 if (tv_param_treble >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
913 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
|
914 if (tv_param_balance >= 0) |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
915 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
|
916 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
|
917 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
|
918 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
|
919 priv->audio_id, |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 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
|
924 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
925 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
926 /* launch capture threads */ |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
927 priv->shutdown = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
928 if (!tv_param_noaudio) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
929 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
|
930 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
|
931 pthread_mutex_lock(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
932 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
|
933 } |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
934 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
|
935 /* 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
|
936 |
2837 | 937 return(1); |
2790 | 938 } |
939 | |
9663 | 940 // 2nd order polynomial with p(-100)=0, p(100)=65535, p(0)=y0 |
941 static int poly(int x, int y0) | |
942 { | |
943 return ((65535-2*y0)*x*x+6553500*x+20000*y0)/20000; | |
944 } | |
945 | |
2790 | 946 static int control(priv_t *priv, int cmd, void *arg) |
947 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
948 mp_msg(MSGT_TV, MSGL_DBG2, "\ndebug: control(priv=%p, cmd=%d, arg=%p)\n", |
2802 | 949 priv, cmd, arg); |
2790 | 950 switch(cmd) |
951 { | |
2802 | 952 /* ========== GENERIC controls =========== */ |
953 case TVI_CONTROL_IS_VIDEO: | |
954 { | |
955 if (priv->capability.type & VID_TYPE_CAPTURE) | |
956 return(TVI_CONTROL_TRUE); | |
957 return(TVI_CONTROL_FALSE); | |
958 } | |
959 case TVI_CONTROL_IS_AUDIO: | |
9634
8bb1a24ed0a8
report TRUE for IS_AUDIO control when user forces the audio recording
henry
parents:
9624
diff
changeset
|
960 if (tv_param_force_audio) return(TVI_CONTROL_TRUE); |
2841 | 961 if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO) |
3815 | 962 { |
2841 | 963 return(TVI_CONTROL_TRUE); |
3815 | 964 } |
8774 | 965 return(TVI_CONTROL_FALSE); |
2802 | 966 case TVI_CONTROL_IS_TUNER: |
967 { | |
2841 | 968 // if (priv->capability.type & VID_TYPE_TUNER) |
969 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 970 return(TVI_CONTROL_TRUE); |
971 return(TVI_CONTROL_FALSE); | |
972 } | |
973 | |
974 /* ========== VIDEO controls =========== */ | |
2790 | 975 case TVI_CONTROL_VID_GET_FORMAT: |
2802 | 976 { |
977 int output_fmt = -1; | |
978 | |
979 output_fmt = priv->format; | |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
980 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
981 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
982 mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting sh_video->format to mjpg\n"); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
983 output_fmt = 0x47504a4d; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
984 output_fmt = 0x67706a6d; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
985 (int)*(void **)arg = output_fmt; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
986 mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", "mjpg"); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
987 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
988 else |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
989 { |
2802 | 990 (int)*(void **)arg = output_fmt; |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
991 mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
992 } |
2802 | 993 return(TVI_CONTROL_TRUE); |
994 } | |
995 case TVI_CONTROL_VID_SET_FORMAT: | |
996 priv->format = (int)*(void **)arg; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
997 // !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
|
998 // 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
|
999 // 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
|
1000 // 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
|
1001 if (IMGFMT_IS_RGB(priv->format)) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1002 priv->format &= ~IMGFMT_RGB_MASK; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1003 priv->format |= IMGFMT_BGR; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1004 } |
2790 | 1005 return(TVI_CONTROL_TRUE); |
1006 case TVI_CONTROL_VID_GET_PLANES: | |
3220 | 1007 (int)*(void **)arg = 1; /* FIXME, also not needed at this time */ |
2790 | 1008 return(TVI_CONTROL_TRUE); |
1009 case TVI_CONTROL_VID_GET_BITS: | |
2810 | 1010 (int)*(void **)arg = palette2depth(format2palette(priv->format)); |
2790 | 1011 return(TVI_CONTROL_TRUE); |
1012 case TVI_CONTROL_VID_GET_WIDTH: | |
1013 (int)*(void **)arg = priv->width; | |
1014 return(TVI_CONTROL_TRUE); | |
1015 case TVI_CONTROL_VID_CHK_WIDTH: | |
1016 { | |
1017 int req_width = (int)*(void **)arg; | |
1018 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
1019 mp_msg(MSGT_TV, MSGL_V, "Requested width: %d\n", req_width); |
2810 | 1020 if ((req_width >= priv->capability.minwidth) && |
1021 (req_width <= priv->capability.maxwidth)) | |
2790 | 1022 return(TVI_CONTROL_TRUE); |
1023 return(TVI_CONTROL_FALSE); | |
1024 } | |
1025 case TVI_CONTROL_VID_SET_WIDTH: | |
1026 priv->width = (int)*(void **)arg; | |
1027 return(TVI_CONTROL_TRUE); | |
1028 case TVI_CONTROL_VID_GET_HEIGHT: | |
1029 (int)*(void **)arg = priv->height; | |
1030 return(TVI_CONTROL_TRUE); | |
1031 case TVI_CONTROL_VID_CHK_HEIGHT: | |
1032 { | |
1033 int req_height = (int)*(void **)arg; | |
1034 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
1035 mp_msg(MSGT_TV, MSGL_V, "Requested height: %d\n", req_height); |
2810 | 1036 if ((req_height >= priv->capability.minheight) && |
1037 (req_height <= priv->capability.maxheight)) | |
2790 | 1038 return(TVI_CONTROL_TRUE); |
1039 return(TVI_CONTROL_FALSE); | |
1040 } | |
1041 case TVI_CONTROL_VID_SET_HEIGHT: | |
1042 priv->height = (int)*(void **)arg; | |
1043 return(TVI_CONTROL_TRUE); | |
2937 | 1044 case TVI_CONTROL_VID_GET_PICTURE: |
3815 | 1045 if (ioctl(priv->video_fd, VIDIOCGPICT, &priv->picture) == -1) |
2937 | 1046 { |
1047 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
1048 return(TVI_CONTROL_FALSE); | |
1049 } | |
1050 return(TVI_CONTROL_TRUE); | |
1051 case TVI_CONTROL_VID_SET_PICTURE: | |
3815 | 1052 if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1) |
2937 | 1053 { |
1054 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get picture failed: %s\n", strerror(errno)); | |
1055 return(TVI_CONTROL_FALSE); | |
1056 } | |
1057 return(TVI_CONTROL_TRUE); | |
1058 case TVI_CONTROL_VID_SET_BRIGHTNESS: | |
9663 | 1059 priv->picture.brightness = 65535*((int)*(void **)arg+100)/200; |
2937 | 1060 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); |
1061 return(TVI_CONTROL_TRUE); | |
1062 case TVI_CONTROL_VID_SET_HUE: | |
9663 | 1063 priv->picture.hue = 65535*((int)*(void **)arg+100)/200; |
2937 | 1064 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); |
1065 return(TVI_CONTROL_TRUE); | |
1066 case TVI_CONTROL_VID_SET_SATURATION: | |
9663 | 1067 priv->picture.colour = 65535*((int)*(void **)arg+100)/200; |
2937 | 1068 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); |
1069 return(TVI_CONTROL_TRUE); | |
1070 case TVI_CONTROL_VID_SET_CONTRAST: | |
9663 | 1071 priv->picture.contrast = poly((int)*(void **)arg, 24576); |
2937 | 1072 control(priv, TVI_CONTROL_VID_SET_PICTURE, 0); |
1073 return(TVI_CONTROL_TRUE); | |
6529
8552767dbb46
tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents:
6305
diff
changeset
|
1074 case TVI_CONTROL_VID_GET_FPS: |
10019 | 1075 *(float *)arg=priv->fps; |
6529
8552767dbb46
tv audio fixing patch by Paul Ortyl <ortylp at 3miasto.net>
alex
parents:
6305
diff
changeset
|
1076 return(TVI_CONTROL_TRUE); |
2790 | 1077 |
2802 | 1078 /* ========== TUNER controls =========== */ |
1079 case TVI_CONTROL_TUN_GET_FREQ: | |
1080 { | |
1081 unsigned long freq; | |
1082 | |
3815 | 1083 if (ioctl(priv->video_fd, VIDIOCGFREQ, &freq) == -1) |
2802 | 1084 { |
2818 | 1085 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get freq failed: %s\n", strerror(errno)); |
2802 | 1086 return(TVI_CONTROL_FALSE); |
1087 } | |
1088 | |
1089 /* tuner uses khz not mhz ! */ | |
2837 | 1090 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
1091 // freq /= 1000; | |
2802 | 1092 (unsigned long)*(void **)arg = freq; |
1093 return(TVI_CONTROL_TRUE); | |
1094 } | |
2790 | 1095 case TVI_CONTROL_TUN_SET_FREQ: |
1096 { | |
2802 | 1097 /* argument is in MHz ! */ |
1098 unsigned long freq = (unsigned long)*(void **)arg; | |
1099 | |
8703 | 1100 if (priv->capability.audios) { |
1101 priv->audio[priv->audio_id].volume = 0; | |
1102 priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE; | |
1103 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
1104 } | |
1105 | |
2837 | 1106 mp_msg(MSGT_TV, MSGL_V, "requested frequency: %.3f\n", (float)freq/16); |
2802 | 1107 |
1108 /* tuner uses khz not mhz ! */ | |
2837 | 1109 // if (priv->tuner.flags & VIDEO_TUNER_LOW) |
1110 // freq *= 1000; | |
1111 // mp_msg(MSGT_TV, MSGL_V, " requesting from driver: freq=%.3f\n", (float)freq/16); | |
3815 | 1112 if (ioctl(priv->video_fd, VIDIOCSFREQ, &freq) == -1) |
2802 | 1113 { |
2818 | 1114 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set freq failed: %s\n", strerror(errno)); |
2802 | 1115 return(TVI_CONTROL_FALSE); |
1116 } | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1117 usleep(100000); // wait to supress noise during switching |
8703 | 1118 |
1119 if (priv->capability.audios) { | |
1120 priv->audio[priv->audio_id].volume = tv_param_volume; | |
1121 priv->audio[priv->audio_id].flags &= ~VIDEO_AUDIO_MUTE; | |
1122 ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]); | |
1123 } | |
1124 | |
2802 | 1125 return(TVI_CONTROL_TRUE); |
1126 } | |
1127 case TVI_CONTROL_TUN_GET_TUNER: | |
1128 { | |
3815 | 1129 if (ioctl(priv->video_fd, VIDIOCGTUNER, &priv->tuner) == -1) |
2802 | 1130 { |
2818 | 1131 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get tuner failed: %s\n", strerror(errno)); |
2802 | 1132 return(TVI_CONTROL_FALSE); |
1133 } | |
1134 | |
7318
85897ab199a4
changed message leveles (too many non-sense info messages)
alex
parents:
7317
diff
changeset
|
1135 mp_msg(MSGT_TV, MSGL_V, "Tuner (%s) range: %lu -> %lu\n", priv->tuner.name, |
2802 | 1136 priv->tuner.rangelow, priv->tuner.rangehigh); |
1137 return(TVI_CONTROL_TRUE); | |
1138 } | |
1139 case TVI_CONTROL_TUN_SET_TUNER: | |
1140 { | |
3815 | 1141 if (ioctl(priv->video_fd, VIDIOCSTUNER, &priv->tuner) == -1) |
2802 | 1142 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1143 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set tuner failed: %s\n", strerror(errno)); |
2802 | 1144 return(TVI_CONTROL_FALSE); |
1145 } | |
1146 return(TVI_CONTROL_TRUE); | |
1147 } | |
1148 case TVI_CONTROL_TUN_SET_NORM: | |
1149 { | |
1150 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
|
1151 |
8477 | 1152 if ((req_mode != TV_NORM_PAL) && (req_mode != TV_NORM_NTSC) && (req_mode != TV_NORM_SECAM) |
1153 && (req_mode != TV_NORM_PALNC) && (req_mode != TV_NORM_PALM) && (req_mode != TV_NORM_PALN) | |
1154 && (req_mode != TV_NORM_NTSCJP)) { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1155 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
|
1156 return(TVI_CONTROL_FALSE); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1157 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1158 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1159 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
|
1160 int prev_mode; |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1161 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1162 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
8477 | 1163 if (((req_mode == TV_NORM_PAL |
1164 || req_mode == TV_NORM_PALNC | |
1165 || req_mode == TV_NORM_PALN) && !(priv->tuner.flags & VIDEO_TUNER_PAL)) || | |
1166 ((req_mode == TV_NORM_NTSC | |
1167 || req_mode == TV_NORM_NTSCJP | |
1168 || 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
|
1169 ((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
|
1170 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1171 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
|
1172 return(TVI_CONTROL_FALSE); |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1173 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1174 |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1175 prev_mode = priv->tuner.mode; |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1176 |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1177 switch(req_mode) { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1178 case TV_NORM_PAL: |
8477 | 1179 case TV_NORM_PALNC: |
1180 case TV_NORM_PALN: | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1181 priv->tuner.mode = VIDEO_MODE_PAL; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1182 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1183 case TV_NORM_NTSC: |
8477 | 1184 case TV_NORM_NTSCJP: |
1185 case TV_NORM_PALM: | |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1186 priv->tuner.mode = VIDEO_MODE_NTSC; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1187 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1188 case TV_NORM_SECAM: |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1189 priv->tuner.mode = VIDEO_MODE_SECAM; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1190 break; |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1191 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1192 |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1193 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
|
1194 // 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
|
1195 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
|
1196 } |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1197 |
2802 | 1198 } |
1199 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1200 switch(req_mode) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1201 case TV_NORM_PAL: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1202 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
|
1203 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1204 case TV_NORM_NTSC: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1205 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
|
1206 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1207 case TV_NORM_SECAM: |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1208 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
|
1209 break; |
8477 | 1210 case TV_NORM_PALNC: |
1211 priv->channels[priv->act_channel].norm = 3; | |
1212 break; | |
1213 case TV_NORM_PALM: | |
1214 priv->channels[priv->act_channel].norm = 4; | |
1215 break; | |
1216 case TV_NORM_PALN: | |
1217 priv->channels[priv->act_channel].norm = 5; | |
1218 break; | |
1219 case TV_NORM_NTSCJP: | |
1220 priv->channels[priv->act_channel].norm = 6; | |
1221 break; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1222 } |
7532
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1223 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
|
1224 { |
26cd91676fb6
complex patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7472
diff
changeset
|
1225 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
|
1226 return(TVI_CONTROL_FALSE); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1227 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1228 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1229 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
|
1230 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno)); |
2802 | 1231 return(TVI_CONTROL_FALSE); |
7058
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 |
8477 | 1234 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
|
1235 priv->fps = PAL_FPS; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1236 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1237 |
8477 | 1238 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
|
1239 priv->fps = NTSC_FPS; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1240 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1241 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1242 if(priv->height > priv->capability.maxheight) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1243 priv->height = priv->capability.maxheight; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1244 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1245 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1246 if(priv->width > priv->capability.maxwidth) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1247 priv->width = priv->capability.maxwidth; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1248 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1249 |
2802 | 1250 return(TVI_CONTROL_TRUE); |
1251 } | |
1252 case TVI_CONTROL_TUN_GET_NORM: | |
1253 { | |
1254 (int)*(void **)arg = priv->tuner.mode; | |
1255 | |
1256 return(TVI_CONTROL_TRUE); | |
1257 } | |
1258 | |
1259 /* ========== AUDIO controls =========== */ | |
1260 case TVI_CONTROL_AUD_GET_FORMAT: | |
1261 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1262 (int)*(void **)arg = AFMT_S16_LE; |
2802 | 1263 return(TVI_CONTROL_TRUE); |
1264 } | |
1265 case TVI_CONTROL_AUD_GET_CHANNELS: | |
1266 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1267 (int)*(void **)arg = priv->audio_in.channels; |
2802 | 1268 return(TVI_CONTROL_TRUE); |
1269 } | |
1270 case TVI_CONTROL_AUD_GET_SAMPLERATE: | |
1271 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1272 (int)*(void **)arg = priv->audio_in.samplerate; |
2802 | 1273 return(TVI_CONTROL_TRUE); |
1274 } | |
1275 case TVI_CONTROL_AUD_GET_SAMPLESIZE: | |
1276 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1277 (int)*(void **)arg = priv->audio_in.bytes_per_sample; |
2802 | 1278 return(TVI_CONTROL_TRUE); |
1279 } | |
5941 | 1280 case TVI_CONTROL_AUD_SET_SAMPLERATE: |
1281 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1282 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
|
1283 setup_audio_buffer_sizes(priv); |
5941 | 1284 return(TVI_CONTROL_TRUE); |
1285 } | |
2802 | 1286 /* ========== SPECIFIC controls =========== */ |
1287 case TVI_CONTROL_SPC_GET_INPUT: | |
1288 { | |
1289 int req_chan = (int)*(void **)arg; | |
1290 int i; | |
1291 | |
1292 for (i = 0; i < priv->capability.channels; i++) | |
1293 { | |
1294 if (priv->channels[i].channel == req_chan) | |
1295 break; | |
1296 } | |
2841 | 1297 |
1298 priv->act_channel = i; | |
2802 | 1299 |
3815 | 1300 if (ioctl(priv->video_fd, VIDIOCGCHAN, &priv->channels[i]) == -1) |
2802 | 1301 { |
2818 | 1302 mp_msg(MSGT_TV, MSGL_ERR, "ioctl get channel failed: %s\n", strerror(errno)); |
2802 | 1303 return(TVI_CONTROL_FALSE); |
1304 } | |
1305 return(TVI_CONTROL_TRUE); | |
1306 } | |
1307 | |
1308 case TVI_CONTROL_SPC_SET_INPUT: | |
1309 { | |
1310 struct video_channel chan; | |
1311 int req_chan = (int)*(void **)arg; | |
1312 int i; | |
1313 | |
1314 if (req_chan >= priv->capability.channels) | |
1315 { | |
2818 | 1316 mp_msg(MSGT_TV, MSGL_ERR, "Invalid input requested: %d, valid: 0-%d\n", |
9215 | 1317 req_chan, priv->capability.channels - 1); |
2802 | 1318 return(TVI_CONTROL_FALSE); |
1319 } | |
1320 | |
1321 for (i = 0; i < priv->capability.channels; i++) | |
1322 { | |
1323 if (priv->channels[i].channel == req_chan) | |
1324 chan = priv->channels[i]; | |
1325 } | |
1326 | |
3815 | 1327 if (ioctl(priv->video_fd, VIDIOCSCHAN, &chan) == -1) |
2802 | 1328 { |
2818 | 1329 mp_msg(MSGT_TV, MSGL_ERR, "ioctl set chan failed: %s\n", strerror(errno)); |
2802 | 1330 return(TVI_CONTROL_FALSE); |
1331 } | |
2818 | 1332 mp_msg(MSGT_TV, MSGL_INFO, "Using input '%s'\n", chan.name); |
2802 | 1333 |
2841 | 1334 priv->act_channel = i; |
1335 | |
2802 | 1336 /* update tuner state */ |
2841 | 1337 // if (priv->capability.type & VID_TYPE_TUNER) |
1338 if (priv->channels[priv->act_channel].flags & VIDEO_VC_TUNER) | |
2802 | 1339 control(priv, TVI_CONTROL_TUN_GET_TUNER, 0); |
1340 | |
1341 /* update local channel list */ | |
1342 control(priv, TVI_CONTROL_SPC_GET_INPUT, &req_chan); | |
1343 return(TVI_CONTROL_TRUE); | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1344 case TVI_CONTROL_IMMEDIATE: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1345 priv->immediate_mode = 1; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1346 return(TVI_CONTROL_TRUE); |
2790 | 1347 } |
1348 } | |
1349 | |
1350 return(TVI_CONTROL_UNKNOWN); | |
1351 } | |
1352 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1353 // copies a video frame |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1354 // 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
|
1355 // 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
|
1356 static inline void copy_frame(priv_t *priv, unsigned char *dest, unsigned char *source) |
2790 | 1357 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1358 int i; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1359 unsigned char *sptr; |
2802 | 1360 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1361 // 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
|
1362 if (priv->format == IMGFMT_YV12) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1363 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
|
1364 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
|
1365 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
|
1366 return; |
2790 | 1367 } |
3711 | 1368 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1369 switch (priv->picture.palette) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1370 case VIDEO_PALETTE_RGB24: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1371 case VIDEO_PALETTE_RGB32: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1372 case VIDEO_PALETTE_RGB555: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1373 case VIDEO_PALETTE_RGB565: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1374 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
|
1375 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
|
1376 memcpy(dest, sptr, priv->bytesperline); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1377 dest += priv->bytesperline; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1378 sptr -= priv->bytesperline; |
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 break; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1381 case VIDEO_PALETTE_UYVY: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1382 case VIDEO_PALETTE_YUV420P: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1383 default: |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1384 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
|
1385 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1386 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1387 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1388 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1389 // maximum skew change, in frames |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1390 #define MAX_SKEW_DELTA 0.6 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1391 static void *video_grabber(void *data) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1392 { |
9608 | 1393 #define MAXTOL (priv->nbuf) |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1394 priv_t *priv = (priv_t*)data; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1395 struct timeval curtime; |
8131 | 1396 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
|
1397 int frame; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1398 int i; |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1399 int framecount; |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
1400 int tolerance; |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1401 unsigned long num; |
3711 | 1402 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1403 /* 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
|
1404 |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1405 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1406 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1407 mp_msg(MSGT_TV, MSGL_INFO, " MJP: gonna capture ! \n"); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1408 for (i=0; i < priv->nbuf; i++) { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1409 num = i; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1410 if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1411 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1412 mp_msg(MSGT_TV, MSGL_ERR, |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1413 "\n MJP: ioctl MJPIOC_QBUF_CAPT b failed: %s\n", strerror(errno)); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1414 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1415 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1416 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1417 else |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1418 { |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1419 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
|
1420 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
|
1421 { |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1422 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
|
1423 } |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1424 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1425 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1426 |
9608 | 1427 gettimeofday(&curtime, NULL); |
1428 priv->starttime = (long long)1e6*curtime.tv_sec + curtime.tv_usec; | |
1429 priv->audio_skew_measure_time = 0; | |
1430 pthread_mutex_unlock(&priv->audio_starter); | |
1431 xskew = 0; | |
1432 skew = 0; | |
1433 interval = 0; | |
1434 | |
8131 | 1435 prev_interval = 0; |
1436 prev_skew = 0; | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1437 |
9608 | 1438 tolerance = MAXTOL; |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
1439 |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1440 for (framecount = 0; !priv->shutdown;) |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1441 { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1442 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
|
1443 |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1444 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
|
1445 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
|
1446 usleep(10000); |
7834 | 1447 if (priv->shutdown) { |
1448 return NULL; | |
1449 } | |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1450 } |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1451 } |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1452 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1453 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
|
1454 |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1455 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1456 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1457 while (ioctl(priv->video_fd, MJPIOC_SYNC, &priv->buf[frame].frame) < 0 && |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1458 (errno == EAGAIN || errno == EINTR)); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1459 |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1460 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1461 else |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1462 { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1463 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
|
1464 (errno == EAGAIN || errno == EINTR)); |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1465 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1466 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
|
1467 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1468 gettimeofday(&curtime, NULL); |
9608 | 1469 if (!priv->immediate_mode) { |
1470 interval = (long long)1e6*curtime.tv_sec + curtime.tv_usec - priv->starttime; | |
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
|
1471 } else { |
9608 | 1472 interval = (long long)1e6*framecount/priv->fps; |
1473 } | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1474 |
9608 | 1475 if (!priv->immediate_mode) { |
1476 long long period, orig_interval; | |
1477 | |
1478 if (tolerance == 0) { | |
8485
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1479 if (interval - prev_interval == 0) { |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1480 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
|
1481 } 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
|
1482 || (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
|
1483 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
|
1484 (double)1e6/(interval - prev_interval)); |
4e32317f08be
don't give up when set_tuner fails; more zero div sanity checks
henry
parents:
8477
diff
changeset
|
1485 } |
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
|
1486 } |
cfd6a99021ac
some cleanups for video_grabber() which fix a race condition by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7532
diff
changeset
|
1487 |
9608 | 1488 // correct the rate fluctuations on a small scale |
1489 orig_interval = interval; | |
1490 period = priv->video_interval_sum/VIDEO_AVG_BUFFER_SIZE; | |
9609 | 1491 if (interval - prev_interval > 105*period/100) { |
9608 | 1492 if (tolerance > 0) { |
1493 mp_msg(MSGT_TV, MSGL_DBG3, "correcting timestamp\n"); | |
1494 interval = prev_interval + priv->video_interval_sum/VIDEO_AVG_BUFFER_SIZE; | |
1495 tolerance--; | |
1496 } else { | |
1497 mp_msg(MSGT_TV, MSGL_DBG3, "bad - frames were dropped\n"); | |
1498 tolerance = MAXTOL; | |
1499 } | |
1500 } else { | |
1501 if (tolerance < MAXTOL) { | |
1502 mp_msg(MSGT_TV, MSGL_DBG3, "fluctuation overcome\n"); | |
1503 } | |
1504 tolerance = MAXTOL; | |
1505 } | |
1506 | |
1507 priv->video_interval_sum -= priv->video_avg_buffer[priv->video_avg_ptr]; | |
1508 priv->video_avg_buffer[priv->video_avg_ptr++] = orig_interval-prev_interval; | |
1509 priv->video_interval_sum += orig_interval-prev_interval; | |
1510 if (priv->video_avg_ptr >= VIDEO_AVG_BUFFER_SIZE) priv->video_avg_ptr = 0; | |
1511 | |
1512 // fprintf(stderr, "fps: %lf\n", (double)1e6*VIDEO_AVG_BUFFER_SIZE/priv->video_interval_sum); | |
1513 | |
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
|
1514 // 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
|
1515 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
|
1516 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
|
1517 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
|
1518 // 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
|
1519 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
|
1520 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
|
1521 } 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
|
1522 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
|
1523 } 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
|
1524 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
|
1525 } |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1526 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1527 |
8131 | 1528 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
|
1529 (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
|
1530 (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
|
1531 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
|
1532 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1533 prev_skew = skew; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1534 prev_interval = interval; |
9607
e2eaeb3cb089
correct small framerate fluctuations directly in the capture thread
henry
parents:
9216
diff
changeset
|
1535 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1536 /* 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
|
1537 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
|
1538 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
|
1539 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
|
1540 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
|
1541 if (newbuf) { |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1542 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
|
1543 (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
|
1544 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
|
1545 (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
|
1546 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
|
1547 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
|
1548 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
|
1549 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1550 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1551 } |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1552 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
|
1553 |
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1554 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
|
1555 if (!priv->immediate_mode) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1556 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
|
1557 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1558 } else { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1559 if (priv->immediate_mode) { |
7803
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1560 priv->video_timebuffer[priv->video_tail] = interval; |
172ee2b4612f
Stop grabbing from v4l when paused by Jindrich Makovicka
alex
parents:
7585
diff
changeset
|
1561 } else { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1562 // compensate for audio skew |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1563 // 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
|
1564 // 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
|
1565 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
|
1566 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1567 |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1568 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1569 copy_frame(priv, priv->video_ringbuffer[priv->video_tail], |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1570 priv->mmap+(priv->mjpeg_bufsize)*i); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1571 else |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1572 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
|
1573 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
|
1574 priv->video_cnt++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1575 } |
2931 | 1576 |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1577 if ( tv_param_mjpeg ) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1578 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1579 num = frame; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1580 if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0) |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1581 { |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1582 mp_msg(MSGT_TV, MSGL_ERR, "\n MJP: ioctl MJPIOC_QBUF_CAPT end failed: %s\n", |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1583 strerror(errno)); |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1584 continue; |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1585 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1586 } |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1587 else |
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1588 { |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1589 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
|
1590 { |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1591 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
|
1592 continue; |
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1593 } |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1594 } |
8650
cf1d4f48aecf
allow utilization of more v4l buffers, patch by Carsten Schulz <carsten@gnocchi.dialup.fu-berlin.de>
henry
parents:
8627
diff
changeset
|
1595 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1596 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1597 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1598 } |
9620
ce4cd85498f3
hardware mjpeg encoding using v4l by Iv«¡n Sz«¡nt«Ñ <szivan@freemail.hu>
henry
parents:
9609
diff
changeset
|
1599 mp_msg(MSGT_TV, MSGL_INFO, " MJP: returning! \n"); |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7318
diff
changeset
|
1600 return NULL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1601 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1602 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1603 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
|
1604 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1605 double interval; |
2802 | 1606 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1607 if (priv->first) { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1608 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
|
1609 priv->first = 0; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1610 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1611 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1612 while (priv->video_cnt == 0) { |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1613 usleep(10000); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1614 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1615 |
8417
15e3d9c2c0ac
allocate the video buffer on the fly, instead of one big chunk at startup
henry
parents:
8335
diff
changeset
|
1616 pthread_mutex_lock(&priv->video_buffer_mutex); |
8131 | 1617 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
|
1618 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
|
1619 priv->video_cnt--; |
8671
e1337452fe62
Obvious patch to avoid undefined behaviour of multiple side effects in
arpi
parents:
8650
diff
changeset
|
1620 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
|
1621 pthread_mutex_unlock(&priv->video_buffer_mutex); |
9608 | 1622 |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1623 return interval; |
2790 | 1624 } |
1625 | |
1626 static int get_video_framesize(priv_t *priv) | |
1627 { | |
2931 | 1628 return(priv->bytesperline * priv->height); |
2790 | 1629 } |
1630 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1631 static void *audio_grabber(void *data) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1632 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1633 priv_t *priv = (priv_t*)data; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1634 struct timeval tv; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1635 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
|
1636 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
|
1637 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1638 pthread_mutex_lock(&priv->audio_starter); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1639 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1640 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
|
1641 for (i = 0; i < priv->aud_skew_cnt; i++) |
8131 | 1642 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
|
1643 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1644 for (; !priv->shutdown;) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1645 { |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1646 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
|
1647 continue; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1648 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1649 gettimeofday(&tv, NULL); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1650 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1651 priv->audio_recv_blocks_total++; |
8131 | 1652 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
|
1653 |
8131 | 1654 priv->audio_skew_total -= priv->audio_skew_buffer[audio_skew_ptr]; |
1655 priv->audio_skew_buffer[audio_skew_ptr] = current_time | |
1656 - 1e6*priv->audio_secs_per_block*priv->audio_recv_blocks_total; | |
1657 priv->audio_skew_total += priv->audio_skew_buffer[audio_skew_ptr]; | |
1658 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
|
1659 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1660 pthread_mutex_lock(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1661 // 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
|
1662 // 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
|
1663 // of the interval |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1664 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
|
1665 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
|
1666 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
|
1667 } else { |
8131 | 1668 // this smoothes the evolution of audio_skew at startup a bit |
1669 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
|
1670 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1671 // current skew factor (assuming linearity) |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1672 // 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
|
1673 // 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
|
1674 // 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
|
1675 // 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
|
1676 // where audio_skew remains a long while behind |
8444 | 1677 if ((priv->audio_skew_measure_time != 0) && (current_time - priv->audio_skew_measure_time != 0)) { |
1678 priv->audio_skew_factor = (double)(priv->audio_skew-prev_skew)/(current_time - priv->audio_skew_measure_time); | |
1679 } else { | |
1680 priv->audio_skew_factor = 0.0; | |
1681 } | |
1682 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1683 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
|
1684 prev_skew = priv->audio_skew; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1685 pthread_mutex_unlock(&priv->skew_mutex); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1686 |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1687 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
|
1688 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
|
1689 priv->audio_drop++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1690 } else { |
8671
e1337452fe62
Obvious patch to avoid undefined behaviour of multiple side effects in
arpi
parents:
8650
diff
changeset
|
1691 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
|
1692 priv->audio_cnt++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1693 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1694 } |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7318
diff
changeset
|
1695 return NULL; |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1696 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1697 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5088
diff
changeset
|
1698 static double grab_audio_frame(priv_t *priv, char *buffer, int len) |
2790 | 1699 { |
5088 | 1700 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n", |
3815 | 1701 priv, buffer, len); |
1702 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1703 // compensate for dropped audio frames |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1704 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
|
1705 priv->audio_drop--; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1706 priv->audio_sent_blocks_total++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1707 memset(buffer, 0, len); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1708 return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block; |
3815 | 1709 } |
1710 | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1711 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
|
1712 usleep(10000); |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1713 } |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1714 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
|
1715 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
|
1716 priv->audio_cnt--; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1717 priv->audio_sent_blocks_total++; |
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1718 return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block; |
2790 | 1719 } |
1720 | |
1721 static int get_audio_framesize(priv_t *priv) | |
1722 { | |
7058
2e5c07262861
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
6553
diff
changeset
|
1723 return(priv->audio_in.blocksize); |
2790 | 1724 } |
1725 | |
1726 #endif /* USE_TV */ |