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