From 0b950fe240936fa48fd41204bcfd04f35bbf39c3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 14:10:49 +0200 Subject: [PATCH 01/17] lavc: introduce avcodec_open2() as a replacement for avcodec_open(). Adds support for decoder-private options and makes setting other options simpler. --- ffprobe.c | 2 +- ffserver.c | 2 +- libavcodec/avcodec.h | 39 ++++++++++++++++++++++++++++++++++++++ libavcodec/mpegvideo_enc.c | 2 +- libavcodec/utils.c | 24 ++++++++++++++++++++++- libavcodec/version.h | 3 +++ libavfilter/vsrc_movie.c | 2 +- 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/ffprobe.c b/ffprobe.c index edda454cde..cb4a4c3106 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -291,7 +291,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) { fprintf(stderr, "Unsupported codec with id %d for input stream %d\n", stream->codec->codec_id, stream->index); - } else if (avcodec_open(stream->codec, codec) < 0) { + } else if (avcodec_open2(stream->codec, codec, NULL) < 0) { fprintf(stderr, "Error while opening codec for input stream %d\n", stream->index); } diff --git a/ffserver.c b/ffserver.c index b4deb8ffd0..a12d7082b6 100644 --- a/ffserver.c +++ b/ffserver.c @@ -2117,7 +2117,7 @@ static void open_parser(AVFormatContext *s, int i) codec = avcodec_find_decoder(st->codec->codec_id); if (codec && (codec->capabilities & CODEC_CAP_PARSE_ONLY)) { st->codec->parse_only = 1; - if (avcodec_open(st->codec, codec) < 0) + if (avcodec_open2(st->codec, codec, NULL) < 0) st->codec->parse_only = 0; } } diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b26bac7bef..ba0c636292 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -30,6 +30,7 @@ #include "libavutil/samplefmt.h" #include "libavutil/avutil.h" #include "libavutil/cpu.h" +#include "libavutil/dict.h" #include "libavutil/log.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" @@ -3619,6 +3620,7 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); //FIXME func typedef +#if FF_API_AVCODEC_OPEN /** * Initialize the AVCodecContext to use the given AVCodec. Prior to using this * function the context has to be allocated. @@ -3645,8 +3647,45 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, * @param codec The codec to use within the context. * @return zero on success, a negative value on error * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close + * + * @deprecated use avcodec_open2 */ +attribute_deprecated int avcodec_open(AVCodecContext *avctx, AVCodec *codec); +#endif + +/** + * Initialize the AVCodecContext to use the given AVCodec. Prior to using this + * function the context has to be allocated with avcodec_alloc_context(). + * + * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), + * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for + * retrieving a codec. + * + * @warning This function is not thread safe! + * + * @code + * avcodec_register_all(); + * av_dict_set(&opts, "b", "2.5M", 0); + * codec = avcodec_find_decoder(CODEC_ID_H264); + * if (!codec) + * exit(1); + * + * context = avcodec_alloc_context(); + * + * if (avcodec_open(context, codec, opts) < 0) + * exit(1); + * @endcode + * + * @param avctx The context to initialize. + * @param options A dictionary filled with AVCodecContext and codec-private options. + * On return this object will be filled with options that were not found. + * + * @return zero on success, a negative value on error + * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(), + * av_dict_set(), av_opt_find(). + */ +int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options); /** * Decode the audio frame of size avpkt->size from avpkt->data into samples. diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 73bcc5b229..f298993c0c 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -973,7 +973,7 @@ static int estimate_best_b_count(MpegEncContext *s){ c->time_base= s->avctx->time_base; c->max_b_frames= s->max_b_frames; - if (avcodec_open(c, codec) < 0) + if (avcodec_open2(c, codec, NULL) < 0) return -1; for(i=0; imax_b_frames+2; i++){ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 722f758231..5ad0c51d02 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -32,6 +32,7 @@ #include "libavutil/audioconvert.h" #include "libavutil/imgutils.h" #include "libavutil/samplefmt.h" +#include "libavutil/dict.h" #include "avcodec.h" #include "dsputil.h" #include "libavutil/opt.h" @@ -467,9 +468,20 @@ AVFrame *avcodec_alloc_frame(void){ return pic; } +#if FF_API_AVCODEC_OPEN int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) +{ + return avcodec_open2(avctx, codec, NULL); +} +#endif + +int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) { int ret = 0; + AVDictionary *tmp = NULL; + + if (options) + av_dict_copy(&tmp, *options, 0); /* If there is a user-supplied mutex locking routine, call it. */ if (ff_lockmgr_cb) { @@ -496,14 +508,18 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ret = AVERROR(ENOMEM); goto end; } - if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3() + if (codec->priv_class) { *(AVClass**)avctx->priv_data= codec->priv_class; av_opt_set_defaults(avctx->priv_data); } } + if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp) < 0)) + goto free_and_end; } else { avctx->priv_data = NULL; } + if ((ret = av_opt_set_dict(avctx, &tmp)) < 0) + goto free_and_end; if(avctx->coded_width && avctx->coded_height) avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); @@ -615,8 +631,14 @@ end: if (ff_lockmgr_cb) { (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); } + if (options) { + av_dict_free(options); + *options = tmp; + } + return ret; free_and_end: + av_dict_free(&tmp); av_freep(&avctx->priv_data); avctx->codec= NULL; goto end; diff --git a/libavcodec/version.h b/libavcodec/version.h index aded68e83e..f4a0ecd868 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -68,5 +68,8 @@ #ifndef FF_API_GET_PIX_FMT_NAME #define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_AVCODEC_OPEN +#define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 7556fa2e9e..bd74f95545 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -139,7 +139,7 @@ static int movie_init(AVFilterContext *ctx) return AVERROR(EINVAL); } - if ((ret = avcodec_open(movie->codec_ctx, codec)) < 0) { + if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n"); return ret; } From a67c061e0f3b55ffcc96f336fc0998e44b86c8e4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 22 May 2011 19:24:59 +0200 Subject: [PATCH 02/17] lavf: add avformat_find_stream_info() It supports passing options to codecs. --- libavfilter/vsrc_movie.c | 2 +- libavformat/avformat.h | 27 +++++++++++++++++++++++++++ libavformat/utils.c | 18 +++++++++++++----- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index bd74f95545..b018ba7418 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -96,7 +96,7 @@ static int movie_init(AVFilterContext *ctx) "Failed to avformat_open_input '%s'\n", movie->file_name); return ret; } - if ((ret = av_find_stream_info(movie->format_ctx)) < 0) + if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0) av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n"); // if seeking requested, we execute it diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 2cdf11be12..6e861de262 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1093,6 +1093,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma */ AVFormatContext *avformat_alloc_context(void); +#if FF_API_FORMAT_PARAMETERS /** * Read packets of a media file to get stream information. This * is useful for file formats with no headers such as MPEG. This @@ -1105,8 +1106,34 @@ AVFormatContext *avformat_alloc_context(void); * @return >=0 if OK, AVERROR_xxx on error * @todo Let the user decide somehow what information is needed so that * we do not waste time getting stuff the user does not need. + * + * @deprecated use avformat_find_stream_info. */ int av_find_stream_info(AVFormatContext *ic); +#endif + +/** + * Read packets of a media file to get stream information. This + * is useful for file formats with no headers such as MPEG. This + * function also computes the real framerate in case of MPEG-2 repeat + * frame mode. + * The logical file position is not changed by this function; + * examined packets may be buffered for later processing. + * + * @param ic media file handle + * @param options If non-NULL, an ic.nb_streams long array of pointers to + * dictionaries, where i-th member contains options for + * codec corresponding to i-th stream. + * On return each dictionary will be filled with options that were not found. + * @return >=0 if OK, AVERROR_xxx on error + * + * @note this function isn't guaranteed to open all the codecs, so + * options being non-empty at return is a perfectly normal behavior. + * + * @todo Let the user decide somehow what information is needed so that + * we do not waste time getting stuff the user does not need. + */ +int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options); /** * Find the "best" stream in the file. diff --git a/libavformat/utils.c b/libavformat/utils.c index e38d9efa60..a3825a0c93 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2074,7 +2074,7 @@ static int has_decode_delay_been_guessed(AVStream *st) st->codec_info_nb_frames >= 6 + st->codec->has_b_frames; } -static int try_decode_frame(AVStream *st, AVPacket *avpkt) +static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options) { int16_t *samples; AVCodec *codec; @@ -2085,7 +2085,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt) codec = avcodec_find_decoder(st->codec->codec_id); if (!codec) return -1; - ret = avcodec_open(st->codec, codec); + ret = avcodec_open2(st->codec, codec, options); if (ret < 0) return ret; } @@ -2204,12 +2204,20 @@ static int tb_unreliable(AVCodecContext *c){ return 0; } +#if FF_API_FORMAT_PARAMETERS int av_find_stream_info(AVFormatContext *ic) +{ + return avformat_find_stream_info(ic, NULL); +} +#endif + +int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { int i, count, ret, read_size, j; AVStream *st; AVPacket pkt1, *pkt; int64_t old_offset = avio_tell(ic->pb); + int orig_nb_streams = ic->nb_streams; // new streams might appear, no options for those for(i=0;inb_streams;i++) { AVCodec *codec; @@ -2235,12 +2243,12 @@ int av_find_stream_info(AVFormatContext *ic) /* Ensure that subtitle_header is properly set. */ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && codec && !st->codec->codec) - avcodec_open(st->codec, codec); + avcodec_open2(st->codec, codec, options ? &options[i] : NULL); //try to just open decoders, in case this is enough to get parameters if(!has_codec_parameters(st->codec)){ if (codec && !st->codec->codec) - avcodec_open(st->codec, codec); + avcodec_open2(st->codec, codec, options ? &options[i] : NULL); } } @@ -2383,7 +2391,7 @@ int av_find_stream_info(AVFormatContext *ic) !has_decode_delay_been_guessed(st) || (st->codec->codec && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF)) - try_decode_frame(st, pkt); + try_decode_frame(st, pkt, (options && i <= orig_nb_streams )? &options[i] : NULL); st->codec_info_nb_frames++; count++; From 9b83919f44eb1c87dc9431112944f0cccf6a599f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 20 May 2011 22:37:59 +0200 Subject: [PATCH 03/17] ac3dec: add a drc_scale private option Deprecate corresponding AVCodecContext option. This is the first test of decoder private options. --- libavcodec/ac3dec.c | 17 +++++++++++++++++ libavcodec/ac3dec.h | 2 ++ libavcodec/avcodec.h | 5 ++++- libavcodec/options.c | 2 ++ libavcodec/version.h | 3 +++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 42b62ef701..663acc0ac9 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -30,6 +30,7 @@ #include #include "libavutil/crc.h" +#include "libavutil/opt.h" #include "internal.h" #include "aac_ac3_parser.h" #include "ac3_parser.h" @@ -1440,6 +1441,20 @@ static av_cold int ac3_decode_end(AVCodecContext *avctx) return 0; } +#define OFFSET(x) offsetof(AC3DecodeContext, x) +#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM) +static const AVOption options[] = { + { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {1.0}, 0.0, 1.0, PAR }, + { NULL}, +}; + +static const AVClass ac3_decoder_class = { + .class_name = "(E-)AC3 decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_ac3_decoder = { .name = "ac3", .type = AVMEDIA_TYPE_AUDIO, @@ -1452,6 +1467,7 @@ AVCodec ff_ac3_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .priv_class = &ac3_decoder_class, }; #if CONFIG_EAC3_DECODER @@ -1467,5 +1483,6 @@ AVCodec ff_eac3_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .priv_class = &ac3_decoder_class, }; #endif diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index aed87432f5..a7cebafbe9 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -63,6 +63,7 @@ #define SPX_MAX_BANDS 17 typedef struct { + AVClass *class; ///< class for AVOptions AVCodecContext *avctx; ///< parent context GetBitContext gbc; ///< bitstream reader uint8_t *input_buffer; ///< temp buffer to prevent overread @@ -141,6 +142,7 @@ typedef struct { ///@name Dynamic range float dynamic_range[2]; ///< dynamic range + float drc_scale; ///< percentage of dynamic range compression to be applied ///@} ///@name Bandwidth diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index ba0c636292..7c7a0c6a97 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2544,13 +2544,16 @@ typedef struct AVCodecContext { int request_channels; #endif +#if FF_API_DRC_SCALE /** * Percentage of dynamic range compression to be applied by the decoder. * The default value is 1.0, corresponding to full compression. * - encoding: unused * - decoding: Set by user. + * @deprecated use AC3 decoder private option instead. */ - float drc_scale; + attribute_deprecated float drc_scale; +#endif /** * opaque 64bit number (generally a PTS) that will be reordered and diff --git a/libavcodec/options.c b/libavcodec/options.c index ae9e0c902d..545887a7c1 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -413,7 +413,9 @@ static const AVOption options[]={ #if FF_API_REQUEST_CHANNELS {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D}, #endif +#if FF_API_DRC_SCALE {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0.0, 1.0, A|D}, +#endif {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"}, {"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MBTREE }, INT_MIN, INT_MAX, V|E, "flags2"}, {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, diff --git a/libavcodec/version.h b/libavcodec/version.h index f4a0ecd868..7e4c02d91e 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -71,5 +71,8 @@ #ifndef FF_API_AVCODEC_OPEN #define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_DRC_SCALE +#define FF_API_DRC_SCALE (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ From 18c007ba37b2c7dee5bd2f1a3eb3bfee9b6b3d26 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 6 Jun 2011 18:37:46 +0200 Subject: [PATCH 04/17] lavc: remove a half-working attempt at different defaults for audio/video codecs. It should be replaced with proper per-codec defaults. --- libavcodec/options.c | 2 +- tests/lavf-regression.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index 545887a7c1..a876ce0404 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -69,7 +69,7 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, i static const AVOption options[]={ {"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE }, INT_MIN, INT_MAX, V|E}, -{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, {.dbl = 64*1000 }, INT_MIN, INT_MAX, A|E}, +{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE }, INT_MIN, INT_MAX, A|E}, {"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE*20 }, 1, INT_MAX, V|E}, {"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, V|A|E|D, "flags"}, {"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_4MV }, INT_MIN, INT_MAX, V|E, "flags"}, diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index d7e684032c..6d2d6d8162 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -14,7 +14,7 @@ eval do_$test=y do_lavf() { file=${outfile}lavf.$1 - do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2 + do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -ab 64k -t 1 -qscale 10 $2 do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3 } @@ -53,7 +53,7 @@ fi if [ -n "$do_rm" ] ; then file=${outfile}lavf.rm -do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed +do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed -ab 64k # broken #do_ffmpeg_crc $file -i $target_path/$file fi From 71a861cf4010ab835fab383a250f27903eb61a34 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 18 Jun 2011 13:40:48 +0200 Subject: [PATCH 05/17] lavc: make avcodec_alloc_context3 officially public. Deprecate avcodec_alloc_context/2. --- cmdutils.c | 2 +- ffserver.c | 4 ++-- libavcodec/api-example.c | 8 ++++---- libavcodec/avcodec.h | 27 ++++++++++++++++++++++----- libavcodec/motion-test.c | 2 +- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/options.c | 4 ++++ libavcodec/version.h | 3 +++ libavformat/movenc.c | 2 +- libavformat/movenchint.c | 2 +- libavformat/utils.c | 2 +- 11 files changed, 41 insertions(+), 17 deletions(-) diff --git a/cmdutils.c b/cmdutils.c index 943a77c82c..2124ca1439 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -63,7 +63,7 @@ void init_opts(void) { int i; for (i = 0; i < AVMEDIA_TYPE_NB; i++) - avcodec_opts[i] = avcodec_alloc_context2(i); + avcodec_opts[i] = avcodec_alloc_context3(NULL); avformat_opts = avformat_alloc_context(); #if CONFIG_SWSCALE sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); diff --git a/ffserver.c b/ffserver.c index a12d7082b6..1dc8a17f2f 100644 --- a/ffserver.c +++ b/ffserver.c @@ -3468,7 +3468,7 @@ static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int cop if (!fst) return NULL; if (copy) { - fst->codec= avcodec_alloc_context(); + fst->codec = avcodec_alloc_context3(NULL); memcpy(fst->codec, codec, sizeof(AVCodecContext)); if (codec->extradata_size) { fst->codec->extradata = av_malloc(codec->extradata_size); @@ -3885,7 +3885,7 @@ static void add_codec(FFStream *stream, AVCodecContext *av) st = av_mallocz(sizeof(AVStream)); if (!st) return; - st->codec = avcodec_alloc_context(); + st->codec = avcodec_alloc_context3(NULL); stream->streams[stream->nb_streams++] = st; memcpy(st->codec, av, sizeof(AVCodecContext)); } diff --git a/libavcodec/api-example.c b/libavcodec/api-example.c index 1792d60d77..ec71b0d031 100644 --- a/libavcodec/api-example.c +++ b/libavcodec/api-example.c @@ -65,7 +65,7 @@ static void audio_encode_example(const char *filename) exit(1); } - c= avcodec_alloc_context(); + c = avcodec_alloc_context3(codec); /* put sample parameters */ c->bit_rate = 64000; @@ -135,7 +135,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) exit(1); } - c= avcodec_alloc_context(); + c = avcodec_alloc_context3(codec); /* open it */ if (avcodec_open(c, codec) < 0) { @@ -216,7 +216,7 @@ static void video_encode_example(const char *filename) exit(1); } - c= avcodec_alloc_context(); + c = avcodec_alloc_context3(codec); picture= avcodec_alloc_frame(); /* put sample parameters */ @@ -347,7 +347,7 @@ static void video_decode_example(const char *outfilename, const char *filename) exit(1); } - c= avcodec_alloc_context(); + c = avcodec_alloc_context3(codec); picture= avcodec_alloc_frame(); if(codec->capabilities&CODEC_CAP_TRUNCATED) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7c7a0c6a97..3f016807ab 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3529,21 +3529,38 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType); * we WILL change its arguments and name a few times! */ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec); +#if FF_API_ALLOC_CONTEXT /** * Allocate an AVCodecContext and set its fields to default values. The * resulting struct can be deallocated by simply calling av_free(). * * @return An AVCodecContext filled with default values or NULL on failure. * @see avcodec_get_context_defaults + * + * @deprecated use avcodec_alloc_context3() */ +attribute_deprecated AVCodecContext *avcodec_alloc_context(void); /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! * we WILL change its arguments and name a few times! */ +attribute_deprecated AVCodecContext *avcodec_alloc_context2(enum AVMediaType); +#endif -/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! - * we WILL change its arguments and name a few times! */ +/** + * Allocate an AVCodecContext and set its fields to default values. The + * resulting struct can be deallocated by simply calling av_free(). + * + * @param codec if non-NULL, allocate private data and initialize defaults + * for the given codec. It is illegal to then call avcodec_open() + * with a different codec. + * + * @return An AVCodecContext filled with default values or NULL on failure. + * @see avcodec_get_context_defaults + * + * @deprecated use avcodec_alloc_context3() + */ AVCodecContext *avcodec_alloc_context3(AVCodec *codec); /** @@ -3553,7 +3570,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec); * can use this AVCodecContext to decode/encode video/audio data. * * @param dest target codec context, should be initialized with - * avcodec_alloc_context(), but otherwise uninitialized + * avcodec_alloc_context3(), but otherwise uninitialized * @param src source codec context * @return AVERROR() on error (e.g. memory allocation error), 0 on success */ @@ -3640,7 +3657,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, * if (!codec) * exit(1); * - * context = avcodec_alloc_context(); + * context = avcodec_alloc_context3(codec); * * if (avcodec_open(context, codec) < 0) * exit(1); @@ -3649,7 +3666,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, * @param avctx The context which will be set up to use the given codec. * @param codec The codec to use within the context. * @return zero on success, a negative value on error - * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close + * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close * * @deprecated use avcodec_open2 */ diff --git a/libavcodec/motion-test.c b/libavcodec/motion-test.c index b88917c988..7ac5cc7d4a 100644 --- a/libavcodec/motion-test.c +++ b/libavcodec/motion-test.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) printf("ffmpeg motion test\n"); - ctx = avcodec_alloc_context(); + ctx = avcodec_alloc_context3(NULL); ctx->dsp_mask = AV_CPU_FLAG_FORCE; dsputil_init(&cctx, ctx); for (c = 0; c < flags_size; c++) { diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index f298993c0c..68bd080960 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -944,7 +944,7 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ static int estimate_best_b_count(MpegEncContext *s){ AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); - AVCodecContext *c= avcodec_alloc_context(); + AVCodecContext *c = avcodec_alloc_context3(NULL); AVFrame input[FF_MAX_B_FRAMES+2]; const int scale= s->avctx->brd_scale; int i, j, out_size, p_lambda, b_lambda, lambda2; diff --git a/libavcodec/options.c b/libavcodec/options.c index a876ce0404..1e7fe522ea 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -540,6 +540,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){ return avctx; } +#if FF_API_ALLOC_CONTEXT AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){ AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); @@ -549,14 +550,17 @@ AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){ return avctx; } +#endif void avcodec_get_context_defaults(AVCodecContext *s){ avcodec_get_context_defaults2(s, AVMEDIA_TYPE_UNKNOWN); } +#if FF_API_ALLOC_CONTEXT AVCodecContext *avcodec_alloc_context(void){ return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN); } +#endif int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { diff --git a/libavcodec/version.h b/libavcodec/version.h index 7e4c02d91e..32b2bb314c 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -68,6 +68,9 @@ #ifndef FF_API_GET_PIX_FMT_NAME #define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_ALLOC_CONTEXT +#define FF_API_ALLOC_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #ifndef FF_API_AVCODEC_OPEN #define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54) #endif diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 0de7c4d44d..ae6f603e86 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2102,7 +2102,7 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum) track->mode = mov->mode; track->tag = MKTAG('t','e','x','t'); track->timescale = MOV_TIMESCALE; - track->enc = avcodec_alloc_context(); + track->enc = avcodec_alloc_context3(NULL); track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; for (i = 0; i < s->nb_chapters; i++) { diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 615714627c..683d58b7c5 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -36,7 +36,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->tag = MKTAG('r','t','p',' '); track->src_track = src_index; - track->enc = avcodec_alloc_context(); + track->enc = avcodec_alloc_context3(NULL); if (!track->enc) goto fail; track->enc->codec_type = AVMEDIA_TYPE_DATA; diff --git a/libavformat/utils.c b/libavformat/utils.c index a3825a0c93..bbd1b2d07b 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2668,7 +2668,7 @@ AVStream *av_new_stream(AVFormatContext *s, int id) return NULL; } - st->codec= avcodec_alloc_context(); + st->codec = avcodec_alloc_context3(NULL); if (s->iformat) { /* no default bitrate if decoding */ st->codec->bit_rate = 0; From 84626b364babc27c5a3db454ebf6a02aeaa186fe Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 8 Jun 2011 08:27:53 +0200 Subject: [PATCH 06/17] lavc: add support for codec-specific defaults. --- libavcodec/avcodec.h | 7 +++++++ libavcodec/internal.h | 5 +++++ libavcodec/options.c | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3f016807ab..ba6342a09e 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2860,6 +2860,8 @@ typedef struct AVProfile { const char *name; ///< short name for the profile } AVProfile; +typedef struct AVCodecDefault AVCodecDefault; + /** * AVCodec. */ @@ -2922,6 +2924,11 @@ typedef struct AVCodec { */ int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src); /** @} */ + + /** + * Private codec-specific defaults. + */ + const AVCodecDefault *defaults; } AVCodec; /** diff --git a/libavcodec/internal.h b/libavcodec/internal.h index fe853ab87e..9a444fcae7 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -27,6 +27,11 @@ #include #include "avcodec.h" +struct AVCodecDefault { + const uint8_t *key; + const uint8_t *value; +}; + /** * Determine whether pix_fmt is a hardware accelerated format. */ diff --git a/libavcodec/options.c b/libavcodec/options.c index 1e7fe522ea..4869046665 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -25,6 +25,8 @@ */ #include "avcodec.h" +#include "internal.h" +#include "libavutil/avassert.h" #include "libavutil/opt.h" #include /* FLT_MIN, FLT_MAX */ @@ -524,6 +526,15 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){ av_opt_set_defaults(s->priv_data); } } + if (codec && codec->defaults) { + int ret; + AVCodecDefault *d = codec->defaults; + while (d->key) { + ret = av_set_string3(s, d->key, d->value, 0, NULL); + av_assert0(ret >= 0); + d++; + } + } return 0; } From 31ad14c21e0735387ba8082c6e3436241f7ccfc8 Mon Sep 17 00:00:00 2001 From: Aaron Colwell Date: Sat, 9 Jul 2011 07:48:43 +0200 Subject: [PATCH 07/17] matroskadec: defer parsing of cues element until we seek. This decreases startup latency. Signed-off-by: Ronald S. Bultje Signed-off-by: Anton Khirnov --- libavformat/matroskadec.c | 131 +++++++++++++++++++++++++------------- 1 file changed, 86 insertions(+), 45 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index a1e827f093..37ce3342b1 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -244,6 +244,9 @@ typedef struct { /* What to skip before effectively reading a packet. */ int skip_to_keyframe; uint64_t skip_to_timecode; + + /* File has a CUES element, but we defer parsing until it is needed. */ + int cues_parsing_deferred; } MatroskaDemuxContext; typedef struct { @@ -1110,7 +1113,7 @@ static void matroska_convert_tags(AVFormatContext *s) } } -static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) +static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx) { EbmlList *seekhead_list = &matroska->seekhead; MatroskaSeekhead *seekhead = seekhead_list->elem; @@ -1118,34 +1121,25 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) int64_t before_pos = avio_tell(matroska->ctx->pb); uint32_t saved_id = matroska->current_id; MatroskaLevel level; - int i; + int64_t offset; + int ret = 0; - // we should not do any seeking in the streaming case - if (!matroska->ctx->pb->seekable || - (matroska->ctx->flags & AVFMT_FLAG_IGNIDX)) - return; - - for (i=0; inb_elem; i++) { - int64_t offset = seekhead[i].pos + matroska->segment_start; - - if (seekhead[i].pos <= before_pos - || seekhead[i].id == MATROSKA_ID_SEEKHEAD - || seekhead[i].id == MATROSKA_ID_CLUSTER) - continue; + if (idx >= seekhead_list->nb_elem + || seekhead[idx].id == MATROSKA_ID_SEEKHEAD + || seekhead[idx].id == MATROSKA_ID_CLUSTER) + return 0; /* seek */ - if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) != offset) - continue; - + offset = seekhead[idx].pos + matroska->segment_start; + if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) == offset) { /* We don't want to lose our seekhead level, so we add * a dummy. This is a crude hack. */ if (matroska->num_levels == EBML_MAX_DEPTH) { av_log(matroska->ctx, AV_LOG_INFO, "Max EBML element depth (%d) reached, " "cannot parse further.\n", EBML_MAX_DEPTH); - break; - } - + ret = AVERROR_INVALIDDATA; + } else { level.start = 0; level.length = (uint64_t)-1; matroska->levels[matroska->num_levels] = level; @@ -1161,11 +1155,76 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) break; } } - + } /* seek back */ avio_seek(matroska->ctx->pb, before_pos, SEEK_SET); matroska->level_up = level_up; matroska->current_id = saved_id; + + return ret; +} + +static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) +{ + EbmlList *seekhead_list = &matroska->seekhead; + MatroskaSeekhead *seekhead = seekhead_list->elem; + int64_t before_pos = avio_tell(matroska->ctx->pb); + int i; + + // we should not do any seeking in the streaming case + if (!matroska->ctx->pb->seekable || + (matroska->ctx->flags & AVFMT_FLAG_IGNIDX)) + return; + + for (i = 0; i < seekhead_list->nb_elem; i++) { + if (seekhead[i].pos <= before_pos) + continue; + + // defer cues parsing until we actually need cue data. + if (seekhead[i].id == MATROSKA_ID_CUES) { + matroska->cues_parsing_deferred = 1; + continue; + } + + if (matroska_parse_seekhead_entry(matroska, i) < 0) + break; + } +} + +static void matroska_parse_cues(MatroskaDemuxContext *matroska) { + EbmlList *seekhead_list = &matroska->seekhead; + MatroskaSeekhead *seekhead = seekhead_list->elem; + EbmlList *index_list; + MatroskaIndex *index; + int index_scale = 1; + int i, j; + + for (i = 0; i < seekhead_list->nb_elem; i++) + if (seekhead[i].id != MATROSKA_ID_CUES) + break; + assert(i <= seekhead_list->nb_elem); + + matroska_parse_seekhead_entry(matroska, i); + + index_list = &matroska->index; + index = index_list->elem; + if (index_list->nb_elem + && index[0].time > 1E14/matroska->time_scale) { + av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n"); + index_scale = matroska->time_scale; + } + for (i = 0; i < index_list->nb_elem; i++) { + EbmlList *pos_list = &index[i].pos; + MatroskaIndexPos *pos = pos_list->elem; + for (j = 0; j < pos_list->nb_elem; j++) { + MatroskaTrack *track = matroska_find_track_by_num(matroska, pos[j].track); + if (track && track->stream) + av_add_index_entry(track->stream, + pos[j].pos + matroska->segment_start, + index[i].time/index_scale, 0, 0, + AVINDEX_KEYFRAME); + } + } } static int matroska_aac_profile(char *codec_id) @@ -1197,9 +1256,6 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) EbmlList *chapters_list = &matroska->chapters; MatroskaChapter *chapters; MatroskaTrack *tracks; - EbmlList *index_list; - MatroskaIndex *index; - int index_scale = 1; uint64_t max_start = 0; Ebml ebml = { 0 }; AVStream *st; @@ -1529,27 +1585,6 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) max_start = chapters[i].start; } - index_list = &matroska->index; - index = index_list->elem; - if (index_list->nb_elem - && index[0].time > 100000000000000/matroska->time_scale) { - av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n"); - index_scale = matroska->time_scale; - } - for (i=0; inb_elem; i++) { - EbmlList *pos_list = &index[i].pos; - MatroskaIndexPos *pos = pos_list->elem; - for (j=0; jnb_elem; j++) { - MatroskaTrack *track = matroska_find_track_by_num(matroska, - pos[j].track); - if (track && track->stream) - av_add_index_entry(track->stream, - pos[j].pos + matroska->segment_start, - index[i].time/index_scale, 0, 0, - AVINDEX_KEYFRAME); - } - } - matroska_convert_tags(s); return 0; @@ -1898,6 +1933,12 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, AVStream *st = s->streams[stream_index]; int i, index, index_sub, index_min; + /* Parse the CUES now since we need the index data to seek. */ + if (matroska->cues_parsing_deferred) { + matroska_parse_cues(matroska); + matroska->cues_parsing_deferred = 0; + } + if (!st->nb_index_entries) return 0; timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); From f47ac3c6ca966d72b2966495958184b524d001f7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Jul 2011 08:11:30 +0200 Subject: [PATCH 08/17] matroskadec: reindent --- libavformat/matroskadec.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 37ce3342b1..e1e555df80 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1129,7 +1129,7 @@ static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx || seekhead[idx].id == MATROSKA_ID_CLUSTER) return 0; - /* seek */ + /* seek */ offset = seekhead[idx].pos + matroska->segment_start; if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) == offset) { /* We don't want to lose our seekhead level, so we add @@ -1140,22 +1140,22 @@ static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx "cannot parse further.\n", EBML_MAX_DEPTH); ret = AVERROR_INVALIDDATA; } else { - level.start = 0; - level.length = (uint64_t)-1; - matroska->levels[matroska->num_levels] = level; - matroska->num_levels++; - matroska->current_id = 0; + level.start = 0; + level.length = (uint64_t)-1; + matroska->levels[matroska->num_levels] = level; + matroska->num_levels++; + matroska->current_id = 0; - ebml_parse(matroska, matroska_segment, matroska); + ebml_parse(matroska, matroska_segment, matroska); - /* remove dummy level */ - while (matroska->num_levels) { - uint64_t length = matroska->levels[--matroska->num_levels].length; - if (length == (uint64_t)-1) - break; + /* remove dummy level */ + while (matroska->num_levels) { + uint64_t length = matroska->levels[--matroska->num_levels].length; + if (length == (uint64_t)-1) + break; + } } } - } /* seek back */ avio_seek(matroska->ctx->pb, before_pos, SEEK_SET); matroska->level_up = level_up; From 0f6fc8660e32a69c406cba44cf31df6f7a7543d2 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 9 Jul 2011 11:03:01 +0100 Subject: [PATCH 09/17] 9/10-bit: simplify clipping macros Signed-off-by: Mans Rullgard --- libavcodec/bit_depth_template.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libavcodec/bit_depth_template.c b/libavcodec/bit_depth_template.c index c0a6eafe89..4da0a6e0c9 100644 --- a/libavcodec/bit_depth_template.c +++ b/libavcodec/bit_depth_template.c @@ -43,15 +43,6 @@ # undef PIXEL_SPLAT_X4 #else # define AVCODEC_H264_HIGH_DEPTH_H -# define CLIP_PIXEL(depth)\ - static inline uint16_t av_clip_pixel_ ## depth (int p)\ - {\ - const int pixel_max = (1 << depth)-1;\ - return (p & ~pixel_max) ? (-p)>>31 & pixel_max : p;\ - } - -CLIP_PIXEL( 9) -CLIP_PIXEL(10) #endif #if BIT_DEPTH > 8 @@ -70,6 +61,9 @@ CLIP_PIXEL(10) # define AV_WN4P AV_WN64 # define AV_WN4PA AV_WN64A # define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL) + +# define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH) +# define CLIP(a) av_clip_uintp2(a, BIT_DEPTH) #else # define pixel uint8_t # define pixel2 uint16_t @@ -86,21 +80,18 @@ CLIP_PIXEL(10) # define AV_WN4P AV_WN32 # define AV_WN4PA AV_WN32A # define PIXEL_SPLAT_X4(x) ((x)*0x01010101U) + +# define av_clip_pixel(a) av_clip_uint8(a) +# define CLIP(a) cm[a] #endif #if BIT_DEPTH == 8 -# define av_clip_pixel(a) av_clip_uint8(a) -# define CLIP(a) cm[a] # define FUNC(a) a ## _8 # define FUNCC(a) a ## _8_c #elif BIT_DEPTH == 9 -# define av_clip_pixel(a) av_clip_pixel_9(a) -# define CLIP(a) av_clip_pixel_9(a) # define FUNC(a) a ## _9 # define FUNCC(a) a ## _9_c #elif BIT_DEPTH == 10 -# define av_clip_pixel(a) av_clip_pixel_10(a) -# define CLIP(a) av_clip_pixel_10(a) # define FUNC(a) a ## _10 # define FUNCC(a) a ## _10_c #endif From 710b8df949248b29446e5ee8b081b611a83951fa Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 9 Jul 2011 11:38:39 +0100 Subject: [PATCH 10/17] dsputil: remove ff_emulated_edge_mc macro used in one place This macro can cause problems in conjunction with the bitdepth template expansion. It was presumably added to keep source compatibility when high bitdepth support was added. However, emulated_edge_mc is a dsputil pointer and should not be called directly, so there is little reason to keep such a macro. Signed-off-by: Mans Rullgard --- libavcodec/dsputil.h | 2 -- libavcodec/x86/dsputil_mmx.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index ef2956eecb..5a97b442ad 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -211,8 +211,6 @@ EMULATED_EDGE(8) EMULATED_EDGE(9) EMULATED_EDGE(10) -#define ff_emulated_edge_mc ff_emulated_edge_mc_8 - void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); void ff_put_signed_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index b06a34ddce..4e84f63378 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -1879,7 +1879,7 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int o int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height) { gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, - width, height, &ff_emulated_edge_mc); + width, height, &ff_emulated_edge_mc_8); } #endif From 39c2a6bf44b25534fdbc9b6ac3844dab28ba5b0e Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 9 Jul 2011 11:44:07 +0100 Subject: [PATCH 11/17] bitdepth: simplify FUNC/FUNCC macros Signed-off-by: Mans Rullgard --- libavcodec/bit_depth_template.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libavcodec/bit_depth_template.c b/libavcodec/bit_depth_template.c index 4da0a6e0c9..9071ec2a35 100644 --- a/libavcodec/bit_depth_template.c +++ b/libavcodec/bit_depth_template.c @@ -85,13 +85,7 @@ # define CLIP(a) cm[a] #endif -#if BIT_DEPTH == 8 -# define FUNC(a) a ## _8 -# define FUNCC(a) a ## _8_c -#elif BIT_DEPTH == 9 -# define FUNC(a) a ## _9 -# define FUNCC(a) a ## _9_c -#elif BIT_DEPTH == 10 -# define FUNC(a) a ## _10 -# define FUNCC(a) a ## _10_c -#endif +#define FUNC3(a, b, c) a ## _ ## b ## c +#define FUNC2(a, b, c) FUNC3(a, b, c) +#define FUNC(a) FUNC2(a, BIT_DEPTH,) +#define FUNCC(a) FUNC2(a, BIT_DEPTH, _c) From 11043d80f60ca37330f5f1afb8ee956665a71290 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 9 Jul 2011 12:37:08 +0100 Subject: [PATCH 12/17] ARM: use const macro to define constant data in asm Signed-off-by: Mans Rullgard --- libavcodec/arm/fft_neon.S | 16 +++++++++------- libavcodec/arm/h264idct_neon.S | 5 +++-- libavcodec/arm/h264pred_neon.S | 7 ++----- libavcodec/arm/simple_idct_neon.S | 5 ++--- libavcodec/arm/vp3dsp_neon.S | 8 ++------ libavcodec/arm/vp8_armv6.S | 4 ++-- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/libavcodec/arm/fft_neon.S b/libavcodec/arm/fft_neon.S index 887621834e..b79a2dc265 100644 --- a/libavcodec/arm/fft_neon.S +++ b/libavcodec/arm/fft_neon.S @@ -349,9 +349,7 @@ function ff_fft_permute_neon, export=1 pop {r4,pc} endfunc - .section .rodata - .align 4 -fft_tab_neon: +const fft_tab_neon .word fft4_neon .word fft8_neon .word fft16_neon @@ -367,8 +365,12 @@ fft_tab_neon: .word fft16384_neon .word fft32768_neon .word fft65536_neon -ELF .size fft_tab_neon, . - fft_tab_neon +endconst - .align 4 -pmmp: .float +1.0, -1.0, -1.0, +1.0 -mppm: .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +const pmmp, align=4 + .float +1.0, -1.0, -1.0, +1.0 +endconst + +const mppm, align=4 + .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +endconst diff --git a/libavcodec/arm/h264idct_neon.S b/libavcodec/arm/h264idct_neon.S index eadf2e711d..6c62e0f7cb 100644 --- a/libavcodec/arm/h264idct_neon.S +++ b/libavcodec/arm/h264idct_neon.S @@ -383,8 +383,8 @@ function ff_h264_idct8_add4_neon, export=1 pop {r4-r8,pc} endfunc - .section .rodata -scan8: .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 +const scan8 + .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 .byte 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8 .byte 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8 .byte 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8 @@ -396,3 +396,4 @@ scan8: .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 .byte 6+11*8, 7+11*8, 6+12*8, 7+12*8 .byte 4+13*8, 5+13*8, 4+14*8, 5+14*8 .byte 6+13*8, 7+13*8, 6+14*8, 7+14*8 +endconst diff --git a/libavcodec/arm/h264pred_neon.S b/libavcodec/arm/h264pred_neon.S index fe8a369a90..815b67b81f 100644 --- a/libavcodec/arm/h264pred_neon.S +++ b/libavcodec/arm/h264pred_neon.S @@ -166,12 +166,9 @@ function ff_pred16x16_plane_neon, export=1 bx lr endfunc - .section .rodata - .align 4 -p16weight: +const p16weight, align=4 .short 1,2,3,4,5,6,7,8 - - .text +endconst function ff_pred8x8_hor_neon, export=1 sub r2, r0, #1 diff --git a/libavcodec/arm/simple_idct_neon.S b/libavcodec/arm/simple_idct_neon.S index cbed9eefe4..0c4e05d869 100644 --- a/libavcodec/arm/simple_idct_neon.S +++ b/libavcodec/arm/simple_idct_neon.S @@ -243,10 +243,9 @@ function idct_col4_st8_neon bx lr endfunc - .section .rodata - .align 4 -idct_coeff_neon: +const idct_coeff_neon, align=4 .short W1, W2, W3, W4, W5, W6, W7, W4c +endconst .macro idct_start data push {r4-r7, lr} diff --git a/libavcodec/arm/vp3dsp_neon.S b/libavcodec/arm/vp3dsp_neon.S index c1a55cad2f..279b13225b 100644 --- a/libavcodec/arm/vp3dsp_neon.S +++ b/libavcodec/arm/vp3dsp_neon.S @@ -20,11 +20,9 @@ #include "asm.S" -.section .rodata -.align 4 - -vp3_idct_constants: +const vp3_idct_constants, align=4 .short 64277, 60547, 54491, 46341, 36410, 25080, 12785 +endconst #define xC1S7 d0[0] #define xC2S6 d0[1] @@ -34,8 +32,6 @@ vp3_idct_constants: #define xC6S2 d1[1] #define xC7S1 d1[2] -.text - .macro vp3_loop_filter vsubl.u8 q3, d18, d17 vsubl.u8 q2, d16, d19 diff --git a/libavcodec/arm/vp8_armv6.S b/libavcodec/arm/vp8_armv6.S index 1d89c68909..594046d709 100644 --- a/libavcodec/arm/vp8_armv6.S +++ b/libavcodec/arm/vp8_armv6.S @@ -240,9 +240,9 @@ A orrcs r8, r8, r10, lsl r6 b 5b endfunc - .section .rodata -zigzag_scan: +const zigzag_scan .byte 0, 2, 8, 16 .byte 10, 4, 6, 12 .byte 18, 24, 26, 20 .byte 14, 22, 28, 30 +endconst From b695256eddf2b3608e6f8da4663d31dcf96612af Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 10 Jul 2011 16:17:55 +0100 Subject: [PATCH 13/17] configure: fix --cpu=host with gcc 4.6 The output from -v with gcc 4.6 has changed such that the search pattern matches too soon without making it more strict. Signed-off-by: Mans Rullgard --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index f5b4a5c767..02bcd0989c 100755 --- a/configure +++ b/configure @@ -2103,7 +2103,7 @@ if test "$cpu" = host; then gcc|llvm_gcc) check_native(){ $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return - sed -n "/$1=/{ + sed -n "/cc1.*$1=/{ s/.*$1=\\([^ ]*\\).*/\\1/ p q From 28e1c97916b026c8785f54ec591718379b251bbb Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 10 Jul 2011 20:26:25 +0100 Subject: [PATCH 14/17] build: rework rules for things in the tools dir Declaring tools associated with each library in their respective makefiles allows these tools to easily depend on the correct prerequisites and link against the libs they need. Signed-off-by: Mans Rullgard --- Makefile | 21 ++++++++------------- common.mak | 6 ++++++ libavfilter/Makefile | 2 ++ libavformat/Makefile | 1 + subdir.mak | 4 ++-- tests/Makefile | 3 --- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 9f7b4361d4..720936a604 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,8 @@ PROGS := $(PROGS-yes:%=%$(EXESUF)) OBJS = $(PROGS-yes:%=%.o) cmdutils.o TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64 HOSTPROGS := $(TESTTOOLS:%=tests/%) +TOOLS = qt-faststart trasher +TOOLS-$(CONFIG_ZLIB) += cws2fws BASENAMES = ffmpeg ffplay ffprobe ffserver ALLPROGS = $(BASENAMES:%=%$(EXESUF)) @@ -86,6 +88,11 @@ FF_DEP_LIBS := $(DEP_LIBS) all: $(FF_DEP_LIBS) $(PROGS) +$(TOOLS): %$(EXESUF): %.o + $(LD) $(LDFLAGS) -o $@ $< $(ELIBS) + +tools/cws2fws$(EXESUF): ELIBS = -lz + config.h: .config .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c)) @-tput bold 2>/dev/null @@ -94,7 +101,7 @@ config.h: .config SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \ ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \ - HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS + HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS TOOLS define RESET $(1) := @@ -116,18 +123,6 @@ ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS) $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) -TOOLS = cws2fws graph2dot lavfi-showfiltfmts pktdumper probetest qt-faststart trasher -TOOLOBJS := $(TOOLS:%=tools/%.o) -TOOLS := $(TOOLS:%=tools/%$(EXESUF)) - -alltools: $(TOOLS) - -tools/%$(EXESUF): tools/%.o - $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) - -$(TOOLOBJS): %.o: %.c | tools - $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $< - OBJDIRS += tools -include $(wildcard tools/*.d) diff --git a/common.mak b/common.mak index bd210462b9..da51495a16 100644 --- a/common.mak +++ b/common.mak @@ -20,6 +20,9 @@ TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o) TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF)) HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o) HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF)) +TOOLS += $(TOOLS-yes) +TOOLOBJS := $(TOOLS:%=tools/%.o) +TOOLS := $(TOOLS:%=tools/%$(EXESUF)) DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME)) @@ -28,6 +31,8 @@ SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-) SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%) checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho)) +alltools: $(TOOLS) + $(HOSTOBJS): %.o: %.c $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< @@ -37,6 +42,7 @@ $(HOSTPROGS): %$(HOSTEXESUF): %.o $(OBJS): | $(dir $(OBJS)) $(HOSTOBJS): | $(dir $(HOSTOBJS)) $(TESTOBJS): | $(dir $(TESTOBJS)) +$(TOOLOBJS): | tools OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS)) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 02016076bf..1a6fd9b68f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -62,4 +62,6 @@ OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o DIRS = x86 +TOOLS = graph2dot lavfi-showfiltfmts + include $(SRC_PATH)/subdir.mak diff --git a/libavformat/Makefile b/libavformat/Makefile index a20db26b03..ca337e0167 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -335,6 +335,7 @@ OBJS-$(CONFIG_JACK_INDEV) += timefilter.o EXAMPLES = metadata output TESTPROGS = timefilter +TOOLS = pktdumper probetest include $(SRC_PATH)/subdir.mak diff --git a/subdir.mak b/subdir.mak index 3a38dafe63..a88955bdfb 100644 --- a/subdir.mak +++ b/subdir.mak @@ -34,7 +34,7 @@ install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared define RULES -$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o +$(TESTPROGS) $(TOOLS): %$(EXESUF): %.o $$(LD) $(FFLDFLAGS) -o $$@ $$^ -l$(FULLNAME) $(FFEXTRALIBS) $$(ELIBS) $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR) @@ -91,7 +91,7 @@ endef $(eval $(RULES)) -$(EXAMPLES) $(TESTPROGS): $(THIS_LIB) $(DEP_LIBS) +$(EXAMPLES) $(TESTPROGS) $(TOOLS): $(THIS_LIB) $(DEP_LIBS) examples: $(EXAMPLES) testprogs: $(TESTPROGS) diff --git a/tests/Makefile b/tests/Makefile index 431a404219..501a72f879 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -31,9 +31,6 @@ tests/data/asynth1.sw tests/vsynth%/00.pgm: TAG = GEN tests/seek_test$(EXESUF): tests/seek_test.o $(FF_DEP_LIBS) $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) -tools/lavfi-showfiltfmts$(EXESUF): tools/lavfi-showfiltfmts.o $(FF_DEP_LIBS) - $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) - include $(SRC_PATH)/tests/fate.mak include $(SRC_PATH)/tests/fate2.mak From 3e5cce81e77fae6af91fcf8de11dafe9c8b1744d Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 10 Jul 2011 21:05:45 +0200 Subject: [PATCH 15/17] build: remove duplicates from order-only directory prerequisite list This reduces startup latency for make invocations, which is especially noticeable on systems that are slow or have slow I/O, like Windows. --- common.mak | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common.mak b/common.mak index da51495a16..8a2aa7cf0d 100644 --- a/common.mak +++ b/common.mak @@ -39,9 +39,9 @@ $(HOSTOBJS): %.o: %.c $(HOSTPROGS): %$(HOSTEXESUF): %.o $(HOSTCC) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS) -$(OBJS): | $(dir $(OBJS)) -$(HOSTOBJS): | $(dir $(HOSTOBJS)) -$(TESTOBJS): | $(dir $(TESTOBJS)) +$(OBJS): | $(sort $(dir $(OBJS))) +$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS))) +$(TESTOBJS): | $(sort $(dir $(TESTOBJS))) $(TOOLOBJS): | tools OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS)) From fdb94444beb9c32beb8cfc70656f5115d9eec58b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 10 Jul 2011 20:48:23 +0100 Subject: [PATCH 16/17] matroskadec: fix stupid typo (!= -> ==) Signed-off-by: Mans Rullgard --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e1e555df80..70bb765ab4 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1200,7 +1200,7 @@ static void matroska_parse_cues(MatroskaDemuxContext *matroska) { int i, j; for (i = 0; i < seekhead_list->nb_elem; i++) - if (seekhead[i].id != MATROSKA_ID_CUES) + if (seekhead[i].id == MATROSKA_ID_CUES) break; assert(i <= seekhead_list->nb_elem); From 142e76f1055de5dde44696e71a5f63f2cb11dedf Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Sun, 10 Jul 2011 20:07:43 +0400 Subject: [PATCH 17/17] swscale: fix crash with dithering due incorrect offset calculation. ptrdiff_t can be 4 bytes, which leads to the next element being 4-byte aligned and thus at a different offset than intended. Forcing 8-byte alignment forces equal offset of dither16/32 on x86-32 and x86-64. Signed-off-by: Ronald S. Bultje --- libswscale/swscale_internal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index b602541044..9492303301 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -345,10 +345,13 @@ typedef struct SwsContext { DECLARE_ALIGNED(8, uint64_t, v_temp); DECLARE_ALIGNED(8, uint64_t, y_temp); int32_t alpMmxFilter[4*MAX_FILTER_SIZE]; + // alignment of these values is not necessary, but merely here + // to maintain the same offset across x8632 and x86-64. Once we + // use proper offset macros in the asm, they can be removed. DECLARE_ALIGNED(8, ptrdiff_t, uv_off_px); ///< offset (in pixels) between u and v planes DECLARE_ALIGNED(8, ptrdiff_t, uv_off_byte); ///< offset (in bytes) between u and v planes - uint16_t dither16[8]; - uint32_t dither32[8]; + DECLARE_ALIGNED(8, uint16_t, dither16)[8]; + DECLARE_ALIGNED(8, uint32_t, dither32)[8]; const uint8_t *chrDither8, *lumDither8;