Browse code

Merge branch 'release/0.8' into release/0.7

* release/0.8: (31 commits)
svq1dec: call avcodec_set_dimensions() after dimensions changed. Fixes NGS00148
vp3dec: Check coefficient index in vp3_dequant() Fixes NGS00145
qdm2dec: fix buffer overflow. Fixes NGS00144
h264: Fix invalid interlaced progressive MB combinations for direct mode prediction. Fixes Ticket312
mpegvideo: dont use ff_mspel_motion() for vc1 Fixes Ticket655
imgutils: Fix illegal read.
ac3probe: Detect Sonic Foundry Soft Encode AC3 as raw AC3. Our ac3 code chain can handle it fine. More ideal would be to write a demuxer that actually extracts what can be from the additional headers and uses it for whatever it can be used for.
mjpeg: support mpo Fixes stereoscopic_photo.mpo
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().
rawdec: use a default sample rate if none is specified. Fixes "ffmpeg -f s16le -i /dev/zero"
rawdec: add check on sample_rate
qdm2dec: check remaining input bits in the mainloop of qdm2_fft_decode_tones() This is neccessary but likely not sufficient to prevent out of array reads.
cinepak: check strip_size
wma: Check channel number before init. Fixes Ticket240
Do not try to read 16bit gray png files with alpha channel.
...

Conflicts:
libavcodec/version.h
libavformat/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/11/22 03:41:08
Showing 29 changed files
... ...
@@ -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,
... ...
@@ -2135,7 +2135,12 @@ static int stream_component_open(VideoState *is, int stream_index)
2135 2135
 
2136 2136
     avctx->workaround_bugs = workaround_bugs;
2137 2137
     avctx->lowres = lowres;
