Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-26 05:00:37 +0400
committerMichael Niedermayer <michaelni@gmx.at>2011-05-26 05:28:22 +0400
commit39e4206dc672a596c742809c1466f8643a787208 (patch)
tree36b642fc5221090e5bd8d7bc1968a966a5c6c104 /libavdevice
parent189db9c9829b970b3e28006c9f00d6960f71cff1 (diff)
parenta2ee2843c09a6116b090020eff8213b86ea98bdb (diff)
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')
-rw-r--r--libavdevice/alsa-audio-dec.c39
-rw-r--r--libavdevice/alsa-audio.h4
-rw-r--r--libavdevice/bktr.c34
-rw-r--r--libavdevice/dv1394.c35
-rw-r--r--libavdevice/libdc1394.c33
-rw-r--r--libavdevice/oss_audio.c26
-rw-r--r--libavdevice/sndio_common.h2
-rw-r--r--libavdevice/sndio_dec.c26
-rw-r--r--libavdevice/v4l.c39
-rw-r--r--libavdevice/v4l2.c70
10 files changed, 241 insertions, 67 deletions
diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c
index 8ee0e52642..24abc7c187 100644
--- a/libavdevice/alsa-audio-dec.c
+++ b/libavdevice/alsa-audio-dec.c
@@ -47,6 +47,7 @@
#include <alsa/asoundlib.h>
#include "libavformat/avformat.h"
+#include "libavutil/opt.h"
#include "alsa-audio.h"
@@ -56,21 +57,16 @@ static av_cold int audio_read_header(AVFormatContext *s1,
AlsaData *s = s1->priv_data;
AVStream *st;
int ret;
- unsigned int sample_rate;
enum CodecID codec_id;
snd_pcm_sw_params_t *sw_params;
- if (ap->sample_rate <= 0) {
- av_log(s1, AV_LOG_ERROR, "Bad sample rate %d\n", ap->sample_rate);
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->sample_rate > 0)
+ s->sample_rate = ap->sample_rate;
- return AVERROR(EIO);
- }
-
- if (ap->channels <= 0) {
- av_log(s1, AV_LOG_ERROR, "Bad channels number %d\n", ap->channels);
-
- return AVERROR(EIO);
- }
+ if (ap->channels > 0)
+ s->channels = ap->channels;
+#endif
st = av_new_stream(s1, 0);
if (!st) {
@@ -78,10 +74,9 @@ static av_cold int audio_read_header(AVFormatContext *s1,
return AVERROR(ENOMEM);
}
- sample_rate = ap->sample_rate;
codec_id = s1->audio_codec_id;
- ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &sample_rate, ap->channels,
+ ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels,
&codec_id);
if (ret < 0) {
return AVERROR(EIO);
@@ -113,8 +108,8 @@ static av_cold int audio_read_header(AVFormatContext *s1,
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = codec_id;
- st->codec->sample_rate = sample_rate;
- st->codec->channels = ap->channels;
+ st->codec->sample_rate = s->sample_rate;
+ st->codec->channels = s->channels;
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
return 0;
@@ -163,6 +158,19 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
return 0;
}
+static const AVOption options[] = {
+ { "sample_rate", "", offsetof(AlsaData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(AlsaData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass alsa_demuxer_class = {
+ .class_name = "ALSA demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_alsa_demuxer = {
"alsa",
NULL_IF_CONFIG_SMALL("ALSA audio input"),
@@ -172,4 +180,5 @@ AVInputFormat ff_alsa_demuxer = {
audio_read_packet,
ff_alsa_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &alsa_demuxer_class,
};
diff --git a/libavdevice/alsa-audio.h b/libavdevice/alsa-audio.h
index 8c7c516585..a7a000c18c 100644
--- a/libavdevice/alsa-audio.h
+++ b/libavdevice/alsa-audio.h
@@ -33,6 +33,7 @@
#include <alsa/asoundlib.h>
#include "config.h"
#include "libavformat/avformat.h"
+#include "libavutil/log.h"
/* XXX: we make the assumption that the soundcard accepts this format */
/* XXX: find better solution with "preinit" method, needed also in
@@ -42,12 +43,15 @@
typedef void (*ff_reorder_func)(const void *, void *, int);
typedef struct {
+ AVClass *class;
snd_pcm_t *h;
int frame_size; ///< preferred size for reads and writes
int period_size; ///< bytes per sample * channels
ff_reorder_func reorder_func;
void *reorder_buf;
int reorder_buf_size; ///< in frames
+ int sample_rate; ///< sample rate set by user
+ int channels; ///< number of channels set by user
} AlsaData;
/**
diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index 6378ce7873..0e57258f14 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -25,6 +25,8 @@
*/
#include "libavformat/avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#if HAVE_DEV_BKTR_IOCTL_METEOR_H && HAVE_DEV_BKTR_IOCTL_BT848_H
# include <dev/bktr/ioctl_meteor.h>
# include <dev/bktr/ioctl_bt848.h>
@@ -47,12 +49,14 @@
#include <strings.h>
typedef struct {
+ AVClass *class;
int video_fd;
int tuner_fd;
int width, height;
int frame_rate;
int frame_rate_base;
uint64_t per_frame;
+ int standard;
} VideoData;
@@ -245,7 +249,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
int width, height;
int frame_rate;
int frame_rate_base;
- int format = -1;
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
return -1;
@@ -274,16 +277,18 @@ 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"))
- format = PAL;
+ s->standard = PAL;
else if (!strcasecmp(ap->standard, "secam"))
- format = SECAM;
+ s->standard = SECAM;
else if (!strcasecmp(ap->standard, "ntsc"))
- format = NTSC;
+ s->standard = NTSC;
}
+#endif
- if (bktr_init(s1->filename, width, height, format,
+ if (bktr_init(s1->filename, width, height, s->standard,
&(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0)
return AVERROR(EIO);
@@ -311,6 +316,24 @@ static int grab_read_close(AVFormatContext *s1)
return 0;
}
+static const AVOption options[] = {
+ { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "SECAM", "", 0, FF_OPT_TYPE_CONST, {.dbl = SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PALN", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALN}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PALM", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSCJ", "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { NULL },
+};
+
+static const AVClass bktr_class = {
+ .class_name = "BKTR grab interface",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_bktr_demuxer = {
"bktr",
NULL_IF_CONFIG_SMALL("video grab"),
@@ -320,4 +343,5 @@ AVInputFormat ff_bktr_demuxer = {
grab_read_packet,
grab_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &bktr_class,
};
diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c
index a9bc058dc9..7fa73bdf95 100644
--- a/libavdevice/dv1394.c
+++ b/libavdevice/dv1394.c
@@ -30,6 +30,8 @@
#include <time.h>
#include <strings.h>
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "libavformat/avformat.h"
#undef DV1394_DEBUG
@@ -38,6 +40,7 @@
#include "dv1394.h"
struct dv1394_data {
+ AVClass *class;
int fd;
int channel;
int format;
@@ -90,15 +93,17 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
if (!dv->dv_demux)
goto failed;
- if (ap->standard && !strcasecmp(ap->standard, "pal"))
- dv->format = DV1394_PAL;
- else
- dv->format = DV1394_NTSC;
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->standard) {
+ if (!strcasecmp(ap->standard, "pal"))
+ dv->format = DV1394_PAL;
+ else
+ dv->format = DV1394_NTSC;
+ }
if (ap->channel)
dv->channel = ap->channel;
- else
- dv->channel = DV1394_DEFAULT_CHANNEL;
+#endif
/* Open and initialize DV1394 device */
dv->fd = open(context->filename, O_RDONLY);
@@ -227,6 +232,21 @@ static int dv1394_close(AVFormatContext * context)
return 0;
}
+static const AVOption options[] = {
+ { "standard", "", offsetof(struct dv1394_data, format), FF_OPT_TYPE_INT, {.dbl = DV1394_NTSC}, DV1394_PAL, DV1394_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "channel", "", offsetof(struct dv1394_data, channel), FF_OPT_TYPE_INT, {.dbl = DV1394_DEFAULT_CHANNEL}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass dv1394_class = {
+ .class_name = "DV1394 indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_dv1394_demuxer = {
.name = "dv1394",
.long_name = NULL_IF_CONFIG_SMALL("DV1394 A/V grab"),
@@ -234,5 +254,6 @@ AVInputFormat ff_dv1394_demuxer = {
.read_header = dv1394_read_header,
.read_packet = dv1394_read_packet,
.read_close = dv1394_close,
- .flags = AVFMT_NOFILE
+ .flags = AVFMT_NOFILE,
+ .priv_class = &dv1394_class,
};
diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c
index abd82dc981..838f01993a 100644
--- a/libavdevice/libdc1394.c
+++ b/libavdevice/libdc1394.c
@@ -22,6 +22,8 @@
#include "config.h"
#include "libavformat/avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#if HAVE_LIBDC1394_2
#include <dc1394/dc1394.h>
@@ -45,9 +47,11 @@
#undef free
typedef struct dc1394_data {
+ AVClass *class;
#if HAVE_LIBDC1394_1
raw1394handle_t handle;
dc1394_cameracapture camera;
+ int channel;
#elif HAVE_LIBDC1394_2
dc1394_t *d;
dc1394camera_t *camera;
@@ -155,6 +159,11 @@ 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 */
if (!dc1394->handle) {
@@ -162,11 +171,11 @@ static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
goto out;
}
camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
- if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) {
- av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel);
+ if (!camera_nodes || camera_nodes[dc1394->channel] == DC1394_NO_CAMERA) {
+ av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", dc1394->channel);
goto out_handle;
}
- res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel],
+ res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[dc1394->channel],
0,
FORMAT_VGA_NONCOMPRESSED,
fmt->frame_size_id,
@@ -236,6 +245,20 @@ static int dc1394_v1_close(AVFormatContext * context)
return 0;
}
+static const AVOption options[] = {
+#if HAVE_LIBDC1394_1
+ { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+#endif
+ { NULL },
+};
+
+static const AVClass libdc1394_class = {
+ .class_name = "libdc1394 indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
#elif HAVE_LIBDC1394_2
static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
@@ -356,6 +379,7 @@ AVInputFormat ff_libdc1394_demuxer = {
.read_packet = dc1394_v2_read_packet,
.read_close = dc1394_v2_close,
.flags = AVFMT_NOFILE
+ .priv_class = &libdc1394_class,
};
#endif
@@ -367,6 +391,7 @@ AVInputFormat ff_libdc1394_demuxer = {
.read_header = dc1394_v1_read_header,
.read_packet = dc1394_v1_read_packet,
.read_close = dc1394_v1_close,
- .flags = AVFMT_NOFILE
+ .flags = AVFMT_NOFILE,
+ .priv_class = &libdc1394_class,
};
#endif
diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c
index fc5d3c3dd1..66c303272e 100644
--- a/libavdevice/oss_audio.c
+++ b/libavdevice/oss_audio.c
@@ -37,12 +37,14 @@
#include <sys/select.h>
#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#define AUDIO_BLOCK_SIZE 4096
typedef struct {
+ AVClass *class;
int fd;
int sample_rate;
int channels;
@@ -214,15 +216,17 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
AVStream *st;
int ret;
- if (ap->sample_rate <= 0 || ap->channels <= 0)
- return -1;
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->sample_rate > 0)
+ s->sample_rate = ap->sample_rate;
+ if (ap->channels > 0)
+ s->channels = ap->channels;
+#endif
st = av_new_stream(s1, 0);
if (!st) {
return AVERROR(ENOMEM);
}
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
ret = audio_open(s1, 0, s1->filename);
if (ret < 0) {
@@ -291,6 +295,19 @@ static int audio_read_close(AVFormatContext *s1)
}
#if CONFIG_OSS_INDEV
+static const AVOption options[] = {
+ { "sample_rate", "", offsetof(AudioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(AudioData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass oss_demuxer_class = {
+ .class_name = "OSS demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_oss_demuxer = {
"oss",
NULL_IF_CONFIG_SMALL("Open Sound System capture"),
@@ -300,6 +317,7 @@ AVInputFormat ff_oss_demuxer = {
audio_read_packet,
audio_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &oss_demuxer_class,
};
#endif
diff --git a/libavdevice/sndio_common.h b/libavdevice/sndio_common.h
index 485bf93240..1d0039564e 100644
--- a/libavdevice/sndio_common.h
+++ b/libavdevice/sndio_common.h
@@ -26,8 +26,10 @@
#include <sndio.h>
#include "libavformat/avformat.h"
+#include "libavutil/log.h"
typedef struct {
+ AVClass *class;
struct sio_hdl *hdl;
enum CodecID codec_id;
int64_t hwpos;
diff --git a/libavdevice/sndio_dec.c b/libavdevice/sndio_dec.c
index 9582b5490e..3014fd2787 100644
--- a/libavdevice/sndio_dec.c
+++ b/libavdevice/sndio_dec.c
@@ -23,6 +23,7 @@
#include <sndio.h>
#include "libavformat/avformat.h"
+#include "libavutil/opt.h"
#include "sndio_common.h"
@@ -33,16 +34,17 @@ static av_cold int audio_read_header(AVFormatContext *s1,
AVStream *st;
int ret;
- if (ap->sample_rate <= 0 || ap->channels <= 0)
- return AVERROR(EINVAL);
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->sample_rate > 0)
+ s->sample_rate = ap->sample_rate;
+ if (ap->channels > 0)
+ s->channels = ap->channels;
+#endif
st = av_new_stream(s1, 0);
if (!st)
return AVERROR(ENOMEM);
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
-
ret = ff_sndio_open(s1, 0, s1->filename);
if (ret < 0)
return ret;
@@ -97,6 +99,19 @@ static av_cold int audio_read_close(AVFormatContext *s1)
return 0;
}
+static const AVOption options[] = {
+ { "sample_rate", "", offsetof(SndioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "channels", "", offsetof(SndioData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass sndio_demuxer_class = {
+ .class_name = "sndio indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_sndio_demuxer = {
.name = "sndio",
.long_name = NULL_IF_CONFIG_SMALL("sndio audio capture"),
@@ -105,4 +120,5 @@ AVInputFormat ff_sndio_demuxer = {
.read_packet = audio_read_packet,
.read_close = audio_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &sndio_demuxer_class,
};
diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c
index 9a155f9df6..a49ca8005f 100644
--- a/libavdevice/v4l.c
+++ b/libavdevice/v4l.c
@@ -23,6 +23,8 @@
#include "config.h"
#include "libavutil/rational.h"
#include "libavutil/imgutils.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include "libavformat/avformat.h"
#include "libavcodec/dsputil.h"
#include <unistd.h>
@@ -36,6 +38,7 @@
#include <strings.h>
typedef struct {
+ AVClass *class;
int fd;
int frame_format; /* see VIDEO_PALETTE_xxx */
int use_mmap;
@@ -49,6 +52,7 @@ typedef struct {
struct video_mbuf gb_buffers;
struct video_mmap gb_buf;
int gb_frame;
+ int standard;
} VideoData;
static const struct {
@@ -131,13 +135,18 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
/* set tv standard */
- if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
- if (!strcasecmp(ap->standard, "pal"))
- tuner.mode = VIDEO_MODE_PAL;
- else if (!strcasecmp(ap->standard, "secam"))
- tuner.mode = VIDEO_MODE_SECAM;
- else
- tuner.mode = VIDEO_MODE_NTSC;
+ if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
+#if FF_API_FORMAT_PARAMETERS
+ if (ap->standard) {
+ if (!strcasecmp(ap->standard, "pal"))
+ s->standard = VIDEO_MODE_PAL;
+ else if (!strcasecmp(ap->standard, "secam"))
+ s->standard = VIDEO_MODE_SECAM;
+ else
+ s->standard = VIDEO_MODE_NTSC;
+ }
+#endif
+ tuner.mode = s->standard;
ioctl(video_fd, VIDIOCSTUNER, &tuner);
}
@@ -339,6 +348,21 @@ static int grab_read_close(AVFormatContext *s1)
return 0;
}
+static const AVOption options[] = {
+ { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "SECAM", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { "NTSC", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
+ { NULL },
+};
+
+static const AVClass v4l_class = {
+ .class_name = "V4L indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_v4l_demuxer = {
"video4linux",
NULL_IF_CONFIG_SMALL("Video4Linux device grab"),
@@ -348,4 +372,5 @@ AVInputFormat ff_v4l_demuxer = {
grab_read_packet,
grab_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &v4l_class,
};
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,
};