Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
adpcm: Clip step_index values read from the bitstream at the beginning of each frame.
oma: don't read beyond end of leaf_table.
doxygen: Remove documentation for non-existing parameters; misc small fixes.
Indeo3: fix crashes on corrupt bitstreams.
msmpeg4: Replace forward declaration by proper #include.
segment: implement wrap around
avf: reorder AVStream and AVFormatContext
aacdec: Remove erroneous reference to global gain from the out of bounds scalefactor error message.

Conflicts:
libavcodec/indeo3.c
libavformat/avformat.h
libavutil/avutil.h

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

Michael Niedermayer authored on 2012/02/29 08:30:35
Showing 14 changed files
... ...
@@ -362,6 +362,8 @@ Set segment duration to @var{t} seconds.
362 362
 Generate also a listfile named @var{name}.
363 363
 @item segment_list_size @var{size}
364 364
 Overwrite the listfile once it reaches @var{size} entries.
365
+@item segment_wrap @var{limit}
366
+Wrap around segment index once it reaches @var{limit}.
365 367
 @end table
366 368
 
367 369
 @example
... ...
@@ -399,8 +399,6 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
399 399
 /**
400 400
  * Configure output channel order based on the current program configuration element.
401 401
  *
402
- * @param   che_pos current channel position configuration
403
- *
404 402
  * @return  Returns error status. 0 - OK, !0 - error
405 403
  */
