annotate stream/tvi_v4l.c @ 28952:4c44f716c9da

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