24 #undef __STRICT_ANSI__ //workaround due to broken kernel headers
31 #include "libavcodec/dsputil.h"
34 #include <sys/ioctl.h>
37 #define _LINUX_TIME_H 1
38 #include <linux/videodev.h>
49 struct video_capability video_cap;
50 struct video_audio audio_saved;
51 struct video_window video_win;
53 struct video_mbuf gb_buffers;
54 struct video_mmap gb_buf;
80 int desired_palette, desired_depth;
81 struct video_tuner tuner;
82 struct video_audio audio;
83 struct video_picture pict;
87 av_log(s1,
AV_LOG_WARNING,
"V4L input device is deprecated and will be removed in the next release.");
89 if (ap->time_base.den <= 0) {
103 video_fd = open(s1->
filename, O_RDWR);
109 if (ioctl(video_fd, VIDIOCGCAP, &s->
video_cap) < 0) {
114 if (!(s->
video_cap.type & VID_TYPE_CAPTURE)) {
130 desired_palette = -1;
132 for (j = 0; j < vformat_num; j++) {
141 if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
143 ioctl(video_fd, VIDIOCSTUNER, &tuner);
148 ioctl(video_fd, VIDIOCGAUDIO, &audio);
150 audio.flags &= ~VIDEO_AUDIO_MUTE;
151 ioctl(video_fd, VIDIOCSAUDIO, &audio);
153 ioctl(video_fd, VIDIOCGPICT, &pict);
154 av_dlog(s1,
"v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
155 pict.colour, pict.hue, pict.brightness, pict.contrast, pict.whiteness);
157 pict.palette = desired_palette;
158 pict.depth= desired_depth;
159 if (desired_palette == -1 || ioctl(video_fd, VIDIOCSPICT, &pict) < 0) {
160 for (j = 0; j < vformat_num; j++) {
163 if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict))
166 if (j >= vformat_num)
170 if (ioctl(video_fd, VIDIOCGMBUF, &s->
gb_buffers) < 0) {
179 if (ioctl(video_fd, VIDIOCSWIN, s->
video_win) < 0) {
187 if (ioctl(video_fd, VIDIOCCAPTURE, &val) < 0) {
196 if ((
unsigned char*)-1 == s->
video_buf) {
197 s->
video_buf = mmap(0, s->
gb_buffers.size, PROT_READ|PROT_WRITE, MAP_PRIVATE, video_fd, 0);
198 if ((
unsigned char*)-1 == s->
video_buf) {
210 s->
gb_buf.format = pict.palette;
212 if (ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
213 if (errno != EAGAIN) {
223 ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf);
229 for (j = 0; j < vformat_num; j++) {
237 if (j >= vformat_num)
260 while (ioctl(s->
fd, VIDIOCSYNC, &s->
gb_frame) < 0 &&
261 (errno == EAGAIN || errno == EINTR));
268 if (ioctl(s->
fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
285 int64_t curtime, delay;
302 ts.tv_sec = delay / 1000000;
303 ts.tv_nsec = (delay % 1000000) * 1000;
304 nanosleep(&ts,
NULL);
339 {
"standard",
"", offsetof(
VideoData, standard),
AV_OPT_TYPE_INT, {.i64 = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC,
AV_OPT_FLAG_DECODING_PARAM,
"standard" },
355 .
name =
"video4linux,v4l",
362 .priv_class = &v4l_class,