2138
-    if(lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE;
2138
+    if(avctx->lowres > codec->max_lowres){
2139
+        av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
2140
+                codec->max_lowres);
2141
+        avctx->lowres= codec->max_lowres;
2142
+    }
2143
+    if(avctx->lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE;
2139 2144
     avctx->idct_algo= idct;
2140 2145
     if(fast) avctx->flags2 |= CODEC_FLAG2_FAST;
2141 2146
     avctx->skip_frame= skip_frame;
... ...
@@ -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
 
... ...
@@ -3784,6 +3785,7 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v
3784 3784
 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
3785 3785
 //FIXME func typedef
3786 3786
 
3787
+#if FF_API_AVCODEC_OPEN
3787 3788
 /**
3788 3789
  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3789 3790
  * function the context has to be allocated.
... ...
@@ -3810,8 +3812,44 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
3810 3810
  * @param codec The codec to use within the context.
3811 3811
  * @return zero on success, a negative value on error
3812 3812
  * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
3813
+ *
3814
+ * @deprecated use avcodec_open2
3813 3815
  */
3814 3816
 int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
3817
+#endif
3818
+
3819
+/**
3820
+ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3821
+ * function the context has to be allocated with avcodec_alloc_context().
3822
+ *
3823
+ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
3824
+ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
3825
+ * retrieving a codec.
3826
+ *
3827
+ * @warning This function is not thread safe!
3828
+ *
3829
+ * @code
3830
+ * avcodec_register_all();
3831
+ * av_dict_set(&opts, "b", "2.5M", 0);
3832
+ * codec = avcodec_find_decoder(CODEC_ID_H264);
3833
+ * if (!codec)
3834
+ *     exit(1);
3835
+ *
3836
+ * context = avcodec_alloc_context();
3837
+ *
3838
+ * if (avcodec_open(context, codec, opts) < 0)
3839
+ *     exit(1);
3840
+ * @endcode
3841
+ *
3842
+ * @param avctx The context to initialize.
3843
+ * @param options A dictionary filled with AVCodecContext and codec-private options.
3844
+ *                On return this object will be filled with options that were not found.
3845
+ *
3846
+ * @return zero on success, a negative value on error
3847
+ * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
3848
+ *      av_dict_set(), av_opt_find().
3849
+ */
3850
+int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
3815 3851
 
3816 3852
 #if FF_API_AUDIO_OLD
3817 3853
 /**
... ...
@@ -365,6 +365,8 @@ static int cinepak_decode (CinepakContext *s)
365 365
         s->strips[i].x2 = s->avctx->width;
366 366
 
367 367
         strip_size = AV_RB24 (&s->data[1]) - 12;
368
+        if(strip_size < 0)
369
+            return -1;
368 370
         s->data   += 12;
369 371
         strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
370 372
 
... ...
@@ -1079,7 +1079,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
1079 1079
             q->subpacket[s].subbands = bytestream_get_be16(&edata_ptr);
1080 1080
             extradata_size -= 8;
1081 1081
         }
1082
-        if (avctx->extradata_size >= 8){
1082
+        if (extradata_size >= 8){
1083 1083
             bytestream_get_be32(&edata_ptr);    //Unknown unused
1084 1084
             q->subpacket[s].js_subband_start = bytestream_get_be16(&edata_ptr);
1085 1085
             q->subpacket[s].js_vlc_bits = bytestream_get_be16(&edata_ptr);
... ...
@@ -253,6 +253,10 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
253 253
             mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
254 254
             b8_stride = 2+4*s->mb_stride;
255 255
             b4_stride *= 6;
256
+            if(IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])){
257
+                mb_type_col[0] &= ~MB_TYPE_INTERLACED;
258
+                mb_type_col[1] &= ~MB_TYPE_INTERLACED;
259
+            }
256 260
 
257 261
             sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
258 262
             if(    (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
... ...
@@ -725,7 +725,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
725 725
                         0, 0, 0,
726 726
                         ref_picture, pix_op, qpix_op,
727 727
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
728
-        }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel){
728
+        }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel && s->codec_id == CODEC_ID_WMV2){
729 729
             ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
730 730
                         ref_picture, pix_op,
731 731
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
... ...
@@ -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++){
... ...
@@ -471,7 +471,8 @@ static int decode_frame(AVCodecContext *avctx,
471 471
                     avctx->pix_fmt = PIX_FMT_MONOBLACK;
472 472
                 } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
473 473
                     avctx->pix_fmt = PIX_FMT_PAL8;
474
-                } else if (s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
474
+                } else if (s->bit_depth == 8 &&
475
+                           s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
475 476
                     avctx->pix_fmt = PIX_FMT_GRAY8A;
476 477
                 } else {
477 478
                     goto fail;
... ...
@@ -76,6 +76,7 @@ do { \
76 76
 #define SAMPLES_NEEDED_2(why) \
77 77
      av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
78 78
 
79
+#define QDM2_MAX_FRAME_SIZE 512
79 80
 
80 81
 typedef int8_t sb_int8_array[2][30][64];
81 82
 
... ...
@@ -168,7 +169,7 @@ typedef struct {
168 168
     /// I/O data
169 169
     const uint8_t *compressed_data;
170 170
     int compressed_size;
171
-    float output_buffer[1024];
171
+    float output_buffer[QDM2_MAX_FRAME_SIZE * MPA_MAX_CHANNELS * 2];
172 172
 
173 173
     /// Synthesis filter
174 174
     MPADSPContext mpadsp;
... ...
@@ -1327,7 +1328,7 @@ static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *
1327 1327
     local_int_10 = 1 << (q->group_order - duration - 1);
1328 1328
     offset = 1;
1329 1329
 
1330
-    while (1) {
1330
+    while (get_bits_left(gb)>0) {
1331 1331
         if (q->superblocktype_2_3) {
1332 1332
             while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
1333 1333
                 offset = 1;
... ...
@@ -1822,7 +1823,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
1822 1822
     // something like max decodable tones
1823 1823
     s->group_order = av_log2(s->group_size) + 1;
1824 1824
     s->frame_size = s->group_size / 16; // 16 iterations per super block
1825
-    if (s->frame_size > FF_ARRAY_ELEMS(s->output_buffer) / 2)
1825
+
1826
+    if (s->frame_size > QDM2_MAX_FRAME_SIZE)
1826 1827
         return AVERROR_INVALIDDATA;
1827 1828
 
1828 1829
     s->sub_sampling = s->fft_order - 7;
... ...
@@ -1893,6 +1895,9 @@ static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
1893 1893
     int ch, i;
1894 1894
     const int frame_size = (q->frame_size * q->channels);
1895 1895
 
1896
+    if((unsigned)frame_size > FF_ARRAY_ELEMS(q->output_buffer)/2)
1897
+        return -1;
1898
+
1896 1899
     /* select input buffer */
1897 1900
     q->compressed_data = in;
1898 1901
     q->compressed_size = q->checksum_size;
... ...
@@ -658,6 +658,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
658 658
     av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n",result);
659 659
     return result;
660 660
   }
