[Ffmpeg-devel] [PATCH] support v4l2 video source and normid input

Limin Wang lance.lmwang
Sat Mar 24 04:45:45 CET 2007


Hi,

* Luca Abeni <lucabe72 at email.it> [2007-03-23 13:01:53 +0100]:

> Hi Limin,
> 
> >failed:\n");
> >+        return AVERROR_IO;
> >+    }
> >+
> Can you put this code in a separate (static) function, and call it here?

OK, fixed.

> 
> >Index: libavformat/avformat.h
> >===================================================================
> >--- libavformat/avformat.h	(revision 8487)
> >+++ libavformat/avformat.h	(working copy)
> >@@ -144,6 +144,8 @@
> > #if LIBAVFORMAT_VERSION_INT < (52<<16)
> >     const char *device; /**< video, audio or DV device */
> > #endif
> >+    int tv_video_input; /**< tv video source input */
> AVFormatParameters already contains a "channel" field that seems to be 
> used only by DV input. Can we reuse it instead of introducing a new 
> "tv_video_input" field?
> 
> In the same way, the "video_channel" variable and "-vc" option in 
> ffmpeg.c can be used for selecting the v4l2 input.
> (as I said, I believe that the "tv_normid" field can be avoided too, and 
> "standard" can be used instead).

That's OK for me, the new patch reuse this options for input. Please review it
again.

Thanks,
Limin
-------------- next part --------------
Index: libavformat/v4l2.c
===================================================================
--- libavformat/v4l2.c	(revision 8491)
+++ libavformat/v4l2.c	(working copy)
@@ -422,6 +422,57 @@
     av_free(s->buf_len);
 }
 
+static int v4l2_set_parameters( AVFormatContext *s1, AVFormatParameters *ap )
+{
+    struct video_data *s = s1->priv_data;
+    struct v4l2_input input;
+    struct v4l2_standard standard;
+    int i;
+
+    /* set tv video input */
+    memset (&input, 0, sizeof (input));
+    input.index = ap->channel;
+    if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
+        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
+        return AVERROR_IO;
+    }
+
+    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
+           ap->channel, input.index, input.name);
+    if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) {
+        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n",
+            ap->channel);
+        return AVERROR_IO;
+    }
+
+    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
+           ap->standard );
+    /* set tv standard */
+    memset (&standard, 0, sizeof (standard));
+    for(i=0;;i++) {
+        standard.index = i;
+        if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+            av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
+                   ap->standard);
+            return AVERROR_IO;
+        }
+
+        if(!strcasecmp(standard.name, ap->standard)) {
+            break;
+        }
+    }
+
+    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %d\n",
+           ap->standard, standard.id);
+    if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
+        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
+            ap->standard);
+        return AVERROR_IO;
+    }
+
+    return 0;
+}
+
 static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
 {
     struct video_data *s = s1->priv_data;
@@ -494,6 +545,9 @@
     }
     s->frame_format = desired_format;
 
+    if( v4l2_set_parameters( s1, ap ) < 0 )
+        return AVERROR_IO;
+
     st->codec->pix_fmt = fmt_v4l2ff(desired_format);
     s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height);
     if (capabilities & V4L2_CAP_STREAMING) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070324/e1361c59/attachment.pgp>



More information about the ffmpeg-devel mailing list