aboutsummaryrefslogtreecommitdiffstats
path: root/libavdevice/v4l2.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-26 03:00:37 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-26 03:28:22 +0200
commit39e4206dc672a596c742809c1466f8643a787208 (patch)
tree36b642fc5221090e5bd8d7bc1968a966a5c6c104 /libavdevice/v4l2.c
parent189db9c9829b970b3e28006c9f00d6960f71cff1 (diff)
parenta2ee2843c09a6116b090020eff8213b86ea98bdb (diff)
downloadffmpeg-39e4206dc672a596c742809c1466f8643a787208.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: (32 commits) doc: create separate section for audio encoders swscale: Remove orphaned, commented-out function declaration. swscale: Eliminate rgb24toyv12_c() duplication. Remove h263_msmpeg4 from MpegEncContext. APIchanges: Fill in git hash for fps_probe_size (30315a8) avformat: Add fpsprobesize as an AVOption. avoptions: Return explicitly NAN or {0,0} if the option isn't found rtmp: Reindent rtmp: Don't try to do av_malloc(0) tty: replace AVFormatParameters.sample_rate abuse with a private option. Fix end time of last chapter in compute_chapters_end ffmpeg: get rid of useless AVInputStream.nb_streams. ffmpeg: simplify managing input files and streams ffmpeg: purge redundant AVInputStream.index. lavf: deprecate AVFormatParameters.channel. libdc1394: add a private option for channel. dv1394: add a private option for channel. v4l2: reindent. v4l2: add a private option for channel. lavf: deprecate AVFormatParameters.standard. ... Conflicts: doc/APIchanges doc/encoders.texi ffmpeg.c libavdevice/alsa-audio.h libavformat/version.h libavutil/opt.c libswscale/rgb2rgb.h libswscale/rgb2rgb_template.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
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,
};