annotate stream/tvi_v4l2.c @ 34117:39ca8e25ba79

Change and add comment. Replace "file name" by "file path" and explain the need of converting the filename.
author ib
date Sun, 16 Oct 2011 10:48:23 +0000
parents c15dabfa2380
children 389d43c448b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1 /*
28106
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
2 * Video 4 Linux 2 input
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
3 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
4 * copyright (c) 2003 Martin Olschewski <olschewski@zpr.uni-koeln.de>
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
5 * copyright (c) 2003 Jindrich Makovicka <makovick@gmail.com>
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
6 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
7 * Some ideas are based on works from
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
8 * Alex Beregszaszi <alex@fsn.hu>
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
9 * Gerd Knorr <kraxel@bytesex.org>
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
10 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
11 * This file is part of MPlayer.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
12 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
13 * MPlayer is free software; you can redistribute it and/or modify
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
14 * it under the terms of the GNU General Public License as published by
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
16 * (at your option) any later version.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
17 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
18 * MPlayer is distributed in the hope that it will be useful,
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
21 * GNU General Public License for more details.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
22 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
23 * You should have received a copy of the GNU General Public License along
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27461
diff changeset
26 */
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
27
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
28 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
29
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
30 known issues:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
31 - norm setting isn't consistent with tvi_v4l
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
32 - the same for volume/bass/treble/balance
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
33
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
34 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
35
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
36 #include "config.h"
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
37
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
38 #include <errno.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
39 #include <fcntl.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
40 #include <pthread.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
41 #include <stdio.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
42 #include <string.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
43 #include <sys/ioctl.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
44 #include <sys/mman.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
45 #include <sys/time.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
46 #include <sys/types.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
47 #include <unistd.h>
27461
5a30f5bc23a0 Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents: 27390
diff changeset
48 #include <math.h>
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
49 #ifdef HAVE_SYS_SYSINFO_H
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
50 #include <sys/sysinfo.h>
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
51 #endif
33163
d941d34d5b0f Add V4L2 support for OpenBSD (and NetBSD).
diego
parents: 32668
diff changeset
52 #ifdef HAVE_SYS_VIDEOIO_H
d941d34d5b0f Add V4L2 support for OpenBSD (and NetBSD).
diego
parents: 32668
diff changeset
53 #include <sys/videoio.h>
d941d34d5b0f Add V4L2 support for OpenBSD (and NetBSD).
diego
parents: 32668
diff changeset
54 #else
16442
11331109ecad - remove useless /dev/video* checks
henry
parents: 16289
diff changeset
55 #include <linux/types.h>
11331109ecad - remove useless /dev/video* checks
henry
parents: 16289
diff changeset
56 #include <linux/videodev2.h>
33163
d941d34d5b0f Add V4L2 support for OpenBSD (and NetBSD).
diego
parents: 32668
diff changeset
57 #endif
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16962
diff changeset
58 #include "mp_msg.h"
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 19271
diff changeset
59 #include "libmpcodecs/img_format.h"
29759
d287e2785570 Move teletext specific code from stream into libmpcodecs.
cehoyos
parents: 29263
diff changeset
60 #include "libmpcodecs/dec_teletext.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16962
diff changeset
61 #include "libaf/af_format.h"
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
62 #include "tv.h"
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
63 #include "audio_in.h"
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
64
22381
6cabac4d35b5 tv driver loading rework. As a side effect "-tv driver=help" option is
voroshil
parents: 21587
diff changeset
65 #define info tvi_info_v4l2
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
66 static tvi_handle_t *tvi_init_v4l2(tv_param_t* tv_param);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
67 /* information about this file */
25689
7d5823bd4517 Make all tvi_info_t const
reimar
parents: 25005
diff changeset
68 const tvi_info_t tvi_info_v4l2 = {
22381
6cabac4d35b5 tv driver loading rework. As a side effect "-tv driver=help" option is
voroshil
parents: 21587
diff changeset
69 tvi_init_v4l2,
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
70 "Video 4 Linux 2 input",
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
71 "v4l2",
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
72 "Martin Olschewski <olschewski@zpr.uni-koeln.de>",
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
73 "first try, more to come ;-)"
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
74 };
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
75
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
76 struct map {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
77 struct v4l2_buffer buf;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
78 void *addr;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
79 size_t len;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
80 };
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
81
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
82 #define BUFFER_COUNT 6
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
83
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
84 /** video ringbuffer entry */
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
85 typedef struct {
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
86 unsigned char *data; ///< frame contents
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
87 long long timestamp; ///< frame timestamp
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
88 int framesize; ///< actual frame size
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
89 } video_buffer_entry;
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
90
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
91 /* private data */
31322
016194f71de3 Fix function pointer types in tvi_functions struct
reimar
parents: 29949
diff changeset
92 typedef struct priv {
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
93 /* video */
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
94 char *video_dev;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
95 int video_fd;
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
96 char *vbi_dev;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
97 int vbi_fd;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
98 int vbi_bufsize;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
99 int vbi_shutdown;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
100 pthread_t vbi_grabber_thread;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
101 void *priv_vbi;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
102 int mp_format;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
103 struct v4l2_capability capability;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
104 struct v4l2_input input;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
105 struct v4l2_format format;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
106 struct v4l2_standard standard;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
107 struct v4l2_tuner tuner;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
108 struct map *map;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
109 int mapcount;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
110 int frames;
10851
41bad7ce4cc9 yet another sync fix
henry
parents: 10810
diff changeset
111 volatile long long first_frame;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
112 long long curr_frame;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
113 /* audio video interleaving ;-) */
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
114 volatile int streamon;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
115 pthread_t audio_grabber_thread;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
116 pthread_mutex_t skew_mutex;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
117
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
118 /* 2nd level video buffers */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
119 int first;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
120 int immediate_mode;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
121
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
122 int video_buffer_size_max;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
123 volatile int video_buffer_size_current;
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
124 video_buffer_entry *video_ringbuffer;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
125 volatile int video_head;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
126 volatile int video_tail;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
127 volatile int video_cnt;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
128 pthread_t video_grabber_thread;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
129 pthread_mutex_t video_buffer_mutex;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
130
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
131 /* audio */
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
132 char *audio_dev;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
133 audio_in_t audio_in;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
134
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
135 long long audio_start_time;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
136 int audio_buffer_size;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
137 int aud_skew_cnt;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
138 unsigned char *audio_ringbuffer;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
139 long long *audio_skew_buffer;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
140 long long *audio_skew_delta_buffer;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
141 volatile int audio_head;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
142 volatile int audio_tail;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
143 volatile int audio_cnt;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
144 volatile long long audio_skew;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
145 volatile double audio_skew_factor;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
146 volatile long long audio_skew_measure_time;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
147 volatile int audio_drop;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
148 volatile int shutdown;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
149
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
150 int audio_initialized;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
151 double audio_secs_per_block;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
152 long long audio_usecs_per_block;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
153 long long audio_skew_total;
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
154 long long audio_skew_delta_total;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
155 long audio_recv_blocks_total;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
156 long audio_sent_blocks_total;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
157 pthread_mutex_t audio_mutex;
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
158 int audio_insert_null_samples;
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
159 volatile long audio_null_blocks_inserted;
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
160 volatile long long dropped_frames_timeshift;
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
161 long long dropped_frames_compensated;
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
162
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
163 tv_param_t *tv_param;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
164 } priv_t;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
165
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
166 #include "tvi_def.h"
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
167
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
168 static void *audio_grabber(void *data);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
169 static void *video_grabber(void *data);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
170
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
171 /**********************************************************************\
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
172
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
173 Only few of the fourccs are the same in v4l2 and mplayer:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
174
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
175 IMGFMT_YVU9 == V4L2_PIX_FMT_YVU410
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
176 IMGFMT_YV12 == V4L2_PIX_FMT_YVU420
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
177 IMGFMT_NV12 == V4L2_PIX_FMT_NV12
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
178 IMGFMT_422P == V4L2_PIX_FMT_YUV422P
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
179 IMGFMT_411P == V4L2_PIX_FMT_YUV411P
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
180 IMGFMT_UYVY == V4L2_PIX_FMT_UYVY
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
181 IMGFMT_Y41P == V4L2_PIX_FMT_Y41P
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
182
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
183 This may be an useful translation table for some others:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
184
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
185 IMGFMT_RGB8 == V4L2_PIX_FMT_RGB332
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
186 IMGFMT_BGR15 == V4L2_PIX_FMT_RGB555
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
187 IMGFMT_BGR16 == V4L2_PIX_FMT_RGB565
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
188 IMGFMT_RGB24 == V4L2_PIX_FMT_RGB24
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
189 IMGFMT_RGB32 == V4L2_PIX_FMT_RGB32
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
190 IMGFMT_BGR24 == V4L2_PIX_FMT_BGR24
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
191 IMGFMT_BGR32 == V4L2_PIX_FMT_BGR32
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
192 IMGFMT_Y800 == V4L2_PIX_FMT_GREY
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
193 IMGFMT_IF09 == V4L2_PIX_FMT_YUV410
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
194 IMGFMT_I420 == V4L2_PIX_FMT_YUV420
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
195 IMGFMT_YUY2 == V4L2_PIX_FMT_YUYV
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
196
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
197 \**********************************************************************/
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
198
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
199 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
200 ** Translate a mplayer fourcc to a video4linux2 pixel format.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
201 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
202 static int fcc_mp2vl(int fcc)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
203 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
204 switch (fcc) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
205 case IMGFMT_RGB8: return V4L2_PIX_FMT_RGB332;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
206 case IMGFMT_BGR15: return V4L2_PIX_FMT_RGB555;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
207 case IMGFMT_BGR16: return V4L2_PIX_FMT_RGB565;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
208 case IMGFMT_RGB24: return V4L2_PIX_FMT_RGB24;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
209 case IMGFMT_RGB32: return V4L2_PIX_FMT_RGB32;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
210 case IMGFMT_BGR24: return V4L2_PIX_FMT_BGR24;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
211 case IMGFMT_BGR32: return V4L2_PIX_FMT_BGR32;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
212 case IMGFMT_Y800: return V4L2_PIX_FMT_GREY;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
213 case IMGFMT_IF09: return V4L2_PIX_FMT_YUV410;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
214 case IMGFMT_I420: return V4L2_PIX_FMT_YUV420;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
215 case IMGFMT_YUY2: return V4L2_PIX_FMT_YUYV;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
216 case IMGFMT_YV12: return V4L2_PIX_FMT_YVU420;
11657
36879e2df6cd UYVY support (port from v4l1)
henry
parents: 10852
diff changeset
217 case IMGFMT_UYVY: return V4L2_PIX_FMT_UYVY;
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
218 case IMGFMT_MJPEG: return V4L2_PIX_FMT_MJPEG;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
219 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
220 return fcc;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
221 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
222
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
223 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
224 ** Translate a video4linux2 fourcc aka pixel format to mplayer.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
225 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
226 static int fcc_vl2mp(int fcc)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
227 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
228 switch (fcc) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
229 case V4L2_PIX_FMT_RGB332: return IMGFMT_RGB8;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
230 case V4L2_PIX_FMT_RGB555: return IMGFMT_BGR15;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
231 case V4L2_PIX_FMT_RGB565: return IMGFMT_BGR16;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
232 case V4L2_PIX_FMT_RGB24: return IMGFMT_RGB24;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
233 case V4L2_PIX_FMT_RGB32: return IMGFMT_RGB32;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
234 case V4L2_PIX_FMT_BGR24: return IMGFMT_BGR24;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
235 case V4L2_PIX_FMT_BGR32: return IMGFMT_BGR32;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
236 case V4L2_PIX_FMT_GREY: return IMGFMT_Y800;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
237 case V4L2_PIX_FMT_YUV410: return IMGFMT_IF09;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
238 case V4L2_PIX_FMT_YUV420: return IMGFMT_I420;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
239 case V4L2_PIX_FMT_YVU420: return IMGFMT_YV12;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
240 case V4L2_PIX_FMT_YUYV: return IMGFMT_YUY2;
11657
36879e2df6cd UYVY support (port from v4l1)
henry
parents: 10852
diff changeset
241 case V4L2_PIX_FMT_UYVY: return IMGFMT_UYVY;
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
242 case V4L2_PIX_FMT_MJPEG: return IMGFMT_MJPEG;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
243 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
244 return fcc;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
245 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
246
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
247 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
248 ** Translate a video4linux2 fourcc aka pixel format
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
249 ** to a human readable string.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
250 */
19108
5e767cabf4cd marks several read-only string parameters and function return-values which can only be used read-only as const. Patch by Stefan Huehner, stefan _AT huener-org
reynaldo
parents: 18958
diff changeset
251 static const char *pixfmt2name(int pixfmt)
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
252 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
253 static char unknown[24];
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
254
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
255 switch (pixfmt) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
256 case V4L2_PIX_FMT_RGB332: return "RGB332";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
257 case V4L2_PIX_FMT_RGB555: return "RGB555";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
258 case V4L2_PIX_FMT_RGB565: return "RGB565";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
259 case V4L2_PIX_FMT_RGB555X: return "RGB555X";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
260 case V4L2_PIX_FMT_RGB565X: return "RGB565X";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
261 case V4L2_PIX_FMT_BGR24: return "BGR24";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
262 case V4L2_PIX_FMT_RGB24: return "RGB24";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
263 case V4L2_PIX_FMT_BGR32: return "BGR32";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
264 case V4L2_PIX_FMT_RGB32: return "RGB32";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
265 case V4L2_PIX_FMT_GREY: return "GREY";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
266 case V4L2_PIX_FMT_YVU410: return "YVU410";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
267 case V4L2_PIX_FMT_YVU420: return "YVU420";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
268 case V4L2_PIX_FMT_YUYV: return "YUYV";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
269 case V4L2_PIX_FMT_UYVY: return "UYVY";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
270 /* case V4L2_PIX_FMT_YVU422P: return "YVU422P"; */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
271 /* case V4L2_PIX_FMT_YVU411P: return "YVU411P"; */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
272 case V4L2_PIX_FMT_YUV422P: return "YUV422P";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
273 case V4L2_PIX_FMT_YUV411P: return "YUV411P";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
274 case V4L2_PIX_FMT_Y41P: return "Y41P";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
275 case V4L2_PIX_FMT_NV12: return "NV12";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
276 case V4L2_PIX_FMT_NV21: return "NV21";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
277 case V4L2_PIX_FMT_YUV410: return "YUV410";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
278 case V4L2_PIX_FMT_YUV420: return "YUV420";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
279 case V4L2_PIX_FMT_YYUV: return "YYUV";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
280 case V4L2_PIX_FMT_HI240: return "HI240";
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
281 case V4L2_PIX_FMT_WNVA: return "WNVA";
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
282 case V4L2_PIX_FMT_MJPEG: return "MJPEG";
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
283 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
284 sprintf(unknown, "unknown (0x%x)", pixfmt);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
285 return unknown;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
286 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
287
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
288
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
289 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
290 ** Gives the depth of a video4linux2 fourcc aka pixel format in bits.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
291 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
292 static int pixfmt2depth(int pixfmt)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
293 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
294 switch (pixfmt) {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
295 case V4L2_PIX_FMT_RGB332:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
296 return 8;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
297 case V4L2_PIX_FMT_RGB555:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
298 case V4L2_PIX_FMT_RGB565:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
299 case V4L2_PIX_FMT_RGB555X:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
300 case V4L2_PIX_FMT_RGB565X:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
301 return 16;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
302 case V4L2_PIX_FMT_BGR24:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
303 case V4L2_PIX_FMT_RGB24:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
304 return 24;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
305 case V4L2_PIX_FMT_BGR32:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
306 case V4L2_PIX_FMT_RGB32:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
307 return 32;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
308 case V4L2_PIX_FMT_GREY:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
309 return 8;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
310 case V4L2_PIX_FMT_YVU410:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
311 return 9;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
312 case V4L2_PIX_FMT_YVU420:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
313 return 12;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
314 case V4L2_PIX_FMT_YUYV:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
315 case V4L2_PIX_FMT_UYVY:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
316 case V4L2_PIX_FMT_YUV422P:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
317 case V4L2_PIX_FMT_YUV411P:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
318 return 16;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
319 case V4L2_PIX_FMT_Y41P:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
320 case V4L2_PIX_FMT_NV12:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
321 case V4L2_PIX_FMT_NV21:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
322 return 12;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
323 case V4L2_PIX_FMT_YUV410:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
324 return 9;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
325 case V4L2_PIX_FMT_YUV420:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
326 return 12;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
327 case V4L2_PIX_FMT_YYUV:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
328 return 16;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
329 case V4L2_PIX_FMT_HI240:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
330 return 8;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
331
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
332 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
333 return 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
334 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
335
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
336 static int amode2v4l(int amode)
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
337 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
338 switch (amode) {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
339 case 0:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
340 return V4L2_TUNER_MODE_MONO;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
341 case 1:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
342 return V4L2_TUNER_MODE_STEREO;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
343 case 2:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
344 return V4L2_TUNER_MODE_LANG1;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
345 case 3:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
346 return V4L2_TUNER_MODE_LANG2;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
347 default:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
348 return -1;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
349 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
350 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
351
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
352
27138
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
353 /*
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
354 ** Get current FPS.
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
355 */
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
356 static double getfps(priv_t *priv)
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
357 {
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
358 if (priv->tv_param->fps > 0)
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
359 return priv->tv_param->fps;
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
360 if (priv->standard.frameperiod.denominator && priv->standard.frameperiod.numerator)
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
361 return (double)priv->standard.frameperiod.denominator / priv->standard.frameperiod.numerator;
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
362 return 25.0;
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
363 }
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
364
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
365 // sets and sanitizes audio buffer/block sizes
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
366 static void setup_audio_buffer_sizes(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
367 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
368 int bytes_per_sample = priv->audio_in.bytes_per_sample;
27138
62916b06a055 Fix division by zero in tvi_v4l2 which occures when capture device
voroshil
parents: 26756
diff changeset
369 int seconds = priv->video_buffer_size_max/getfps(priv);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
370
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
371 if (seconds < 5) seconds = 5;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
372 if (seconds > 500) seconds = 500;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
373
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
374 // make the audio buffer at least as the video buffer capacity (or 5 seconds) long
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
375 priv->audio_buffer_size = 1 + seconds*priv->audio_in.samplerate
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
376 *priv->audio_in.channels
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
377 *bytes_per_sample/priv->audio_in.blocksize;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
378 if (priv->audio_buffer_size < 256) priv->audio_buffer_size = 256;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
379
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
380 // make the skew buffer at least 1 second long
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
381 priv->aud_skew_cnt = 1 + 1*priv->audio_in.samplerate
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
382 *priv->audio_in.channels
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
383 *bytes_per_sample/priv->audio_in.blocksize;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
384 if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
385
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
386 mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
387 priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
388 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
389
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
390 static void init_audio(priv_t *priv)
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
391 {
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
392 if (priv->audio_initialized) return;
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
393
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
394 if (!priv->tv_param->noaudio) {
27390
9d95dc936e66 Introduce CONFIG_ALSA preprocessor directive for ALSA 0.9 and 1.x.
diego
parents: 27387
diff changeset
395 #ifdef CONFIG_ALSA
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
396 if (priv->tv_param->alsa)
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
397 audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
398 else
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
399 audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
400 #else
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
401 audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
402 #endif
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
403
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
404 if (priv->audio_dev) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
405 audio_in_set_device(&priv->audio_in, priv->audio_dev);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
406 }
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
407
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
408 audio_in_set_samplerate(&priv->audio_in, 44100);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
409 if (priv->capability.capabilities & V4L2_CAP_TUNER) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
410 if (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
411 audio_in_set_channels(&priv->audio_in, 2);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
412 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
413 audio_in_set_channels(&priv->audio_in, 1);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
414 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
415 } else {
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
416 if (priv->tv_param->forcechan >= 0) {
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
417 audio_in_set_channels(&priv->audio_in, priv->tv_param->forcechan);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
418 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
419 audio_in_set_channels(&priv->audio_in, 2);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
420 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
421 }
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
422
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
423 if (audio_in_setup(&priv->audio_in) < 0) return;
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
424
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
425 priv->audio_initialized = 1;
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
426 }
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
427 }
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
428
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
429 #if 0
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
430 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
431 ** the number of milliseconds elapsed between time0 and time1
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
432 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
433 static size_t difftv(struct timeval time1, struct timeval time0)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
434 {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
435 return (time1.tv_sec - time0.tv_sec) * 1000 +
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
436 (time1.tv_usec - time0.tv_usec) / 1000;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
437 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
438 #endif
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
439
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
440 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
441 ** Get current video capture format.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
442 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
443 static int getfmt(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
444 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
445 int i;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
446
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
447 priv->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
448 if ((i = ioctl(priv->video_fd, VIDIOC_G_FMT, &priv->format)) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
449 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get format failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
450 info.short_name, strerror(errno));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
451 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
452 return i;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
453 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
454
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
455
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
456 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
457 ** Get current video capture standard.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
458 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
459 static int getstd(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
460 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
461 v4l2_std_id id;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
462 int i=0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
463
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
464 if (ioctl(priv->video_fd, VIDIOC_G_STD, &id) < 0) {
27139
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
465 struct v4l2_streamparm parm;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
466
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
467 parm.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
468 if(ioctl(priv->video_fd, VIDIOC_G_PARM, &parm) >= 0) {
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
469 mp_msg(MSGT_TV, MSGL_WARN, "%s: your device driver does not support VIDIOC_G_STD ioctl,"
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
470 " VIDIOC_G_PARM was used instead.\n", info.short_name);
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
471 priv->standard.index=0;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
472 priv->standard.id=0;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
473 priv->standard.frameperiod=parm.parm.capture.timeperframe;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
474 return 0;
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
475 }
0917bf2bed6c Try to get frame rate information through VIDIOC_G_PARM if
voroshil
parents: 27138
diff changeset
476
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
477 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get standard failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
478 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
479 return -1;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
480 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
481 do {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
482 priv->standard.index = i++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
483 if (ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
484 return -1;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
485 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
486 } while (priv->standard.id != id);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
487 return 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
488 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
489
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
490 /***********************************************************************\
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
491 * *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
492 * *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
493 * Interface to mplayer *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
494 * *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
495 * *
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
496 \***********************************************************************/
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
497
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
498 static int set_mute(priv_t *priv, int value)
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
499 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
500 struct v4l2_control control;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
501 control.id = V4L2_CID_AUDIO_MUTE;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
502 control.value = value;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
503 if (ioctl(priv->video_fd, VIDIOC_S_CTRL, &control) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
504 mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set mute failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
505 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
506 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
507 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
508 return 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
509 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
510
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
511 /*
12860
03d3ab9f6400 embarassing typo
diego
parents: 12380
diff changeset
512 ** MPlayer uses values from -100 up to 100 for controls.
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
513 ** Here they are scaled to what the tv card needs and applied.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
514 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
515 static int set_control(priv_t *priv, struct v4l2_control *control, int val_signed) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
516 struct v4l2_queryctrl qctrl;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
517 qctrl.id = control->id;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
518 if (ioctl(priv->video_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
519 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
520 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
521 return TVI_CONTROL_FALSE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
522 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
523
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
524 if (val_signed) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
525 if (control->value < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
526 control->value = qctrl.default_value + control->value *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
527 (qctrl.default_value - qctrl.minimum) / 100;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
528 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
529 control->value = qctrl.default_value + control->value *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
530 (qctrl.maximum - qctrl.default_value) / 100;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
531 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
532 } else {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
533 if (control->value < 50) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
534 control->value = qctrl.default_value + (control->value-50) *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
535 (qctrl.default_value - qctrl.minimum) / 50;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
536 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
537 control->value = qctrl.default_value + (control->value-50) *
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
538 (qctrl.maximum - qctrl.default_value) / 50;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
539 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
540 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
541
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
542
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
543 if (ioctl(priv->video_fd, VIDIOC_S_CTRL, control) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
544 mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl set %s %d failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
545 info.short_name, qctrl.name, control->value, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
546 return TVI_CONTROL_FALSE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
547 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
548 mp_msg(MSGT_TV, MSGL_V, "%s: set %s: %d [%d, %d]\n", info.short_name,
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
549 qctrl.name, control->value, qctrl.minimum, qctrl.maximum);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
550
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
551 return TVI_CONTROL_TRUE;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
552 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
553
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
554
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
555 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
556 ** Scale the control values back to what mplayer needs.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
557 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
558 static int get_control(priv_t *priv, struct v4l2_control *control, int val_signed) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
559 struct v4l2_queryctrl qctrl;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
560
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
561 qctrl.id = control->id;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
562 if (ioctl(priv->video_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
563 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
564 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
565 return TVI_CONTROL_FALSE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
566 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
567
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
568 if (ioctl(priv->video_fd, VIDIOC_G_CTRL, control) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
569 mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl get %s failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
570 info.short_name, qctrl.name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
571 return TVI_CONTROL_FALSE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
572 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
573 mp_msg(MSGT_TV, MSGL_V, "%s: get %s: %d [%d, %d]\n", info.short_name,
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
574 qctrl.name, control->value, qctrl.minimum, qctrl.maximum);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
575
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
576 if (val_signed) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
577 if (control->value < qctrl.default_value) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
578 control->value = (control->value - qctrl.default_value) * 100 /
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
579 (qctrl.default_value - qctrl.minimum);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
580 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
581 control->value = (control->value - qctrl.default_value) * 100 /
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
582 (qctrl.maximum - qctrl.default_value);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
583 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
584 } else {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
585 if (control->value < qctrl.default_value) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
586 control->value = (control->value - qctrl.default_value) * 50 /
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
587 (qctrl.default_value - qctrl.minimum) + 50;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
588 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
589 control->value = (control->value - qctrl.default_value) * 50 /
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
590 (qctrl.maximum - qctrl.default_value) + 50;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
591 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
592 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
593
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
594 return TVI_CONTROL_TRUE;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
595 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
596
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
597 static int vbi_init(priv_t* priv,char* device)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
598 {
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
599 int vbi_fd=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
600 struct v4l2_capability cap;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
601 struct v4l2_format fmt;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
602 int res;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
603
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
604 if(!device)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
605 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
606
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
607 priv->vbi_dev=strdup(device);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
608
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
609 vbi_fd=open(priv->vbi_dev,O_RDWR);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
610 if(vbi_fd<0){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
611 mp_msg(MSGT_TV,MSGL_ERR,"vbi: could not open device %s\n",priv->vbi_dev);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
612 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
613 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
614
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
615 if(ioctl(vbi_fd,VIDIOC_QUERYCAP,&cap)<0){
31834
64ba1daa147a various spelling fixes, found by the Debian QA tool 'lintian'
siretart
parents: 31322
diff changeset
616 mp_msg(MSGT_TV,MSGL_ERR,"vbi: Query capabilities failed for %s\n",priv->vbi_dev);
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
617 close(vbi_fd);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
618 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
619 }
29949
fc8f901ee516 100l, fix check for V4L2 capture capability flag.
reimar
parents: 29809
diff changeset
620 if(!(cap.capabilities & V4L2_CAP_VBI_CAPTURE)){
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
621 mp_msg(MSGT_TV,MSGL_ERR,"vbi: %s does not support VBI capture\n",priv->vbi_dev);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
622 close(vbi_fd);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
623 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
624 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
625
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
626 memset(&fmt,0,sizeof(struct v4l2_format));
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
627 fmt.type=V4L2_BUF_TYPE_VBI_CAPTURE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
628 if((res=ioctl(vbi_fd,VIDIOC_G_FMT,&fmt))<0){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
629 mp_msg(MSGT_TV,MSGL_ERR,"vbi: Query format failed: %x\n",res);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
630 close(vbi_fd);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
631 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
632 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
633 if(fmt.fmt.vbi.sample_format!=V4L2_PIX_FMT_GREY){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
634 mp_msg(MSGT_TV,MSGL_ERR,"vbi: format 0x%x is not supported\n",fmt.fmt.vbi.sample_format);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
635 close(vbi_fd);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
636 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
637 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
638 priv->vbi_fd=vbi_fd;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
639 mp_msg(MSGT_TV,MSGL_DBG3,"vbi: init ok\n");
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
640 return TVI_CONTROL_TRUE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
641 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
642
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
643 static int vbi_get_props(priv_t* priv,tt_stream_props* ptsp)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
644 {
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
645 struct v4l2_format fmt;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
646 int res;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
647 if(!priv || !ptsp)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
648 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
649
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
650 memset(&fmt,0,sizeof(struct v4l2_format));
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
651 fmt.type=V4L2_BUF_TYPE_VBI_CAPTURE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
652 if((res=ioctl(priv->vbi_fd,VIDIOC_G_FMT,&fmt))<0){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
653 mp_msg(MSGT_TV,MSGL_ERR,"vbi_get_props: Query format failed: %x\n",res);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
654 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
655 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
656
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
657 ptsp->interlaced=(fmt.fmt.vbi.flags& V4L2_VBI_INTERLACED?1:0);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
658
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
659 ptsp->offset=fmt.fmt.vbi.offset;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
660 ptsp->sampling_rate=fmt.fmt.vbi.sampling_rate;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
661 ptsp->samples_per_line=fmt.fmt.vbi.samples_per_line,
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
662
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
663 ptsp->count[0]=fmt.fmt.vbi.count[0];
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
664 ptsp->count[1]=fmt.fmt.vbi.count[1];
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
665 ptsp->bufsize = ptsp->samples_per_line * (ptsp->count[0] + ptsp->count[1]);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
666
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
667 mp_msg(MSGT_TV,MSGL_V,"vbi_get_props: sampling_rate=%d,offset:%d,samples_per_line: %d\n interlaced:%s, count=[%d,%d]\n",
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
668 ptsp->sampling_rate,
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
669 ptsp->offset,
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
670 ptsp->samples_per_line,
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
671 ptsp->interlaced?"Yes":"No",
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
672 ptsp->count[0],
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
673 ptsp->count[1]);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
674
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
675 return TVI_CONTROL_TRUE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
676 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
677
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
678 static void *vbi_grabber(void *data)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
679 {
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
680 priv_t *priv = (priv_t *) data;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
681 int bytes,seq,prev_seq;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
682 unsigned char* buf;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
683 tt_stream_props tsp;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
684
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
685 if(!priv->priv_vbi){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
686 mp_msg(MSGT_TV,MSGL_WARN,"vbi: vbi not initialized. stopping thread.\n");
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
687 return NULL;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
688 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
689
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
690 if(vbi_get_props(priv,&tsp)!=TVI_CONTROL_TRUE)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
691 return NULL;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
692
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
693 buf=malloc(tsp.bufsize);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
694 seq=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
695 prev_seq=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
696 mp_msg(MSGT_TV,MSGL_V,"vbi: vbi capture thread started.\n");
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
697
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
698 while (!priv->vbi_shutdown){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
699 bytes=read(priv->vbi_fd,buf,tsp.bufsize);
24763
5d7f6e5e0847 After receiving EINTR 'read' syscall should be restarted.
voroshil
parents: 24553
diff changeset
700 if(bytes<0 && errno==EINTR)
5d7f6e5e0847 After receiving EINTR 'read' syscall should be restarted.
voroshil
parents: 24553
diff changeset
701 continue;
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
702 if (bytes!=tsp.bufsize){
23979
33928da6ba62 Added missing newline.
cehoyos
parents: 23901
diff changeset
703 mp_msg(MSGT_TV,MSGL_WARN,"vbi: expecting bytes: %d, got: %d\n",tsp.bufsize,bytes);
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
704 break;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
705 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
706 seq=*(int*)(buf+bytes-4);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
707 if(seq<=1) continue;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
708 if (prev_seq && seq!=prev_seq+1){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
709 prev_seq=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
710 seq=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
711 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
712 prev_seq=seq;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
713 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_DECODE_PAGE,&buf);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
714 mp_msg(MSGT_TV,MSGL_DBG3,"grabber: seq:%d\n",seq);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
715 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
716 free(buf);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
717 return NULL;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
718 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
719
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
720 static int control(priv_t *priv, int cmd, void *arg)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
721 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
722 struct v4l2_control control;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
723 struct v4l2_frequency frequency;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
724
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
725 switch(cmd) {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
726 case TVI_CONTROL_IS_VIDEO:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
727 return priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
728 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
17765
7bf483eaa99a If we have a tuner, use that as a reason we have audio support, and do
aurel
parents: 17626
diff changeset
729 case TVI_CONTROL_IS_AUDIO:
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
730 if (priv->tv_param->force_audio) return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
731 case TVI_CONTROL_IS_TUNER:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
732 return priv->capability.capabilities & V4L2_CAP_TUNER?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
733 TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
734 case TVI_CONTROL_IMMEDIATE:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
735 priv->immediate_mode = 1;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
736 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
737 case TVI_CONTROL_VID_GET_FPS:
32668
cb671a73f3a3 Use getfps helper function everywhere, simplifies code and avoids a possible division by 0.
reimar
parents: 32511
diff changeset
738 *(float *)arg = getfps(priv);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
739 mp_msg(MSGT_TV, MSGL_V, "%s: get fps: %f\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
740 *(float *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
741 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
742 case TVI_CONTROL_VID_GET_BITS:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
743 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
744 *(int *)arg = pixfmt2depth(priv->format.fmt.pix.pixelformat);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
745 mp_msg(MSGT_TV, MSGL_V, "%s: get depth: %d\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
746 *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
747 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
748 case TVI_CONTROL_VID_GET_FORMAT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
749 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
750 *(int *)arg = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
751 mp_msg(MSGT_TV, MSGL_V, "%s: get format: %s\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
752 pixfmt2name(priv->format.fmt.pix.pixelformat));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
753 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
754 case TVI_CONTROL_VID_SET_FORMAT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
755 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
756 priv->format.fmt.pix.pixelformat = fcc_mp2vl(*(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
757 priv->format.fmt.pix.field = V4L2_FIELD_ANY;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
758
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
759 priv->mp_format = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
760 mp_msg(MSGT_TV, MSGL_V, "%s: set format: %s\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
761 pixfmt2name(priv->format.fmt.pix.pixelformat));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
762 if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
763 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
764 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
765 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
766 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
767 /* according to the v4l2 specs VIDIOC_S_FMT should not fail, inflexible drivers
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
768 might even always return the default parameters -> update the format here*/
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
769 priv->mp_format = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
770 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
771 case TVI_CONTROL_VID_GET_WIDTH:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
772 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
773 *(int *)arg = priv->format.fmt.pix.width;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
774 mp_msg(MSGT_TV, MSGL_V, "%s: get width: %d\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
775 *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
776 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
777 case TVI_CONTROL_VID_CHK_WIDTH:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
778 return TVI_CONTROL_TRUE;
28940
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
779 case TVI_CONTROL_VID_SET_WIDTH_HEIGHT:
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
780 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
781 priv->format.fmt.pix.width = ((int *)arg)[0];
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
782 priv->format.fmt.pix.height = ((int *)arg)[1];
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
783 priv->format.fmt.pix.field = V4L2_FIELD_ANY;
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
784 if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0)
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
785 return TVI_CONTROL_FALSE;
7406e7f30d4e Add TVI_CONTROL_VID_SET_WIDTH_HEIGHT to set width and height together for v4l2,
reimar
parents: 28927
diff changeset
786 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
787 case TVI_CONTROL_VID_SET_WIDTH:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
788 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
789 priv->format.fmt.pix.width = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
790 mp_msg(MSGT_TV, MSGL_V, "%s: set width: %d\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
791 *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
792 if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
793 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set width failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
794 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
795 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
796 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
797 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
798 case TVI_CONTROL_VID_GET_HEIGHT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
799 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
800 *(int *)arg = priv->format.fmt.pix.height;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
801 mp_msg(MSGT_TV, MSGL_V, "%s: get height: %d\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
802 *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
803 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
804 case TVI_CONTROL_VID_CHK_HEIGHT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
805 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
806 case TVI_CONTROL_VID_SET_HEIGHT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
807 if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
808 priv->format.fmt.pix.height = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
809 priv->format.fmt.pix.field = V4L2_FIELD_ANY;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
810 mp_msg(MSGT_TV, MSGL_V, "%s: set height: %d\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
811 *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
812 if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
813 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set height failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
814 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
815 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
816 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
817 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
818 case TVI_CONTROL_VID_GET_BRIGHTNESS:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
819 control.id = V4L2_CID_BRIGHTNESS;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
820 if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
821 *(int *)arg = control.value;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
822 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
823 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
824 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
825 case TVI_CONTROL_VID_SET_BRIGHTNESS:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
826 control.id = V4L2_CID_BRIGHTNESS;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
827 control.value = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
828 return set_control(priv, &control, 1);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
829 case TVI_CONTROL_VID_GET_HUE:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
830 control.id = V4L2_CID_HUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
831 if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
832 *(int *)arg = control.value;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
833 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
834 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
835 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
836 case TVI_CONTROL_VID_SET_HUE:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
837 control.id = V4L2_CID_HUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
838 control.value = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
839 return set_control(priv, &control, 1);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
840 case TVI_CONTROL_VID_GET_SATURATION:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
841 control.id = V4L2_CID_SATURATION;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
842 if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
843 *(int *)arg = control.value;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
844 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
845 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
846 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
847 case TVI_CONTROL_VID_SET_SATURATION:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
848 control.id = V4L2_CID_SATURATION;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
849 control.value = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
850 return set_control(priv, &control, 1);
24553
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
851 case TVI_CONTROL_VID_GET_GAIN:
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
852 {
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
853
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
854 control.id = V4L2_CID_AUTOGAIN;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
855 if(get_control(priv,&control,0)!=TVI_CONTROL_TRUE)
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
856 return TVI_CONTROL_FALSE;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
857
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
858 if(control.value){ //Auto Gain control is enabled
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
859 *(int*)arg=0;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
860 return TVI_CONTROL_TRUE;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
861 }
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
862
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
863 //Manual Gain control
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
864 control.id = V4L2_CID_GAIN;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
865 if(get_control(priv,&control,0)!=TVI_CONTROL_TRUE)
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
866 return TVI_CONTROL_FALSE;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
867
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
868 *(int*)arg=control.value?control.value:1;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
869
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
870 return TVI_CONTROL_TRUE;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
871 }
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
872 case TVI_CONTROL_VID_SET_GAIN:
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
873 {
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
874 //value==0 means automatic gain control
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
875 int value=*(int*)arg;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
876
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
877 if (value < 0 || value>100)
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
878 return TVI_CONTROL_FALSE;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
879
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
880 control.id=value?V4L2_CID_GAIN:V4L2_CID_AUTOGAIN;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
881 control.value=value?value:1;
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
882
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
883 return set_control(priv,&control,0);
d6bba2781d01 Implement setting gain control for video devices (usually webcams)
voroshil
parents: 24346
diff changeset
884 }
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
885 case TVI_CONTROL_VID_GET_CONTRAST:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
886 control.id = V4L2_CID_CONTRAST;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
887 if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
888 *(int *)arg = control.value;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
889 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
890 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
891 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
892 case TVI_CONTROL_VID_SET_CONTRAST:
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
893 control.id = V4L2_CID_CONTRAST;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
894 control.value = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
895 return set_control(priv, &control, 1);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
896 case TVI_CONTROL_TUN_GET_FREQ:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
897 frequency.tuner = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
898 frequency.type = V4L2_TUNER_ANALOG_TV;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
899 if (ioctl(priv->video_fd, VIDIOC_G_FREQUENCY, &frequency) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
900 mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl get frequency failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
901 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
902 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
903 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
904 *(int *)arg = frequency.frequency;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
905 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
906 case TVI_CONTROL_TUN_SET_FREQ:
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
907 #if 0
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
908 set_mute(priv, 1);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
909 usleep(100000); // wait to suppress noise during switching
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
910 #endif
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
911 frequency.tuner = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
912 frequency.type = V4L2_TUNER_ANALOG_TV;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
913 frequency.frequency = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
914 if (ioctl(priv->video_fd, VIDIOC_S_FREQUENCY, &frequency) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
915 mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set frequency failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
916 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
917 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
918 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
919 #if 0
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
920 usleep(100000); // wait to suppress noise during switching
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
921 set_mute(priv, 0);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
922 #endif
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
923 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
924 case TVI_CONTROL_TUN_GET_TUNER:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
925 mp_msg(MSGT_TV, MSGL_V, "%s: get tuner\n",info.short_name);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
926 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
927 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
928 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
929 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
930 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
931 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
932 case TVI_CONTROL_TUN_SET_TUNER:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
933 mp_msg(MSGT_TV, MSGL_V, "%s: set tuner\n",info.short_name);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
934 if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
935 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
936 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
937 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
938 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
939 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
940 case TVI_CONTROL_TUN_GET_NORM:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
941 *(int *)arg = priv->standard.index;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
942 return TVI_CONTROL_TRUE;
24105
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
943 case TVI_CONTROL_TUN_GET_SIGNAL:
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
944 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) {
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
945 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n",
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
946 info.short_name, strerror(errno));
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
947 return TVI_CONTROL_FALSE;
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
948 }
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
949 *(int*)arg=100*(priv->tuner.signal>>8)/255;
9e71e0345c35 Automatic TV channels scanning ability for MPlayer.
voroshil
parents: 23979
diff changeset
950 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
951 case TVI_CONTROL_TUN_SET_NORM:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
952 priv->standard.index = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
953 if (ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
954 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl enum norm failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
955 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
956 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
957 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
958 mp_msg(MSGT_TV, MSGL_V, "%s: set norm: %s\n", info.short_name, priv->standard.name);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
959 if (ioctl(priv->video_fd, VIDIOC_S_STD, &priv->standard.id) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
960 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set norm failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
961 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
962 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
963 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
964 return TVI_CONTROL_TRUE;
13978
2a9afbfc79d7 setting the norm using text ID instead of numeric
henry
parents: 12860
diff changeset
965 case TVI_CONTROL_SPC_GET_NORMID:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
966 {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
967 int i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
968 for (i = 0;; i++) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
969 struct v4l2_standard standard;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
970 memset(&standard, 0, sizeof(standard));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
971 standard.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
972 if (-1 == ioctl(priv->video_fd, VIDIOC_ENUMSTD, &standard))
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
973 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
974 if (!strcasecmp(standard.name, (char *)arg)) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
975 *(int *)arg = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
976 return TVI_CONTROL_TRUE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
977 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
978 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
979 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
980 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
981 case TVI_CONTROL_SPC_GET_INPUT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
982 if (ioctl(priv->video_fd, VIDIOC_G_INPUT, (int *)arg) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
983 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get input failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
984 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
985 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
986 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
987 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
988 case TVI_CONTROL_SPC_SET_INPUT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
989 mp_msg(MSGT_TV, MSGL_V, "%s: set input: %d\n", info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
990 priv->input.index = *(int *)arg;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
991 if (ioctl(priv->video_fd, VIDIOC_ENUMINPUT, &priv->input) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
992 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl enum input failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
993 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
994 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
995 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
996 if (ioctl(priv->video_fd, VIDIOC_S_INPUT, (int *)arg) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
997 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set input failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
998 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
999 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1000 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1001 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1002 case TVI_CONTROL_AUD_GET_FORMAT:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1003 init_audio(priv);
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1004 if (!priv->audio_initialized) return TVI_CONTROL_FALSE;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1005 *(int *)arg = AF_FORMAT_S16_LE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1006 mp_msg(MSGT_TV, MSGL_V, "%s: get audio format: %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1007 info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1008 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1009 case TVI_CONTROL_AUD_GET_SAMPLERATE:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1010 init_audio(priv);
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1011 if (!priv->audio_initialized) return TVI_CONTROL_FALSE;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1012 *(int *)arg = priv->audio_in.samplerate;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1013 mp_msg(MSGT_TV, MSGL_V, "%s: get audio samplerate: %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1014 info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1015 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1016 case TVI_CONTROL_AUD_GET_SAMPLESIZE:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1017 init_audio(priv);
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1018 if (!priv->audio_initialized) return TVI_CONTROL_FALSE;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1019 *(int *)arg = priv->audio_in.bytes_per_sample;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1020 mp_msg(MSGT_TV, MSGL_V, "%s: get audio samplesize: %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1021 info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1022 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1023 case TVI_CONTROL_AUD_GET_CHANNELS:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1024 init_audio(priv);
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1025 if (!priv->audio_initialized) return TVI_CONTROL_FALSE;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1026 *(int *)arg = priv->audio_in.channels;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1027 mp_msg(MSGT_TV, MSGL_V, "%s: get audio channels: %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1028 info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1029 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1030 case TVI_CONTROL_AUD_SET_SAMPLERATE:
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1031 init_audio(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1032 mp_msg(MSGT_TV, MSGL_V, "%s: set audio samplerate: %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1033 info.short_name, *(int *)arg);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1034 if (audio_in_set_samplerate(&priv->audio_in, *(int*)arg) < 0) return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1035 // setup_audio_buffer_sizes(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1036 return TVI_CONTROL_TRUE;
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1037 case TVI_CONTROL_VBI_INIT:
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1038 {
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1039 void* ptr;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1040 tt_stream_props tsp;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1041
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1042 if (vbi_init(priv,*(char**)arg)!=TVI_CONTROL_TRUE)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1043 return TVI_CONTROL_FALSE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1044 if(vbi_get_props(priv,&tsp)==TVI_CONTROL_TRUE)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1045 {
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1046 ptr=&tsp;
29760
1cc8a20520e8 Add MSGT_TELETEXT, rename TVI_CONTROL as VBI_CONTROL and fix some paths
cehoyos
parents: 29759
diff changeset
1047 if(teletext_control(NULL,TV_VBI_CONTROL_START,&ptr)==VBI_CONTROL_TRUE)
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1048 priv->priv_vbi=ptr;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1049 else
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1050 priv->priv_vbi=NULL;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1051 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1052 return TVI_CONTROL_TRUE;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1053 }
29806
a5e7590ffdbd Separate teletext from tv support.
cehoyos
parents: 29760
diff changeset
1054 case TVI_CONTROL_GET_VBI_PTR:
a5e7590ffdbd Separate teletext from tv support.
cehoyos
parents: 29760
diff changeset
1055 *(void **)arg=priv->priv_vbi;
a5e7590ffdbd Separate teletext from tv support.
cehoyos
parents: 29760
diff changeset
1056 return TVI_CONTROL_TRUE;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1057 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1058 mp_msg(MSGT_TV, MSGL_V, "%s: unknown control: %d\n", info.short_name, cmd);
26756
c43ce7268677 cosmetics: Remove useless parentheses from return statements.
diego
parents: 25962
diff changeset
1059 return TVI_CONTROL_UNKNOWN;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1060 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1061
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1062
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1063 #define PRIV ((priv_t *) (tvi_handle->priv))
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1064
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1065 /* handler creator - entry point ! */
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
1066 static tvi_handle_t *tvi_init_v4l2(tv_param_t* tv_param)
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1067 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1068 tvi_handle_t *tvi_handle;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1069
32141
2802b8095bf7 Move TV input new_handle static function to tv.c and make it non-static.
diego
parents: 32090
diff changeset
1070 tvi_handle = tv_new_handle(sizeof(priv_t), &functions);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1071 if (!tvi_handle) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1072 return NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1073 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1074 PRIV->video_fd = -1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1075
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
1076 PRIV->video_dev = strdup(tv_param->device? tv_param->device: "/dev/video0");
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1077 if (!PRIV->video_dev) {
32090
535ebcd085e4 Move TV input free_handle static function to tv.c and make it non-static.
diego
parents: 31834
diff changeset
1078 tv_free_handle(tvi_handle);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1079 return NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1080 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1081
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
1082 if (tv_param->adevice) {
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
1083 PRIV->audio_dev = strdup(tv_param->adevice);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1084 if (!PRIV->audio_dev) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1085 free(PRIV->video_dev);
32090
535ebcd085e4 Move TV input free_handle static function to tv.c and make it non-static.
diego
parents: 31834
diff changeset
1086 tv_free_handle(tvi_handle);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1087 return NULL;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1088 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1089 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1090
23883
d65439444b75 Removing global variables from tv://
voroshil
parents: 23423
diff changeset
1091 PRIV->tv_param=tv_param;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1092 return tvi_handle;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1093 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1094
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1095 #undef PRIV
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1096
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1097
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1098 static int uninit(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1099 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1100 int i, frames, dropped = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1101
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1102 priv->vbi_shutdown=1;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1103 if(priv->vbi_grabber_thread)
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1104 pthread_join(priv->vbi_grabber_thread, NULL);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1105
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1106 teletext_control(priv->priv_vbi,TV_VBI_CONTROL_STOP,(void*)1);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1107 priv->priv_vbi=NULL;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1108
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1109 if(priv->vbi_fd){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1110 close(priv->vbi_fd);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1111 priv->vbi_fd=0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1112 }
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1113
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32352
diff changeset
1114 free(priv->vbi_dev);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32352
diff changeset
1115 priv->vbi_dev = NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1116 priv->shutdown = 1;
16185
973b82bf1187 do not crash when /dev/video0 is not present
faust3
parents: 15987
diff changeset
1117 if(priv->video_grabber_thread)
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1118 pthread_join(priv->video_grabber_thread, NULL);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1119 pthread_mutex_destroy(&priv->video_buffer_mutex);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1120
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1121 if (priv->streamon) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1122 struct v4l2_buffer buf;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1123
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1124 /* get performance */
28927
8f7c8a1cb8b7 100l fix calculation of dropped frames, number of frames is time * fps, not time / fps.
reimar
parents: 28106
diff changeset
1125 frames = 1 + lrintf((double)(priv->curr_frame - priv->first_frame) / 1e6 * getfps(priv));
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1126 dropped = frames - priv->frames;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1127
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1128 /* turn off streaming */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1129 if (ioctl(priv->video_fd, VIDIOC_STREAMOFF, &(priv->map[0].buf.type)) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1130 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl streamoff failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1131 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1132 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1133 priv->streamon = 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1134
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1135 /* unqueue all remaining buffers */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1136 memset(&buf,0,sizeof(buf));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1137 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1138 buf.memory = V4L2_MEMORY_MMAP;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1139 while (!ioctl(priv->video_fd, VIDIOC_DQBUF, &buf));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1140 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1141
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1142 /* unmap all buffers */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1143 for (i = 0; i < priv->mapcount; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1144 if (munmap(priv->map[i].addr, priv->map[i].len) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1145 mp_msg(MSGT_TV, MSGL_ERR, "%s: munmap capture buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1146 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1147 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1148 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1149
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1150 /* stop audio thread */
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1151 if (!priv->tv_param->noaudio && priv->audio_grabber_thread) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1152 pthread_join(priv->audio_grabber_thread, NULL);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1153 pthread_mutex_destroy(&priv->skew_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1154 pthread_mutex_destroy(&priv->audio_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1155 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1156
17626
5627625b0cdb Don't test the v4l2_input audioset field for audio capabilities but still try changing the mute setting (patch by Jesse Allen < the3dfxdude _at_ gmail.com >)
aurel
parents: 17199
diff changeset
1157 set_mute(priv, 1);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1158
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1159 /* free memory and close device */
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1160 free(priv->map); priv->map = NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1161 priv->mapcount = 0;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1162 if(priv->video_fd!=-1)close(priv->video_fd); priv->video_fd = -1;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1163 free(priv->video_dev); priv->video_dev = NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1164
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1165 if (priv->video_ringbuffer) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1166 int i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1167 for (i = 0; i < priv->video_buffer_size_current; i++) {
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1168 free(priv->video_ringbuffer[i].data);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1169 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1170 free(priv->video_ringbuffer);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1171 }
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1172 if (!priv->tv_param->noaudio) {
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32352
diff changeset
1173 free(priv->audio_ringbuffer);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32352
diff changeset
1174 free(priv->audio_skew_buffer);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 32352
diff changeset
1175 free(priv->audio_skew_delta_buffer);
25005
1635b2b31bdd Add missing call to audio_in_uninit in v4l2 tv driver.
voroshil
parents: 24763
diff changeset
1176
1635b2b31bdd Add missing call to audio_in_uninit in v4l2 tv driver.
voroshil
parents: 24763
diff changeset
1177 audio_in_uninit(&priv->audio_in);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1178 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1179
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1180 /* show some nice statistics ;-) */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1181 mp_msg(MSGT_TV, MSGL_INFO,
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1182 "%s: %d frames successfully processed, %d frames dropped.\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1183 info.short_name, priv->frames, dropped);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1184 mp_msg(MSGT_TV, MSGL_V, "%s: up to %u video frames buffered.\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1185 info.short_name, priv->video_buffer_size_current);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1186 return 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1187 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1188
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1189
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1190 /* initialisation */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1191 static int init(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1192 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1193 int i;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1194
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1195 priv->audio_ringbuffer = NULL;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1196 priv->audio_skew_buffer = NULL;
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1197 priv->audio_skew_delta_buffer = NULL;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1198
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1199 priv->audio_initialized = 0;
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
1200
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1201 /* Open the video device. */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1202 priv->video_fd = open(priv->video_dev, O_RDWR);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1203 if (priv->video_fd < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1204 mp_msg(MSGT_TV, MSGL_ERR, "%s: unable to open '%s': %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1205 info.short_name, priv->video_dev, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1206 uninit(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1207 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1208 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1209 mp_msg(MSGT_TV, MSGL_DBG2, "%s: video fd: %s: %d\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1210 info.short_name, priv->video_dev, priv->video_fd);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1211
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1212 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1213 ** Query the video capabilities and current settings
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1214 ** for further control calls.
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1215 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1216 if (ioctl(priv->video_fd, VIDIOC_QUERYCAP, &priv->capability) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1217 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query capabilities failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1218 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1219 uninit(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1220 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1221 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1222
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1223 if (!(priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE))
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1224 {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1225 mp_msg(MSGT_TV, MSGL_ERR, "Device %s is not a video capture device.\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1226 priv->video_dev);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1227 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1228 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1229
18073
8ceb31f028ee make failures during e.g. setting the TV norm non-fatal.
reimar
parents: 17765
diff changeset
1230 if (getfmt(priv) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1231 uninit(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1232 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1233 }
18073
8ceb31f028ee make failures during e.g. setting the TV norm non-fatal.
reimar
parents: 17765
diff changeset
1234 getstd(priv);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1235 /*
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1236 ** if this device has got a tuner query it's settings
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1237 ** otherwise set some nice defaults
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1238 */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1239 if (priv->capability.capabilities & V4L2_CAP_TUNER) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1240 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1241 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1242 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1243 uninit(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1244 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1245 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1246 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1247 mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.card);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1248 if (priv->capability.capabilities & V4L2_CAP_TUNER) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1249 mp_msg(MSGT_TV, MSGL_INFO, " Tuner cap:%s%s%s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1250 (priv->tuner.capability & V4L2_TUNER_CAP_STEREO) ? " STEREO" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1251 (priv->tuner.capability & V4L2_TUNER_CAP_LANG1) ? " LANG1" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1252 (priv->tuner.capability & V4L2_TUNER_CAP_LANG2) ? " LANG2" : "");
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1253 mp_msg(MSGT_TV, MSGL_INFO, " Tuner rxs:%s%s%s%s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1254 (priv->tuner.rxsubchans & V4L2_TUNER_SUB_MONO) ? " MONO" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1255 (priv->tuner.rxsubchans & V4L2_TUNER_SUB_STEREO) ? " STEREO" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1256 (priv->tuner.rxsubchans & V4L2_TUNER_SUB_LANG1) ? " LANG1" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1257 (priv->tuner.rxsubchans & V4L2_TUNER_SUB_LANG2) ? " LANG2" : "");
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1258 }
31834
64ba1daa147a various spelling fixes, found by the Debian QA tool 'lintian'
siretart
parents: 31322
diff changeset
1259 mp_msg(MSGT_TV, MSGL_INFO, " Capabilities:%s%s%s%s%s%s%s%s%s%s%s\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1260 priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1261 " video capture": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1262 priv->capability.capabilities & V4L2_CAP_VIDEO_OUTPUT?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1263 " video output": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1264 priv->capability.capabilities & V4L2_CAP_VIDEO_OVERLAY?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1265 " video overlay": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1266 priv->capability.capabilities & V4L2_CAP_VBI_CAPTURE?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1267 " VBI capture device": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1268 priv->capability.capabilities & V4L2_CAP_VBI_OUTPUT?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1269 " VBI output": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1270 priv->capability.capabilities & V4L2_CAP_RDS_CAPTURE?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1271 " RDS data capture": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1272 priv->capability.capabilities & V4L2_CAP_TUNER?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1273 " tuner": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1274 priv->capability.capabilities & V4L2_CAP_AUDIO?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1275 " audio": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1276 priv->capability.capabilities & V4L2_CAP_READWRITE?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1277 " read/write": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1278 priv->capability.capabilities & V4L2_CAP_ASYNCIO?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1279 " async i/o": "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1280 priv->capability.capabilities & V4L2_CAP_STREAMING?
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1281 " streaming": "");
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1282 mp_msg(MSGT_TV, MSGL_INFO, " supported norms:");
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1283 for (i = 0;; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1284 struct v4l2_standard standard;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1285 memset(&standard, 0, sizeof(standard));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1286 standard.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1287 if (-1 == ioctl(priv->video_fd, VIDIOC_ENUMSTD, &standard))
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1288 break;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1289 mp_msg(MSGT_TV, MSGL_INFO, " %d = %s;", i, standard.name);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1290 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1291 mp_msg(MSGT_TV, MSGL_INFO, "\n inputs:");
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1292 for (i = 0; 1; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1293 struct v4l2_input input;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1294
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1295 input.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1296 if (ioctl(priv->video_fd, VIDIOC_ENUMINPUT, &input) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1297 break;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1298 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1299 mp_msg(MSGT_TV, MSGL_INFO, " %d = %s;", i, input.name);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1300 }
29121
bae666342ba9 Make tvi_v4l2 print -1 as "Current input" if the ioctl to read it failed.
reimar
parents: 28940
diff changeset
1301 i = -1;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1302 if (ioctl(priv->video_fd, VIDIOC_G_INPUT, &i) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1303 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get input failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1304 info.short_name, strerror(errno));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1305 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1306 mp_msg(MSGT_TV, MSGL_INFO, "\n Current input: %d\n", i);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1307 for (i = 0; ; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1308 struct v4l2_fmtdesc fmtdesc;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1309
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1310 fmtdesc.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1311 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1312 if (ioctl(priv->video_fd, VIDIOC_ENUM_FMT, &fmtdesc) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1313 break;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1314 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1315 mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s): %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1316 pixfmt2name(fmtdesc.pixelformat), pixfmt2depth(fmtdesc.pixelformat),
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1317 fmtdesc.description, vo_format_name(fcc_vl2mp(fmtdesc.pixelformat)));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1318 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1319 mp_msg(MSGT_TV, MSGL_INFO, " Current format: %s\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1320 pixfmt2name(priv->format.fmt.pix.pixelformat));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1321
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1322 /* set some nice defaults */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1323 if (getfmt(priv) < 0) return 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1324 priv->format.fmt.pix.width = 640;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1325 priv->format.fmt.pix.height = 480;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1326 if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1327 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1328 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1329 uninit(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1330 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1331 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1332
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1333 // if (!(priv->capability.capabilities & V4L2_CAP_AUDIO) && !priv->tv_param->force_audio) priv->tv_param->noaudio = 1;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1334
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1335 if (priv->capability.capabilities & V4L2_CAP_TUNER) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1336 struct v4l2_control control;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1337 if (priv->tv_param->amode >= 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1338 mp_msg(MSGT_TV, MSGL_V, "%s: setting audio mode\n", info.short_name);
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1339 priv->tuner.audmode = amode2v4l(priv->tv_param->amode);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1340 if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1341 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1342 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1343 return TVI_CONTROL_FALSE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1344 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1345 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1346 mp_msg(MSGT_TV, MSGL_INFO, "%s: current audio mode is :%s%s%s%s\n", info.short_name,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1347 (priv->tuner.audmode == V4L2_TUNER_MODE_MONO) ? " MONO" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1348 (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) ? " STEREO" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1349 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG1) ? " LANG1" : "",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1350 (priv->tuner.audmode == V4L2_TUNER_MODE_LANG2) ? " LANG2" : "");
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1351
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1352 if (priv->tv_param->volume >= 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1353 control.id = V4L2_CID_AUDIO_VOLUME;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1354 control.value = priv->tv_param->volume;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1355 set_control(priv, &control, 0);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1356 }
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1357 if (priv->tv_param->bass >= 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1358 control.id = V4L2_CID_AUDIO_BASS;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1359 control.value = priv->tv_param->bass;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1360 set_control(priv, &control, 0);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1361 }
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1362 if (priv->tv_param->treble >= 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1363 control.id = V4L2_CID_AUDIO_TREBLE;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1364 control.value = priv->tv_param->treble;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1365 set_control(priv, &control, 0);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1366 }
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1367 if (priv->tv_param->balance >= 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1368 control.id = V4L2_CID_AUDIO_BALANCE;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1369 control.value = priv->tv_param->balance;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1370 set_control(priv, &control, 0);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1371 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1372 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1373
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1374 return 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1375 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1376
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1377 static int get_capture_buffer_size(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1378 {
33644
c15dabfa2380 Do a proper calculation of free RAM to be used as V4L buffers.
iive
parents: 33163
diff changeset
1379 uint64_t bufsize;
c15dabfa2380 Do a proper calculation of free RAM to be used as V4L buffers.
iive
parents: 33163
diff changeset
1380 int cnt;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1381
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1382 if (priv->tv_param->buffer_size >= 0) {
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1383 bufsize = priv->tv_param->buffer_size*1024*1024;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1384 } else {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1385 #ifdef HAVE_SYS_SYSINFO_H
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1386 struct sysinfo si;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1387
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1388 sysinfo(&si);
33644
c15dabfa2380 Do a proper calculation of free RAM to be used as V4L buffers.
iive
parents: 33163
diff changeset
1389 bufsize = (si.freeram/2)*si.mem_unit;
c15dabfa2380 Do a proper calculation of free RAM to be used as V4L buffers.
iive
parents: 33163
diff changeset
1390 if ( bufsize < 16*1024*1024)
c15dabfa2380 Do a proper calculation of free RAM to be used as V4L buffers.
iive
parents: 33163
diff changeset
1391 #endif
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1392 bufsize = 16*1024*1024;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1393 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1394
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1395 cnt = bufsize/priv->format.fmt.pix.sizeimage;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1396 if (cnt < 2) cnt = 2;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1397
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1398 return cnt;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1399 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1400
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1401 /* that's the real start, we'got the format parameters (checked with control) */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1402 static int start(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1403 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1404 struct v4l2_requestbuffers request;
24346
9fb68e85180a Fix for:
voroshil
parents: 24105
diff changeset
1405 unsigned int i;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1406
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1407 /* setup audio parameters */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1408
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
1409 init_audio(priv);
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25689
diff changeset
1410 if (!priv->tv_param->noaudio && !priv->audio_initialized) return 0;
15464
a57ec42d7df1 do not modify tv_param_noaudio
henry
parents: 15462
diff changeset
1411
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1412 /* we need this to size the audio buffer properly */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1413 if (priv->immediate_mode) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1414 priv->video_buffer_size_max = 2;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1415 } else {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1416 priv->video_buffer_size_max = get_capture_buffer_size(priv);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1417 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1418
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1419 if (!priv->tv_param->noaudio) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1420 setup_audio_buffer_sizes(priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1421 priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1422 if (!priv->audio_skew_buffer) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1423 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1424 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1425 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1426 priv->audio_skew_delta_buffer = calloc(priv->aud_skew_cnt, sizeof(long long));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1427 if (!priv->audio_skew_delta_buffer) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1428 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1429 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1430 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1431
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1432 priv->audio_ringbuffer = calloc(priv->audio_in.blocksize, priv->audio_buffer_size);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1433 if (!priv->audio_ringbuffer) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1434 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate audio buffer: %s\n", strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1435 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1436 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1437
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1438 priv->audio_secs_per_block = (double)priv->audio_in.blocksize/(priv->audio_in.samplerate
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1439 *priv->audio_in.channels
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1440 *priv->audio_in.bytes_per_sample);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1441 priv->audio_usecs_per_block = 1e6*priv->audio_secs_per_block;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1442 priv->audio_head = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1443 priv->audio_tail = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1444 priv->audio_cnt = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1445 priv->audio_drop = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1446 priv->audio_skew = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1447 priv->audio_skew_total = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1448 priv->audio_skew_delta_total = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1449 priv->audio_recv_blocks_total = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1450 priv->audio_sent_blocks_total = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1451 priv->audio_null_blocks_inserted = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1452 priv->audio_insert_null_samples = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1453 priv->dropped_frames_timeshift = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1454 priv->dropped_frames_compensated = 0;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1455
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1456 pthread_mutex_init(&priv->skew_mutex, NULL);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1457 pthread_mutex_init(&priv->audio_mutex, NULL);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1458 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1459
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1460 /* setup video parameters */
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1461 if (!priv->tv_param->noaudio) {
32668
cb671a73f3a3 Use getfps helper function everywhere, simplifies code and avoids a possible division by 0.
reimar
parents: 32511
diff changeset
1462 if (priv->video_buffer_size_max < 3*getfps(priv)*priv->audio_secs_per_block) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1463 mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n"
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1464 "You will probably experience heavy framedrops.\n");
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1465 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1466 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1467
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1468 {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1469 int bytesperline = priv->format.fmt.pix.width*pixfmt2depth(priv->format.fmt.pix.pixelformat)/8;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1470
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1471 mp_msg(MSGT_TV, MSGL_V, "Using a ring buffer for maximum %d frames, %d MB total size.\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1472 priv->video_buffer_size_max,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1473 priv->video_buffer_size_max*priv->format.fmt.pix.height*bytesperline/(1024*1024));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1474 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1475
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1476 priv->video_ringbuffer = calloc(priv->video_buffer_size_max, sizeof(video_buffer_entry));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1477 if (!priv->video_ringbuffer) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1478 mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate video buffer: %s\n", strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1479 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1480 }
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1481 memset(priv->video_ringbuffer,0,priv->video_buffer_size_max * sizeof(video_buffer_entry));
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1482
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1483 pthread_mutex_init(&priv->video_buffer_mutex, NULL);
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1484
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1485 priv->video_head = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1486 priv->video_tail = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1487 priv->video_cnt = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1488
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1489 /* request buffers */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1490 if (priv->immediate_mode) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1491 request.count = 2;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1492 } else {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1493 request.count = BUFFER_COUNT;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1494 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1495
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1496 request.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1497 request.memory = V4L2_MEMORY_MMAP;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1498 if (ioctl(priv->video_fd, VIDIOC_REQBUFS, &request) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1499 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl request buffers failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1500 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1501 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1502 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1503
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1504 /* query buffers */
18558
4928dd61f136 Fix potential integer overflows in memory allocation.
rtogni
parents: 18176
diff changeset
1505 if (!(priv->map = calloc(request.count, sizeof(struct map)))) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1506 mp_msg(MSGT_TV, MSGL_ERR, "%s: malloc capture buffers failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1507 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1508 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1509 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1510
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1511 /* map and queue buffers */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1512 for (i = 0; i < request.count; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1513 memset(&priv->map[i].buf,0,sizeof(priv->map[i].buf));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1514 priv->map[i].buf.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1515 priv->map[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1516 priv->map[i].buf.memory = V4L2_MEMORY_MMAP;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1517 if (ioctl(priv->video_fd, VIDIOC_QUERYBUF, &(priv->map[i].buf)) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1518 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1519 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1520 free(priv->map);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1521 priv->map = NULL;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1522 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1523 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1524 priv->map[i].addr = mmap (0, priv->map[i].buf.length, PROT_READ |
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1525 PROT_WRITE, MAP_SHARED, priv->video_fd, priv->map[i].buf.m.offset);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1526 if (priv->map[i].addr == MAP_FAILED) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1527 mp_msg(MSGT_TV, MSGL_ERR, "%s: mmap capture buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1528 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1529 priv->map[i].len = 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1530 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1531 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1532 priv->map[i].len = priv->map[i].buf.length;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1533 /* count up to make sure this is correct everytime */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1534 priv->mapcount++;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1535
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1536 if (ioctl(priv->video_fd, VIDIOC_QBUF, &(priv->map[i].buf)) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1537 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1538 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1539 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1540 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1541 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1542
23901
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1543 /* start vbi thread */
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1544 if(priv->priv_vbi){
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1545 priv->vbi_shutdown = 0;
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1546 pthread_create(&priv->vbi_grabber_thread, NULL, vbi_grabber, priv);
657236b9eacb Teletext support
voroshil
parents: 23886
diff changeset
1547 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1548 /* start audio thread */
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1549 priv->shutdown = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1550 priv->audio_skew_measure_time = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1551 priv->first_frame = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1552 priv->audio_skew = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1553 priv->first = 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1554
17626
5627625b0cdb Don't test the v4l2_input audioset field for audio capabilities but still try changing the mute setting (patch by Jesse Allen < the3dfxdude _at_ gmail.com >)
aurel
parents: 17199
diff changeset
1555 set_mute(priv, 0);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1556
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1557 return 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1558 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1559
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1560 // copies a video frame
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1561 static inline void copy_frame(priv_t *priv, video_buffer_entry *dest, unsigned char *source,int len)
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1562 {
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1563 dest->framesize=len;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1564 if(priv->tv_param->automute>0){
23422
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1565 if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) >= 0) {
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1566 if(priv->tv_param->automute<<8>priv->tuner.signal){
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1567 fill_blank_frame(dest->data,dest->framesize,fcc_vl2mp(priv->format.fmt.pix.pixelformat));
23422
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1568 set_mute(priv,1);
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1569 return;
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1570 }
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1571 }
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1572 set_mute(priv,0);
e7b4c913dc31 New "automute" tv:// option.
voroshil
parents: 23362
diff changeset
1573 }
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1574 memcpy(dest->data, source, len);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1575 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1576
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1577 // maximum skew change, in frames
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1578 #define MAX_SKEW_DELTA 0.6
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1579 static void *video_grabber(void *data)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1580 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1581 priv_t *priv = (priv_t*)data;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1582 long long skew, prev_skew, xskew, interval, prev_interval, delta;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1583 int i;
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1584 int framesize = priv->format.fmt.pix.sizeimage;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1585 fd_set rdset;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1586 struct timeval timeout;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1587 struct v4l2_buffer buf;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1588
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1589 xskew = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1590 skew = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1591 interval = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1592 prev_interval = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1593 prev_skew = 0;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1594
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1595 mp_msg(MSGT_TV, MSGL_V, "%s: going to capture\n", info.short_name);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1596 if (ioctl(priv->video_fd, VIDIOC_STREAMON, &(priv->format.type)) < 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1597 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl streamon failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1598 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1599 return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1600 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1601 priv->streamon = 1;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1602
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1603 if (!priv->tv_param->noaudio) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1604 pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1605 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1606
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1607 for (priv->frames = 0; !priv->shutdown;)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1608 {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1609 int ret;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1610
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1611 if (priv->immediate_mode) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1612 while (priv->video_cnt == priv->video_buffer_size_max) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1613 usleep(10000);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1614 if (priv->shutdown) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1615 return NULL;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1616 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1617 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1618 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1619
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1620 FD_ZERO (&rdset);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1621 FD_SET (priv->video_fd, &rdset);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1622
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1623 timeout.tv_sec = 1;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1624 timeout.tv_usec = 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1625
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1626 i = select(priv->video_fd + 1, &rdset, NULL, NULL, &timeout);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1627 if (i < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1628 mp_msg(MSGT_TV, MSGL_ERR, "%s: select failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1629 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1630 continue;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1631 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1632 else if (i == 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1633 mp_msg(MSGT_TV, MSGL_ERR, "%s: select timeout\n", info.short_name);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1634 continue;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1635 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1636 else if (!FD_ISSET(priv->video_fd, &rdset)) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1637 continue;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1638 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1639
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1640 memset(&buf,0,sizeof(buf));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1641 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1642 buf.memory = V4L2_MEMORY_MMAP;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1643 ret = ioctl(priv->video_fd, VIDIOC_DQBUF, &buf);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1644
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1645 if (ret < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1646 /*
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1647 if there's no signal, the buffer might me dequeued
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1648 so we query all the buffers to see which one we should
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1649 put back to queue
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1650
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1651 observed with saa7134 0.2.8
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1652 don't know if is it a bug or (mis)feature
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1653 */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1654 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl dequeue buffer failed: %s, idx = %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1655 info.short_name, strerror(errno), buf.index);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1656 for (i = 0; i < priv->mapcount; i++) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1657 memset(&buf,0,sizeof(buf));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1658 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1659 buf.memory = V4L2_MEMORY_MMAP;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1660 buf.index = i;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1661 ret = ioctl(priv->video_fd, VIDIOC_QUERYBUF, &buf);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1662 if (ret < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1663 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query buffer failed: %s, idx = %d\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1664 info.short_name, strerror(errno), buf.index);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1665 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1666 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1667 if ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE)) == V4L2_BUF_FLAG_MAPPED) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1668 if (ioctl(priv->video_fd, VIDIOC_QBUF, &(priv->map[i].buf)) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1669 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1670 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1671 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1672 }
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1673 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1674 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1675 continue;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1676 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1677
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1678 /* store the timestamp of the very first frame as reference */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1679 if (!priv->frames++) {
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1680 if (!priv->tv_param->noaudio) pthread_mutex_lock(&priv->skew_mutex);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1681 priv->first_frame = (long long)1e6*buf.timestamp.tv_sec + buf.timestamp.tv_usec;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1682 if (!priv->tv_param->noaudio) pthread_mutex_unlock(&priv->skew_mutex);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1683 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1684 priv->curr_frame = (long long)buf.timestamp.tv_sec*1e6+buf.timestamp.tv_usec;
32352
76f94c00a69f 1000l, %lf is not valid format string for printf (only for scanf) and actually
reimar
parents: 32141
diff changeset
1685 // fprintf(stderr, "idx = %d, ts = %f\n", buf.index, (double)(priv->curr_frame) / 1e6);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1686
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1687 interval = priv->curr_frame - priv->first_frame;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1688 delta = interval - prev_interval;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1689
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1690 if (!priv->immediate_mode) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1691 // interpolate the skew in time
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1692 if (!priv->tv_param->noaudio) pthread_mutex_lock(&priv->skew_mutex);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1693 xskew = priv->audio_skew + (interval - priv->audio_skew_measure_time)*priv->audio_skew_factor;
23886
5af94a1df41e Removing global variables from tv://
voroshil
parents: 23883
diff changeset
1694 if (!priv->tv_param->noaudio) pthread_mutex_unlock(&priv->skew_mutex);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1695 // correct extreme skew changes to avoid (especially) moving backwards in time
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1696 if (xskew - prev_skew > delta*MAX_SKEW_DELTA) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1697 skew = prev_skew + delta*MAX_SKEW_DELTA;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1698 } else if (xskew - prev_skew < -delta*MAX_SKEW_DELTA) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1699 skew = prev_skew - delta*MAX_SKEW_DELTA;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1700 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1701 skew = xskew;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1702 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1703 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1704
32352
76f94c00a69f 1000l, %lf is not valid format string for printf (only for scanf) and actually
reimar
parents: 32141
diff changeset
1705 mp_msg(MSGT_TV, MSGL_DBG3, "\nfps = %f, interval = %f, a_skew = %f, corr_skew = %f\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1706 delta ? (double)1e6/delta : -1,
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1707 (double)1e-6*interval, (double)1e-6*xskew, (double)1e-6*skew);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1708 mp_msg(MSGT_TV, MSGL_DBG3, "vcnt = %d, acnt = %d\n", priv->video_cnt, priv->audio_cnt);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1709
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1710 prev_skew = skew;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1711 prev_interval = interval;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1712
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1713 /* allocate a new buffer, if needed */
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1714 pthread_mutex_lock(&priv->video_buffer_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1715 if (priv->video_buffer_size_current < priv->video_buffer_size_max) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1716 if (priv->video_cnt == priv->video_buffer_size_current) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1717 unsigned char *newbuf = malloc(framesize);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1718 if (newbuf) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1719 memmove(priv->video_ringbuffer+priv->video_tail+1, priv->video_ringbuffer+priv->video_tail,
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1720 (priv->video_buffer_size_current-priv->video_tail)*sizeof(video_buffer_entry));
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1721 priv->video_ringbuffer[priv->video_tail].data = newbuf;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1722 if ((priv->video_head >= priv->video_tail) && (priv->video_cnt > 0)) priv->video_head++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1723 priv->video_buffer_size_current++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1724 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1725 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1726 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1727 pthread_mutex_unlock(&priv->video_buffer_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1728
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1729 if (priv->video_cnt == priv->video_buffer_size_current) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1730 if (!priv->immediate_mode) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1731 mp_msg(MSGT_TV, MSGL_ERR, "\nvideo buffer full - dropping frame\n");
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1732 if (priv->audio_insert_null_samples) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1733 pthread_mutex_lock(&priv->audio_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1734 priv->dropped_frames_timeshift += delta;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1735 pthread_mutex_unlock(&priv->audio_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1736 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1737 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1738 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1739 if (priv->immediate_mode) {
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1740 priv->video_ringbuffer[priv->video_tail].timestamp = 0;
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1741 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1742 // compensate for audio skew
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1743 // negative skew => there are more audio samples, increase interval
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1744 // positive skew => less samples, shorten the interval
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1745 priv->video_ringbuffer[priv->video_tail].timestamp = interval - skew;
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1746 if (priv->audio_insert_null_samples && priv->video_ringbuffer[priv->video_tail].timestamp > 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1747 pthread_mutex_lock(&priv->audio_mutex);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1748 priv->video_ringbuffer[priv->video_tail].timestamp +=
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1749 (priv->audio_null_blocks_inserted
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1750 - priv->dropped_frames_timeshift/priv->audio_usecs_per_block)
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1751 *priv->audio_usecs_per_block;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1752 pthread_mutex_unlock(&priv->audio_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1753 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1754 }
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1755 copy_frame(priv, priv->video_ringbuffer+priv->video_tail, priv->map[buf.index].addr,buf.bytesused);
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1756 priv->video_tail = (priv->video_tail+1)%priv->video_buffer_size_current;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1757 priv->video_cnt++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1758 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1759 if (ioctl(priv->video_fd, VIDIOC_QBUF, &buf) < 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1760 mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n",
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1761 info.short_name, strerror(errno));
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1762 return 0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1763 }
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1764 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1765 return NULL;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1766 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1767
16962
bdc218b5a49a Do not hang forever when the card delivers no new data.
reimar
parents: 16536
diff changeset
1768 #define MAX_LOOP 50
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1769 static double grab_video_frame(priv_t *priv, char *buffer, int len)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1770 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1771 double interval;
16962
bdc218b5a49a Do not hang forever when the card delivers no new data.
reimar
parents: 16536
diff changeset
1772 int loop_cnt = 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1773
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1774 if (priv->first) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1775 pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1776 priv->first = 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1777 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1778
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1779 while (priv->video_cnt == 0) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1780 usleep(10000);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1781 if (loop_cnt++ > MAX_LOOP) return 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1782 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1783
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1784 pthread_mutex_lock(&priv->video_buffer_mutex);
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1785 interval = (double)priv->video_ringbuffer[priv->video_head].timestamp*1e-6;
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1786 memcpy(buffer, priv->video_ringbuffer[priv->video_head].data, len);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1787 priv->video_cnt--;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1788 priv->video_head = (priv->video_head+1)%priv->video_buffer_size_current;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1789 pthread_mutex_unlock(&priv->video_buffer_mutex);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1790
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1791 return interval;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1792 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1793
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1794 static int get_video_framesize(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1795 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1796 /*
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1797 this routine will be called before grab_video_frame
23423
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1798 thus let's return topmost frame's size
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1799 */
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1800 if (priv->video_cnt)
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1801 return priv->video_ringbuffer[priv->video_head].framesize;
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1802 /*
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1803 no video frames yet available. i don't know what to do in this case,
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1804 thus let's return some fallback result (for compressed format this will be
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1805 maximum allowed frame size.
6b18c979dd45 mjpeg support for v4l2 tv:// driver
voroshil
parents: 23422
diff changeset
1806 */
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1807 return priv->format.fmt.pix.sizeimage;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1808 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1809
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1810 //#define DOUBLESPEED
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1811 #ifdef DOUBLESPEED
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1812 // for testing purposes only
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1813 static void read_doublespeed(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1814 {
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 18589
diff changeset
1815 char *bufx = calloc(priv->audio_in.blocksize, 2);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1816 short *s;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1817 short *d;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1818 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1819
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1820 audio_in_read_chunk(&priv->audio_in, bufx);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1821 audio_in_read_chunk(&priv->audio_in, bufx+priv->audio_in.blocksize);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1822
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1823 s = bufx;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1824 d = priv->audio_ringbuffer+priv->audio_tail*priv->audio_in.blocksize;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1825 for (i = 0; i < priv->audio_in.blocksize/2; i++) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1826 *d++ = *s++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1827 *s++;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1828 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1829
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1830 }
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1831 #endif
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1832
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1833 static void *audio_grabber(void *data)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1834 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1835 priv_t *priv = (priv_t*)data;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1836 struct timeval tv;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1837 int i, audio_skew_ptr = 0;
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1838 long long current_time, prev_skew = 0, prev_skew_uncorr = 0;
10852
henry
parents: 10851
diff changeset
1839 long long start_time_avg;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1840
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1841 gettimeofday(&tv, NULL);
10852
henry
parents: 10851
diff changeset
1842 start_time_avg = priv->audio_start_time = (long long)1e6*tv.tv_sec + tv.tv_usec;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1843 audio_in_start_capture(&priv->audio_in);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1844 for (i = 0; i < priv->aud_skew_cnt; i++)
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1845 priv->audio_skew_buffer[i] = 0;
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1846 for (i = 0; i < priv->aud_skew_cnt; i++)
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1847 priv->audio_skew_delta_buffer[i] = 0;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1848
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1849 for (; !priv->shutdown;)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1850 {
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1851 #ifdef DOUBLESPEED
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1852 read_doublespeed(priv);
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1853 #else
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1854 if (audio_in_read_chunk(&priv->audio_in, priv->audio_ringbuffer+priv->audio_tail*priv->audio_in.blocksize) < 0)
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1855 continue;
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1856 #endif
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1857 pthread_mutex_lock(&priv->skew_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1858 if (priv->first_frame == 0) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1859 // there is no first frame yet (unlikely to happen)
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1860 gettimeofday(&tv, NULL);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1861 start_time_avg = priv->audio_start_time = (long long)1e6*tv.tv_sec + tv.tv_usec;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1862 // fprintf(stderr, "warning - first frame not yet available!\n");
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1863 pthread_mutex_unlock(&priv->skew_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1864 continue;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1865 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1866 pthread_mutex_unlock(&priv->skew_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1867
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1868 gettimeofday(&tv, NULL);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1869
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1870 priv->audio_recv_blocks_total++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1871 current_time = (long long)1e6*tv.tv_sec + tv.tv_usec - priv->audio_start_time;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1872
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1873 if (priv->audio_recv_blocks_total < priv->aud_skew_cnt*2) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1874 start_time_avg += (long long)1e6*tv.tv_sec + tv.tv_usec - priv->audio_usecs_per_block*priv->audio_recv_blocks_total;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1875 priv->audio_start_time = start_time_avg/(priv->audio_recv_blocks_total+1);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1876 }
10852
henry
parents: 10851
diff changeset
1877
32352
76f94c00a69f 1000l, %lf is not valid format string for printf (only for scanf) and actually
reimar
parents: 32141
diff changeset
1878 // fprintf(stderr, "spb = %f, bs = %d, skew = %f\n", priv->audio_secs_per_block, priv->audio_in.blocksize,
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1879 // (double)(current_time - 1e6*priv->audio_secs_per_block*priv->audio_recv_blocks_total)/1e6);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1880
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1881 // put the current skew into the ring buffer
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1882 priv->audio_skew_total -= priv->audio_skew_buffer[audio_skew_ptr];
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1883 priv->audio_skew_buffer[audio_skew_ptr] = current_time
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1884 - priv->audio_usecs_per_block*priv->audio_recv_blocks_total;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1885 priv->audio_skew_total += priv->audio_skew_buffer[audio_skew_ptr];
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1886
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1887 pthread_mutex_lock(&priv->skew_mutex);
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1888
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1889 // skew calculation
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1890
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1891 // compute the sliding average of the skews
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1892 if (priv->audio_recv_blocks_total > priv->aud_skew_cnt) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1893 priv->audio_skew = priv->audio_skew_total/priv->aud_skew_cnt;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1894 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1895 priv->audio_skew = priv->audio_skew_total/priv->audio_recv_blocks_total;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1896 }
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1897
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1898 // put the current skew change (skew-prev_skew) into the ring buffer
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1899 priv->audio_skew_delta_total -= priv->audio_skew_delta_buffer[audio_skew_ptr];
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1900 priv->audio_skew_delta_buffer[audio_skew_ptr] = priv->audio_skew - prev_skew_uncorr;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1901 priv->audio_skew_delta_total += priv->audio_skew_delta_buffer[audio_skew_ptr];
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1902 prev_skew_uncorr = priv->audio_skew; // remember the _uncorrected_ average value
10704
1d991eb5cf02 a/v sync cleanups
henry
parents: 10653
diff changeset
1903
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1904 audio_skew_ptr = (audio_skew_ptr+1) % priv->aud_skew_cnt; // rotate the buffer pointer
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1905
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1906 // sliding average approximates the value in the middle of the interval
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1907 // so interpolate the skew value further to the current time
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1908 priv->audio_skew += priv->audio_skew_delta_total/2;
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1909
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1910 // now finally, priv->audio_skew contains fairly good approximation
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1911 // of the current value
10653
d9dfbe5e1011 a/v sync improvements
henry
parents: 10538
diff changeset
1912
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1913 // current skew factor (assuming linearity)
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1914 // used for further interpolation in video_grabber
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1915 // probably overkill but seems to be necessary for
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1916 // stress testing by dropping half of the audio frames ;)
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1917 // especially when using ALSA with large block sizes
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1918 // where audio_skew remains a long while behind
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1919 if ((priv->audio_skew_measure_time != 0) && (current_time - priv->audio_skew_measure_time != 0)) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1920 priv->audio_skew_factor = (double)(priv->audio_skew-prev_skew)/(current_time - priv->audio_skew_measure_time);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1921 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1922 priv->audio_skew_factor = 0.0;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1923 }
10852
henry
parents: 10851
diff changeset
1924
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1925 priv->audio_skew_measure_time = current_time;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1926 prev_skew = priv->audio_skew;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1927 priv->audio_skew += priv->audio_start_time - priv->first_frame;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1928 pthread_mutex_unlock(&priv->skew_mutex);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29121
diff changeset
1929
32352
76f94c00a69f 1000l, %lf is not valid format string for printf (only for scanf) and actually
reimar
parents: 32141
diff changeset
1930 // fprintf(stderr, "audio_skew = %f, delta = %f\n", (double)priv->audio_skew/1e6, (double)priv->audio_skew_delta_total/1e6);
10851
41bad7ce4cc9 yet another sync fix
henry
parents: 10810
diff changeset
1931
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1932 pthread_mutex_lock(&priv->audio_mutex);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1933 if ((priv->audio_tail+1) % priv->audio_buffer_size == priv->audio_head) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1934 mp_msg(MSGT_TV, MSGL_ERR, "\ntoo bad - dropping audio frame !\n");
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1935 priv->audio_drop++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1936 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1937 priv->audio_tail = (priv->audio_tail+1) % priv->audio_buffer_size;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1938 priv->audio_cnt++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1939 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1940 pthread_mutex_unlock(&priv->audio_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1941 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1942 return NULL;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1943 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1944
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1945 static double grab_audio_frame(priv_t *priv, char *buffer, int len)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1946 {
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1947 mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n",
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1948 priv, buffer, len);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1949
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1950 // hack: if grab_audio_frame is called first, it means we are used by mplayer
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1951 // => switch to the mode which outputs audio immediately, even if
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1952 // it should be silence
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1953 if (priv->first) priv->audio_insert_null_samples = 1;
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1954
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1955 pthread_mutex_lock(&priv->audio_mutex);
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1956 while (priv->audio_insert_null_samples
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1957 && priv->dropped_frames_timeshift - priv->dropped_frames_compensated >= priv->audio_usecs_per_block) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1958 // some frames were dropped - drop the corresponding number of audio blocks
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1959 if (priv->audio_drop) {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1960 priv->audio_drop--;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1961 } else {
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1962 if (priv->audio_head == priv->audio_tail) break;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1963 priv->audio_head = (priv->audio_head+1) % priv->audio_buffer_size;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1964 }
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1965 priv->dropped_frames_compensated += priv->audio_usecs_per_block;
10776
80402283a017 Fix immediatemode with mplayer (ie playing both sound and video)
albeu
parents: 10735
diff changeset
1966 }
80402283a017 Fix immediatemode with mplayer (ie playing both sound and video)
albeu
parents: 10735
diff changeset
1967
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1968 // compensate for dropped audio frames
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1969 if (priv->audio_drop && (priv->audio_head == priv->audio_tail)) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1970 priv->audio_drop--;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1971 memset(buffer, 0, len);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1972 goto out;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1973 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1974
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1975 if (priv->audio_insert_null_samples && (priv->audio_head == priv->audio_tail)) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1976 // return silence to avoid desync and stuttering
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1977 memset(buffer, 0, len);
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1978 priv->audio_null_blocks_inserted++;
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1979 goto out;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1980 }
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1981
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1982 pthread_mutex_unlock(&priv->audio_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1983 while (priv->audio_head == priv->audio_tail) {
23151
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1984 // this is mencoder => just wait until some audio is available
d2c6e0c71550 (cosmetics) replace tabs with spaces
voroshil
parents: 22381
diff changeset
1985 usleep(10000);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1986 }
15451
bad4378c5456 10l forgotten comment
henry
parents: 15449
diff changeset
1987 pthread_mutex_lock(&priv->audio_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1988 memcpy(buffer, priv->audio_ringbuffer+priv->audio_head*priv->audio_in.blocksize, len);
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1989 priv->audio_head = (priv->audio_head+1) % priv->audio_buffer_size;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1990 priv->audio_cnt--;
15449
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1991 out:
a7966365a197 improve playback with mplayer -tv immediatemode=0
henry
parents: 15418
diff changeset
1992 pthread_mutex_unlock(&priv->audio_mutex);
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1993 priv->audio_sent_blocks_total++;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1994 return (double)priv->audio_sent_blocks_total*priv->audio_secs_per_block;
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1995 }
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1996
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1997 static int get_audio_framesize(priv_t *priv)
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
1998 {
26756
c43ce7268677 cosmetics: Remove useless parentheses from return statements.
diego
parents: 25962
diff changeset
1999 return priv->audio_in.blocksize;
10536
527e978cb0f8 v4l2 support
henry
parents:
diff changeset
2000 }