24 #undef __STRICT_ANSI__ //workaround due to broken kernel headers
34 #include <sys/ioctl.h>
37 #define _LINUX_TIME_H 1
38 #include <linux/videodev.h>
50 struct video_capability video_cap;
51 struct video_audio audio_saved;
52 struct video_window video_win;
54 struct video_mbuf gb_buffers;
55 struct video_mmap gb_buf;
81 int desired_palette, desired_depth;
82 struct video_tuner tuner;
83 struct video_audio audio;
84 struct video_picture pict;
88 av_log(s1,
AV_LOG_WARNING,
"V4L input device is deprecated and will be removed in the next release.");
90 if (ap->time_base.den <= 0) {
104 video_fd = open(s1->
filename, O_RDWR);
110 if (ioctl(video_fd, VIDIOCGCAP, &s->
video_cap) < 0) {
115 if (!(s->
video_cap.type & VID_TYPE_CAPTURE)) {
131 desired_palette = -1;
133 for (j = 0; j < vformat_num; j++) {
142 if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
144 ioctl(video_fd, VIDIOCSTUNER, &tuner);
149 ioctl(video_fd, VIDIOCGAUDIO, &audio);
151 audio.flags &= ~VIDEO_AUDIO_MUTE;
152 ioctl(video_fd, VIDIOCSAUDIO, &audio);
154 ioctl(video_fd, VIDIOCGPICT, &pict);
155 av_dlog(s1,
"v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
156 pict.colour, pict.hue, pict.brightness, pict.contrast, pict.whiteness);
158 pict.palette = desired_palette;
159 pict.depth= desired_depth;
160 if (desired_palette == -1 || ioctl(video_fd, VIDIOCSPICT, &pict) < 0) {
161 for (j = 0; j < vformat_num; j++) {
164 if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict))
167 if (j >= vformat_num)
171 if (ioctl(video_fd, VIDIOCGMBUF, &s->
gb_buffers) < 0) {
180 if (ioctl(video_fd, VIDIOCSWIN, s->
video_win) < 0) {
188 if (ioctl(video_fd, VIDIOCCAPTURE, &val) < 0) {
197 if ((
unsigned char*)-1 == s->
video_buf) {
198 s->
video_buf = mmap(0, s->
gb_buffers.size, PROT_READ|PROT_WRITE, MAP_PRIVATE, video_fd, 0);
199 if ((
unsigned char*)-1 == s->
video_buf) {
211 s->
gb_buf.format = pict.palette;
213 if (ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
214 if (errno != EAGAIN) {
224 ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf);
230 for (j = 0; j < vformat_num; j++) {
238 if (j >= vformat_num)
261 while (ioctl(s->
fd, VIDIOCSYNC, &s->
gb_frame) < 0 &&
262 (errno == EAGAIN || errno == EINTR));
269 if (ioctl(s->
fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
286 int64_t curtime, delay;
303 ts.tv_sec = delay / 1000000;
304 ts.tv_nsec = (delay % 1000000) * 1000;
305 nanosleep(&ts, NULL);
340 {
"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,