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