661
+  avcodec_set_dimensions(avctx, s->width, s->height);
661 662
 
662 663
   //FIXME this avoids some confusion for "B frames" without 2 references
663 664
   //this should be removed after libavcodec can handle more flexible picture types & ordering
... ...
@@ -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"
... ...
@@ -498,9 +499,20 @@ static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
498 498
     sub->pts = AV_NOPTS_VALUE;
499 499
 }
500 500
 
501
+#if FF_API_AVCODEC_OPEN
501 502
 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
502 503
 {
504
+    return avcodec_open2(avctx, codec, NULL);
505
+}
506
+#endif
507
+
508
+int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
509
+{
503 510
     int ret = 0;
511
+    AVDictionary *tmp = NULL;
512
+
513
+    if (options)
514
+        av_dict_copy(&tmp, *options, 0);
504 515
 
505 516
     /* If there is a user-supplied mutex locking routine, call it. */
506 517
     if (ff_lockmgr_cb) {
... ...
@@ -527,14 +539,18 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
527 527
             ret = AVERROR(ENOMEM);
528 528
             goto end;
529 529
         }
530
-        if(codec->priv_class){ //this can be droped once all user apps use   avcodec_get_context_defaults3()
530
+        if (codec->priv_class) {
531 531
             *(AVClass**)avctx->priv_data= codec->priv_class;
532 532
             av_opt_set_defaults(avctx->priv_data);
533 533
         }
534 534
       }
535
+      if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
536
+          goto free_and_end;
535 537
     } else {
536 538
         avctx->priv_data = NULL;
537 539
     }
540
+    if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
541
+        goto free_and_end;
538 542
 
539 543
     if(avctx->coded_width && avctx->coded_height)
540 544
         avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