406 404
 static av_cold int output_configure(AACContext *ac,
... ...
@@ -459,8 +457,6 @@ static void flush(AVCodecContext *avctx)
459 459
 /**
460 460
  * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
461 461
  *
462
- * @param cpe_map Stereo (Channel Pair Element) map, NULL if stereo bit is not present.
463
- * @param sce_map mono (Single Channel Element) map
464 462
  * @param type speaker type/position for these channels
465 463
  */
466 464
 static void decode_channel_map(uint8_t layout_map[][3],
... ...
@@ -1037,7 +1033,6 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
1037 1037
     int offset[3] = { global_gain, global_gain - 90, 0 };
1038 1038
     int clipped_offset;
1039 1039
     int noise_flag = 1;
1040
-    static const char *const sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
1041 1040
     for (g = 0; g < ics->num_window_groups; g++) {
1042 1041
         for (i = 0; i < ics->max_sfb;) {
1043 1042
             int run_end = band_type_run_end[idx];
... ...
@@ -1076,7 +1071,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
1076 1076
                     offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
1077 1077
                     if (offset[0] > 255U) {
1078 1078
                         av_log(ac->avctx, AV_LOG_ERROR,
1079
-                               "%s (%d) out of range.\n", sf_str[0], offset[0]);
1079
+                               "Scalefactor (%d) out of range.\n", offset[0]);
1080 1080
                         return -1;
1081 1081
                     }
1082 1082
                     sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
... ...
@@ -707,7 +707,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
707 707
         for (channel = 0; channel < avctx->channels; channel++) {
708 708
             cs = &c->status[channel];
709 709
             cs->predictor  = (int16_t)bytestream_get_le16(&src);
710
-            cs->step_index = *src++;
710
+            cs->step_index = av_clip(*src++, 0, 88);
711 711
             src++;
712 712
             *samples++ = cs->predictor;
713 713
         }
... ...
@@ -730,8 +730,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
730 730
 
731 731
         c->status[0].predictor  = (int16_t)AV_RL16(src + 10);
732 732
         c->status[1].predictor  = (int16_t)AV_RL16(src + 12);
733
-        c->status[0].step_index = src[14];
734
-        c->status[1].step_index = src[15];
733
+        c->status[0].step_index = av_clip(src[14], 0, 88);
734
+        c->status[1].step_index = av_clip(src[15], 0, 88);
735 735
         /* sign extend the predictors */
736 736
         src += 16;
737 737
         diff_channel = c->status[1].predictor;
... ...
@@ -771,7 +771,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
771 771
         for (channel = 0; channel < avctx->channels; channel++) {
772 772
             cs = &c->status[channel];
773 773
             cs->predictor  = (int16_t)bytestream_get_le16(&src);
774
-            cs->step_index = *src++;
774
+            cs->step_index = av_clip(*src++, 0, 88);
775 775
             src++;
776 776
         }
777 777
 
... ...
@@ -834,7 +834,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
834 834
         src += 4; // skip sample count (already read)
835 835
 
836 836
         for (i=0; i<=st; i++)
837
-            c->status[i].step_index = bytestream_get_le32(&src);
837
+            c->status[i].step_index = av_clip(bytestream_get_le32(&src), 0, 88);
838 838
         for (i=0; i<=st; i++)
839 839
             c->status[i].predictor  = bytestream_get_le32(&src);
840 840
 
... ...
@@ -1051,11 +1051,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
1051 1051
     case CODEC_ID_ADPCM_IMA_SMJPEG:
1052 1052
         if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) {
1053 1053
             c->status[0].predictor = sign_extend(bytestream_get_le16(&src), 16);
1054
-            c->status[0].step_index = bytestream_get_le16(&src);
1054
+            c->status[0].step_index = av_clip(bytestream_get_le16(&src), 0, 88);
1055 1055
             src += 4;
1056 1056
         } else {
1057 1057
             c->status[0].predictor = sign_extend(bytestream_get_be16(&src), 16);
1058
-            c->status[0].step_index = bytestream_get_byte(&src);
1058
+            c->status[0].step_index = av_clip(bytestream_get_byte(&src), 0, 88);
1059 1059
             src += 1;
1060 1060
         }
1061 1061
 
... ...
@@ -727,6 +727,8 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
727 727
         SPLIT_CELL(ref_cell->height, curr_cell.height);
728 728
         ref_cell->ypos   += curr_cell.height;
729 729
         ref_cell->height -= curr_cell.height;
730
+        if (ref_cell->height <= 0 || curr_cell.height <= 0)
731
+            return AVERROR_INVALIDDATA;
730 732
     } else if (code == V_SPLIT) {
731 733
         if (curr_cell.width > strip_width) {
732 734
             /* split strip */
... ...
@@ -735,6 +737,8 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
735 735
             SPLIT_CELL(ref_cell->width, curr_cell.width);
736 736
         ref_cell->xpos  += curr_cell.width;
737 737
         ref_cell->width -= curr_cell.width;
738
+        if (ref_cell->width <= 0 || curr_cell.width <= 0)
739
+            return AVERROR_INVALIDDATA;
738 740
     }
739 741
 
740 742
     while (get_bits_left(&ctx->gb) >= 2) { /* loop until return */
... ...
@@ -890,14 +894,16 @@ static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
890 890
         return AVERROR_INVALIDDATA;
891 891
 
892 892
     if (width != ctx->width || height != ctx->height) {
893
+        int res;
894
+
893 895
         av_dlog(avctx, "Frame dimensions changed!\n");
894 896
 
895 897
         ctx->width  = width;
896 898
         ctx->height = height;
897 899
 
898 900
         free_frame_buffers(ctx);
899
-        if(allocate_frame_buffers(ctx, avctx) < 0)
900
-            return AVERROR_INVALIDDATA;
901
+        if ((res = allocate_frame_buffers(ctx, avctx)) < 0)
902
+             return res;
901 903
         avcodec_set_dimensions(avctx, width, height);
902 904
     }
903 905
 
... ...
@@ -34,6 +34,7 @@
34 34
 #include "libavutil/x86_cpu.h"
35 35
 #include "h263.h"
36 36
 #include "mpeg4video.h"
37
+#include "vc1data.h"
37 38
 
38 39
 /*
39 40
  * You can also call this codec : MPEG4 with a twist !
... ...
@@ -59,9 +60,6 @@
59 59
 static uint32_t v2_dc_lum_table[512][2];
60 60
 static uint32_t v2_dc_chroma_table[512][2];
61 61
 
62
-/* vc1 externs */
63
-extern const uint8_t ff_wmv3_dc_scale_table[32];
64
-
65 62
 #include "msmpeg4data.h"
66 63
 
67 64
 #if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
... ...
@@ -1481,7 +1481,6 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1481 1481
  *@brief Decode a single WMA packet.
1482 1482
  *@param avctx codec context
1483 1483
  *@param data the output buffer
1484
- *@param data_size number of bytes that were written to the output buffer
1485 1484
  *@param avpkt input packet
1486 1485
  *@return number of bytes that were read from the input buffer
1487 1486
  */
... ...
@@ -1725,9 +1725,6 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
1725 1725
  * (if less than 480), usually used to prevent blanks at track boundaries.
1726 1726
  *
1727 1727
  * @param ctx WMA Voice decoder context
1728
- * @param samples pointer to output buffer for voice samples
1729
- * @param data_size pointer containing the size of #samples on input, and the
1730
- *                  amount of #samples filled on output
1731 1728
  * @return 0 on success, <0 on error or 1 if there was not enough data to
1732 1729
  *         fully parse the superframe
1733 1730
  */
... ...
@@ -146,7 +146,6 @@ x11grab_region_win_init(struct x11_grab *s)
146 146
  * Initialize the x11 grab device demuxer (public device demuxer API).
147 147
  *
148 148
  * @param s1 Context from avformat core
149
- * @param ap Parameters from avformat core
150 149
  * @return <ul>
151 150
  *          <li>AVERROR(ENOMEM) no memory left</li>
152 151
  *          <li>AVERROR(EIO) other failure case</li>
... ...
@@ -577,7 +577,6 @@ typedef struct AVStream {
577 577
      * encoding: set by libavformat in av_write_header
578 578
      */
579 579
     AVRational time_base;
580
-    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
581 580
 
582 581
     /**
583 582
      * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
... ...
@@ -600,6 +599,8 @@ typedef struct AVStream {
600 600
 
601 601
     int disposition; /**< AV_DISPOSITION_* bit field */
602 602
 
603
+    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
604
+
603 605
     /**
604 606
      * sample aspect ratio (0 if unknown)
605 607
      * - encoding: Set by user.
... ...
@@ -623,21 +624,6 @@ typedef struct AVStream {
623 623
      */
624 624
 
625 625
     /**
626
-     * Number of frames that have been demuxed during av_find_stream_info()
627
-     */
628
-    int codec_info_nb_frames;
629
-
630
-    /**
631
-     * Stream Identifier
632
-     * This is the MPEG-TS stream identifier +1
633
-     * 0 means unknown
634
-     */
635
-    int stream_identifier;
636
-
637
-    int64_t interleaver_chunk_size;
638
-    int64_t interleaver_chunk_duration;
639
-
640
-    /**
641 626
      * Stream information used internally by av_find_stream_info()
642 627
      */
643 628
 #define MAX_STD_TIMEBASES (60*12+5)
... ...
@@ -649,9 +635,12 @@ typedef struct AVStream {
649 649
         int64_t codec_info_duration;
650 650
         int nb_decoded_frames;
651 651
     } *info;
652
+
653
+    AVPacket cur_pkt;
652 654
     const uint8_t *cur_ptr;
653 655
     int cur_len;
654
-    AVPacket cur_pkt;
656
+
657
+    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
655 658
 
656 659
     // Timestamp generation support:
657 660
     /**
... ...
@@ -664,8 +653,8 @@ typedef struct AVStream {
664 664
     int64_t reference_dts;
665 665
     int64_t first_dts;
666 666
     int64_t cur_dts;
667
-    int last_IP_duration;
668 667
     int64_t last_IP_pts;
668
+    int last_IP_duration;
669 669
 
670 670
     /**
671 671
      * Number of packets to buffer for codec probing
... ...
@@ -674,23 +663,37 @@ typedef struct AVStream {
674 674
     int probe_packets;
675 675
 
676 676
     /**
677
+     * Number of frames that have been demuxed during av_find_stream_info()
678
+     */
679
+    int codec_info_nb_frames;
680
+
681
+    /**
682
+     * Stream Identifier
683
+     * This is the MPEG-TS stream identifier +1
684
+     * 0 means unknown
685
+     */
686
+    int stream_identifier;
687
+
688
+    int64_t interleaver_chunk_size;
689
+    int64_t interleaver_chunk_duration;
690
+
691
+    /* av_read_frame() support */
692
+    enum AVStreamParseType need_parsing;
693
+    struct AVCodecParserContext *parser;
694
+
695
+    /**
677 696
      * last packet in packet_buffer for this stream when muxing.
678 697
      */
679 698
     struct AVPacketList *last_in_packet_buffer;
680 699
     AVProbeData probe_data;
681 700
 #define MAX_REORDER_DELAY 16
682 701
     int64_t pts_buffer[MAX_REORDER_DELAY+1];
683
-    /* av_read_frame() support */
684
-    enum AVStreamParseType need_parsing;
685
-    struct AVCodecParserContext *parser;
686 702
 
687 703
     AVIndexEntry *index_entries; /**< Only used if the format does not
688 704
                                     support seeking natively. */
689 705
     int nb_index_entries;
690 706
     unsigned int index_entries_allocated_size;
691 707
 
692
-    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
693
-
694 708
     /**
695 709
      * flag to indicate that probing is requested
696 710
      * NOT PART OF PUBLIC API
... ...
@@ -772,6 +775,9 @@ typedef struct AVFormatContext {
772 772
      */
773 773
     AVIOContext *pb;
774 774
 
775
+    /* stream info */
776
+    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
777
+
775 778
     /**
776 779
      * A list of all streams in the file. New streams are created with
777 780
      * avformat_new_stream().
... ...
@@ -785,8 +791,6 @@ typedef struct AVFormatContext {
785 785
     AVStream **streams;
786 786
 
787 787
     char filename[1024]; /**< input or output filename */
788
-    /* stream info */
789
-    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
790 788
 
791 789
     /**
792 790
      * Decoding: position of the first frame of the component, in
... ...
@@ -883,12 +887,6 @@ typedef struct AVFormatContext {
883 883
     unsigned int nb_chapters;
884 884
     AVChapter **chapters;
885 885
 
886
-    /**
887
-     * Flags to enable debugging.
888
-     */
889
-    int debug;
890
-#define FF_FDEBUG_TS        0x0001
891
-
892 886
     AVDictionary *metadata;
893 887
 
894 888
     /**
... ...
@@ -925,6 +923,12 @@ typedef struct AVFormatContext {
925 925
     AVIOInterruptCB interrupt_callback;
926 926
 
927 927
     /**
928
+     * Flags to enable debugging.
929
+     */
930
+    int debug;
931
+#define FF_FDEBUG_TS        0x0001
932
+
933
+    /**
928 934
      * Transport stream id.
929 935
      * This will be moved into demuxer private options. Thus no API/ABI compatibility
930 936
      */
... ...
@@ -961,19 +965,6 @@ typedef struct AVFormatContext {
961 961
      * New public fields should be added right above.
962 962
      *****************************************************************
963 963
      */
964
-    /**
965
-     * Raw packets from the demuxer, prior to parsing and decoding.
966
-     * This buffer is used for buffering packets until the codec can
967
-     * be identified, as parsing cannot be done without knowing the
968
-     * codec.
969
-     */
970
-    struct AVPacketList *raw_packet_buffer;
971
-    struct AVPacketList *raw_packet_buffer_end;
972
-    /**
973
-     * Remaining size available for raw_packet_buffer, in bytes.
974
-     */
975
-#define RAW_PACKET_BUFFER_SIZE 2500000
976
-    int raw_packet_buffer_remaining_size;
977 964
 
978 965
     /**
979 966
      * This buffer is only needed when packets were already buffered but
... ...
@@ -988,6 +979,20 @@ typedef struct AVFormatContext {
988 988
 
989 989
     /* av_seek_frame() support */
990 990
     int64_t data_offset; /**< offset of the first packet */
991
+
992
+    /**
993
+     * Raw packets from the demuxer, prior to parsing and decoding.
994
+     * This buffer is used for buffering packets until the codec can
995
+     * be identified, as parsing cannot be done without knowing the
996
+     * codec.
997
+     */
998
+    struct AVPacketList *raw_packet_buffer;
999
+    struct AVPacketList *raw_packet_buffer_end;
1000
+    /**
1001
+     * Remaining size available for raw_packet_buffer, in bytes.
1002
+     */
1003
+#define RAW_PACKET_BUFFER_SIZE 2500000
1004
+    int raw_packet_buffer_remaining_size;
991 1005
 } AVFormatContext;
992 1006
 
993 1007
 typedef struct AVPacketList {
... ...
@@ -40,9 +40,9 @@
40 40
 uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap);
41 41
 
42 42
 /**
43
- * Get the channel layout for the specified channel layout tag.
43
+ * Get the channel layout for the specified channel label.
44 44
  *
45
- * @param[in]  tag     channel label
45
+ * @param[in]  label   channel label
46 46
  * @return             channel layout mask fragment
47 47
  */
48 48
 uint32_t ff_mov_get_channel_label(uint32_t label);
... ...
@@ -96,10 +96,6 @@ typedef struct {
96 96
  * @param stream_type               STREAM_TYPE_xxx
97 97
  * @param pp                        Descriptor buffer pointer
98 98
  * @param desc_list_end             End of buffer
99
- * @param mp4_dec_config_descr_len  Length of 'mp4_dec_config_descr', or zero if not present
100
- * @param mp4_es_id
101
- * @param pid
102
- * @param mp4_dec_config_descr
103 99
  * @return <0 to stop processing
104 100
  */
105 101
 int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type,
... ...
@@ -69,7 +69,6 @@ static int rl2_probe(AVProbeData *p)
69 69
 /**
70 70
  * read rl2 header data and setup the avstreams
71 71
  * @param s demuxer context
72
- * @param ap format parameters
73 72
  * @return 0 on success, AVERROR otherwise
74 73
  */
75 74
 static av_cold int rl2_read_header(AVFormatContext *s)
... ...
@@ -39,6 +39,7 @@ typedef struct {
39 39
     char *list;            /**< Set by a private option. */
40 40
     float time;            /**< Set by a private option. */
41 41
     int  size;             /**< Set by a private option. */
42
+    int  wrap;             /**< Set by a private option. */
42 43
     int64_t offset_time;
43 44
     int64_t recording_time;
44 45
     int has_video;
... ...
@@ -51,6 +52,9 @@ static int segment_start(AVFormatContext *s)
51 51
     AVFormatContext *oc = c->avf;
52 52
     int err = 0;
53 53
 
54
+    if (c->wrap)
55
+        c->number %= c->wrap;
56
+
54 57
     if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
55 58
                               s->filename, c->number++) < 0)
56 59
         return AVERROR(EINVAL);
... ...
@@ -211,7 +215,6 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
211 211
                 if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,
212 212
                                       &s->interrupt_callback, NULL)) < 0)
213 213
                     goto fail;
214
-
215 214
             }
