From 5dc8214420e4c48cdf48455329138db752d15cd0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:27:19 +0200 Subject: [PATCH 01/32] lavf: add priv_class field to AVInputFormat. --- libavformat/avformat.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 3d4cc68f89..c29f9baf4d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -425,6 +425,8 @@ typedef struct AVInputFormat { const AVMetadataConv *metadata_conv; #endif + const AVClass *priv_class; ///< AVClass for the private context + /* private fields */ struct AVInputFormat *next; } AVInputFormat; From 17a5556db598ba1e5550d89ae3e339c1161a218a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 30 Apr 2011 13:42:55 +0200 Subject: [PATCH 02/32] mpegts: add compute_pcr option. Deprecate the corresponding AVFormatParameters field. --- libavformat/avformat.h | 7 ++++--- libavformat/mpegts.c | 22 +++++++++++++++++++++- libavformat/version.h | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index c29f9baf4d..7e8cd80aee 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -236,9 +236,10 @@ typedef struct AVFormatParameters { int channel; /**< Used to select DV channel. */ const char *standard; /**< TV standard, NTSC, PAL, SECAM */ unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */ - unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport - stream packet (only meaningful if - mpeg2ts_raw is TRUE). */ +#if FF_API_FORMAT_PARAMETERS + /**< deprecated, use mpegtsraw demuxer-specific options instead */ + attribute_deprecated unsigned int mpeg2ts_compute_pcr:1; +#endif unsigned int initial_pause:1; /**< Do not begin to play the stream immediately (RTSP only). */ unsigned int prealloced_context:1; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index e20d6966e3..20528c5bc4 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -25,6 +25,8 @@ #include "libavutil/crc.h" #include "libavutil/intreadwrite.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" #include "libavcodec/bytestream.h" #include "avformat.h" #include "mpegts.h" @@ -86,6 +88,7 @@ struct Program { }; struct MpegTSContext { + const AVClass *class; /* user data */ AVFormatContext *stream; /** raw packet size, including FEC if present */ @@ -122,6 +125,19 @@ struct MpegTSContext { MpegTSFilter *pids[NB_PID_MAX]; }; +static const AVOption options[] = { + {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), FF_OPT_TYPE_INT, + {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +static const AVClass mpegtsraw_class = { + .class_name = "mpegtsraw demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + /* TS stream handling */ enum MpegTSState { @@ -1455,7 +1471,10 @@ static int mpegts_read_header(AVFormatContext *s, int64_t pos; if (ap) { - ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; +#if FF_API_FORMAT_PARAMETERS + if (ap->mpeg2ts_compute_pcr) + ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; +#endif if(ap->mpeg2ts_raw){ av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n"); return -1; @@ -1878,4 +1897,5 @@ AVInputFormat ff_mpegtsraw_demuxer = { #ifdef USE_SYNCPOINT_SEARCH .read_seek2 = read_seek2, #endif + .priv_class = &mpegtsraw_class, }; diff --git a/libavformat/version.h b/libavformat/version.h index 63f419125b..b4fdb6f8b5 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -68,5 +68,8 @@ #ifndef FF_API_SDP_CREATE #define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54) #endif +#ifndef FF_API_FORMAT_PARAMETERS +#define FF_API_FORMAT_PARAMETERS (LIBAVFORMAT_VERSION_MAJOR < 54) +#endif #endif /* AVFORMAT_VERSION_H */ From fb37d573473d615cc323635fa5bc58fe16d14ee4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:06:14 +0200 Subject: [PATCH 03/32] lavf: deprecate AVFormatParameters.mpeg2ts_raw. It doesn't do anything except produce an error message when set. --- libavformat/avformat.h | 2 +- libavformat/mpegts.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7e8cd80aee..35e6c15f81 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -235,8 +235,8 @@ typedef struct AVFormatParameters { enum PixelFormat pix_fmt; int channel; /**< Used to select DV channel. */ const char *standard; /**< TV standard, NTSC, PAL, SECAM */ - unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */ #if FF_API_FORMAT_PARAMETERS + 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; #endif diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 20528c5bc4..7c0f3818d5 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1470,16 +1470,16 @@ static int mpegts_read_header(AVFormatContext *s, int len; int64_t pos; - if (ap) { #if FF_API_FORMAT_PARAMETERS + if (ap) { if (ap->mpeg2ts_compute_pcr) ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; -#endif if(ap->mpeg2ts_raw){ av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n"); return -1; } } +#endif /* read the first 1024 bytes to get packet size */ pos = avio_tell(pb); From a1a15a9993d45b2ec69e370ea1687dd7cb2b5794 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 19:02:08 +0200 Subject: [PATCH 04/32] sndio: add channels and sample_rate private options. --- libavdevice/sndio_common.h | 2 ++ libavdevice/sndio_dec.c | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libavdevice/sndio_common.h b/libavdevice/sndio_common.h index 41c984ba79..e23b96d146 100644 --- a/libavdevice/sndio_common.h +++ b/libavdevice/sndio_common.h @@ -26,8 +26,10 @@ #include #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 ff2adeb0af..abe13e1359 100644 --- a/libavdevice/sndio_dec.c +++ b/libavdevice/sndio_dec.c @@ -23,6 +23,7 @@ #include #include "libavformat/avformat.h" +#include "libavutil/opt.h" #include "sndio_common.h" @@ -33,16 +34,15 @@ 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 (ap->sample_rate > 0) + s->sample_rate = ap->sample_rate; + if (ap->channels > 0) + s->channels = ap->channels; 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 +97,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 +118,5 @@ AVInputFormat ff_sndio_demuxer = { .read_packet = audio_read_packet, .read_close = audio_read_close, .flags = AVFMT_NOFILE, + .priv_class = &sndio_demuxer_class, }; From 003e63b6df7ba08cce18c1830df9c49dd3f0f391 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 19:02:40 +0200 Subject: [PATCH 05/32] oss: add channels and sample_rate private options. --- libavdevice/oss_audio.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c index 7c4a65dda2..bcd6540021 100644 --- a/libavdevice/oss_audio.c +++ b/libavdevice/oss_audio.c @@ -37,12 +37,14 @@ #include #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; @@ -216,15 +218,15 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) AVStream *st; int ret; - if (ap->sample_rate <= 0 || ap->channels <= 0) - return -1; + if (ap->sample_rate > 0) + s->sample_rate = ap->sample_rate; + if (ap->channels > 0) + s->channels = ap->channels; 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) { @@ -293,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"), @@ -302,6 +317,7 @@ AVInputFormat ff_oss_demuxer = { audio_read_packet, audio_read_close, .flags = AVFMT_NOFILE, + .priv_class = &oss_demuxer_class, }; #endif From 2ea8faf39ff6f21c2faaf8f9bd060a6636ea65fc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 19:03:10 +0200 Subject: [PATCH 06/32] ALSA: add channels and sample_rate private options. --- libavdevice/alsa-audio-dec.c | 37 +++++++++++++++++++++--------------- libavdevice/alsa-audio.h | 4 ++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c index c467fc097f..285d338ff5 100644 --- a/libavdevice/alsa-audio-dec.c +++ b/libavdevice/alsa-audio-dec.c @@ -47,6 +47,7 @@ #include #include "libavformat/avformat.h" +#include "libavutil/opt.h" #include "alsa-audio.h" @@ -56,21 +57,14 @@ 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 (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; st = av_new_stream(s1, 0); if (!st) { @@ -78,10 +72,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 +106,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 +156,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 +178,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 7a1b01811b..32c07426ef 100644 --- a/libavdevice/alsa-audio.h +++ b/libavdevice/alsa-audio.h @@ -33,6 +33,7 @@ #include #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 @@ -40,9 +41,12 @@ #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE) typedef struct { + AVClass *class; snd_pcm_t *h; int frame_size; ///< preferred size for reads and writes int period_size; ///< bytes per sample * channels + int sample_rate; ///< sample rate set by user + int channels; ///< number of channels set by user } AlsaData; /** From 5b3865fc5f9675dd55f7dd7d5ae3b9ed58c3310c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 20:05:55 +0200 Subject: [PATCH 07/32] rawdec: add sample_rate/channels private options. --- libavformat/pcmdec.c | 3 ++- libavformat/rawdec.c | 36 +++++++++++++++++++++++++++++++----- libavformat/rawdec.h | 9 +++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index a5b82789d6..343bbf0ae2 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -50,7 +50,7 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) AVInputFormat ff_pcm_ ## name ## _demuxer = {\ #name,\ NULL_IF_CONFIG_SMALL(long_name),\ - 0,\ + sizeof(RawAudioDemuxerContext),\ NULL,\ ff_raw_read_header,\ raw_read_packet,\ @@ -59,6 +59,7 @@ AVInputFormat ff_pcm_ ## name ## _demuxer = {\ .flags= AVFMT_GENERIC_INDEX,\ .extensions = ext,\ .value = codec,\ + .priv_class = &ff_rawaudio_demuxer_class,\ }; PCMDEF(f64be, "PCM 64 bit floating-point big-endian format", diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 7df63a128c..81a6459307 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -23,6 +23,7 @@ #include "avformat.h" #include "avio_internal.h" #include "rawdec.h" +#include "libavutil/opt.h" /* raw input */ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -43,15 +44,26 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_id = id; switch(st->codec->codec_type) { - case AVMEDIA_TYPE_AUDIO: - st->codec->sample_rate = ap->sample_rate; - if(ap->channels) st->codec->channels = ap->channels; - else st->codec->channels = 1; + case AVMEDIA_TYPE_AUDIO: { + RawAudioDemuxerContext *s1 = s->priv_data; + + if (ap->sample_rate) + st->codec->sample_rate = ap->sample_rate; + if (ap->channels) + st->codec->channels = ap->channels; + else st->codec->channels = 1; + + if (s1->sample_rate) + st->codec->sample_rate = s1->sample_rate; + if (s1->channels) + st->codec->channels = s1->channels; + st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); assert(st->codec->bits_per_coded_sample > 0); st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8; av_set_pts_info(st, 64, 1, st->codec->sample_rate); break; + } case AVMEDIA_TYPE_VIDEO: if(ap->time_base.num) av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); @@ -138,17 +150,31 @@ int ff_raw_video_read_header(AVFormatContext *s, /* Note: Do not forget to add new entries to the Makefile as well. */ +static const AVOption audio_options[] = { + { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { "channels", "", offsetof(RawAudioDemuxerContext, channels), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +const AVClass ff_rawaudio_demuxer_class = { + .class_name = "rawaudio demuxer", + .item_name = av_default_item_name, + .option = audio_options, + .version = LIBAVUTIL_VERSION_INT, +}; + #if CONFIG_G722_DEMUXER AVInputFormat ff_g722_demuxer = { "g722", NULL_IF_CONFIG_SMALL("raw G.722"), - 0, + sizeof(RawAudioDemuxerContext), NULL, ff_raw_read_header, ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "g722,722", .value = CODEC_ID_ADPCM_G722, + .priv_class = &ff_rawaudio_demuxer_class, }; #endif diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index 82672b7b53..e473eb2aac 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -23,6 +23,15 @@ #define AVFORMAT_RAWDEC_H #include "avformat.h" +#include "libavutil/log.h" + +typedef struct RawAudioDemuxerContext { + AVClass *class; + int sample_rate; + int channels; +} RawAudioDemuxerContext; + +extern const AVClass ff_rawaudio_demuxer_class; int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap); From bffd4dd1d36b1e9b9479c81b370c134ffb434e1a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 20:13:28 +0200 Subject: [PATCH 08/32] lavf: deprecate AVFormatParameters.{channels,sample_rate}. --- libavdevice/alsa-audio-dec.c | 2 ++ libavdevice/oss_audio.c | 2 ++ libavdevice/sndio_dec.c | 2 ++ libavformat/avformat.h | 6 ++++-- libavformat/rawdec.c | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c index 285d338ff5..937f6a6ef7 100644 --- a/libavdevice/alsa-audio-dec.c +++ b/libavdevice/alsa-audio-dec.c @@ -60,11 +60,13 @@ static av_cold int audio_read_header(AVFormatContext *s1, enum CodecID codec_id; snd_pcm_sw_params_t *sw_params; +#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) { diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c index bcd6540021..af46ea890b 100644 --- a/libavdevice/oss_audio.c +++ b/libavdevice/oss_audio.c @@ -218,10 +218,12 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) AVStream *st; int ret; +#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) { diff --git a/libavdevice/sndio_dec.c b/libavdevice/sndio_dec.c index abe13e1359..2690ee395c 100644 --- a/libavdevice/sndio_dec.c +++ b/libavdevice/sndio_dec.c @@ -34,10 +34,12 @@ static av_cold int audio_read_header(AVFormatContext *s1, AVStream *st; int ret; +#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) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 35e6c15f81..64bbd22396 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -228,8 +228,10 @@ typedef struct AVProbeData { typedef struct AVFormatParameters { AVRational time_base; - int sample_rate; - int channels; +#if FF_API_FORMAT_PARAMETERS + attribute_deprecated int sample_rate; + attribute_deprecated int channels; +#endif int width; int height; enum PixelFormat pix_fmt; diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 81a6459307..b545dbd6d7 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -47,11 +47,13 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) case AVMEDIA_TYPE_AUDIO: { RawAudioDemuxerContext *s1 = s->priv_data; +#if FF_API_FORMAT_PARAMETERS if (ap->sample_rate) st->codec->sample_rate = ap->sample_rate; if (ap->channels) st->codec->channels = ap->channels; else st->codec->channels = 1; +#endif if (s1->sample_rate) st->codec->sample_rate = s1->sample_rate; From e199eb44fdccd06db7d2c373bc0324351543ded0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 20:45:36 +0200 Subject: [PATCH 09/32] bktr: add a private option for video standard. --- libavdevice/bktr.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index dad5c834f1..af184b98d2 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 # include @@ -47,12 +49,14 @@ #include 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; @@ -276,14 +279,14 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) 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; } - 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 +314,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 +341,5 @@ AVInputFormat ff_bktr_demuxer = { grab_read_packet, grab_read_close, .flags = AVFMT_NOFILE, + .priv_class = &bktr_class, }; From eb040dbbd39898f03e5057a21b0981a8ffe9f37b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 20:58:07 +0200 Subject: [PATCH 10/32] dv1394: add a private option for video standard. --- libavdevice/dv1394.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index 70f928ed80..d0760ef269 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -30,6 +30,8 @@ #include #include +#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,10 +93,12 @@ 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 (ap->standard) { + if (!strcasecmp(ap->standard, "pal")) + dv->format = DV1394_PAL; + else + dv->format = DV1394_NTSC; + } if (ap->channel) dv->channel = ap->channel; @@ -227,6 +232,20 @@ 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" }, + { 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 +253,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, }; From a861ffeffa40dfc4f3d20c221c1accca99db23df Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:21:59 +0200 Subject: [PATCH 11/32] v4l: add a private option for video standard. --- libavdevice/v4l.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c index d97282b7e7..8c1134536a 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 @@ -36,6 +38,7 @@ #include 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,16 @@ 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 (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; + } + tuner.mode = s->standard; ioctl(video_fd, VIDIOCSTUNER, &tuner); } @@ -333,6 +340,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"), @@ -342,4 +364,5 @@ AVInputFormat ff_v4l_demuxer = { grab_read_packet, grab_read_close, .flags = AVFMT_NOFILE, + .priv_class = &v4l_class, }; From b3da2692115ea17190544883d15efa36219da99e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:21:59 +0200 Subject: [PATCH 12/32] v4l2: add a private option for video standard. --- libavdevice/v4l2.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) 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, }; From fc68a8f7030227fc4fa8d83b9051aaf598cd12dd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:40:44 +0200 Subject: [PATCH 13/32] 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(-) 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; From a02fd06ab76c0abd7ef32f332a08177e6014b3a8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:53:44 +0200 Subject: [PATCH 14/32] v4l2: add a private option for channel. --- libavdevice/v4l2.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 }, }; From 3d2a418605b23b475b4217a93e8e60660154e198 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:23:29 +0200 Subject: [PATCH 15/32] v4l2: reindent. --- libavdevice/v4l2.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) 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) { From 986f4f491840d7c440ef4ccde7adcef219be26f3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 21:55:44 +0200 Subject: [PATCH 16/32] dv1394: add a private option for channel. --- libavdevice/dv1394.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index 2515f78c8f..0981eff53c 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -104,8 +104,6 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap if (ap->channel) dv->channel = ap->channel; - else - dv->channel = DV1394_DEFAULT_CHANNEL; /* Open and initialize DV1394 device */ dv->fd = open(context->filename, O_RDONLY); @@ -238,6 +236,7 @@ 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 }, }; From 79405e57dc1a1e2746c87cba677052d742dbb7ee Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 22:01:36 +0200 Subject: [PATCH 17/32] libdc1394: add a private option for channel. --- libavdevice/libdc1394.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index e637af5f74..a8406b8c2e 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 @@ -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,9 @@ static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap) if (dc1394_read_common(c,ap,&fmt,&fps) != 0) return -1; + if (ap->channel) + dc1394->channel = ap->channel; + /* Now let us prep the hardware. */ dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */ if (!dc1394->handle) { @@ -162,11 +169,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 +243,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 +377,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 +389,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 From d20576d01b6489e37813302c208df01068418bfb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 22:06:09 +0200 Subject: [PATCH 18/32] 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(-) 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 */ From d2bc4da15becf40c54e37af045963e3d13db5d8d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 21:54:06 +0200 Subject: [PATCH 19/32] ffmpeg: purge redundant AVInputStream.index. AVStream.index stores the same thing. --- ffmpeg.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 86732535c8..ddc48c2354 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -307,7 +307,6 @@ static int nb_output_streams_for_file[MAX_FILES] = { 0 }; typedef struct AVInputStream { int file_index; - int index; AVStream *st; int discard; /* true if stream data should be discarded */ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ @@ -802,7 +801,7 @@ need_realloc: if ((ost->audio_resample && !ost->resample) || resample_changed) { if (resample_changed) { av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n", - ist->file_index, ist->index, + ist->file_index, ist->st->index, ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels, dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels); ost->resample_sample_fmt = dec->sample_fmt; @@ -1165,7 +1164,7 @@ static void do_video_out(AVFormatContext *s, if (resample_changed) { av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", - ist->file_index, ist->index, + ist->file_index, ist->st->index, ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt), dec->width , dec->height , avcodec_get_pix_fmt_name(dec->pix_fmt)); if(!ost->video_resample) @@ -1974,7 +1973,6 @@ static int transcode(AVFormatContext **output_files, ist = ist_table[j++]; ist->st = is->streams[k]; ist->file_index = i; - ist->index = k; ist->discard = 1; /* the stream is discarded by default (changed later) */ @@ -2345,7 +2343,7 @@ static int transcode(AVFormatContext **output_files, codec = avcodec_find_decoder(ist->st->codec->codec_id); if (!codec) { snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d", - ist->st->codec->codec_id, ist->file_index, ist->index); + ist->st->codec->codec_id, ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } @@ -2362,7 +2360,7 @@ static int transcode(AVFormatContext **output_files, if (avcodec_open(ist->st->codec, codec) < 0) { snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d", - ist->file_index, ist->index); + ist->file_index, ist->st->index); ret = AVERROR(EINVAL); goto dump_format; } @@ -2498,13 +2496,13 @@ static int transcode(AVFormatContext **output_files, ost = ost_table[i]; fprintf(stderr, " Stream #%d.%d -> #%d.%d", ist_table[ost->source_index]->file_index, - ist_table[ost->source_index]->index, + ist_table[ost->source_index]->st->index, ost->file_index, ost->index); if (ost->sync_ist != ist_table[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, - ost->sync_ist->index); + ost->sync_ist->st->index); fprintf(stderr, "\n"); } } @@ -2643,12 +2641,12 @@ static int transcode(AVFormatContext **output_files, goto discard_packet; } - //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size); + //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size); if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { if (verbose >= 0) fprintf(stderr, "Error while decoding stream #%d.%d\n", - ist->file_index, ist->index); + ist->file_index, ist->st->index); if (exit_on_error) ffmpeg_exit(1); av_free_packet(&pkt); From 07633154add3cf59f281ba0c9eb689df4284e2cb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 22:12:35 +0200 Subject: [PATCH 20/32] ffmpeg: simplify managing input files and streams Grow the file and stream list in opt_input_file() instead of creating it all at once in transcode(). This is simpler and will be useful for following commits. --- ffmpeg.c | 163 +++++++++++++++++++++++-------------------------------- 1 file changed, 68 insertions(+), 95 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index ddc48c2354..17e95de8cd 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -105,11 +105,9 @@ static const OptionDef options[]; #define FFM_PACKET_SIZE 4096 //XXX a duplicate of the line in ffm.h static const char *last_asked_format = NULL; -static AVFormatContext *input_files[MAX_FILES]; static int64_t input_files_ts_offset[MAX_FILES]; static double *input_files_ts_scale[MAX_FILES] = {NULL}; static AVCodec **input_codecs = NULL; -static int nb_input_files = 0; static int nb_input_codecs = 0; static int nb_input_files_ts_scale[MAX_FILES] = {0}; @@ -327,12 +325,18 @@ typedef struct AVInputStream { } AVInputStream; typedef struct AVInputFile { + AVFormatContext *ctx; int eof_reached; /* true if eof reached */ int ist_index; /* index of first stream in ist_table */ int buffer_size; /* current total buffer size */ int nb_streams; /* nb streams we are aware of */ } AVInputFile; +static AVInputStream *input_streams = NULL; +static int nb_input_streams = 0; +static AVInputFile *input_files = NULL; +static int nb_input_files = 0; + #if CONFIG_AVFILTER static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost) @@ -462,7 +466,7 @@ static int ffmpeg_exit(int ret) av_free(output_streams_for_file[i]); } for(i=0;inb_streams; - j += is->nb_streams; - } - nb_istreams = j; - - ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *)); - if (!ist_table) - goto fail; - - for(i=0;inb_streams;k++) { - ist = ist_table[j++]; - ist->st = is->streams[k]; - ist->file_index = i; - ist->discard = 1; /* the stream is discarded by default - (changed later) */ - - if (rate_emu) { - ist->start = av_gettime(); - } - } - } + if (rate_emu) + for (i = 0; i < nb_input_streams; i++) + input_streams[i].start = av_gettime(); /* output stream init */ nb_ostreams = 0; @@ -2006,7 +1976,7 @@ static int transcode(AVFormatContext **output_files, int si = stream_maps[i].stream_index; if (fi < 0 || fi > nb_input_files - 1 || - si < 0 || si > file_table[fi].nb_streams - 1) { + si < 0 || si > input_files[fi].nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; @@ -2014,7 +1984,7 @@ static int transcode(AVFormatContext **output_files, fi = stream_maps[i].sync_file_index; si = stream_maps[i].sync_stream_index; if (fi < 0 || fi > nb_input_files - 1 || - si < 0 || si > file_table[fi].nb_streams - 1) { + si < 0 || si > input_files[fi].nb_streams - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; @@ -2032,11 +2002,11 @@ static int transcode(AVFormatContext **output_files, ost = ost_table[n] = output_streams_for_file[k][i]; ost->st = os->streams[i]; if (nb_stream_maps > 0) { - ost->source_index = file_table[stream_maps[n].file_index].ist_index + + ost->source_index = input_files[stream_maps[n].file_index].ist_index + stream_maps[n].stream_index; /* Sanity check that the stream types match */ - if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) { + if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) { int i= ost->file_index; av_dump_format(output_files[i], i, output_files[i]->filename, 1); fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", @@ -2049,12 +2019,12 @@ static int transcode(AVFormatContext **output_files, int best_nb_frames=-1; /* get corresponding input stream index : we select the first one with the right type */ found = 0; - for(j=0;jfile_index ]; + AVFormatContext *f = input_files[ist->file_index].ctx; skip=1; for(pi=0; pinb_programs; pi++){ AVProgram *p= f->programs[pi]; @@ -2078,8 +2048,8 @@ static int transcode(AVFormatContext **output_files, if (!found) { if(! opt_programid) { /* try again and reuse existing stream */ - for(j=0;jst->codec->codec_type == ost->st->codec->codec_type && ist->st->discard != AVDISCARD_ALL) { ost->source_index = j; @@ -2096,10 +2066,10 @@ static int transcode(AVFormatContext **output_files, } } } - ist = ist_table[ost->source_index]; + ist = &input_streams[ost->source_index]; ist->discard = 0; ost->sync_ist = (nb_stream_maps > 0) ? - ist_table[file_table[stream_maps[n].sync_file_index].ist_index + + &input_streams[input_files[stream_maps[n].sync_file_index].ist_index + stream_maps[n].sync_stream_index] : ist; } } @@ -2108,7 +2078,7 @@ static int transcode(AVFormatContext **output_files, for(i=0;ifile_index]; - ist = ist_table[ost->source_index]; + ist = &input_streams[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; @@ -2306,7 +2276,7 @@ static int transcode(AVFormatContext **output_files, ost = ost_table[i]; if (ost->encoding_needed) { AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL; - AVCodecContext *dec = ist_table[ost->source_index]->st->codec; + AVCodecContext *dec = input_streams[ost->source_index].st->codec; if (!codec) codec = avcodec_find_encoder(ost->st->codec->codec_id); if (!codec) { @@ -2335,8 +2305,8 @@ static int transcode(AVFormatContext **output_files, } /* open each decoder */ - for(i=0;idecoding_needed) { AVCodec *codec = i < nb_input_codecs ? input_codecs[i] : NULL; if (!codec) @@ -2370,9 +2340,9 @@ static int transcode(AVFormatContext **output_files, } /* init pts */ - for(i=0;ist; ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; ist->next_pts = AV_NOPTS_VALUE; @@ -2402,7 +2372,7 @@ static int transcode(AVFormatContext **output_files, METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file") files[0] = output_files[out_file_index]; - files[1] = input_files[in_file_index]; + files[1] = input_files[in_file_index].ctx; for (j = 0; j < 2; j++) { AVMetaDataMap *map = &meta_data_maps[i][j]; @@ -2433,7 +2403,7 @@ static int transcode(AVFormatContext **output_files, if (metadata_global_autocopy) { for (i = 0; i < nb_output_files; i++) - av_metadata_copy(&output_files[i]->metadata, input_files[0]->metadata, + av_metadata_copy(&output_files[i]->metadata, input_files[0].ctx->metadata, AV_METADATA_DONT_OVERWRITE); } @@ -2460,7 +2430,7 @@ static int transcode(AVFormatContext **output_files, /* copy chapters from the first input file that has them*/ if (!nb_chapter_maps) for (i = 0; i < nb_input_files; i++) { - if (!input_files[i]->nb_chapters) + if (!input_files[i].ctx->nb_chapters) continue; for (j = 0; j < nb_output_files; j++) @@ -2495,11 +2465,11 @@ static int transcode(AVFormatContext **output_files, for(i=0;i #%d.%d", - ist_table[ost->source_index]->file_index, - ist_table[ost->source_index]->st->index, + input_streams[ost->source_index].file_index, + input_streams[ost->source_index].st->index, ost->file_index, ost->index); - if (ost->sync_ist != ist_table[ost->source_index]) + if (ost->sync_ist != &input_streams[ost->source_index]) fprintf(stderr, " [sync #%d.%d]", ost->sync_ist->file_index, ost->sync_ist->st->index); @@ -2539,12 +2509,12 @@ static int transcode(AVFormatContext **output_files, double ipts, opts; ost = ost_table[i]; os = output_files[ost->file_index]; - ist = ist_table[ost->source_index]; + ist = &input_streams[ost->source_index]; if(ist->is_past_recording_time || no_packet[ist->file_index]) continue; opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = (double)ist->pts; - if (!file_table[ist->file_index].eof_reached){ + if (!input_files[ist->file_index].eof_reached){ if(ipts < ipts_min) { ipts_min = ipts; if(input_sync ) file_index = ist->file_index; @@ -2575,7 +2545,7 @@ static int transcode(AVFormatContext **output_files, break; /* read a frame from it and output it in the fifo */ - is = input_files[file_index]; + is = input_files[file_index].ctx; ret= av_read_frame(is, &pkt); if(ret == AVERROR(EAGAIN)){ no_packet[file_index]=1; @@ -2583,7 +2553,7 @@ static int transcode(AVFormatContext **output_files, continue; } if (ret < 0) { - file_table[file_index].eof_reached = 1; + input_files[file_index].eof_reached = 1; if (opt_shortest) break; else @@ -2599,10 +2569,10 @@ static int transcode(AVFormatContext **output_files, } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ - if (pkt.stream_index >= file_table[file_index].nb_streams) + if (pkt.stream_index >= input_files[file_index].nb_streams) goto discard_packet; - ist_index = file_table[file_index].ist_index + pkt.stream_index; - ist = ist_table[ist_index]; + ist_index = input_files[file_index].ist_index + pkt.stream_index; + ist = &input_streams[ist_index]; if (ist->discard) goto discard_packet; @@ -2661,8 +2631,8 @@ static int transcode(AVFormatContext **output_files, } /* at the end of stream, we must flush the decoder buffers */ - for(i=0;idecoding_needed) { output_packet(ist, i, ost_table, nb_ostreams, NULL); } @@ -2692,8 +2662,8 @@ static int transcode(AVFormatContext **output_files, } /* close each decoder */ - for(i=0;idecoding_needed) { avcodec_close(ist->st->codec); } @@ -2704,15 +2674,7 @@ static int transcode(AVFormatContext **output_files, fail: av_freep(&bit_buffer); - av_free(file_table); - if (ist_table) { - for(i=0;inb_streams;i++) { AVStream *st = ic->streams[i]; AVCodecContext *dec = st->codec; + AVInputStream *ist; + dec->thread_count = thread_count; input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1); + + input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1); + ist = &input_streams[nb_input_streams - 1]; + ist->st = st; + ist->file_index = nb_input_files; + ist->discard = 1; + switch (dec->codec_type) { case AVMEDIA_TYPE_AUDIO: input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(audio_codec_name); @@ -3343,13 +3314,15 @@ static void opt_input_file(const char *filename) } } - input_files[nb_input_files] = ic; input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp); /* dump the file content */ if (verbose >= 0) av_dump_format(ic, nb_input_files, filename, 0); - nb_input_files++; + input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); + input_files[nb_input_files - 1].ctx = ic; + input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; + input_files[nb_input_files - 1].nb_streams = ic->nb_streams; video_channel = 0; @@ -3374,7 +3347,7 @@ static void check_inputs(int *has_video_ptr, has_data = 0; for(j=0;jnb_streams;i++) { AVCodecContext *enc = ic->streams[i]->codec; switch(enc->codec_type) { @@ -4070,9 +4043,9 @@ static void opt_target(const char *arg) /* Try to determine PAL/NTSC by peeking in the input files */ if(nb_input_files) { int i, j; - for(j = 0; j < nb_input_files; j++) { - for(i = 0; i < input_files[j]->nb_streams; i++) { - AVCodecContext *c = input_files[j]->streams[i]->codec; + for (j = 0; j < nb_input_files; j++) { + for (i = 0; i < input_files[j].ctx->nb_streams; i++) { + AVCodecContext *c = input_files[j].ctx->streams[i]->codec; if(c->codec_type != AVMEDIA_TYPE_VIDEO) continue; fr = c->time_base.den * 1000 / c->time_base.num; From 2cf8355f98681bdd726b739008acd5483f82f8d7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 17:19:54 +0200 Subject: [PATCH 21/32] ffmpeg: get rid of useless AVInputStream.nb_streams. It's a duplicate of AVFormatContext.nb_streams. --- ffmpeg.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 17e95de8cd..25192dedec 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -329,7 +329,6 @@ typedef struct AVInputFile { int eof_reached; /* true if eof reached */ int ist_index; /* index of first stream in ist_table */ int buffer_size; /* current total buffer size */ - int nb_streams; /* nb streams we are aware of */ } AVInputFile; static AVInputStream *input_streams = NULL; @@ -1976,7 +1975,7 @@ static int transcode(AVFormatContext **output_files, int si = stream_maps[i].stream_index; if (fi < 0 || fi > nb_input_files - 1 || - si < 0 || si > input_files[fi].nb_streams - 1) { + si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; @@ -1984,7 +1983,7 @@ static int transcode(AVFormatContext **output_files, fi = stream_maps[i].sync_file_index; si = stream_maps[i].sync_stream_index; if (fi < 0 || fi > nb_input_files - 1 || - si < 0 || si > input_files[fi].nb_streams - 1) { + si < 0 || si > input_files[fi].ctx->nb_streams - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); ret = AVERROR(EINVAL); goto fail; @@ -2569,7 +2568,7 @@ static int transcode(AVFormatContext **output_files, } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ - if (pkt.stream_index >= input_files[file_index].nb_streams) + if (pkt.stream_index >= input_files[file_index].ctx->nb_streams) goto discard_packet; ist_index = input_files[file_index].ist_index + pkt.stream_index; ist = &input_streams[ist_index]; @@ -3322,7 +3321,6 @@ static void opt_input_file(const char *filename) input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); input_files[nb_input_files - 1].ctx = ic; input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; - input_files[nb_input_files - 1].nb_streams = ic->nb_streams; video_channel = 0; From 656566d7a4fef9680e483f1015d4cc242d825202 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Mon, 23 May 2011 14:26:54 -0700 Subject: [PATCH 22/32] Fix end time of last chapter in compute_chapters_end Parenthesis are misplaced in calculation of max_time. Signed-off-by: Anton Khirnov --- libavformat/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index ad226016aa..8cdd8b3805 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2110,7 +2110,7 @@ enum CodecID av_codec_get_id(const AVCodecTag * const *tags, unsigned int tag) static void compute_chapters_end(AVFormatContext *s) { unsigned int i, j; - int64_t max_time = s->duration + (s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time; + int64_t max_time = s->duration + ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); for (i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->end == AV_NOPTS_VALUE) { From 67540af7baa5c4064753861be217ac8f7c8df997 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 23 May 2011 19:23:55 +0200 Subject: [PATCH 23/32] tty: replace AVFormatParameters.sample_rate abuse with a private option. --- libavformat/tty.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libavformat/tty.c b/libavformat/tty.c index ea8d0c7ece..bc6058d857 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -26,12 +26,13 @@ #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" #include "avformat.h" #include "sauce.h" -#define LINE_RATE 6000 /* characters per second */ - typedef struct { + AVClass *class; int chars_per_frame; uint64_t fsize; /**< file size less metadata buffer */ } TtyDemuxContext; @@ -86,7 +87,11 @@ static int read_header(AVFormatContext *avctx, } /* simulate tty display speed */ - s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1); +#if FF_API_FORMAT_PARAMETERS + if (ap->sample_rate) + s->chars_per_frame = ap->sample_rate; +#endif + s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1); if (avctx->pb->seekable) { s->fsize = avio_size(avctx->pb); @@ -124,6 +129,18 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return 0; } +static const AVOption options[] = { + { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, + { NULL }, +}; + +static const AVClass tty_demuxer_class = { + .class_name = "TTY demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_tty_demuxer = { .name = "tty", .long_name = NULL_IF_CONFIG_SMALL("Tele-typewriter"), @@ -131,4 +148,5 @@ AVInputFormat ff_tty_demuxer = { .read_header = read_header, .read_packet = read_packet, .extensions = "ans,art,asc,diz,ice,nfo,txt,vt", + .priv_class = &tty_demuxer_class, }; From 271c869cc3285dac2b6f2663a87c70bf3ba2b04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 25 May 2011 19:08:29 +0300 Subject: [PATCH 24/32] rtmp: Don't try to do av_malloc(0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some received packets can have size 0. The return value from av_malloc(0) may be NULL, which is ok if the size was 0. On OS X, however, the returned pointer is non-null but leads to crashes when trying to free it. Signed-off-by: Martin Storsjö --- libavformat/rtmppkt.c | 2 ++ libavformat/rtmpproto.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index 63b0628799..93790eb525 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -233,9 +233,11 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size) { + if (size) { pkt->data = av_malloc(size); if (!pkt->data) return AVERROR(ENOMEM); + } pkt->data_size = size; pkt->channel_id = channel_id; pkt->type = type; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 70e4b142d6..f499bd3b71 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -683,7 +683,7 @@ static int get_packet(URLContext *s, int for_header) return AVERROR_EOF; for (;;) { - RTMPPacket rpkt; + RTMPPacket rpkt = { 0 }; if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt, rt->chunk_size, rt->prev_pkt[0])) <= 0) { if (ret == 0) { From 48b1fb1397281dd16df909b6f33c2c36e5626f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 25 May 2011 22:01:15 +0300 Subject: [PATCH 25/32] rtmp: Reindent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtmppkt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index 93790eb525..35ef7fdaae 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -234,9 +234,9 @@ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size) { if (size) { - pkt->data = av_malloc(size); - if (!pkt->data) - return AVERROR(ENOMEM); + pkt->data = av_malloc(size); + if (!pkt->data) + return AVERROR(ENOMEM); } pkt->data_size = size; pkt->channel_id = channel_id; From 80068da3a0bafc7e24ce6b1f91cefec7d793b4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 25 May 2011 16:47:09 +0300 Subject: [PATCH 26/32] avoptions: Return explicitly NAN or {0,0} if the option isn't found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This actually matches what av_get_double did earlier, the 0.0/0.0 division was intentional, for producing NAN. Still keeping the check for the return value from av_get_number, for clarity. Signed-off-by: Martin Storsjö --- libavutil/opt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 9e06b01c52..74c39fee5f 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -291,7 +291,7 @@ double av_get_double(void *obj, const char *name, const AVOption **o_out) int den=1; if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0) - return -1; + return NAN; return num*intnum/den; } @@ -302,7 +302,7 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out) int den=1; if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0) - return (AVRational){-1, 0}; + return (AVRational){0, 0}; if (num == 1.0 && (int)intnum == intnum) return (AVRational){intnum, den}; else From 30315a8d9c9bea98d54260956db58b6df56f9347 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Mon, 9 May 2011 14:34:23 -0700 Subject: [PATCH 27/32] avformat: Add fpsprobesize as an AVOption. --- doc/APIchanges | 3 +++ libavformat/avformat.h | 5 +++++ libavformat/options.c | 1 + libavformat/utils.c | 2 ++ libavformat/version.h | 4 ++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 853975e76d..a99b798d80 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-05-25 - XXXXXXX - lavf 53.1.0 - avformat.h + Add fps_probe_size to AVFormatContext. + 2011-05-18 - 64150ff - lavc 53.4.0 - AVCodecContext.request_sample_fmt Add request_sample_fmt field to AVCodecContext. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 11dbe8b2de..3a652a354b 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -817,6 +817,11 @@ typedef struct AVFormatContext { * - decoding: Unused. */ int64_t start_time_realtime; + + /** + * decoding: number of frames used to probe fps + */ + int fps_probe_size; } AVFormatContext; typedef struct AVPacketList { diff --git a/libavformat/options.c b/libavformat/options.c index 22807c3058..377ba93b44 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -57,6 +57,7 @@ static const AVOption options[]={ {"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"}, {"ts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"}, {"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D}, +{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), FF_OPT_TYPE_INT, -1, -1, INT_MAX-1, D}, {NULL}, }; diff --git a/libavformat/utils.c b/libavformat/utils.c index 8cdd8b3805..89ab1086fe 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2229,6 +2229,8 @@ int av_find_stream_info(AVFormatContext *ic) the correct fps */ if (av_q2d(st->time_base) > 0.0005) fps_analyze_framecount *= 2; + if (ic->fps_probe_size >= 0) + fps_analyze_framecount = ic->fps_probe_size; /* variable fps and no guess at the real fps */ if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num) && st->info->duration_count < fps_analyze_framecount diff --git a/libavformat/version.h b/libavformat/version.h index b4fdb6f8b5..b2ac6d8181 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -24,8 +24,8 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 0 -#define LIBAVFORMAT_VERSION_MICRO 3 +#define LIBAVFORMAT_VERSION_MINOR 1 +#define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ From 19a686b8a373e93807880c63bd73303616c96b71 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 25 May 2011 12:36:41 -0700 Subject: [PATCH 28/32] APIchanges: Fill in git hash for fps_probe_size (30315a8) --- doc/APIchanges | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index a99b798d80..90dd0ec10e 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,7 +13,7 @@ libavutil: 2011-04-18 API changes, most recent first: -2011-05-25 - XXXXXXX - lavf 53.1.0 - avformat.h +2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h Add fps_probe_size to AVFormatContext. 2011-05-18 - 64150ff - lavc 53.4.0 - AVCodecContext.request_sample_fmt From 8c51620f219db0f408d2833c3e5d56cedaf0d95a Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 24 May 2011 16:28:45 -0700 Subject: [PATCH 29/32] Remove h263_msmpeg4 from MpegEncContext. It was long ago superseded by msmpeg4_version. --- libavcodec/h263dec.c | 8 +------- libavcodec/mpegvideo.c | 2 +- libavcodec/mpegvideo.h | 2 -- libavcodec/mpegvideo_enc.c | 8 ++------ 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index fee5d32240..e2627fa8e4 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -69,33 +69,27 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) case CODEC_ID_MPEG4: break; case CODEC_ID_MSMPEG4V1: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=1; break; case CODEC_ID_MSMPEG4V2: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=2; break; case CODEC_ID_MSMPEG4V3: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=3; break; case CODEC_ID_WMV1: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=4; break; case CODEC_ID_WMV2: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=5; break; case CODEC_ID_VC1: case CODEC_ID_WMV3: - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=6; avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; @@ -655,7 +649,7 @@ retry: decode_slice(s); } - if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) + if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){ s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; } diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 09e813476a..f24e11910a 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1986,7 +1986,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } /* add dct residue */ - if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO + if(s->encoding || !( s->msmpeg4_version || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index b4afee29f9..6d5ab19283 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -207,7 +207,6 @@ typedef struct MpegEncContext { /* the following codec id fields are deprecated in favor of codec_id */ int h263_plus; ///< h263 plus headers - int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead) int h263_flv; ///< use flv h263 header enum CodecID codec_id; /* see CODEC_ID_xxx */ @@ -831,4 +830,3 @@ void ff_wmv2_encode_mb(MpegEncContext * s, int motion_x, int motion_y); #endif /* AVCODEC_MPEGVIDEO_H */ - diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 8df05c4c7a..a212149189 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -639,7 +639,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_MSMPEG4V2: s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 2; @@ -648,7 +647,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_MSMPEG4V3: s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 3; @@ -658,7 +656,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_WMV1: s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 4; @@ -668,7 +665,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_WMV2: s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; s->h263_pred = 1; s->unrestricted_mv = 1; s->msmpeg4_version= 5; @@ -2771,7 +2767,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) /* we need to initialize some time vars before we can encode b-frames */ // RAL: Condition added for MPEG1VIDEO - if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) + if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->msmpeg4_version)) set_frame_distances(s); if(CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4) ff_set_mpeg4_time(s); @@ -2940,7 +2936,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) case FMT_H263: if (CONFIG_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2) ff_wmv2_encode_picture_header(s, picture_number); - else if (CONFIG_MSMPEG4_ENCODER && s->h263_msmpeg4) + else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) msmpeg4_encode_picture_header(s, picture_number); else if (CONFIG_MPEG4_ENCODER && s->h263_pred) mpeg4_encode_picture_header(s, picture_number); From 7dc303a60ef7205d88a11ddbcb251f3237a3945e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 25 May 2011 20:49:52 +0200 Subject: [PATCH 30/32] swscale: Eliminate rgb24toyv12_c() duplication. Signed-off-by: Michael Niedermayer Signed-off-by: Diego Biurrun --- libswscale/rgb2rgb.h | 4 +++ libswscale/rgb2rgb_template.c | 8 ++---- libswscale/x86/rgb2rgb_template.c | 47 +------------------------------ 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h index a8d5531cb8..4dd0d95674 100644 --- a/libswscale/rgb2rgb.h +++ b/libswscale/rgb2rgb.h @@ -68,6 +68,10 @@ void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size); void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size); void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size); +void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, + uint8_t *vdst, long width, long height, long lumStride, + long chromStride, long srcStride); + /** * Height should be a multiple of 2 and width should be a multiple of 16. * (If this is a problem for anyone then tell me, and I will fix it.) diff --git a/libswscale/rgb2rgb_template.c b/libswscale/rgb2rgb_template.c index ea39be4f13..fed7e5e195 100644 --- a/libswscale/rgb2rgb_template.c +++ b/libswscale/rgb2rgb_template.c @@ -633,11 +633,9 @@ static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst, * others are ignored in the C version. * FIXME: Write HQ version. */ -static inline void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, - uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, - long srcStride) +void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, + uint8_t *vdst, long width, long height, long lumStride, + long chromStride, long srcStride) { long y; const int chromWidth = width >> 1; diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c index a083fc8674..ce635dfde4 100644 --- a/libswscale/x86/rgb2rgb_template.c +++ b/libswscale/x86/rgb2rgb_template.c @@ -1976,52 +1976,7 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_ SFENCE" \n\t" :::"memory"); - for (; y>RGB2YUV_SHIFT) + 16; - unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128; - unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128; - - udst[i] = U; - vdst[i] = V; - ydst[2*i] = Y; - - b = src[6*i+3]; - g = src[6*i+4]; - r = src[6*i+5]; - - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; - } - ydst += lumStride; - src += srcStride; - - for (i=0; i>RGB2YUV_SHIFT) + 16; - - ydst[2*i] = Y; - - b = src[6*i+3]; - g = src[6*i+4]; - r = src[6*i+5]; - - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; - } - udst += chromStride; - vdst += chromStride; - ydst += lumStride; - src += srcStride; - } + rgb24toyv12_c(src, ydst, udst, vdst, width, height-y, lumStride, chromStride, srcStride); } static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dest, From 6f7a280eadd719d0a5c9b72b63dfca61bb9605f5 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 25 May 2011 22:07:55 +0200 Subject: [PATCH 31/32] swscale: Remove orphaned, commented-out function declaration. --- libswscale/rgb2rgb.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h index 4dd0d95674..6d6154b23b 100644 --- a/libswscale/rgb2rgb.h +++ b/libswscale/rgb2rgb.h @@ -72,14 +72,6 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, long width, long height, long lumStride, long chromStride, long srcStride); -/** - * Height should be a multiple of 2 and width should be a multiple of 16. - * (If this is a problem for anyone then tell me, and I will fix it.) - * Chrominance data is only taken from every second line, others are ignored. - * FIXME: Write high quality version. - */ -//void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - /** * Height should be a multiple of 2 and width should be a multiple of 16. * (If this is a problem for anyone then tell me, and I will fix it.) From a2ee2843c09a6116b090020eff8213b86ea98bdb Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 19 May 2011 19:41:19 +0200 Subject: [PATCH 32/32] doc: create separate section for audio encoders Having a separate section for audio encoders simplifies navigation and is slightly more consistent with the rest of the manual. Signed-off-by: Diego Biurrun --- doc/encoders.texi | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 760ec4bad9..d507b66f51 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -17,11 +17,15 @@ with the options @code{--enable-encoder=@var{ENCODER}} / The option @code{-codecs} of the ff* tools will display the list of enabled encoders. -A description of some of the currently available encoders follows. +@c man end ENCODERS + +@chapter Audio Encoders +@c man begin AUDIO ENCODERS -@section Audio Encoders +A description of some of the currently available audio encoders +follows. -@subsection ac3 and ac3_fixed +@section ac3 and ac3_fixed AC-3 audio encoders. @@ -36,7 +40,7 @@ quality audio for a given bitrate. The @var{ac3_fixed} encoder is not the default codec for any of the output formats, so it must be specified explicitly using the option @code{-acodec ac3_fixed} in order to use it. -@subheading AC-3 Metadata +@subsection AC-3 Metadata The AC-3 metadata options are used to set parameters that describe the audio, but in most cases do not affect the audio encoding itself. Some of the options @@ -55,7 +59,7 @@ documents. @item @uref{http://www.dolby.com/uploadedFiles/zz-_Shared_Assets/English_PDFs/Professional/46_DDEncodingGuidelines.pdf,Dolby Digital Professional Encoding Guidelines} @end itemize -@subsubheading Metadata Control Options +@subsubsection Metadata Control Options @table @option @@ -72,7 +76,7 @@ Metadata values can be changed before encoding each frame. @end table -@subsubheading Downmix Levels +@subsubsection Downmix Levels @table @option @@ -106,7 +110,7 @@ Silence Surround Channel(s) @end table -@subsubheading Audio Production Information +@subsubsection Audio Production Information Audio Production Information is optional information describing the mixing environment. Either none or both of the fields are written to the bitstream. @@ -140,7 +144,7 @@ Small Room @end table -@subsubheading Other Metadata Options +@subsubsection Other Metadata Options @table @option @@ -195,7 +199,7 @@ Original Source (default) @end table -@subsubheading Extended Bitstream Information +@subsection Extended Bitstream Information The extended bitstream options are part of the Alternate Bit Stream Syntax as specified in Annex D of the A/52:2010 standard. It is grouped into 2 parts. If any one parameter in a group is specified, all values in that group will be @@ -205,7 +209,7 @@ will use these values instead of the ones specified in the @code{center_mixlev} and @code{surround_mixlev} options if it supports the Alternate Bit Stream Syntax. -@subsubheading Extended Bitstream Information - Part 1 +@subsubsection Extended Bitstream Information - Part 1 @table @option @@ -302,7 +306,7 @@ Silence Surround Channel(s) @end table -@subsubheading Extended Bitstream Information - Part 2 +@subsubsection Extended Bitstream Information - Part 2 @table @option @@ -353,7 +357,7 @@ HDCD A/D Converter @end table -@subheading Other AC-3 Encoding Options +@subsection Other AC-3 Encoding Options @table @option @@ -408,4 +412,4 @@ Selected by Encoder (default) @end table -@c man end ENCODERS +@c man end AUDIO ENCODERS