... ...
@@ -655,8 +671,14 @@ end:
655 655
     if (ff_lockmgr_cb) {
656 656
         (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
657 657
     }
658
+    if (options) {
659
+        av_dict_free(options);
660
+        *options = tmp;
661
+    }
662
+
658 663
     return ret;
659 664
 free_and_end:
665
+    av_dict_free(&tmp);
660 666
     av_freep(&avctx->priv_data);
661 667
     avctx->codec= NULL;
662 668
     goto end;
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 52
24
-#define LIBAVCODEC_VERSION_MINOR 122
24
+#define LIBAVCODEC_VERSION_MINOR 123
25 25
 #define LIBAVCODEC_VERSION_MICRO  0
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -101,5 +101,8 @@
101 101
 #ifndef FF_API_GET_PIX_FMT_NAME
102 102
 #define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54)
103 103
 #endif
104
+#ifndef FF_API_AVCODEC_OPEN
105
+#define FF_API_AVCODEC_OPEN     (LIBAVCODEC_VERSION_MAJOR < 54)
106
+#endif
104 107
 
105 108
 #endif /* AVCODEC_VERSION_H */
... ...
@@ -1308,6 +1308,10 @@ static inline int vp3_dequant(Vp3DecodeContext *s, Vp3Fragment *frag,
1308 1308
         case 1: // zero run
1309 1309
             s->dct_tokens[plane][i]++;
1310 1310
             i += (token >> 2) & 0x7f;
1311
+            if(i>63){
1312
+                av_log(s->avctx, AV_LOG_ERROR, "Coefficient index overflow\n");
1313
+                return -1;
1314
+            }
1311 1315
             block[perm[i]] = (token >> 9) * dequantizer[perm[i]];
1312 1316
             i++;
1313 1317
             break;
... ...
@@ -183,7 +183,8 @@ static void vp5_parse_coeff(VP56Context *s)
183 183
         model1 = model->coeff_dccv[pt];
184 184
         model2 = model->coeff_dcct[pt][ctx];
185 185
 
186
-        for (coeff_idx=0; coeff_idx<64; ) {
186
+        coeff_idx = 0;
187
+        for (;;) {
187 188
             if (vp56_rac_get_prob(c, model2[0])) {
188 189
                 if (vp56_rac_get_prob(c, model2[2])) {
189 190
                     if (vp56_rac_get_prob(c, model2[3])) {
... ...
@@ -220,8 +221,11 @@ static void vp5_parse_coeff(VP56Context *s)
220 220
                 ct = 0;
221 221
                 s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 0;
222 222
             }
223
+            coeff_idx++;
224
+            if (coeff_idx >= 64)
225
+                break;
223 226
 
224
-            cg = vp5_coeff_groups[++coeff_idx];
227
+            cg = vp5_coeff_groups[coeff_idx];
225 228
             ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx];
226 229
             model1 = model->coeff_ract[pt][ct][cg];
227 230
             model2 = cg > 2 ? model1 : model->coeff_acct[pt][ct][cg][ctx];
... ...
@@ -440,7 +440,8 @@ static void vp6_parse_coeff(VP56Context *s)
440 440
         model1 = model->coeff_dccv[pt];
441 441
         model2 = model->coeff_dcct[pt][ctx];
442 442
 
443
-        for (coeff_idx=0; coeff_idx<64; ) {
443
+        coeff_idx = 0;
444
+        for (;;) {
444 445
             if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
445 446
                 /* parse a coeff */
446 447
                 if (vp56_rac_get_prob(c, model2[2])) {
... ...
@@ -481,8 +482,10 @@ static void vp6_parse_coeff(VP56Context *s)
481 481
                             run += vp56_rac_get_prob(c, model3[i+8]) << i;
482 482
                 }
483 483
             }
484
-
485
-            cg = vp6_coeff_groups[coeff_idx+=run];
484
+            coeff_idx += run;
485
+            if (coeff_idx >= 64)
486
+                break;
487
+            cg = vp6_coeff_groups[coeff_idx];
486 488
             model1 = model2 = model->coeff_ract[pt][ct][cg];
487 489
         }
488 490
 
... ...
@@ -109,6 +109,11 @@ static int wma_decode_init(AVCodecContext * avctx)
109 109
         }
110 110
     }
111 111
 
112
+    if(avctx->channels > MAX_CHANNELS){
113
+        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels (%d)\n", avctx->channels);
114
+        return -1;
115
+    }
116
+
112 117
     if(ff_wma_init(avctx, flags2)<0)
113 118
         return -1;
114 119
 
... ...
@@ -439,7 +439,7 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
439 439
     struct v4l2_streamparm streamparm = {0};
440 440
     struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
441 441
     int i, ret;
442
-    AVRational fps;
442
+    AVRational fps={0};
443 443
 
444 444
     streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
445 445
 
... ...
@@ -69,16 +69,13 @@ static int query_formats(AVFilterContext *ctx)
69 69
         PIX_FMT_BGR555BE,     PIX_FMT_BGR555LE,
70 70
         PIX_FMT_GRAY16BE,     PIX_FMT_GRAY16LE,
71 71
         PIX_FMT_YUV420P16LE,  PIX_FMT_YUV420P16BE,
72
-        PIX_FMT_YUV422P16LE,  PIX_FMT_YUV422P16BE,
73 72
         PIX_FMT_YUV444P16LE,  PIX_FMT_YUV444P16BE,
74 73
         PIX_FMT_NV12,         PIX_FMT_NV21,
75 74
         PIX_FMT_RGB8,         PIX_FMT_BGR8,
76 75
         PIX_FMT_RGB4_BYTE,    PIX_FMT_BGR4_BYTE,
77
-        PIX_FMT_YUV444P,      PIX_FMT_YUV422P,
76
+        PIX_FMT_YUV444P,      PIX_FMT_YUVJ444P,
78 77
         PIX_FMT_YUV420P,      PIX_FMT_YUVJ420P,
79
-        PIX_FMT_YUV411P,      PIX_FMT_YUV410P,
80
-        PIX_FMT_YUVJ444P,     PIX_FMT_YUVJ422P,
81
-        PIX_FMT_YUV440P,      PIX_FMT_YUVJ440P,
78
+        PIX_FMT_YUV410P,
82 79
         PIX_FMT_YUVA420P,     PIX_FMT_GRAY8,
83 80
         PIX_FMT_NONE
84 81
     };
... ...
@@ -248,6 +248,7 @@ OBJS-$(CONFIG_RTPDEC)                    += rdt.o         \
248 248
                                             rtpdec.o      \
249 249
                                             rtpdec_amr.o  \
250 250
                                             rtpdec_asf.o  \
251
+                                            rtpdec_g726.o \
251 252
                                             rtpdec_h263.o \
252 253
                                             rtpdec_h264.o \
253 254
                                             rtpdec_latm.o \
... ...
@@ -40,6 +40,8 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
40 40
         buf2 = buf;
41 41
 
42 42
         for(frames = 0; buf2 < end; frames++) {
43
+            if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8))
44
+                buf2+=16;
43 45
             init_get_bits(&gbc, buf2, 54);
44 46
             if(ff_ac3_parse_header(&gbc, &hdr) < 0)
45 47
                 break;
... ...
@@ -1238,6 +1238,7 @@ AVFormatContext *avformat_alloc_output_context(const char *format,
1238 1238
 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
1239 1239
                                    const char *format_name, const char *filename);
1240 1240
 
1241
+#if FF_API_FORMAT_PARAMETERS
1241 1242
 /**
1242 1243
  * Read packets of a media file to get stream information. This
1243 1244
  * is useful for file formats with no headers such as MPEG. This
... ...
@@ -1250,8 +1251,34 @@ int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oforma
1250 1250
  * @return >=0 if OK, AVERROR_xxx on error
1251 1251
  * @todo Let the user decide somehow what information is needed so that
1252 1252
  *       we do not waste time getting stuff the user does not need.
1253
+ *
1254
+ * @deprecated use avformat_find_stream_info.
1253 1255
  */
1254 1256
 int av_find_stream_info(AVFormatContext *ic);
1257
+#endif
1258
+
1259
+/**
1260
+ * Read packets of a media file to get stream information. This
1261
+ * is useful for file formats with no headers such as MPEG. This
1262
+ * function also computes the real framerate in case of MPEG-2 repeat
1263
+ * frame mode.
1264
+ * The logical file position is not changed by this function;
1265
+ * examined packets may be buffered for later processing.
1266
+ *
1267
+ * @param ic media file handle
1268
+ * @param options  If non-NULL, an ic.nb_streams long array of pointers to
1269
+ *                 dictionaries, where i-th member contains options for
1270
+ *                 codec corresponding to i-th stream.
1271
+ *                 On return each dictionary will be filled with options that were not found.
1272
+ * @return >=0 if OK, AVERROR_xxx on error
1273
+ *
1274
+ * @note this function isn't guaranteed to open all the codecs, so
1275
+ *       options being non-empty at return is a perfectly normal behavior.
1276
+ *
1277
+ * @todo Let the user decide somehow what information is needed so that
1278
+ *       we do not waste time getting stuff the user does not need.
1279
+ */
1280
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
1255 1281
 
1256 1282
 /**
1257 1283
  * Find the "best" stream in the file.
... ...
@@ -59,6 +59,12 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
59 59
 
60 60
             if (s1->sample_rate)
61 61
                 st->codec->sample_rate = s1->sample_rate;
62
+            if (st->codec->sample_rate <= 0) {
63
+                av_log(s, AV_LOG_WARNING, "Invalid sample rate %d specified using default of 44100\n",
64
+                       st->codec->sample_rate);
65
+                st->codec->sample_rate= 44100;
66
+            }
67
+
62 68
             if (s1->channels)
63 69
                 st->codec->channels    = s1->channels;
64 70
 
... ...
@@ -246,7 +252,7 @@ AVInputFormat ff_gsm_demuxer = {
246 246
 #endif
247 247
 
248 248
 #if CONFIG_MJPEG_DEMUXER
249
-FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", CODEC_ID_MJPEG)
249
+FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", CODEC_ID_MJPEG)
250 250
 #endif
251 251
 
252 252
 #if CONFIG_MLP_DEMUXER
... ...
@@ -82,6 +82,11 @@ void av_register_rtp_dynamic_payload_handlers(void)
82 82
     ff_register_dynamic_payload_handler(&ff_qt_rtp_vid_handler);
83 83
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_aud_handler);
84 84
     ff_register_dynamic_payload_handler(&ff_quicktime_rtp_vid_handler);
85
+
86
+    ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler);
87
+    ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler);
88
+    ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler);
89
+    ff_register_dynamic_payload_handler(&ff_g726_40_dynamic_handler);
85 90
 }
86 91
 
87 92
 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
... ...
@@ -33,6 +33,10 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
33 33
 
34 34
 extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler;
35 35
 extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler;
36
+extern RTPDynamicProtocolHandler ff_g726_16_dynamic_handler;
37
+extern RTPDynamicProtocolHandler ff_g726_24_dynamic_handler;
38
+extern RTPDynamicProtocolHandler ff_g726_32_dynamic_handler;
39
+extern RTPDynamicProtocolHandler ff_g726_40_dynamic_handler;
36 40
 extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler;
37 41
 extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler;
38 42
 extern RTPDynamicProtocolHandler ff_h264_dynamic_handler;
39 43
new file mode 100644
... ...
@@ -0,0 +1,94 @@
0
+/*
1
+ * Copyright (c) 2011 Miroslav Slugeň <Thunder.m@seznam.cz>
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "avformat.h"
21
+#include "rtpdec_formats.h"
22
+
23
+static int g726_16_parse_sdp_line(AVFormatContext *s, int st_index,
24
+                              PayloadContext *data, const char *line)
25
+{
26
+    AVStream *stream = s->streams[st_index];
27
+    AVCodecContext *codec = stream->codec;
28
+
29
+    codec->bit_rate = 16000;
30
+
31
+    return 0;
32
+}
33
+
34
+static int g726_24_parse_sdp_line(AVFormatContext *s, int st_index,
35
+                              PayloadContext *data, const char *line)
36
+{
37
+    AVStream *stream = s->streams[st_index];
38
+    AVCodecContext *codec = stream->codec;
39
+
40
+    codec->bit_rate = 24000;
41
+
42
+    return 0;
43
+}
44
+
45
+static int g726_32_parse_sdp_line(AVFormatContext *s, int st_index,
46
+                              PayloadContext *data, const char *line)
47
+{
48
+    AVStream *stream = s->streams[st_index];
49
+    AVCodecContext *codec = stream->codec;
50
+
51
+    codec->bit_rate = 32000;
52
+
53
+    return 0;
54
+}
55
+
56
+static int g726_40_parse_sdp_line(AVFormatContext *s, int st_index,
57
+                              PayloadContext *data, const char *line)
58
+{
59
+    AVStream *stream = s->streams[st_index];
60
+    AVCodecContext *codec = stream->codec;
61
+
62
+    codec->bit_rate = 40000;
63
+
64
+    return 0;
65
+}
66
+
67
+RTPDynamicProtocolHandler ff_g726_16_dynamic_handler = {
68
+    .enc_name         = "G726-16",
69
+    .codec_type       = AVMEDIA_TYPE_AUDIO,
70
+    .codec_id         = CODEC_ID_ADPCM_G726,
71
+    .parse_sdp_a_line = g726_16_parse_sdp_line,
72
+};
73
+
74
+RTPDynamicProtocolHandler ff_g726_24_dynamic_handler = {
75
+    .enc_name         = "G726-24",
76
+    .codec_type       = AVMEDIA_TYPE_AUDIO,
77
+    .codec_id         = CODEC_ID_ADPCM_G726,
78
+    .parse_sdp_a_line = g726_24_parse_sdp_line,
79
+};
80
+
81
+RTPDynamicProtocolHandler ff_g726_32_dynamic_handler = {
82
+    .enc_name         = "G726-32",
83
+    .codec_type       = AVMEDIA_TYPE_AUDIO,
84
+    .codec_id         = CODEC_ID_ADPCM_G726,
85
+    .parse_sdp_a_line = g726_32_parse_sdp_line,
86
+};
87
+
88
+RTPDynamicProtocolHandler ff_g726_40_dynamic_handler = {
89
+    .enc_name         = "G726-40",
90
+    .codec_type       = AVMEDIA_TYPE_AUDIO,
91
+    .codec_id         = CODEC_ID_ADPCM_G726,
92
+    .parse_sdp_a_line = g726_40_parse_sdp_line,
93
+};
... ...
@@ -2190,7 +2190,7 @@ static int has_decode_delay_been_guessed(AVStream *st)
2190 2190
         st->codec_info_nb_frames >= 6 + st->codec->has_b_frames;
2191 2191
 }
2192 2192
 
2193
-static int try_decode_frame(AVStream *st, AVPacket *avpkt)
2193
+static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options)
2194 2194
 {
2195 2195
     int16_t *samples;
2196 2196
     AVCodec *codec;
... ...
@@ -2201,7 +2201,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt)
2201 2201
         codec = avcodec_find_decoder(st->codec->codec_id);
2202 2202
         if (!codec)
2203 2203
             return -1;
2204
-        ret = avcodec_open(st->codec, codec);
2204
+        ret = avcodec_open2(st->codec, codec, options);
2205 2205
         if (ret < 0)
2206 2206
             return ret;
2207 2207
     }
... ...
@@ -2320,12 +2320,20 @@ static int tb_unreliable(AVCodecContext *c){
2320 2320
     return 0;
2321 2321
 }
2322 2322
 
2323
+#if FF_API_FORMAT_PARAMETERS
2323 2324
 int av_find_stream_info(AVFormatContext *ic)
2324 2325
 {
2326
+    return avformat_find_stream_info(ic, NULL);
2327
+}
2328
+#endif
2329
+
2330
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
2331
+{
2325 2332
     int i, count, ret, read_size, j;
2326 2333
     AVStream *st;
2327 2334
     AVPacket pkt1, *pkt;
2328 2335
     int64_t old_offset = avio_tell(ic->pb);
2336
+    int orig_nb_streams = ic->nb_streams;        // new streams might appear, no options for those
2329 2337
 
2330 2338
     for(i=0;i<ic->nb_streams;i++) {
2331 2339
         AVCodec *codec;
... ...
@@ -2362,12 +2370,12 @@ int av_find_stream_info(AVFormatContext *ic)
2362 2362
         /* Ensure that subtitle_header is properly set. */
2363 2363
         if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
2364 2364
             && codec && !st->codec->codec)
