* qatar/release/0.7:
Add a version bump and APIchanges entry for avcodec_open2 and avformat_find_stream_info.
lavf: fix multiplication overflow in avformat_find_stream_info()
lavf: fix invalid reads in avformat_find_stream_info()
lavf: add avformat_find_stream_info()
lavc: fix parentheses placement in avcodec_open2().
lavc: introduce avcodec_open2() as a replacement for avcodec_open().
Conflicts:
doc/APIchanges
libavcodec/utils.c
libavcodec/version.h
libavformat/avformat.h
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -13,6 +13,7 @@ libavutil: 2011-04-18 |
13 | 13 |
|
14 | 14 |
API changes, most recent first: |
15 | 15 |
|
16 |
+ |
|
16 | 17 |
2011-06-19 - xxxxxxx - lavfi 2.23.0 - avfilter.h |
17 | 18 |
Add layout negotiation fields and helper functions. |
18 | 19 |
|
... | ... |
@@ -43,6 +44,12 @@ API changes, most recent first: |
43 | 43 |
2011-06-12 - xxxxxxx - lavfi 2.16.0 - avfilter_graph_parse() |
44 | 44 |
Change avfilter_graph_parse() signature. |
45 | 45 |
|
46 |
+2011-07-10 - xxxxxxx - lavf 53.3.0 |
|
47 |
+ Add avformat_find_stream_info(), deprecate av_find_stream_info(). |
|
48 |
+ |
|
49 |
+2011-07-10 - xxxxxxx - lavc 53.6.0 |
|
50 |
+ Add avcodec_open2(), deprecate avcodec_open(). |
|
51 |
+ |
|
46 | 52 |
2011-06-xx - xxxxxxx - lavf 53.2.0 - avformat.h |
47 | 53 |
Add avformat_open_input and avformat_write_header(). |
48 | 54 |
Deprecate av_open_input_stream, av_open_input_file, |
... | ... |
@@ -30,6 +30,7 @@ |
30 | 30 |
#include "libavutil/samplefmt.h" |
31 | 31 |
#include "libavutil/avutil.h" |
32 | 32 |
#include "libavutil/cpu.h" |
33 |
+#include "libavutil/dict.h" |
|
33 | 34 |
|
34 | 35 |
#include "libavcodec/version.h" |
35 | 36 |
|
... | ... |
@@ -3683,6 +3684,7 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v |
3683 | 3683 |
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); |
3684 | 3684 |
//FIXME func typedef |
3685 | 3685 |
|
3686 |
+#if FF_API_AVCODEC_OPEN |
|
3686 | 3687 |
/** |
3687 | 3688 |
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this |
3688 | 3689 |
* function the context has to be allocated. |
... | ... |
@@ -3709,8 +3711,44 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, |
3709 | 3709 |
* @param codec The codec to use within the context. |
3710 | 3710 |
* @return zero on success, a negative value on error |
3711 | 3711 |
* @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close |
3712 |
+ * |
|
3713 |
+ * @deprecated use avcodec_open2 |
|
3712 | 3714 |
*/ |
3713 | 3715 |
int avcodec_open(AVCodecContext *avctx, AVCodec *codec); |
3716 |
+#endif |
|
3717 |
+ |
|
3718 |
+/** |
|
3719 |
+ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this |
|
3720 |
+ * function the context has to be allocated with avcodec_alloc_context(). |
|
3721 |
+ * |
|
3722 |
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), |
|
3723 |
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for |
|
3724 |
+ * retrieving a codec. |
|
3725 |
+ * |
|
3726 |
+ * @warning This function is not thread safe! |
|
3727 |
+ * |
|
3728 |
+ * @code |
|
3729 |
+ * avcodec_register_all(); |
|
3730 |
+ * av_dict_set(&opts, "b", "2.5M", 0); |
|
3731 |
+ * codec = avcodec_find_decoder(CODEC_ID_H264); |
|
3732 |
+ * if (!codec) |
|
3733 |
+ * exit(1); |
|
3734 |
+ * |
|
3735 |
+ * context = avcodec_alloc_context(); |
|
3736 |
+ * |
|
3737 |
+ * if (avcodec_open(context, codec, opts) < 0) |
|
3738 |
+ * exit(1); |
|
3739 |
+ * @endcode |
|
3740 |
+ * |
|
3741 |
+ * @param avctx The context to initialize. |
|
3742 |
+ * @param options A dictionary filled with AVCodecContext and codec-private options. |
|
3743 |
+ * On return this object will be filled with options that were not found. |
|
3744 |
+ * |
|
3745 |
+ * @return zero on success, a negative value on error |
|
3746 |
+ * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(), |
|
3747 |
+ * av_dict_set(), av_opt_find(). |
|
3748 |
+ */ |
|
3749 |
+int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options); |
|
3714 | 3750 |
|
3715 | 3751 |
/** |
3716 | 3752 |
* Decode the audio frame of size avpkt->size from avpkt->data into samples. |
... | ... |
@@ -973,7 +973,7 @@ static int estimate_best_b_count(MpegEncContext *s){ |
973 | 973 |
c->time_base= s->avctx->time_base; |
974 | 974 |
c->max_b_frames= s->max_b_frames; |
975 | 975 |
|
976 |
- if (avcodec_open(c, codec) < 0) |
|
976 |
+ if (avcodec_open2(c, codec, NULL) < 0) |
|
977 | 977 |
return -1; |
978 | 978 |
|
979 | 979 |
for(i=0; i<s->max_b_frames+2; i++){ |
... | ... |
@@ -32,6 +32,7 @@ |
32 | 32 |
#include "libavutil/audioconvert.h" |
33 | 33 |
#include "libavutil/imgutils.h" |
34 | 34 |
#include "libavutil/samplefmt.h" |
35 |
+#include "libavutil/dict.h" |
|
35 | 36 |
#include "avcodec.h" |
36 | 37 |
#include "dsputil.h" |
37 | 38 |
#include "libavutil/opt.h" |
... | ... |
@@ -485,9 +486,20 @@ static void avcodec_get_subtitle_defaults(AVSubtitle *sub) |
485 | 485 |
sub->pts = AV_NOPTS_VALUE; |
486 | 486 |
} |
487 | 487 |
|
488 |
+#if FF_API_AVCODEC_OPEN |
|
488 | 489 |
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
489 | 490 |
{ |
491 |
+ return avcodec_open2(avctx, codec, NULL); |
|
492 |
+} |
|
493 |
+#endif |
|
494 |
+ |
|
495 |
+int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) |
|
496 |
+{ |
|
490 | 497 |
int ret = 0; |
498 |
+ AVDictionary *tmp = NULL; |
|
499 |
+ |
|
500 |
+ if (options) |
|
501 |
+ av_dict_copy(&tmp, *options, 0); |
|
491 | 502 |
|
492 | 503 |
/* If there is a user-supplied mutex locking routine, call it. */ |
493 | 504 |
if (ff_lockmgr_cb) { |
... | ... |
@@ -514,14 +526,18 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
514 | 514 |
ret = AVERROR(ENOMEM); |
515 | 515 |
goto end; |
516 | 516 |
} |
517 |
- if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3() |
|
517 |
+ if (codec->priv_class) { |
|
518 | 518 |
*(AVClass**)avctx->priv_data= codec->priv_class; |
519 | 519 |
av_opt_set_defaults(avctx->priv_data); |
520 | 520 |
} |
521 | 521 |
} |
522 |
+ if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0) |
|
523 |
+ goto free_and_end; |
|
522 | 524 |
} else { |
523 | 525 |
avctx->priv_data = NULL; |
524 | 526 |
} |
527 |
+ if ((ret = av_opt_set_dict(avctx, &tmp)) < 0) |
|
528 |
+ goto free_and_end; |
|
525 | 529 |
|
526 | 530 |
if(avctx->coded_width && avctx->coded_height) |
527 | 531 |
avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); |
... | ... |
@@ -640,8 +656,14 @@ end: |
640 | 640 |
if (ff_lockmgr_cb) { |
641 | 641 |
(*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); |
642 | 642 |
} |
643 |
+ if (options) { |
|
644 |
+ av_dict_free(options); |
|
645 |
+ *options = tmp; |
|
646 |
+ } |
|
647 |
+ |
|
643 | 648 |
return ret; |
644 | 649 |
free_and_end: |
650 |
+ av_dict_free(&tmp); |
|
645 | 651 |
av_freep(&avctx->priv_data); |
646 | 652 |
avctx->codec= NULL; |
647 | 653 |
goto end; |
... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
#define AVCODEC_VERSION_H |
22 | 22 |
|
23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 53 |
24 |
-#define LIBAVCODEC_VERSION_MINOR 7 |
|
24 |
+#define LIBAVCODEC_VERSION_MINOR 8 |
|
25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
26 | 26 |
|
27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -68,5 +68,8 @@ |
68 | 68 |
#ifndef FF_API_GET_PIX_FMT_NAME |
69 | 69 |
#define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) |
70 | 70 |
#endif |
71 |
+#ifndef FF_API_AVCODEC_OPEN |
|
72 |
+#define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54) |
|
73 |
+#endif |
|
71 | 74 |
|
72 | 75 |
#endif /* AVCODEC_VERSION_H */ |
... | ... |
@@ -1152,6 +1152,7 @@ AVFormatContext *avformat_alloc_output_context(const char *format, |
1152 | 1152 |
int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, |
1153 | 1153 |
const char *format_name, const char *filename); |
1154 | 1154 |
|
1155 |
+#if FF_API_FORMAT_PARAMETERS |
|
1155 | 1156 |
/** |
1156 | 1157 |
* Read packets of a media file to get stream information. This |
1157 | 1158 |
* is useful for file formats with no headers such as MPEG. This |
... | ... |
@@ -1164,8 +1165,34 @@ int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oforma |
1164 | 1164 |
* @return >=0 if OK, AVERROR_xxx on error |
1165 | 1165 |
* @todo Let the user decide somehow what information is needed so that |
1166 | 1166 |
* we do not waste time getting stuff the user does not need. |
1167 |
+ * |
|
1168 |
+ * @deprecated use avformat_find_stream_info. |
|
1167 | 1169 |
*/ |
1168 | 1170 |
int av_find_stream_info(AVFormatContext *ic); |
1171 |
+#endif |
|
1172 |
+ |
|
1173 |
+/** |
|
1174 |
+ * Read packets of a media file to get stream information. This |
|
1175 |
+ * is useful for file formats with no headers such as MPEG. This |
|
1176 |
+ * function also computes the real framerate in case of MPEG-2 repeat |
|
1177 |
+ * frame mode. |
|
1178 |
+ * The logical file position is not changed by this function; |
|
1179 |
+ * examined packets may be buffered for later processing. |
|
1180 |
+ * |
|
1181 |
+ * @param ic media file handle |
|
1182 |
+ * @param options If non-NULL, an ic.nb_streams long array of pointers to |
|
1183 |
+ * dictionaries, where i-th member contains options for |
|
1184 |
+ * codec corresponding to i-th stream. |
|
1185 |
+ * On return each dictionary will be filled with options that were not found. |
|
1186 |
+ * @return >=0 if OK, AVERROR_xxx on error |
|
1187 |
+ * |
|
1188 |
+ * @note this function isn't guaranteed to open all the codecs, so |
|
1189 |
+ * options being non-empty at return is a perfectly normal behavior. |
|
1190 |
+ * |
|
1191 |
+ * @todo Let the user decide somehow what information is needed so that |
|
1192 |
+ * we do not waste time getting stuff the user does not need. |
|
1193 |
+ */ |
|
1194 |
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options); |
|
1169 | 1195 |
|
1170 | 1196 |
/** |
1171 | 1197 |
* Find the "best" stream in the file. |
... | ... |
@@ -2121,7 +2121,7 @@ static int has_decode_delay_been_guessed(AVStream *st) |
2121 | 2121 |
st->codec_info_nb_frames >= 6 + st->codec->has_b_frames; |
2122 | 2122 |
} |
2123 | 2123 |
|
2124 |
-static int try_decode_frame(AVStream *st, AVPacket *avpkt) |
|
2124 |
+static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options) |
|
2125 | 2125 |
{ |
2126 | 2126 |
int16_t *samples; |
2127 | 2127 |
AVCodec *codec; |
... | ... |
@@ -2132,7 +2132,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt) |
2132 | 2132 |
codec = avcodec_find_decoder(st->codec->codec_id); |
2133 | 2133 |
if (!codec) |
2134 | 2134 |
return -1; |
2135 |
- ret = avcodec_open(st->codec, codec); |
|
2135 |
+ ret = avcodec_open2(st->codec, codec, options); |
|
2136 | 2136 |
if (ret < 0) |
2137 | 2137 |
return ret; |
2138 | 2138 |
} |
... | ... |
@@ -2251,12 +2251,20 @@ static int tb_unreliable(AVCodecContext *c){ |
2251 | 2251 |
return 0; |
2252 | 2252 |
} |
2253 | 2253 |
|
2254 |
+#if FF_API_FORMAT_PARAMETERS |
|
2254 | 2255 |
int av_find_stream_info(AVFormatContext *ic) |
2255 | 2256 |
{ |
2257 |
+ return avformat_find_stream_info(ic, NULL); |
|
2258 |
+} |
|
2259 |
+#endif |
|
2260 |
+ |
|
2261 |
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) |
|
2262 |
+{ |
|
2256 | 2263 |
int i, count, ret, read_size, j; |
2257 | 2264 |
AVStream *st; |
2258 | 2265 |
AVPacket pkt1, *pkt; |
2259 | 2266 |
int64_t old_offset = avio_tell(ic->pb); |
2267 |
+ int orig_nb_streams = ic->nb_streams; // new streams might appear, no options for those |
|
2260 | 2268 |
|
2261 | 2269 |
for(i=0;i<ic->nb_streams;i++) { |
2262 | 2270 |
AVCodec *codec; |
... | ... |
@@ -2293,12 +2301,12 @@ int av_find_stream_info(AVFormatContext *ic) |
2293 | 2293 |
/* Ensure that subtitle_header is properly set. */ |
2294 | 2294 |
if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE |
2295 | 2295 |
&& codec && !st->codec->codec) |
2296 |
- avcodec_open(st->codec, codec); |
|
2296 |
+ avcodec_open2(st->codec, codec, options ? &options[i] : NULL); |
|
2297 | 2297 |
|
2298 | 2298 |
//try to just open decoders, in case this is enough to get parameters |
2299 | 2299 |
if(!has_codec_parameters(st->codec)){ |
2300 | 2300 |
if (codec && !st->codec->codec) |
2301 |
- avcodec_open(st->codec, codec); |
|
2301 |
+ avcodec_open2(st->codec, codec, options ? &options[i] : NULL); |
|
2302 | 2302 |
} |
2303 | 2303 |
} |
2304 | 2304 |
|
... | ... |
@@ -2408,7 +2416,7 @@ int av_find_stream_info(AVFormatContext *ic) |
2408 | 2408 |
for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error); i++) { |
2409 | 2409 |
int framerate= get_std_framerate(i); |
2410 | 2410 |
int ticks= lrintf(dur*framerate/(1001*12)); |
2411 |
- double error= dur - ticks*1001*12/(double)framerate; |
|
2411 |
+ double error = dur - (double)ticks*1001*12 / framerate; |
|
2412 | 2412 |
st->info->duration_error[i] += error*error; |
2413 | 2413 |
} |
2414 | 2414 |
st->info->duration_count++; |
... | ... |
@@ -2434,7 +2442,7 @@ int av_find_stream_info(AVFormatContext *ic) |
2434 | 2434 |
it takes longer and uses more memory. For MPEG-4, we need to |
2435 | 2435 |
decompress for QuickTime. */ |
2436 | 2436 |
if (!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)) |
2437 |
- try_decode_frame(st, pkt); |
|
2437 |
+ try_decode_frame(st, pkt, (options && i < orig_nb_streams )? &options[i] : NULL); |
|
2438 | 2438 |
|
2439 | 2439 |
st->codec_info_nb_frames++; |
2440 | 2440 |
count++; |
... | ... |
@@ -24,7 +24,7 @@ |
24 | 24 |
#include "libavutil/avutil.h" |
25 | 25 |
|
26 | 26 |
#define LIBAVFORMAT_VERSION_MAJOR 53 |
27 |
-#define LIBAVFORMAT_VERSION_MINOR 4 |
|
27 |
+#define LIBAVFORMAT_VERSION_MINOR 5 |
|
28 | 28 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
29 | 29 |
|
30 | 30 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |