From b3da2692115ea17190544883d15efa36219da99e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:21:59 +0200 Subject: v4l2: add a private option for video standard. --- libavdevice/v4l2.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'libavdevice/v4l2.c') diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 8e0a6e64db..dca31a8140 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -44,6 +44,8 @@ #include #include #include "libavutil/imgutils.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" static const int desired_video_buffers = 256; @@ -54,6 +56,7 @@ enum io_method { }; struct video_data { + AVClass *class; int fd; int frame_format; /* V4L2_PIX_FMT_* */ enum io_method io_method; @@ -64,6 +67,7 @@ struct video_data { int buffers; void **buf_start; unsigned int *buf_len; + char *standard; }; struct buff_data { @@ -467,31 +471,37 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) } if (ap->standard) { + av_freep(&s->standard); + s->standard = av_strdup(ap->standard); + } + + if (s->standard) { av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n", - ap->standard); + s->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); + s->standard); return AVERROR(EIO); } - if (!strcasecmp(standard.name, ap->standard)) { + if (!strcasecmp(standard.name, s->standard)) { break; } } av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n", - ap->standard, (uint64_t)standard.id); + s->standard, (uint64_t)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); + s->standard); return AVERROR(EIO); } } + av_freep(&s->standard); if (ap->time_base.num && ap->time_base.den) { av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n", @@ -680,6 +690,18 @@ static int v4l2_read_close(AVFormatContext *s1) return 0; } +static const AVOption options[] = { + { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +static const AVClass v4l2_class = { + .class_name = "V4L2 indev", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_v4l2_demuxer = { "video4linux2", NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"), @@ -689,4 +711,5 @@ AVInputFormat ff_v4l2_demuxer = { v4l2_read_packet, v4l2_read_close, .flags = AVFMT_NOFILE, + .priv_class = &v4l2_class, }; -- cgit v1.2.3 From fc68a8f7030227fc4fa8d83b9051aaf598cd12dd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:40:44 +0200 Subject: lavf: deprecate AVFormatParameters.standard. --- libavdevice/bktr.c | 2 ++ libavdevice/dv1394.c | 2 ++ libavdevice/v4l.c | 2 ++ libavdevice/v4l2.c | 2 ++ libavformat/avformat.h | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) (limited to 'libavdevice/v4l2.c') diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index af184b98d2..821567199e 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -277,6 +277,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->codec->time_base.den = frame_rate; st->codec->time_base.num = frame_rate_base; +#if FF_API_FORMAT_PARAMETERS if (ap->standard) { if (!strcasecmp(ap->standard, "pal")) s->standard = PAL; @@ -285,6 +286,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) else if (!strcasecmp(ap->standard, "ntsc")) s->standard = NTSC; } +#endif if (bktr_init(s1->filename, width, height, s->standard, &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index d0760ef269..2515f78c8f 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -93,12 +93,14 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap if (!dv->dv_demux) goto failed; +#if FF_API_FORMAT_PARAMETERS if (ap->standard) { if (!strcasecmp(ap->standard, "pal")) dv->format = DV1394_PAL; else dv->format = DV1394_NTSC; } +#endif if (ap->channel) dv->channel = ap->channel; diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c index 8c1134536a..54d0394ff5 100644 --- a/libavdevice/v4l.c +++ b/libavdevice/v4l.c @@ -136,6 +136,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) /* set tv standard */ if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) { +#if FF_API_FORMAT_PARAMETERS if (ap->standard) { if (!strcasecmp(ap->standard, "pal")) s->standard = VIDEO_MODE_PAL; @@ -144,6 +145,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) else s->standard = VIDEO_MODE_NTSC; } +#endif tuner.mode = s->standard; ioctl(video_fd, VIDIOCSTUNER, &tuner); } diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index dca31a8140..1c3059d850 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -470,10 +470,12 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) } } +#if FF_API_FORMAT_PARAMETERS if (ap->standard) { av_freep(&s->standard); s->standard = av_strdup(ap->standard); } +#endif if (s->standard) { av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n", diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 64bbd22396..424fc920b4 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -236,8 +236,8 @@ typedef struct AVFormatParameters { int height; enum PixelFormat pix_fmt; int channel; /**< Used to select DV channel. */ - const char *standard; /**< TV standard, NTSC, PAL, SECAM */ #if FF_API_FORMAT_PARAMETERS + attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */ attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */ /**< deprecated, use mpegtsraw demuxer-specific options instead */ attribute_deprecated unsigned int mpeg2ts_compute_pcr:1; -- cgit v1.2.3 From a02fd06ab76c0abd7ef32f332a08177e6014b3a8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:53:44 +0200 Subject: v4l2: add a private option for channel. --- libavdevice/v4l2.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'libavdevice/v4l2.c') diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 1c3059d850..59af2c83ec 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -68,6 +68,7 @@ struct video_data { void **buf_start; unsigned int *buf_len; char *standard; + int channel; }; struct buff_data { @@ -452,23 +453,24 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (ap->channel>=0) { + if (ap->channel > 0) + s->channel = ap->channel; + /* set tv video input */ memset (&input, 0, sizeof (input)); - input.index = ap->channel; + input.index = s->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(EIO); } av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", - ap->channel, input.name); + s->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); + s->channel); return AVERROR(EIO); } - } #if FF_API_FORMAT_PARAMETERS if (ap->standard) { @@ -694,6 +696,7 @@ static int v4l2_read_close(AVFormatContext *s1) static const AVOption options[] = { { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; -- cgit v1.2.3 From 3d2a418605b23b475b4217a93e8e60660154e198 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:23:29 +0200 Subject: v4l2: reindent. --- libavdevice/v4l2.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libavdevice/v4l2.c') diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 59af2c83ec..0385a2c6c0 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -456,21 +456,21 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) if (ap->channel > 0) s->channel = ap->channel; - /* set tv video input */ - memset (&input, 0, sizeof (input)); - input.index = s->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(EIO); - } + /* set tv video input */ + memset (&input, 0, sizeof (input)); + input.index = s->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(EIO); + } - av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", - s->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", - s->channel); - return AVERROR(EIO); - } + av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", + s->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", + s->channel); + return AVERROR(EIO); + } #if FF_API_FORMAT_PARAMETERS if (ap->standard) { -- cgit v1.2.3 From d20576d01b6489e37813302c208df01068418bfb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 22:06:09 +0200 Subject: lavf: deprecate AVFormatParameters.channel. --- libavdevice/dv1394.c | 2 +- libavdevice/libdc1394.c | 2 ++ libavdevice/v4l2.c | 2 ++ libavformat/avformat.h | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) (limited to 'libavdevice/v4l2.c') diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index 0981eff53c..c9b7a69d6f 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -100,10 +100,10 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap else dv->format = DV1394_NTSC; } -#endif if (ap->channel) dv->channel = ap->channel; +#endif /* Open and initialize DV1394 device */ dv->fd = open(context->filename, O_RDONLY); diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index a8406b8c2e..96e9e9b88b 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -159,8 +159,10 @@ static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap) if (dc1394_read_common(c,ap,&fmt,&fps) != 0) return -1; +#if FF_API_FORMAT_PARAMETERS if (ap->channel) dc1394->channel = ap->channel; +#endif /* Now let us prep the hardware. */ dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */ diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 0385a2c6c0..566ee92801 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -453,8 +453,10 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +#if FF_API_FORMAT_PARAMETERS if (ap->channel > 0) s->channel = ap->channel; +#endif /* set tv video input */ memset (&input, 0, sizeof (input)); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 424fc920b4..11dbe8b2de 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -235,8 +235,8 @@ typedef struct AVFormatParameters { int width; int height; enum PixelFormat pix_fmt; - int channel; /**< Used to select DV channel. */ #if FF_API_FORMAT_PARAMETERS + attribute_deprecated int channel; /**< Used to select DV channel. */ attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */ attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */ /**< deprecated, use mpegtsraw demuxer-specific options instead */ -- cgit v1.2.3