aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLimin Wang <lance.lmwang@gmail.com>2007-03-29 06:32:54 +0000
committerLuca Abeni <lucabe72@email.it>2007-03-29 06:32:54 +0000
commitf5ad81f5272186e69e9eda256fb4a0baf730686c (patch)
tree1a141370cd20c02d24429bdb46935c6c926f2f31
parent4992d8bf7ddee25641e25e939f616628c64b36c3 (diff)
downloadffmpeg-f5ad81f5272186e69e9eda256fb4a0baf730686c.tar.gz
Allow setting v4l2 input and video standard.
Patch by Limin Wang (lance.lmwang AT gmail DOT com) Originally committed as revision 8542 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/v4l2.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libavformat/v4l2.c b/libavformat/v4l2.c
index ef661ae2ff..aeaac33472 100644
--- a/libavformat/v4l2.c
+++ b/libavformat/v4l2.c
@@ -422,6 +422,57 @@ static void mmap_close(struct video_data *s)
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.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: %"PRIu64"\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 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
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) {