216 215
         }
217 216
     }
... ...
@@ -250,6 +253,7 @@ static const AVOption options[] = {
250 250
     { "segment_time",      "segment length in seconds",               OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E },
251 251
     { "segment_list",      "output the segment list",                 OFFSET(list),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
252 252
     { "segment_list_size", "maximum number of playlist entries",      OFFSET(size),    AV_OPT_TYPE_INT,    {.dbl = 5},     0, INT_MAX, E },
253
+    { "segment_wrap",      "number after which the index wraps",      OFFSET(wrap),    AV_OPT_TYPE_INT,    {.dbl = 0},     0, INT_MAX, E },
253 254
     { NULL },
254 255
 };
255 256
 
... ...
@@ -31,7 +31,7 @@
31 31
  *
32 32
  * @section libav_intro Introduction
33 33
  *
34
- * This document describe the usage of the different libraries
34
+ * This document describes the usage of the different libraries
35 35
  * provided by FFmpeg.
36 36
  *
37 37
  * @li @ref libavc "libavcodec" encoding/decoding library
... ...
@@ -41,7 +41,6 @@
41 41
  * @li @ref lavu "libavutil" common utility library
42 42
  * @li @subpage libpostproc post processing library
43 43
  * @li @subpage libswscale  color conversion and scaling library
44
- *
45 44
  */
46 45
 
47 46
 /**