annotate libmpdemux/tvi_v4l.c @ 11023:f68acf47c3ed

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