summaryrefslogtreecommitdiff
path: root/libavdevice/v4l2.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavdevice/v4l2.c')
-rw-r--r--libavdevice/v4l2.c70
1 files changed, 50 insertions, 20 deletions
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 1f1a4bcfb8..a0fc99242e 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -44,6 +44,8 @@
#include <time.h>
#include <strings.h>
#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,8 @@ struct video_data {
int buffers;
void **buf_start;
unsigned int *buf_len;
+ char *standard;
+ int channel;
};
struct buff_data {
@@ -448,50 +453,61 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (ap->channel>=0) {
- /* 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(EIO);
- }
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->channel > 0)
+ s->channel = ap->channel;
+#endif
- 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(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);
}
+#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",
- 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 +696,19 @@ 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 },
+ { "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 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 +718,5 @@ AVInputFormat ff_v4l2_demuxer = {
v4l2_read_packet,
v4l2_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &v4l2_class,
};