2365
-            avcodec_open(st->codec, codec);
2365
+            avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
2366 2366
 
2367 2367
         //try to just open decoders, in case this is enough to get parameters
2368 2368
         if(!has_codec_parameters(st->codec)){
2369 2369
             if (codec && !st->codec->codec)
2370
-                avcodec_open(st->codec, codec);
2370
+                avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
2371 2371
         }
2372 2372
     }
2373 2373
 
... ...
@@ -2477,7 +2485,7 @@ int av_find_stream_info(AVFormatContext *ic)
2477 2477
                 for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error); i++) {
2478 2478
                     int framerate= get_std_framerate(i);
2479 2479
                     int ticks= lrintf(dur*framerate/(1001*12));
2480
-                    double error= dur - ticks*1001*12/(double)framerate;
2480
+                    double error = dur - (double)ticks*1001*12 / framerate;
2481 2481
                     st->info->duration_error[i] += error*error;
2482 2482
                 }
2483 2483
                 st->info->duration_count++;
... ...
@@ -2503,7 +2511,7 @@ int av_find_stream_info(AVFormatContext *ic)
2503 2503
            it takes longer and uses more memory. For MPEG-4, we need to
2504 2504
            decompress for QuickTime. */
2505 2505
         if (!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st))
2506
-            try_decode_frame(st, pkt);
2506
+            try_decode_frame(st, pkt, (options && i < orig_nb_streams )? &options[i] : NULL);
2507 2507
 
2508 2508
         st->codec_info_nb_frames++;
2509 2509
         count++;
... ...
@@ -24,7 +24,7 @@
24 24
 #include "libavutil/avutil.h"
25 25
 
26 26
 #define LIBAVFORMAT_VERSION_MAJOR 52
27
-#define LIBAVFORMAT_VERSION_MINOR 110
27
+#define LIBAVFORMAT_VERSION_MINOR 111
28 28
 #define LIBAVFORMAT_VERSION_MICRO  0
29 29
 
30 30
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
... ...
@@ -125,7 +125,7 @@ int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int heigh
125 125
         has_plane[desc->comp[i].plane] = 1;
126 126
 
127 127
     total_size = size[0];
128
-    for (i = 1; has_plane[i] && i < 4; i++) {
128
+    for (i = 1; i < 4 && has_plane[i]; i++) {
129 129
         int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
130 130
         data[i] = data[i-1] + size[i-1];
131 131
         h = (height + (1 << s) - 1) >> s;