Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (58 commits)
amrnbdec: check frame size before decoding.
cscd: use negative error values to indicate decode_init() failures.
h264: prevent overreads in intra PCM decoding.
FATE: do not decode audio in the nuv test.
dxa: set audio stream time base using the sample rate
psx-str: do not allow seeking by bytes
asfdec: Do not set AVCodecContext.frame_size
vqf: set packet parameters after av_new_packet()
mpegaudiodec: use DSPUtil.butterflies_float().
FATE: add mp3 test for sample that exhibited false overreads
fate: add cdxl test for bit line plane arrangement
vmnc: return error on decode_init() failure.
libvorbis: add/update error messages
libvorbis: use AVFifoBuffer for output packet buffer
libvorbis: remove unneeded e_o_s check
libvorbis: check return values for functions that can return errors
libvorbis: use float input instead of s16
libvorbis: do not flush libvorbis analysis if dsp state was not initialized
libvorbis: use VBR by default, with default quality of 3
libvorbis: fix use of minrate/maxrate AVOptions
...

Conflicts:
Changelog
doc/APIchanges
libavcodec/avcodec.h
libavcodec/dpxenc.c
libavcodec/libvorbis.c
libavcodec/vmnc.c
libavformat/asfdec.c
libavformat/id3v2enc.c
libavformat/internal.h
libavformat/mp3enc.c
libavformat/utils.c
libavformat/version.h
libswscale/utils.c
tests/fate/video.mak
tests/ref/fate/nuv
tests/ref/fate/prores-alpha
tests/ref/lavf/ffm
tests/ref/vsynth1/prores
tests/ref/vsynth2/prores

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

Michael Niedermayer authored on 2012/03/01 09:13:16
Showing 64 changed files
... ...
@@ -8,6 +8,7 @@ version next:
8 8
 - Apple ProRes encoder
9 9
 - ffprobe -count_packets and -count_frames options
10 10
 - Sun Rasterfile Encoder
11
+- ID3v2 attached pictures reading and writing
11 12
 
12 13
 
13 14
 version 0.10:
... ...
@@ -13,6 +13,7 @@ libavutil:   2011-04-18
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+<<<<<<< HEAD
16 17
 2012-02-21 - xxxxxxx - lavc 54.4.100
17 18
   Add av_get_pcm_codec() function.
18 19
 
... ...
@@ -35,6 +36,13 @@ API changes, most recent first:
35 35
 2012-01-24 - xxxxxxx - lavfi 2.60.100
36 36
   Add avfilter_graph_dump.
37 37
 
38
+||||||| merged common ancestors
39
+=======
40
+2012-xx-xx - xxxxxxx - lavf 54.2.0 - avformat.h
41
+  Add AVStream.attached_pic and AV_DISPOSITION_ATTACHED_PIC,
42
+  used for dealing with attached pictures/cover art.
43
+
44
+>>>>>>> qatar/master
38 45
 2012-02-25 - c9bca80 - lavu 51.24.0 - error.h
39 46
   Add AVERROR_UNKNOWN
40 47
 
... ...
@@ -370,5 +370,39 @@ Wrap around segment index once it reaches @var{limit}.
370 370
 ffmpeg -i in.mkv -c copy -map 0 -f segment -list out.list out%03d.nut
371 371
 @end example
372 372
 
373
+@section mp3
374
+
375
+The MP3 muxer writes a raw MP3 stream with an ID3v2 header at the beginning and
376
+optionally an ID3v1 tag at the end. ID3v2.3 and ID3v2.4 are supported, the
377
+@code{id3v2_version} option controls which one is used. The legacy ID3v1 tag is
378
+not written by default, but may be enabled with the @code{write_id3v1} option.
379
+
380
+For seekable output the muxer also writes a Xing frame at the beginning, which
381
+contains the number of frames in the file. It is useful for computing duration
382
+of VBR files.
383
+
384
+The muxer supports writing ID3v2 attached pictures (APIC frames). The pictures
385
+are supplied to the muxer in form of a video stream with a single packet. There
386
+can be any number of those streams, each will correspond to a single APIC frame.
387
+The stream metadata tags @var{title} and @var{comment} map to APIC
388
+@var{description} and @var{picture type} respectively. See
389
+@url{http://id3.org/id3v2.4.0-frames} for allowed picture types.
390
+
391
+Note that the APIC frames must be written at the beginning, so the muxer will
392
+buffer the audio frames until it gets all the pictures. It is therefore advised
393
+to provide the pictures as soon as possible to avoid excessive buffering.
394
+
395
+Examples:
396
+
397
+Write an mp3 with an ID3v2.3 header and an ID3v1 footer:
398
+@example
399
+ffmpeg -i INPUT -id3v2_version 3 -write_id3v1 1 out.mp3
400
+@end example
401
+
402
+Attach a picture to an mp3:
403
+@example
404
+ffmpeg -i input.mp3 -i cover.png -c copy -metadata:s:v title="Album cover"
405
+-metadata:s:v comment="Cover (Front)" out.mp3
406
+@end example
373 407
 
374 408
 @c man end MUXERS
... ...
@@ -114,55 +114,6 @@ static VLC vlc_spectral[11];
114 114
 
115 115
 static const char overread_err[] = "Input buffer exhausted before END element found\n";
116 116
 
117
-static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
118
-{
119
-    // For PCE based channel configurations map the channels solely based on tags.
120
-    if (!ac->m4ac.chan_config) {
121
-        return ac->tag_che_map[type][elem_id];
122
-    }
123
-    // For indexed channel configurations map the channels solely based on position.
124
-    switch (ac->m4ac.chan_config) {
125
-    case 7:
126
-        if (ac->tags_mapped == 3 && type == TYPE_CPE) {
127
-            ac->tags_mapped++;
128
-            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
129
-        }
130
-    case 6:
131
-        /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
132
-           instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
133
-           encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
134
-        if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
135
-            ac->tags_mapped++;
136
-            return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
137
-        }
138
-    case 5:
139
-        if (ac->tags_mapped == 2 && type == TYPE_CPE) {
140
-            ac->tags_mapped++;
141
-            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
142
-        }
143
-    case 4:
144
-        if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
145
-            ac->tags_mapped++;
146
-            return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
147
-        }
148
-    case 3:
149
-    case 2:
150
-        if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
151
-            ac->tags_mapped++;
152
-            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
153
-        } else if (ac->m4ac.chan_config == 2) {
154
-            return NULL;
155
-        }
156
-    case 1:
157
-        if (!ac->tags_mapped && type == TYPE_SCE) {
158
-            ac->tags_mapped++;
159
-            return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
160
-        }
161
-    default:
162
-        return NULL;
163
-    }
164
-}
165
-
166 117
 static int count_channels(uint8_t (*layout)[3], int tags)
167 118
 {
168 119
     int i, sum = 0;
... ...
@@ -455,6 +406,90 @@ static void flush(AVCodecContext *avctx)
455 455
 }
456 456
 
457 457
 /**
458
+ * Set up channel positions based on a default channel configuration
459
+ * as specified in table 1.17.
460
+ *
461
+ * @return  Returns error status. 0 - OK, !0 - error
462
+ */
463
+static av_cold int set_default_channel_config(AVCodecContext *avctx,
464
+                                              uint8_t (*layout_map)[3],
465
+                                              int *tags,
466
+                                              int channel_config)
467
+{
468
+    if (channel_config < 1 || channel_config > 7) {
469
+        av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
470
+               channel_config);
471
+        return -1;
472
+    }
473
+    *tags = tags_per_config[channel_config];
474
+    memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
475
+    return 0;
476
+}
477
+
478
+static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
479
+{
480
+    // For PCE based channel configurations map the channels solely based on tags.
481
+    if (!ac->m4ac.chan_config) {
482
+        return ac->tag_che_map[type][elem_id];
483
+    }
484
+    // Allow single CPE stereo files to be signalled with mono configuration.
485
+    if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) {
486
+        uint8_t layout_map[MAX_ELEM_ID*4][3];
487
+        int layout_map_tags;
488
+
489
+        if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags,
490
+                                       2) < 0)
491
+            return NULL;
492
+        if (output_configure(ac, layout_map, layout_map_tags,
493
+                             2, OC_TRIAL_FRAME) < 0)
494
+            return NULL;
495
+
496
+        ac->m4ac.chan_config = 2;
497
+    }
498
+    // For indexed channel configurations map the channels solely based on position.
499
+    switch (ac->m4ac.chan_config) {
500
+    case 7:
501
+        if (ac->tags_mapped == 3 && type == TYPE_CPE) {
502
+            ac->tags_mapped++;
503
+            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
504
+        }
505
+    case 6:
506
+        /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
507
+           instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
508
+           encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
509
+        if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
510
+            ac->tags_mapped++;
511
+            return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
512
+        }
513
+    case 5:
514
+        if (ac->tags_mapped == 2 && type == TYPE_CPE) {
515
+            ac->tags_mapped++;
516
+            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
517
+        }
518
+    case 4:
519
+        if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
520
+            ac->tags_mapped++;
521
+            return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
522
+        }
523
+    case 3:
524
+    case 2:
525
+        if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
526
+            ac->tags_mapped++;
527
+            return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
528
+        } else if (ac->m4ac.chan_config == 2) {
529
+            return NULL;
530
+        }
531
+    case 1:
532
+        if (!ac->tags_mapped && type == TYPE_SCE) {
533
+            ac->tags_mapped++;
534
+            return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
535
+        }
536
+    default:
537
+        return NULL;
538
+    }
539
+}
540
+
541
+/**
458 542
  * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
459 543
  *
460 544
  * @param type speaker type/position for these channels
... ...
@@ -551,27 +586,6 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
551 551
 }
552 552
 
553 553
 /**
554
- * Set up channel positions based on a default channel configuration
555
- * as specified in table 1.17.
556
- *
557
- * @return  Returns error status. 0 - OK, !0 - error
558
- */
559
-static av_cold int set_default_channel_config(AVCodecContext *avctx,
560
-                                              uint8_t (*layout_map)[3],
561
-                                              int *tags,
562
-                                              int channel_config)
563
-{
564
-    if (channel_config < 1 || channel_config > 7) {
565
-        av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
566
-               channel_config);
567
-        return -1;
568
-    }
569
-    *tags = tags_per_config[channel_config];
570
-    memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
571
-    return 0;
572
-}
573
-
574
-/**
575 554
  * Decode GA "General Audio" specific configuration; reference: table 4.1.
576 555
  *
577 556
  * @param   ac          pointer to AACContext, may be null
... ...
@@ -2138,6 +2138,17 @@ static av_cold int validate_options(AC3EncodeContext *s)
2138 2138
     s->bit_alloc.sr_code  = i % 3;
2139 2139
     s->bitstream_id       = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
2140 2140
 
2141
+    /* select a default bit rate if not set by the user */
2142
+    if (!avctx->bit_rate) {
2143
+        switch (s->fbw_channels) {
2144
+        case 1: avctx->bit_rate =  96000; break;
2145
+        case 2: avctx->bit_rate = 192000; break;
2146
+        case 3: avctx->bit_rate = 320000; break;
2147
+        case 4: avctx->bit_rate = 384000; break;
2148
+        case 5: avctx->bit_rate = 448000; break;
2149
+        }
2150
+    }
2151
+
2141 2152
     /* validate bit rate */
2142 2153
     if (s->eac3) {
2143 2154
         int max_br, min_br, wpf, min_br_dist, min_br_code;
... ...
@@ -2186,15 +2197,20 @@ static av_cold int validate_options(AC3EncodeContext *s)
2186 2186
             wpf--;
2187 2187
         s->frame_size_min = 2 * wpf;
2188 2188
     } else {
2189
+        int best_br = 0, best_code = 0, best_diff = INT_MAX;
2189 2190
         for (i = 0; i < 19; i++) {
2190
-            if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)
2191
+            int br   = (ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift) * 1000;
2192
+            int diff = abs(br - avctx->bit_rate);
2193
+            if (diff < best_diff) {
2194
+                best_br   = br;
2195
+                best_code = i;
2196
+                best_diff = diff;
2197
+            }
2198
+            if (!best_diff)
2191 2199
                 break;
2192 2200
         }
2193
-        if (i == 19) {
2194
-            av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n");
2195
-            return AVERROR(EINVAL);
2196
-        }
2197
-        s->frame_size_code = i << 1;
2201
+        avctx->bit_rate    = best_br;
2202
+        s->frame_size_code = best_code << 1;
2198 2203
         s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
2199 2204
         s->num_blks_code   = 0x3;
2200 2205
         s->num_blocks      = 6;
... ...
@@ -157,4 +157,5 @@ AVCodec ff_ac3_fixed_encoder = {
157 157
     .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
158 158
     .priv_class = &ac3enc_class,
159 159
     .channel_layouts = ff_ac3_channel_layouts,
160
+    .defaults        = ac3_defaults,
160 161
 };
... ...
@@ -155,5 +155,6 @@ AVCodec ff_ac3_encoder = {
155 155
     .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
156 156
     .priv_class = &ac3enc_class,
157 157
     .channel_layouts = ff_ac3_channel_layouts,
158
+    .defaults        = ac3_defaults,
158 159
 };
159 160
 #endif
... ...
@@ -20,6 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "libavutil/opt.h"
23
+#include "internal.h"
23 24
 #include "ac3.h"
24 25
 
25 26
 #if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED
... ...
@@ -78,3 +79,8 @@ static const AVOption eac3_options[] = {
78 78
     {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
79 79
 {NULL}
80 80
 };
81
+
82
+static const AVCodecDefault ac3_defaults[] = {
83
+    { "b",  "0" },
84
+    { NULL }
85
+};
... ...
@@ -200,6 +200,10 @@ static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf,
200 200
     p->bad_frame_indicator = !get_bits1(&gb); // quality bit
201 201
     skip_bits(&gb, 2);                        // two padding bits
202 202
 
203
+    if (mode >= N_MODES || buf_size < frame_sizes_nb[mode] + 1) {
204
+        return NO_DATA;
205
+    }
206
+
203 207
     if (mode < MODE_DTX)
204 208
         ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1,
205 209
                            amr_unpacking_bitmaps_per_mode[mode]);
... ...
@@ -947,6 +951,10 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data,
947 947
     buf_out = (float *)p->avframe.data[0];
948 948
 
949 949
     p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);
950
+    if (p->cur_frame_mode == NO_DATA) {
951
+        av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n");
952
+        return AVERROR_INVALIDDATA;
953
+    }
950 954
     if (p->cur_frame_mode == MODE_DTX) {
951 955
         av_log_missing_feature(avctx, "dtx mode", 0);
952 956
         av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n");
... ...
@@ -582,17 +582,19 @@ typedef struct RcOverride{
582 582
 #define CODEC_FLAG_BITEXACT       0x00800000 ///< Use only bitexact stuff (except (I)DCT).
583 583
 /* Fx : Flag for h263+ extra options */
584 584
 #define CODEC_FLAG_AC_PRED        0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
585
-#define CODEC_FLAG_CBP_RD         0x04000000 ///< Use rate distortion optimization for cbp.
586
-#define CODEC_FLAG_QP_RD          0x08000000 ///< Use rate distortion optimization for qp selectioon.
587 585
 #define CODEC_FLAG_LOOP_FILTER    0x00000800 ///< loop filter
588 586
 #define CODEC_FLAG_INTERLACED_ME  0x20000000 ///< interlaced motion estimation
589 587
 #define CODEC_FLAG_CLOSED_GOP     0x80000000
590 588
 #define CODEC_FLAG2_FAST          0x00000001 ///< Allow non spec compliant speedup tricks.
591
-#define CODEC_FLAG2_STRICT_GOP    0x00000002 ///< Strictly enforce GOP size.
592 589
 #define CODEC_FLAG2_NO_OUTPUT     0x00000004 ///< Skip bitstream encoding.
593 590
 #define CODEC_FLAG2_LOCAL_HEADER  0x00000008 ///< Place global headers at every keyframe instead of in extradata.
594 591
 #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
592
+#if FF_API_MPV_GLOBAL_OPTS
593
+#define CODEC_FLAG_CBP_RD         0x04000000 ///< Use rate distortion optimization for cbp.
594
+#define CODEC_FLAG_QP_RD          0x08000000 ///< Use rate distortion optimization for qp selectioon.
595
+#define CODEC_FLAG2_STRICT_GOP    0x00000002 ///< Strictly enforce GOP size.
595 596
 #define CODEC_FLAG2_SKIP_RD       0x00004000 ///< RD optimal MB level residual skipping
597
+#endif
596 598
 #define CODEC_FLAG2_CHUNKS        0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
597 599
 #define CODEC_FLAG2_SHOW_ALL      0x00400000 ///< Show all frames before the first keyframe
598 600
 
... ...
@@ -1492,19 +1494,21 @@ typedef struct AVCodecContext {
1492 1492
 
1493 1493
     int b_frame_strategy;
1494 1494
 
1495
+#if FF_API_MPV_GLOBAL_OPTS
1495 1496
     /**
1496 1497
      * luma single coefficient elimination threshold
1497 1498
      * - encoding: Set by user.
1498 1499
      * - decoding: unused
1499 1500
      */
1500
-    int luma_elim_threshold;
1501
+    attribute_deprecated int luma_elim_threshold;
1501 1502
 
1502 1503
     /**
1503 1504
      * chroma single coeff elimination threshold
1504 1505
      * - encoding: Set by user.
1505 1506
      * - decoding: unused
1506 1507
      */
1507
-    int chroma_elim_threshold;
1508
+    attribute_deprecated int chroma_elim_threshold;
1509
+#endif
1508 1510
 
1509 1511
     /**
1510 1512
      * qscale offset between IP and B-frames
... ...
@@ -1735,13 +1739,15 @@ typedef struct AVCodecContext {
1735 1735
      */
1736 1736
     int inter_quant_bias;
1737 1737
 
1738
+#if FF_API_COLOR_TABLE_ID
1738 1739
     /**
1739 1740
      * color table ID
1740 1741
      * - encoding: unused
1741 1742
      * - decoding: Which clrtable should be used for 8bit RGB images.
1742 1743
      *             Tables have to be stored somewhere. FIXME
1743 1744
      */
1744
-    int color_table_id;
1745
+    attribute_deprecated int color_table_id;
1746
+#endif
1745 1747
 
1746 1748
     /**
1747 1749
      * slice flags
... ...
@@ -1799,19 +1805,19 @@ typedef struct AVCodecContext {
1799 1799
      */
1800 1800
     int noise_reduction;
1801 1801
 
1802
+#if FF_API_INTER_THRESHOLD
1802 1803
     /**
1803
-     *
1804
-     * - encoding: Set by user.
1805
-     * - decoding: unused
1804
+     * @deprecated this field is unused
1806 1805
      */
1807
-    int inter_threshold;
1806
+    attribute_deprecated int inter_threshold;
1807
+#endif
1808 1808
 
1809
+#if FF_API_MPV_GLOBAL_OPTS
1809 1810
     /**
1810
-     * quantizer noise shaping
1811
-     * - encoding: Set by user.
1812
-     * - decoding: unused
1811
+     * @deprecated use mpegvideo private options instead
1813 1812
      */
1814
-    int quantizer_noise_shaping;
1813
+    attribute_deprecated int quantizer_noise_shaping;
1814
+#endif
1815 1815
 
1816 1816
     /**
1817 1817
      * Motion estimation threshold below which no motion estimation is
... ...
@@ -228,7 +228,7 @@ static av_cold int decode_init(AVCodecContext *avctx) {
228 228
             av_log(avctx, AV_LOG_ERROR,
229 229
                    "CamStudio codec error: invalid depth %i bpp\n",
230 230
                    avctx->bits_per_coded_sample);
231
-            return 1;
231
+            return AVERROR_INVALIDDATA;
232 232
     }
233 233
     c->bpp = avctx->bits_per_coded_sample;
234 234
     avcodec_get_frame_defaults(&c->pic);
... ...
@@ -242,7 +242,7 @@ static av_cold int decode_init(AVCodecContext *avctx) {
242 242
     c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING);
243 243
     if (!c->decomp_buf) {
244 244
         av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
245
-        return 1;
245
+        return AVERROR(ENOMEM);
246 246
     }
247 247
     return 0;
248 248
 }
... ...
@@ -131,9 +131,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
131 131
     memcpy (buf +   8, "V1.0", 4);
132 132
     write32(buf +  20, 1); /* new image */
133 133
     write32(buf +  24, HEADER_SIZE);
134
-    if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
134
+    if (!(avctx->flags & CODEC_FLAG_BITEXACT))
135 135
         memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));
136
-    }
137 136
     write32(buf + 660, 0xFFFFFFFF); /* unencrypted */
138 137
 
139 138
     /* Image information header */
... ...
@@ -258,5 +258,6 @@ AVCodec ff_eac3_encoder = {
258 258
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
259 259
     .priv_class      = &eac3enc_class,
260 260
     .channel_layouts = ff_ac3_channel_layouts,
261
+    .defaults        = ac3_defaults,
261 262
 };
262 263
 #endif
... ...
@@ -84,6 +84,8 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, in
84 84
     }
85 85
 }
86 86
 
87
+FF_MPV_GENERIC_CLASS(flv)
88
+
87 89
 AVCodec ff_flv_encoder = {
88 90
     .name           = "flv",
89 91
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -94,4 +96,5 @@ AVCodec ff_flv_encoder = {
94 94
     .close          = ff_MPV_encode_end,
95 95
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
96 96
     .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
97
+    .priv_class     = &flv_class,
97 98
 };
... ...
@@ -321,6 +321,8 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
321 321
     }
322 322
 }
323 323
 
324
+FF_MPV_GENERIC_CLASS(h261)
325
+
324 326
 AVCodec ff_h261_encoder = {
325 327
     .name           = "h261",
326 328
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -331,4 +333,5 @@ AVCodec ff_h261_encoder = {
331 331
     .close          = ff_MPV_encode_end,
332 332
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
333 333
     .long_name= NULL_IF_CONFIG_SMALL("H.261"),
334
+    .priv_class     = &h261_class,
334 335
 };
... ...
@@ -148,7 +148,7 @@ static inline int get_p_cbp(MpegEncContext * s,
148 148
                       int motion_x, int motion_y){
149 149
     int cbp, i;
150 150
 
151
-    if(s->flags & CODEC_FLAG_CBP_RD){
151
+    if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
152 152
         int best_cbpy_score= INT_MAX;
153 153
         int best_cbpc_score= INT_MAX;
154 154
         int cbpc = (-1), cbpy= (-1);
... ...
@@ -1998,6 +1998,8 @@ decode_intra_mb:
1998 1998
         }
1999 1999
 
2000 2000
         // The pixels are stored in the same order as levels in h->mb array.
2001
+        if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
2002
+            return -1;
2001 2003
         memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
2002 2004
 
2003 2005
         ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
... ...
@@ -20,12 +20,13 @@
20 20
 
21 21
 /**
22 22
  * @file
23
- * Ogg Vorbis codec support via libvorbisenc.
23
+ * Vorbis encoding support via libvorbisenc.
24 24
  * @author Mark Hills <mark@pogo.org.uk>
25 25
  */
26 26
 
27 27
 #include <vorbis/vorbisenc.h>
28 28
 
29
+#include "libavutil/fifo.h"
29 30
 #include "libavutil/opt.h"
30 31
 #include "avcodec.h"
31 32
 #include "bytestream.h"
... ...
@@ -35,32 +36,41 @@
35 35
 #undef NDEBUG
36 36
 #include <assert.h>
37 37
 
38
+/* Number of samples the user should send in each call.
39
+ * This value is used because it is the LCD of all possible frame sizes, so
40
+ * an output packet will always start at the same point as one of the input
41
+ * packets.
42
+ */
38 43
 #define OGGVORBIS_FRAME_SIZE 64
39 44
 
40 45
 #define BUFFER_SIZE (1024 * 64)
41 46
 
42 47
 typedef struct OggVorbisContext {
43
-    AVClass *av_class;
44
-    vorbis_info vi;
45
-    vorbis_dsp_state vd;
46
-    vorbis_block vb;
47
-    uint8_t buffer[BUFFER_SIZE];
48
-    int buffer_index;
49
-    int eof;
50
-
51
-    /* decoder */
52
-    vorbis_comment vc;
53
-    ogg_packet op;
54
-
55
-    double iblock;
48
+    AVClass *av_class;                  /**< class for AVOptions            */
49
+    vorbis_info vi;                     /**< vorbis_info used during init   */
50
+    vorbis_dsp_state vd;                /**< DSP state used for analysis    */
51
+    vorbis_block vb;                    /**< vorbis_block used for analysis */
52
+    AVFifoBuffer *pkt_fifo;             /**< output packet buffer           */
53
+    int eof;                            /**< end-of-file flag               */
54
+    int dsp_initialized;                /**< vd has been initialized        */
55
+    vorbis_comment vc;                  /**< VorbisComment info             */
56
+    ogg_packet op;                      /**< ogg packet                     */
57
+    double iblock;                      /**< impulse block bias option      */
56 58
 } OggVorbisContext;
57 59
 
58 60
 static const AVOption options[] = {
59 61
     { "iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
60 62
     { NULL }
61 63
 };
64
+
65
+static const AVCodecDefault defaults[] = {
66
+    { "b",  "0" },
67
+    { NULL },
68
+};
69
+
62 70
 static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
63 71
 
72
+
64 73
 static int vorbis_error_to_averror(int ov_err)
65 74
 {
66 75
     switch (ov_err) {
... ...
@@ -71,27 +81,34 @@ static int vorbis_error_to_averror(int ov_err)
71 71
     }
72 72
 }
73 73
 
74
-static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)
74
+static av_cold int oggvorbis_init_encoder(vorbis_info *vi,
75
+                                          AVCodecContext *avctx)
75 76
 {
76
-    OggVorbisContext *context = avccontext->priv_data;
77
+    OggVorbisContext *s = avctx->priv_data;
77 78
     double cfreq;
78 79
     int ret;
79 80
 
80
-    if (avccontext->flags & CODEC_FLAG_QSCALE) {
81
-        /* variable bitrate */
82
-        float q = avccontext->global_quality / (float)FF_QP2LAMBDA;
83
-        if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels,
84
-                                           avccontext->sample_rate,
81
+    if (avctx->flags & CODEC_FLAG_QSCALE || !avctx->bit_rate) {
82
+        /* variable bitrate
83
+         * NOTE: we use the oggenc range of -1 to 10 for global_quality for
84
+         *       user convenience, but libvorbis uses -0.1 to 1.0.
85
+         */
86
+        float q = avctx->global_quality / (float)FF_QP2LAMBDA;
87
+        /* default to 3 if the user did not set quality or bitrate */
88
+        if (!(avctx->flags & CODEC_FLAG_QSCALE))
89
+            q = 3.0;
90
+        if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels,
91
+                                           avctx->sample_rate,
85 92
                                            q / 10.0)))
86 93
             goto error;
87 94
     } else {
88
-        int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1;
89
-        int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1;
95
+        int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1;
96
+        int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
90 97
 
91
-        /* constant bitrate */
92
-        if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels,
93
-                                               avccontext->sample_rate, minrate,
94
-                                               avccontext->bit_rate, maxrate)))
98
+        /* average bitrate */
99
+        if ((ret = vorbis_encode_setup_managed(vi, avctx->channels,
100
+                                               avctx->sample_rate, maxrate,
101
+                                               avctx->bit_rate, minrate)))
95 102
             goto error;
96 103
 
97 104
         /* variable bitrate by estimate, disable slow rate management */
... ...
@@ -101,43 +118,44 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco
101 101
     }
102 102
 
103 103
     /* cutoff frequency */
104
-    if (avccontext->cutoff > 0) {
105
-        cfreq = avccontext->cutoff / 1000.0;
104
+    if (avctx->cutoff > 0) {
105
+        cfreq = avctx->cutoff / 1000.0;
106 106
         if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
107 107
             goto error; /* should not happen */
108 108
     }
109 109
 
110
-    if (context->iblock) {
111
-        if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock)))
110
+    /* impulse block bias */
111
+    if (s->iblock) {
112
+        if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock)))
112 113
             goto error;
113 114
     }
114 115
 
115
-    if (avccontext->channels == 3 &&
116
-            avccontext->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
117
-        avccontext->channels == 4 &&
118
-            avccontext->channel_layout != AV_CH_LAYOUT_2_2 &&
119
-            avccontext->channel_layout != AV_CH_LAYOUT_QUAD ||
120
-        avccontext->channels == 5 &&
121
-            avccontext->channel_layout != AV_CH_LAYOUT_5POINT0 &&
122
-            avccontext->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
123
-        avccontext->channels == 6 &&
124
-            avccontext->channel_layout != AV_CH_LAYOUT_5POINT1 &&
125
-            avccontext->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
126
-        avccontext->channels == 7 &&
127
-            avccontext->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
128
-        avccontext->channels == 8 &&
129
-            avccontext->channel_layout != AV_CH_LAYOUT_7POINT1) {
130
-        if (avccontext->channel_layout) {
116
+    if (avctx->channels == 3 &&
117
+            avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
118
+        avctx->channels == 4 &&
119
+            avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
120
+            avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
121
+        avctx->channels == 5 &&
122
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
123
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
124
+        avctx->channels == 6 &&
125
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
126
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
127
+        avctx->channels == 7 &&
128
+            avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
129
+        avctx->channels == 8 &&
130
+            avctx->channel_layout != AV_CH_LAYOUT_7POINT1) {
131
+        if (avctx->channel_layout) {
131 132
             char name[32];
132
-            av_get_channel_layout_string(name, sizeof(name), avccontext->channels,
133
-                                         avccontext->channel_layout);
134
-            av_log(avccontext, AV_LOG_ERROR, "%s not supported by Vorbis: "
133
+            av_get_channel_layout_string(name, sizeof(name), avctx->channels,
134
+                                         avctx->channel_layout);
135
+            av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: "
135 136
                                              "output stream will have incorrect "
136 137
                                              "channel layout.\n", name);
137 138
         } else {
138
-            av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder "
139
+            av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
139 140
                                                "will use Vorbis channel layout for "
140
-                                               "%d channels.\n", avccontext->channels);
141
+                                               "%d channels.\n", avctx->channels);
141 142
         }
142 143
     }
143 144
 
... ...
@@ -155,59 +173,64 @@ static int xiph_len(int l)
155 155
     return 1 + l / 255 + l;
156 156
 }
157 157
 
158
-static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)
158
+static av_cold int oggvorbis_encode_close(AVCodecContext *avctx)
159 159
 {
160
-    OggVorbisContext *context = avccontext->priv_data;
161
-/*  ogg_packet op ; */
160
+    OggVorbisContext *s = avctx->priv_data;
162 161
 
163
-    vorbis_analysis_wrote(&context->vd, 0);  /* notify vorbisenc this is EOF */
162
+    /* notify vorbisenc this is EOF */
163
+    if (s->dsp_initialized)
164
+        vorbis_analysis_wrote(&s->vd, 0);
164 165
 
165
-    vorbis_block_clear(&context->vb);
166
-    vorbis_dsp_clear(&context->vd);
167
-    vorbis_info_clear(&context->vi);
166
+    vorbis_block_clear(&s->vb);
167
+    vorbis_dsp_clear(&s->vd);
168
+    vorbis_info_clear(&s->vi);
168 169
 
169
-    av_freep(&avccontext->coded_frame);
170
-    av_freep(&avccontext->extradata);
170
+    av_fifo_free(s->pkt_fifo);
171
+    av_freep(&avctx->coded_frame);
172
+    av_freep(&avctx->extradata);
171 173
 
172 174
     return 0;
173 175
 }
174 176
 
175
-static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
177
+static av_cold int oggvorbis_encode_init(AVCodecContext *avctx)
176 178
 {
177
-    OggVorbisContext *context = avccontext->priv_data;
179
+    OggVorbisContext *s = avctx->priv_data;
178 180
     ogg_packet header, header_comm, header_code;
179 181
     uint8_t *p;
180 182
     unsigned int offset;
181 183
     int ret;
182 184
 
183
-    vorbis_info_init(&context->vi);
184
-    if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) {
185
-        av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n");
185
+    vorbis_info_init(&s->vi);
186
+    if ((ret = oggvorbis_init_encoder(&s->vi, avctx))) {
187
+        av_log(avctx, AV_LOG_ERROR, "encoder setup failed\n");
186 188
         goto error;
187 189
     }
188
-    if ((ret = vorbis_analysis_init(&context->vd, &context->vi))) {
190
+    if ((ret = vorbis_analysis_init(&s->vd, &s->vi))) {
191
+        av_log(avctx, AV_LOG_ERROR, "analysis init failed\n");
189 192
         ret = vorbis_error_to_averror(ret);
190 193
         goto error;
191 194
     }
192
-    if ((ret = vorbis_block_init(&context->vd, &context->vb))) {
195
+    s->dsp_initialized = 1;
196
+    if ((ret = vorbis_block_init(&s->vd, &s->vb))) {
197
+        av_log(avctx, AV_LOG_ERROR, "dsp init failed\n");
193 198
         ret = vorbis_error_to_averror(ret);
194 199
         goto error;
195 200
     }
196 201
 
197
-    vorbis_comment_init(&context->vc);
198
-    vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT);
202
+    vorbis_comment_init(&s->vc);
203
+    vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT);
199 204
 
200
-    if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header,
201
-                                         &header_comm, &header_code))) {
205
+    if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
206
+                                         &header_code))) {
202 207
         ret = vorbis_error_to_averror(ret);
203 208
         goto error;
204 209
     }
205 210
 
206
-    avccontext->extradata_size =
207
-        1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) +
208
-        header_code.bytes;
209
-    p = avccontext->extradata =
210
-            av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
211
+    avctx->extradata_size = 1 + xiph_len(header.bytes)      +
212
+                                xiph_len(header_comm.bytes) +
213
+                                header_code.bytes;
214
+    p = avctx->extradata = av_malloc(avctx->extradata_size +
215
+                                     FF_INPUT_BUFFER_PADDING_SIZE);
211 216
     if (!p) {
212 217
         ret = AVERROR(ENOMEM);
213 218
         goto error;
... ...
@@ -222,100 +245,107 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
222 222
     offset += header_comm.bytes;
223 223
     memcpy(&p[offset], header_code.packet, header_code.bytes);
224 224
     offset += header_code.bytes;
225
-    assert(offset == avccontext->extradata_size);
225
+    assert(offset == avctx->extradata_size);
226 226
 
227
-#if 0
228
-    vorbis_block_clear(&context->vb);
229
-    vorbis_dsp_clear(&context->vd);
230
-    vorbis_info_clear(&context->vi);
231
-#endif
232
-    vorbis_comment_clear(&context->vc);
227
+    vorbis_comment_clear(&s->vc);
233 228
 
234
-    avccontext->frame_size = OGGVORBIS_FRAME_SIZE;
229
+    avctx->frame_size = OGGVORBIS_FRAME_SIZE;
230
+
231
+    s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE);
232
+    if (!s->pkt_fifo) {
233
+        ret = AVERROR(ENOMEM);
234
+        goto error;
235
+    }
235 236
 
236
-    avccontext->coded_frame = avcodec_alloc_frame();
237
-    if (!avccontext->coded_frame) {
237
+    avctx->coded_frame = avcodec_alloc_frame();
238
+    if (!avctx->coded_frame) {
238 239
         ret = AVERROR(ENOMEM);
239 240
         goto error;
240 241
     }
241 242
 
242 243
     return 0;
243 244
 error:
244
-    oggvorbis_encode_close(avccontext);
245
+    oggvorbis_encode_close(avctx);
245 246
     return ret;
246 247
 }
247 248
 
248
-static int oggvorbis_encode_frame(AVCodecContext *avccontext,
249
-                                  unsigned char *packets,
249
+static int oggvorbis_encode_frame(AVCodecContext *avctx, unsigned char *packets,
250 250
                                   int buf_size, void *data)
251 251
 {
252
-    OggVorbisContext *context = avccontext->priv_data;
252
+    OggVorbisContext *s = avctx->priv_data;
253 253
     ogg_packet op;
254
-    signed short *audio = data;
255
-    int l;
254
+    float *audio = data;
255
+    int pkt_size, ret;
256 256
 
257
+    /* send samples to libvorbis */
257 258
     if (data) {
258
-        const int samples = avccontext->frame_size;
259
+        const int samples = avctx->frame_size;
259 260
         float **buffer;
260
-        int c, channels = context->vi.channels;
261
+        int c, channels = s->vi.channels;
261 262
 
262
-        buffer = vorbis_analysis_buffer(&context->vd, samples);
263
+        buffer = vorbis_analysis_buffer(&s->vd, samples);
263 264
         for (c = 0; c < channels; c++) {
265
+            int i;
264 266
             int co = (channels > 8) ? c :
265 267
                      ff_vorbis_encoding_channel_layout_offsets[channels - 1][c];
266
-            for (l = 0; l < samples; l++)
267
-                buffer[c][l] = audio[l * channels + co] / 32768.f;
268
+            for (i = 0; i < samples; i++)
269
+                buffer[c][i] = audio[i * channels + co];
270
+        }
271
+        if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) {
272
+            av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
273
+            return vorbis_error_to_averror(ret);
268 274
         }
269
-        vorbis_analysis_wrote(&context->vd, samples);
270 275
     } else {
271
-        if (!context->eof)
272
-            vorbis_analysis_wrote(&context->vd, 0);
273
-        context->eof = 1;
276
+        if (!s->eof)
277
+            if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) {
278
+                av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
279
+                return vorbis_error_to_averror(ret);
280
+            }
281
+        s->eof = 1;
274 282
     }
275 283
 
276
-    while (vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {
277
-        vorbis_analysis(&context->vb, NULL);
278
-        vorbis_bitrate_addblock(&context->vb);
279
-
280
-        while (vorbis_bitrate_flushpacket(&context->vd, &op)) {
281
-            /* i'd love to say the following line is a hack, but sadly it's
282
-             * not, apparently the end of stream decision is in libogg. */
283
-            if (op.bytes == 1 && op.e_o_s)
284
-                continue;
285
-            if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) {
286
-                av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
287
-                return AVERROR(EINVAL);
284
+    /* retrieve available packets from libvorbis */
285
+    while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) {
286
+        if ((ret = vorbis_analysis(&s->vb, NULL)) < 0)
287
+            break;
288
+        if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0)
289
+            break;
290
+
291
+        /* add any available packets to the output packet buffer */
292
+        while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) {
293
+            if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) {
294
+                av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n");
295
+                return AVERROR_BUG;
288 296
             }
289
-            memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));
290
-            context->buffer_index += sizeof(ogg_packet);
291
-            memcpy(context->buffer + context->buffer_index, op.packet, op.bytes);
292
-            context->buffer_index += op.bytes;
293
-//            av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes);
297
+            av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
298
+            av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL);
299
+        }
300
+        if (ret < 0) {
301
+            av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
302
+            break;
294 303
         }
295 304
     }
305
+    if (ret < 0) {
306
+        av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
307
+        return vorbis_error_to_averror(ret);
308
+    }
296 309
 
297
-    l = 0;
298
-    if (context->buffer_index) {
299
-        ogg_packet *op2 = (ogg_packet *)context->buffer;
300
-        op2->packet = context->buffer + sizeof(ogg_packet);
301
-
302
-        l = op2->bytes;
303
-        avccontext->coded_frame->pts = ff_samples_to_time_base(avccontext,
304
-                                                               op2->granulepos);
305
-        //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
306
-
307
-        if (l > buf_size) {
308
-            av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
310
+    /* output then next packet from the output buffer, if available */
311
+    pkt_size = 0;
312
+    if (av_fifo_size(s->pkt_fifo) >= sizeof(ogg_packet)) {
313
+        av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
314
+        pkt_size = op.bytes;
315
+        // FIXME: we should use the user-supplied pts and duration
316
+        avctx->coded_frame->pts = ff_samples_to_time_base(avctx,
317
+                                                          op.granulepos);
318
+        if (pkt_size > buf_size) {
319
+            av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
309 320
             return AVERROR(EINVAL);
310 321
         }
311
-
312
-        memcpy(packets, op2->packet, l);
313
-        context->buffer_index -= l + sizeof(ogg_packet);
314
-        memmove(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index);
315
-//        av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l);
322
+        av_fifo_generic_read(s->pkt_fifo, packets, pkt_size, NULL);
316 323
     }
317 324
 
318
-    return l;
325
+    return pkt_size;
319 326
 }
320 327
 
321 328
 AVCodec ff_libvorbis_encoder = {
... ...
@@ -327,7 +357,9 @@ AVCodec ff_libvorbis_encoder = {
327 327
     .encode         = oggvorbis_encode_frame,
328 328
     .close          = oggvorbis_encode_close,
329 329
     .capabilities   = CODEC_CAP_DELAY,
330
-    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
330
+    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
331
+                                                      AV_SAMPLE_FMT_NONE },
331 332
     .long_name      = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),
332 333
     .priv_class     = &class,
334
+    .defaults       = defaults,
333 335
 };
... ...
@@ -939,6 +939,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
939 939
 
940 940
 static const AVOption mpeg1_options[] = {
941 941
     COMMON_OPTS
942
+    FF_MPV_COMMON_OPTS
942 943
     { NULL },
943 944
 };
944 945
 
... ...
@@ -946,6 +947,7 @@ static const AVOption mpeg2_options[] = {
946 946
     COMMON_OPTS
947 947
     { "non_linear_quant",    "Use nonlinear quantizer.",          OFFSET(q_scale_type),         AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
948 948
     { "alternate_scan",      "Enable alternate scantable.",       OFFSET(alternate_scan),       AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
949
+    FF_MPV_COMMON_OPTS
949 950
     { NULL },
950 951
 };
951 952
 
... ...
@@ -430,7 +430,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
430 430
 {
431 431
     int cbp = 0, i;
432 432
 
433
-    if (s->flags & CODEC_FLAG_CBP_RD) {
433
+    if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
434 434
         int score = 0;
435 435
         const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
436 436
 
... ...
@@ -1330,6 +1330,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
1330 1330
 static const AVOption options[] = {
1331 1331
     { "data_partitioning",       "Use data partitioning.",      OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
1332 1332
     { "alternate_scan",          "Enable alternate scantable.", OFFSET(alternate_scan),    AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
1333
+    FF_MPV_COMMON_OPTS
1333 1334
     { NULL },
1334 1335
 };
1335 1336
 
... ...
@@ -31,6 +31,7 @@
31 31
 #include "get_bits.h"
32 32
 #include "mathops.h"
33 33
 #include "mpegaudiodsp.h"
34
+#include "dsputil.h"
34 35
 
35 36
 /*
36 37
  * TODO:
... ...
@@ -82,6 +83,7 @@ typedef struct MPADecodeContext {
82 82
     int err_recognition;
83 83
     AVCodecContext* avctx;
84 84
     MPADSPContext mpadsp;
85
+    DSPContext dsp;
85 86
     AVFrame frame;
86 87
 } MPADecodeContext;
87 88
 
... ...
@@ -434,6 +436,7 @@ static av_cold int decode_init(AVCodecContext * avctx)
434 434
     s->avctx = avctx;
435 435
 
436 436
     ff_mpadsp_init(&s->mpadsp);
437
+    ff_dsputil_init(&s->dsp, avctx);
437 438
 
438 439
     avctx->sample_fmt= OUT_FMT;
439 440
     s->err_recognition = avctx->err_recognition;
... ...
@@ -1155,6 +1158,9 @@ found2:
1155 1155
         /* ms stereo ONLY */
1156 1156
         /* NOTE: the 1/sqrt(2) normalization factor is included in the
1157 1157
            global gain */
1158
+#if CONFIG_FLOAT
1159
+       s-> dsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
1160
+#else
1158 1161
         tab0 = g0->sb_hybrid;
1159 1162
         tab1 = g1->sb_hybrid;
1160 1163
         for (i = 0; i < 576; i++) {
... ...
@@ -1163,6 +1169,7 @@ found2:
1163 1163
             tab0[i] = tmp0 + tmp1;
1164 1164
             tab1[i] = tmp0 - tmp1;
1165 1165
         }
1166
+#endif
1166 1167
     }
1167 1168
 }
1168 1169
 
... ...
@@ -38,6 +38,8 @@
38 38
 #include "rl.h"
39 39
 #include "libavutil/timecode.h"
40 40
 
41
+#include "libavutil/opt.h"
42
+
41 43
 #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
42 44
 
43 45
 enum OutputFormat {
... ...
@@ -695,6 +697,9 @@ typedef struct MpegEncContext {
695 695
     int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
696 696
     int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
697 697
     void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
698
+
699
+    int mpv_flags;      ///< flags set by private options
700
+    int quantizer_noise_shaping;
698 701
 } MpegEncContext;
699 702
 
700 703
 #define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
... ...
@@ -702,6 +707,36 @@ typedef struct MpegEncContext {
702 702
         &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
703 703
     : NULL)
704 704
 
705
+/* mpegvideo_enc common options */
706
+#define FF_MPV_FLAG_SKIP_RD      0x0001
707
+#define FF_MPV_FLAG_STRICT_GOP   0x0002
708
+#define FF_MPV_FLAG_QP_RD        0x0004
709
+#define FF_MPV_FLAG_CBP_RD       0x0008
710
+
711
+#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
712
+#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
713
+#define FF_MPV_COMMON_OPTS \
714
+{ "mpv_flags",      "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
715
+{ "skip_rd",        "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
716
+{ "strict_gop",     "Strictly enforce gop size",             0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
717
+{ "qp_rd",          "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD },  0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
718
+{ "cbp_rd",         "use rate distortion optimization for CBP",          0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
719
+{ "luma_elim_threshold",   "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
720
+                                                                      FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
721
+{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
722
+                                                                      FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
723
+{ "quantizer_noise_shaping", NULL,                                  FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { 0 },       0, INT_MAX, FF_MPV_OPT_FLAGS },
724
+
725
+extern const AVOption ff_mpv_generic_options[];
726
+
727
+#define FF_MPV_GENERIC_CLASS(name) \
728
+static const AVClass name ## _class = {\
729
+    .class_name = #name " encoder",\
730
+    .item_name  = av_default_item_name,\
731
+    .option     = ff_mpv_generic_options,\
732
+    .version    = LIBAVUTIL_VERSION_INT,\
733
+};
734
+
705 735
 void ff_MPV_decode_defaults(MpegEncContext *s);
706 736
 int ff_MPV_common_init(MpegEncContext *s);
707 737
 void ff_MPV_common_end(MpegEncContext *s);
... ...
@@ -63,6 +63,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int
63 63
 static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
64 64
 static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
65 65
 
66
+const AVOption ff_mpv_generic_options[] = {
67
+    FF_MPV_COMMON_OPTS
68
+    { NULL },
69
+};
70
+
66 71
 void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
67 72
                        uint16_t (*qmat16)[2][64],
68 73
                        const uint16_t *quant_matrix,
... ...
@@ -352,8 +357,12 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
352 352
     s->flags2       = avctx->flags2;
353 353
     s->max_b_frames = avctx->max_b_frames;
354 354
     s->codec_id     = avctx->codec->id;
355
-    s->luma_elim_threshold   = avctx->luma_elim_threshold;
356
-    s->chroma_elim_threshold = avctx->chroma_elim_threshold;
355
+#if FF_API_MPV_GLOBAL_OPTS
356
+    if (avctx->luma_elim_threshold)
357
+        s->luma_elim_threshold   = avctx->luma_elim_threshold;
358
+    if (avctx->chroma_elim_threshold)
359
+        s->chroma_elim_threshold = avctx->chroma_elim_threshold;
360
+#endif
357 361
     s->strict_std_compliance = avctx->strict_std_compliance;
358 362
     s->quarter_sample     = (avctx->flags & CODEC_FLAG_QPEL) != 0;
359 363
     s->mpeg_quant         = avctx->mpeg_quant;
... ...
@@ -373,13 +382,18 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
373 373
     /* Fixed QSCALE */
374 374
     s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
375 375
 
376
+#if FF_API_MPV_GLOBAL_OPTS
377
+    if (s->flags & CODEC_FLAG_QP_RD)
378
+        s->mpv_flags |= FF_MPV_FLAG_QP_RD;
379
+#endif
380
+
376 381
     s->adaptive_quant = (s->avctx->lumi_masking ||
377 382
                          s->avctx->dark_masking ||
378 383
                          s->avctx->temporal_cplx_masking ||
379 384
                          s->avctx->spatial_cplx_masking  ||
380 385
                          s->avctx->p_masking      ||
381 386
                          s->avctx->border_masking ||
382
-                         (s->flags & CODEC_FLAG_QP_RD)) &&
387
+                         (s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
383 388
                         !s->fixed_qscale;
384 389
 
385 390
     s->loop_filter      = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
... ...
@@ -488,12 +502,17 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
488 488
         return -1;
489 489
     }
490 490
 
491
-    if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {
491
+#if FF_API_MPV_GLOBAL_OPTS
492
+    if (s->flags & CODEC_FLAG_CBP_RD)
493
+        s->mpv_flags |= FF_MPV_FLAG_CBP_RD;
494
+#endif
495
+
496
+    if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
492 497
         av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
493 498
         return -1;
494 499
     }
495 500
 
496
-    if ((s->flags & CODEC_FLAG_QP_RD) &&
501
+    if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
497 502
         s->avctx->mb_decision != FF_MB_DECISION_RD) {
498 503
         av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
499 504
         return -1;
... ...
@@ -610,6 +629,15 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
610 610
     }
611 611
     s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
612 612
 
613
+#if FF_API_MPV_GLOBAL_OPTS
614
+    if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
615
+        s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
616
+    if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP)
617
+        s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP;
618
+    if (avctx->quantizer_noise_shaping)
619
+        s->quantizer_noise_shaping = avctx->quantizer_noise_shaping;
620
+#endif
621
+
613 622
     switch (avctx->codec->id) {
614 623
     case CODEC_ID_MPEG1VIDEO:
615 624
         s->out_format = FMT_MPEG1;
... ...
@@ -1301,7 +1329,7 @@ static int select_input_picture(MpegEncContext *s)
1301 1301
             }
1302 1302
 
1303 1303
             if (s->picture_in_gop_number + b_frames >= s->gop_size) {
1304
-                if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) &&
1304
+                if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
1305 1305
                     s->gop_size > s->picture_in_gop_number) {
1306 1306
                     b_frames = s->gop_size - s->picture_in_gop_number - 1;
1307 1307
                 } else {
... ...
@@ -1726,7 +1754,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
1726 1726
         s->lambda = s->lambda_table[mb_xy];
1727 1727
         update_qscale(s);
1728 1728
 
1729
-        if (!(s->flags & CODEC_FLAG_QP_RD)) {
1729
+        if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {
1730 1730
             s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
1731 1731
             s->dquant = s->qscale - last_qp;
1732 1732
 
... ...
@@ -1746,7 +1774,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
1746 1746
             }
1747 1747
         }
1748 1748
         ff_set_qscale(s, last_qp + s->dquant);
1749
-    } else if (s->flags & CODEC_FLAG_QP_RD)
1749
+    } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)
1750 1750
         ff_set_qscale(s, s->qscale + s->dquant);
1751 1751
 
1752 1752
     wrap_y = s->linesize;
... ...
@@ -1934,7 +1962,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
1934 1934
         }
1935 1935
     }
1936 1936
 
1937
-    if (s->avctx->quantizer_noise_shaping) {
1937
+    if (s->quantizer_noise_shaping) {
1938 1938
         if (!skip_dct[0])
1939 1939
             get_visual_weight(weight[0], ptr_y                 , wrap_y);
1940 1940
         if (!skip_dct[1])
... ...
@@ -1975,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
1975 1975
             } else
1976 1976
                 s->block_last_index[i] = -1;
1977 1977
         }
1978
-        if (s->avctx->quantizer_noise_shaping) {
1978
+        if (s->quantizer_noise_shaping) {
1979 1979
             for (i = 0; i < mb_block_count; i++) {
1980 1980
                 if (!skip_dct[i]) {
1981 1981
                     s->block_last_index[i] =
... ...
@@ -1992,7 +2020,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
1992 1992
             for (i = 4; i < mb_block_count; i++)
1993 1993
                 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
1994 1994
 
1995
-        if (s->flags & CODEC_FLAG_CBP_RD) {
1995
+        if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
1996 1996
             for (i = 0; i < mb_block_count; i++) {
1997 1997
                 if (s->block_last_index[i] == -1)
1998 1998
                     s->coded_score[i] = INT_MAX / 256;
... ...
@@ -2513,7 +2541,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
2513 2513
             s->mb_skipped=0;
2514 2514
             s->dquant=0; //only for QP_RD
2515 2515
 
2516
-            if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD
2516
+            if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { // more than 1 MB type possible or FF_MPV_FLAG_QP_RD
2517 2517
                 int next_block=0;
2518 2518
                 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
2519 2519
 
... ...
@@ -2650,7 +2678,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
2650 2650
                     }
2651 2651
                 }
2652 2652
 
2653
-                if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){
2653
+                if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) {
2654 2654
                     if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
2655 2655
                         const int last_qp= backup_s.qscale;
2656 2656
                         int qpi, qp, dc[6];
... ...
@@ -2715,7 +2743,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
2715 2715
                     encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2716 2716
                                  &dmin, &next_block, 0, 0);
2717 2717
                 }
2718
-                if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
2718
+                if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {
2719 2719
                     int coded=0;
2720 2720
                     for(i=0; i<6; i++)
2721 2721
                         coded |= s->block_last_index[i];
... ...
@@ -3755,7 +3783,7 @@ STOP_TIMER("init rem[]")
3755 3755
 #ifdef REFINE_STATS
3756 3756
 {START_TIMER
3757 3757
 #endif
3758
-        analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
3758
+        analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3;
3759 3759
 
3760 3760
         if(analyze_gradient){
3761 3761
 #ifdef REFINE_STATS
... ...
@@ -3813,7 +3841,7 @@ STOP_TIMER("dct")}
3813 3813
             const int level= block[j];
3814 3814
             int change, old_coeff;
3815 3815
 
3816
-            if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
3816
+            if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
3817 3817
                 break;
3818 3818
 
3819 3819
             if(level){
... ...
@@ -3831,7 +3859,7 @@ STOP_TIMER("dct")}
3831 3831
                 int score, new_coeff, unquant_change;
3832 3832
 
3833 3833
                 score=0;
3834
-                if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
3834
+                if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
3835 3835
                    continue;
3836 3836
 
3837 3837
                 if(new_level){
... ...
@@ -4089,6 +4117,7 @@ int ff_dct_quantize_c(MpegEncContext *s,
4089 4089
 static const AVOption h263_options[] = {
4090 4090
     { "obmc",         "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4091 4091
     { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4092
+    FF_MPV_COMMON_OPTS
4092 4093
     { NULL },
4093 4094
 };
4094 4095
 
... ...
@@ -4117,6 +4146,7 @@ static const AVOption h263p_options[] = {
4117 4117
     { "aiv",        "Use alternative inter VLC.",       OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4118 4118
     { "obmc",       "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
4119 4119
     { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
4120
+    FF_MPV_COMMON_OPTS
4120 4121
     { NULL },
4121 4122
 };
4122 4123
 static const AVClass h263p_class = {
... ...
@@ -4140,6 +4170,8 @@ AVCodec ff_h263p_encoder = {
4140 4140
     .priv_class     = &h263p_class,
4141 4141
 };
4142 4142
 
4143
+FF_MPV_GENERIC_CLASS(msmpeg4v2)
4144
+
4143 4145
 AVCodec ff_msmpeg4v2_encoder = {
4144 4146
     .name           = "msmpeg4v2",
4145 4147
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -4150,8 +4182,11 @@ AVCodec ff_msmpeg4v2_encoder = {
4150 4150
     .close          = ff_MPV_encode_end,
4151 4151
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4152 4152
     .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
4153
+    .priv_class     = &msmpeg4v2_class,
4153 4154
 };
4154 4155
 
4156
+FF_MPV_GENERIC_CLASS(msmpeg4v3)
4157
+
4155 4158
 AVCodec ff_msmpeg4v3_encoder = {
4156 4159
     .name           = "msmpeg4",
4157 4160
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -4162,8 +4197,11 @@ AVCodec ff_msmpeg4v3_encoder = {
4162 4162
     .close          = ff_MPV_encode_end,
4163 4163
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4164 4164
     .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
4165
+    .priv_class     = &msmpeg4v3_class,
4165 4166
 };
4166 4167
 
4168
+FF_MPV_GENERIC_CLASS(wmv1)
4169
+
4167 4170
 AVCodec ff_wmv1_encoder = {
4168 4171
     .name           = "wmv1",
4169 4172
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -4174,4 +4212,5 @@ AVCodec ff_wmv1_encoder = {
4174 4174
     .close          = ff_MPV_encode_end,
4175 4175
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
4176 4176
     .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
4177
+    .priv_class     = &wmv1_class,
4177 4178
 };
... ...
@@ -98,12 +98,16 @@ static const AVOption options[]={
98 98
 {"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
99 99
 {"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
100 100
 {"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},
101
-{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
102
-{"qprd", "use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
101
+#if FF_API_MPV_GLOBAL_OPTS
102
+{"cbp", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
103
+{"qprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
104
+#endif
103 105
 {"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
104 106
 {"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
105 107
 {"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
106
-{"sgop", "strictly enforce gop size", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
108
+#if FF_API_MPV_GLOBAL_OPTS
109
+{"sgop", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
110
+#endif
107 111
 {"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
108 112
 {"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
109 113
 {"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"},
... ...
@@ -167,8 +171,10 @@ static const AVOption options[]={
167 167
 {"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
168 168
 {"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
169 169
 {"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
170
+#if FF_API_MPV_GLOBAL_OPTS
170 171
 {"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
171 172
 {"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
173
+#endif
172 174
 {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
173 175
 {"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
174 176
 {"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
... ...
@@ -194,8 +200,8 @@ static const AVOption options[]={
194 194
 {"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
195 195
 {"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
196 196
 {"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
197
-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
198
-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
197
+{"maxrate", "set max bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
198
+{"minrate", "set min bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
199 199
 {"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},
200 200
 {"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},
201 201
 {"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},
... ...
@@ -296,7 +302,9 @@ static const AVOption options[]={
296 296
 {"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
297 297
 {"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
298 298
 {"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
299
+#if FF_API_COLOR_TABLE_ID
299 300
 {"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
301
+#endif
300 302
 {"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
301 303
 {"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},
302 304
 {"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},
... ...
@@ -317,10 +325,14 @@ static const AVOption options[]={
317 317
 {"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
318 318
 {"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
319 319
 {"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
320
+#if FF_API_INTER_THRESHOLD
320 321
 {"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
322
+#endif
321 323
 {"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT}, 0, UINT_MAX, V|A|E|D, "flags2"},
322 324
 {"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
323
-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
325
+#if FF_API_MPV_GLOBAL_OPTS
326
+{"qns", "deprecated, use mpegvideo private options instead", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
327
+#endif
324 328
 {"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"},
325 329
 {"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"},
326 330
 {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
... ...
@@ -366,7 +378,9 @@ static const AVOption options[]={
366 366
 {"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
367 367
 {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
368 368
 {"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
369
-{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
369
+#if FF_API_MPV_GLOBAL_OPTS
370
+{"skiprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
371
+#endif
370 372
 {"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
371 373
 {"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
372 374
 {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
... ...
@@ -165,6 +165,10 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
165 165
         ctx->picture.top_field_first  = ctx->frame_type & 1;
166 166
     }
167 167
 
168
+    avctx->color_primaries = buf[14];
169
+    avctx->color_trc       = buf[15];
170
+    avctx->colorspace      = buf[16];
171
+
168 172
     ctx->alpha_info = buf[17] & 0xf;
169 173
     if (ctx->alpha_info)
170 174
         av_log_missing_feature(avctx, "alpha channel", 0);
... ...
@@ -411,7 +415,7 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
411 411
                                int data_size, uint16_t *out_ptr,
412 412
                                int linesize, int mbs_per_slice,
413 413
                                int blocks_per_mb, int plane_size_factor,
414
-                               const int16_t *qmat)
414
+                               const int16_t *qmat, int is_chroma)
415 415
 {
416 416
     GetBitContext gb;
417 417
     DCTELEM *block_ptr;
... ...
@@ -431,18 +435,33 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
431 431
     /* inverse quantization, inverse transform and output */
432 432
     block_ptr = td->blocks;
433 433
 
434
-    for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
435
-        ctx->dsp.idct_put(out_ptr,                    linesize, block_ptr, qmat);
436
-        block_ptr += 64;
437
-        if (blocks_per_mb > 2) {
438
-            ctx->dsp.idct_put(out_ptr + 8,            linesize, block_ptr, qmat);
434
+    if (!is_chroma) {
435
+        for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
436
+            ctx->dsp.idct_put(out_ptr,                    linesize, block_ptr, qmat);
437
+            block_ptr += 64;
438
+            if (blocks_per_mb > 2) {
439
+                ctx->dsp.idct_put(out_ptr + 8,            linesize, block_ptr, qmat);
440
+                block_ptr += 64;
441
+            }
442
+            ctx->dsp.idct_put(out_ptr + linesize * 4,     linesize, block_ptr, qmat);
439 443
             block_ptr += 64;
444
+            if (blocks_per_mb > 2) {
445
+                ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
446
+                block_ptr += 64;
447
+            }
440 448
         }
441
-        ctx->dsp.idct_put(out_ptr + linesize * 4,     linesize, block_ptr, qmat);
442
-        block_ptr += 64;
443
-        if (blocks_per_mb > 2) {
444
-            ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
449
+    } else {
450
+        for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
451
+            ctx->dsp.idct_put(out_ptr,                    linesize, block_ptr, qmat);
452
+            block_ptr += 64;
453
+            ctx->dsp.idct_put(out_ptr + linesize * 4,     linesize, block_ptr, qmat);
445 454
             block_ptr += 64;
455
+            if (blocks_per_mb > 2) {
456
+                ctx->dsp.idct_put(out_ptr + 8,            linesize, block_ptr, qmat);
457
+                block_ptr += 64;
458
+                ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
459
+                block_ptr += 64;
460
+            }
446 461
         }
447 462
     }
448 463
 }
... ...
@@ -523,7 +542,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
523 523
                        (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
524 524
                                     (mb_x_pos << 5)), y_linesize,
525 525
                        mbs_per_slice, 4, slice_width_factor + 2,
526
-                       td->qmat_luma_scaled);
526
+                       td->qmat_luma_scaled, 0);
527 527
 
528 528
     /* decode U chroma plane */
529 529
     decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,
... ...
@@ -531,7 +550,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
531 531
                                     (mb_x_pos << ctx->mb_chroma_factor)),
532 532
                        u_linesize, mbs_per_slice, ctx->num_chroma_blocks,
533 533
                        slice_width_factor + ctx->chroma_factor - 1,
534
-                       td->qmat_chroma_scaled);
534
+                       td->qmat_chroma_scaled, 1);
535 535
 
536 536
     /* decode V chroma plane */
537 537
     decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,
... ...
@@ -540,7 +559,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
540 540
                                     (mb_x_pos << ctx->mb_chroma_factor)),
541 541
                        v_linesize, mbs_per_slice, ctx->num_chroma_blocks,
542 542
                        slice_width_factor + ctx->chroma_factor - 1,
543
-                       td->qmat_chroma_scaled);
543
+                       td->qmat_chroma_scaled, 1);
544 544
 
545 545
     return 0;
546 546
 }
... ...
@@ -171,7 +171,7 @@ typedef struct ProresContext {
171 171
 static void get_slice_data(ProresContext *ctx, const uint16_t *src,
172 172
                            int linesize, int x, int y, int w, int h,
173 173
                            DCTELEM *blocks,
174
-                           int mbs_per_slice, int blocks_per_mb)
174
+                           int mbs_per_slice, int blocks_per_mb, int is_chroma)
175 175
 {
176 176
     const uint16_t *esrc;
177 177
     const int mb_width = 4 * blocks_per_mb;
... ...
@@ -189,37 +189,50 @@ static void get_slice_data(ProresContext *ctx, const uint16_t *src,
189 189
             elinesize = linesize;
190 190
         } else {
191 191
             int bw, bh, pix;
192
-            const int estride = 16 / sizeof(*ctx->emu_buf);
193 192
 
194 193
             esrc      = ctx->emu_buf;
195
-            elinesize = 16;
194
+            elinesize = 16 * sizeof(*ctx->emu_buf);
196 195
 
197 196
             bw = FFMIN(w - x, mb_width);
198 197
             bh = FFMIN(h - y, 16);
199 198
 
200 199
             for (j = 0; j < bh; j++) {
201
-                memcpy(ctx->emu_buf + j * estride, src + j * linesize,
200
+                memcpy(ctx->emu_buf + j * 16,
201
+                       (const uint8_t*)src + j * linesize,
202 202
                        bw * sizeof(*src));
203
-                pix = ctx->emu_buf[j * estride + bw - 1];
203
+                pix = ctx->emu_buf[j * 16 + bw - 1];
204 204
                 for (k = bw; k < mb_width; k++)
205
-                    ctx->emu_buf[j * estride + k] = pix;
205
+                    ctx->emu_buf[j * 16 + k] = pix;
206 206
             }
207 207
             for (; j < 16; j++)
208
-                memcpy(ctx->emu_buf + j * estride,
209
-                       ctx->emu_buf + (bh - 1) * estride,
208
+                memcpy(ctx->emu_buf + j * 16,
209
+                       ctx->emu_buf + (bh - 1) * 16,
210 210
                        mb_width * sizeof(*ctx->emu_buf));
211 211
         }
212
-        ctx->dsp.fdct(esrc, elinesize, blocks);
213
-        blocks += 64;
214
-        if (blocks_per_mb > 2) {
215
-            ctx->dsp.fdct(src + 8, linesize, blocks);
212
+        if (!is_chroma) {
213
+            ctx->dsp.fdct(esrc, elinesize, blocks);
216 214
             blocks += 64;
217
-        }
218
-        ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
219
-        blocks += 64;
220
-        if (blocks_per_mb > 2) {
221
-            ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
215
+            if (blocks_per_mb > 2) {
216
+                ctx->dsp.fdct(src + 8, linesize, blocks);
217
+                blocks += 64;
218
+            }
219
+            ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
222 220
             blocks += 64;
221
+            if (blocks_per_mb > 2) {
222
+                ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
223
+                blocks += 64;
224
+            }
225
+        } else {
226
+            ctx->dsp.fdct(esrc, elinesize, blocks);
227
+            blocks += 64;
228
+            ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
229
+            blocks += 64;
230
+            if (blocks_per_mb > 2) {
231
+                ctx->dsp.fdct(src + 8, linesize, blocks);
232
+                blocks += 64;
233
+                ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
234
+                blocks += 64;
235
+            }
223 236
         }
224 237
 
225 238
         x += mb_width;
... ...
@@ -383,7 +396,7 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,
383 383
 
384 384
         get_slice_data(ctx, src, pic->linesize[i], xp, yp,
385 385
                        pwidth, avctx->height, ctx->blocks[0],
386
-                       mbs_per_slice, num_cblocks);
386
+                       mbs_per_slice, num_cblocks, is_chroma);
387 387
         sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i],
388 388
                                       mbs_per_slice, ctx->blocks[0],
389 389
                                       num_cblocks, plane_factor,
... ...
@@ -539,7 +552,7 @@ static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic,
539 539
 
540 540
         get_slice_data(ctx, src, pic->linesize[i], xp, yp,
541 541
                        pwidth, avctx->height, ctx->blocks[i],
542
-                       mbs_per_slice, num_cblocks[i]);
542
+                       mbs_per_slice, num_cblocks[i], is_chroma[i]);
543 543
     }
544 544
 
545 545
     for (q = min_quant; q < max_quant + 2; q++) {
... ...
@@ -676,9 +689,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
676 676
     bytestream_put_be16  (&buf, avctx->height);
677 677
     bytestream_put_byte  (&buf, ctx->chroma_factor << 6); // frame flags
678 678
     bytestream_put_byte  (&buf, 0);             // reserved
679
-    bytestream_put_byte  (&buf, 0);             // primaries
680
-    bytestream_put_byte  (&buf, 0);             // transfer function
681
-    bytestream_put_byte  (&buf, 6);             // colour matrix - ITU-R BT.601-4
679
+    bytestream_put_byte  (&buf, avctx->color_primaries);
680
+    bytestream_put_byte  (&buf, avctx->color_trc);
681
+    bytestream_put_byte  (&buf, avctx->colorspace);
682 682
     bytestream_put_byte  (&buf, 0x40);          // source format and alpha information
683 683
     bytestream_put_byte  (&buf, 0);             // reserved
684 684
     bytestream_put_byte  (&buf, 0x03);          // matrix flags - both matrices are present
... ...
@@ -424,7 +424,7 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx)
424 424
     default:
425 425
         av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
426 426
             avctx->bits_per_coded_sample);
427
-        break;
427
+        return AVERROR_INVALIDDATA;
428 428
     }
429 429
 
430 430
     avcodec_get_frame_defaults(&s->frame);
... ...
@@ -183,6 +183,8 @@ static void rpza_decode_stream(RpzaContext *s)
183 183
             color4[1] |= ((11 * ta + 21 * tb) >> 5);
184 184
             color4[2] |= ((21 * ta + 11 * tb) >> 5);
185 185
 
186
+            if (s->size - stream_ptr < n_blocks * 4)
187
+                return;
186 188
             while (n_blocks--) {
187 189
                 block_ptr = row_ptr + pixel_ptr;
188 190
                 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
... ...
@@ -200,6 +202,8 @@ static void rpza_decode_stream(RpzaContext *s)
200 200
 
201 201
         /* Fill block with 16 colors */
202 202
         case 0x00:
203
+            if (s->size - stream_ptr < 16)
204
+                return;
203 205
             block_ptr = row_ptr + pixel_ptr;
204 206
             for (pixel_y = 0; pixel_y < 4; pixel_y++) {
205 207
                 for (pixel_x = 0; pixel_x < 4; pixel_x++){
... ...
@@ -56,6 +56,8 @@ void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
56 56
     put_bits(&s->pb, 3, 0);     /* ignored */
57 57
 }
58 58
 
59
+FF_MPV_GENERIC_CLASS(rv10)
60
+
59 61
 AVCodec ff_rv10_encoder = {
60 62
     .name           = "rv10",
61 63
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -66,4 +68,5 @@ AVCodec ff_rv10_encoder = {
66 66
     .close          = ff_MPV_encode_end,
67 67
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
68 68
     .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
69
+    .priv_class     = &rv10_class,
69 70
 };
... ...
@@ -57,6 +57,8 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){
57 57
     }
58 58
 }
59 59
 
60
+FF_MPV_GENERIC_CLASS(rv20)
61
+
60 62
 AVCodec ff_rv20_encoder = {
61 63
     .name           = "rv20",
62 64
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -67,4 +69,5 @@ AVCodec ff_rv20_encoder = {
67 67
     .close          = ff_MPV_encode_end,
68 68
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
69 69
     .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
70
+    .priv_class     = &rv20_class,
70 71
 };
... ...
@@ -60,5 +60,14 @@
60 60
 #ifndef FF_API_OLD_ENCODE_VIDEO
61 61
 #define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55)
62 62
 #endif
63
+#ifndef FF_API_MPV_GLOBAL_OPTS
64
+#define FF_API_MPV_GLOBAL_OPTS  (LIBAVCODEC_VERSION_MAJOR < 55)
65
+#endif
66
+#ifndef FF_API_COLOR_TABLE_ID
67
+#define FF_API_COLOR_TABLE_ID   (LIBAVCODEC_VERSION_MAJOR < 55)
68
+#endif
69
+#ifndef FF_API_INTER_THRESHOLD
70
+#define FF_API_INTER_THRESHOLD  (LIBAVCODEC_VERSION_MAJOR < 55)
71
+#endif
63 72
 
64 73
 #endif /* AVCODEC_VERSION_H */
... ...
@@ -484,7 +484,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
484 484
         break;
485 485
     default:
486 486
         av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
487
-        return AVERROR_PATCHWELCOME;
487
+        return AVERROR_INVALIDDATA;
488 488
     }
489 489
 
490 490
     return 0;
... ...
@@ -57,6 +57,11 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
57 57
         }
58 58
         rows = vp56_rac_gets(c, 8);  /* number of stored macroblock rows */
59 59
         cols = vp56_rac_gets(c, 8);  /* number of stored macroblock cols */
60
+        if (!rows || !cols) {
61
+            av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n",
62
+                   cols << 4, rows << 4);
63
+            return 0;
64
+        }
60 65
         vp56_rac_gets(c, 8);  /* number of displayed macroblock rows */
61 66
         vp56_rac_gets(c, 8);  /* number of displayed macroblock cols */
62 67
         vp56_rac_gets(c, 2);
... ...
@@ -77,6 +77,10 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
77 77
         cols = buf[3];  /* number of stored macroblock cols */
78 78
         /* buf[4] is number of displayed macroblock rows */
79 79
         /* buf[5] is number of displayed macroblock cols */
80
+        if (!rows || !cols) {
81
+            av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4);
82
+            return 0;
83
+        }
80 84
 
81 85
         if (!s->macroblocks || /* first frame */
82 86
             16*cols != s->avctx->coded_width ||
... ...
@@ -97,7 +101,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
97 97
             vrt_shift = 5;
98 98
         s->sub_version = sub_version;
99 99
     } else {
100
-        if (!s->sub_version)
100
+        if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
101 101
             return 0;
102 102
 
103 103
         if (separated_coeff || !s->filter_header) {
... ...
@@ -26,7 +26,6 @@
26 26
 #include "libavutil/avstring.h"
27 27
 #include "libavutil/dict.h"
28 28
 #include "libavutil/mathematics.h"
29
-#include "libavcodec/mpegaudio.h"
30 29
 #include "avformat.h"
31 30
 #include "internal.h"
32 31
 #include "avio_internal.h"
... ...
@@ -199,6 +198,8 @@ static int asf_read_file_properties(AVFormatContext *s, int64_t size)
199 199
     asf->hdr.flags              = avio_rl32(pb);
200 200
     asf->hdr.min_pktsize        = avio_rl32(pb);
201 201
     asf->hdr.max_pktsize        = avio_rl32(pb);
202
+    if (asf->hdr.min_pktsize >= (1U<<29))
203
+        return AVERROR_INVALIDDATA;
202 204
     asf->hdr.max_bitrate        = avio_rl32(pb);
203 205
     s->packet_size = asf->hdr.max_pktsize;
204 206
 
... ...
@@ -317,25 +318,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
317 317
                     || asf_st->ds_packet_size % asf_st->ds_chunk_size)
318 318
                 asf_st->ds_span = 0; // disable descrambling
319 319
         }
320
-        switch (st->codec->codec_id) {
321
-            case CODEC_ID_MP3:
322
-                st->codec->frame_size = MPA_FRAME_SIZE;
323
-                break;
324
-            case CODEC_ID_PCM_S16LE:
325
-            case CODEC_ID_PCM_S16BE:
326
-            case CODEC_ID_PCM_U16LE:
327
-            case CODEC_ID_PCM_U16BE:
328
-            case CODEC_ID_PCM_S8:
329
-            case CODEC_ID_PCM_U8:
330
-            case CODEC_ID_PCM_ALAW:
331
-            case CODEC_ID_PCM_MULAW:
332
-                st->codec->frame_size = 1;
333
-                break;
334
-            default:
335
-                /* This is probably wrong, but it prevents a crash later */
336
-                st->codec->frame_size = 1;
337
-                break;
338
-        }
339 320
     } else if (type == AVMEDIA_TYPE_VIDEO &&
340 321
             size - (avio_tell(pb) - pos1 + 24) >= 51) {
341 322
         avio_rl32(pb);
... ...
@@ -612,7 +594,9 @@ static int asf_read_header(AVFormatContext *s)
612 612
         if (gsize < 24)
613 613
             return -1;
614 614
         if (!ff_guidcmp(&g, &ff_asf_file_header)) {
615
-            asf_read_file_properties(s, gsize);
615
+            int ret = asf_read_file_properties(s, gsize);
616
+            if (ret < 0)
617
+                return ret;
616 618
         } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
617 619
             asf_read_stream_properties(s, gsize);
618 620
         } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
... ...
@@ -541,6 +541,13 @@ typedef struct AVIndexEntry {
541 541
 #define AV_DISPOSITION_HEARING_IMPAIRED  0x0080  /**< stream for hearing impaired audiences */
542 542
 #define AV_DISPOSITION_VISUAL_IMPAIRED   0x0100  /**< stream for visual impaired audiences */
543 543
 #define AV_DISPOSITION_CLEAN_EFFECTS     0x0200  /**< stream without voice */
544
+/**
545
+ * The stream is stored in the file as an attached picture/"cover art" (e.g.
546
+ * APIC frame in ID3v2). The single packet associated with it will be returned
547
+ * among the first few packets read from the file unless seeking takes place.
548
+ * It can also be accessed at any time in AVStream.attached_pic.
549
+ */
550
+#define AV_DISPOSITION_ATTACHED_PIC      0x0400
544 551
 
545 552
 /**
546 553
  * Stream structure.
... ...
@@ -615,6 +622,15 @@ typedef struct AVStream {
615 615
      */
616 616
     AVRational avg_frame_rate;
617 617
 
618
+    /**
619
+     * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
620
+     * will contain the attached picture.
621
+     *
622
+     * decoding: set by libavformat, must not be modified by the caller.
623
+     * encoding: unused
624
+     */
625
+    AVPacket attached_pic;
626
+
618 627
     /*****************************************************************
619 628
      * All fields below this line are not part of the public API. They
620 629
      * may not be used outside of libavformat and can be changed and
... ...
@@ -107,6 +107,8 @@ static int dxa_read_header(AVFormatContext *s)
107 107
         ret = ff_get_wav_header(pb, ast->codec, fsize);
108 108
         if (ret < 0)
109 109
             return ret;
110
+        if (ast->codec->sample_rate > 0)
111
+            avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
110 112
         // find 'data' chunk
111 113
         while(avio_tell(pb) < c->vidpos && !url_feof(pb)){
112 114
             tag = avio_rl32(pb);
... ...
@@ -338,8 +338,6 @@ static int ffm_read_header(AVFormatContext *s)
338 338
             codec->dct_algo = avio_rb32(pb);
339 339
             codec->strict_std_compliance = avio_rb32(pb);
340 340
             codec->max_b_frames = avio_rb32(pb);
341
-            codec->luma_elim_threshold = avio_rb32(pb);
342
-            codec->chroma_elim_threshold = avio_rb32(pb);
343 341
             codec->mpeg_quant = avio_rb32(pb);
344 342
             codec->intra_dc_precision = avio_rb32(pb);
345 343
             codec->me_method = avio_rb32(pb);
... ...
@@ -144,8 +144,6 @@ static int ffm_write_header(AVFormatContext *s)
144 144
             avio_wb32(pb, codec->dct_algo);
145 145
             avio_wb32(pb, codec->strict_std_compliance);
146 146
             avio_wb32(pb, codec->max_b_frames);
147
-            avio_wb32(pb, codec->luma_elim_threshold);
148
-            avio_wb32(pb, codec->chroma_elim_threshold);
149 147
             avio_wb32(pb, codec->mpeg_quant);
150 148
             avio_wb32(pb, codec->intra_dc_precision);
151 149
             avio_wb32(pb, codec->me_method);
... ...
@@ -38,6 +38,7 @@
38 38
 #include "libavutil/intreadwrite.h"
39 39
 #include "libavutil/dict.h"
40 40
 #include "avio_internal.h"
41
+#include "internal.h"
41 42
 
42 43
 const AVMetadataConv ff_id3v2_34_metadata_conv[] = {
43 44
     { "TALB", "album"},
... ...
@@ -99,6 +100,38 @@ const char ff_id3v2_3_tags[][4] = {
99 99
    { 0 },
100 100
 };
101 101
 
102
+const char *ff_id3v2_picture_types[21] = {
103
+    "Other",
104
+    "32x32 pixels 'file icon'",
105
+    "Other file icon",
106
+    "Cover (front)",
107
+    "Cover (back)",
108
+    "Leaflet page",
109
+    "Media (e.g. label side of CD)",
110
+    "Lead artist/lead performer/soloist",
111
+    "Artist/performer",
112
+    "Conductor",
113
+    "Band/Orchestra",
114
+    "Composer",
115
+    "Lyricist/text writer",
116
+    "Recording Location",
117
+    "During recording",
118
+    "During performance",
119
+    "Movie/video screen capture",
120
+    "A bright coloured fish",
121
+    "Illustration",
122
+    "Band/artist logotype",
123
+    "Publisher/Studio logotype",
124
+};
125
+
126
+const CodecMime ff_id3v2_mime_tags[] = {
127
+    {"image/gif" , CODEC_ID_GIF},
128
+    {"image/jpeg", CODEC_ID_MJPEG},
129
+    {"image/png" , CODEC_ID_PNG},
130
+    {"image/tiff", CODEC_ID_TIFF},
131
+    {"",           CODEC_ID_NONE},
132
+};
133
+
102 134
 int ff_id3v2_match(const uint8_t *buf, const char * magic)
103 135
 {
104 136
     return  buf[0]         == magic[0] &&
... ...
@@ -394,6 +427,84 @@ finish:
394 394
         av_dict_set(m, "date", date, 0);
395 395
 }
396 396
 
397
+static void free_apic(void *obj)
398
+{
399
+    ID3v2ExtraMetaAPIC *apic = obj;
400
+    av_freep(&apic->data);
401
+    av_freep(&apic->description);
402
+    av_freep(&apic);
403
+}
404
+
405
+static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
406
+{
407
+    int enc, pic_type;
408
+    char             mimetype[64];
409
+    const CodecMime     *mime = ff_id3v2_mime_tags;
410
+    enum CodecID           id = CODEC_ID_NONE;
411
+    ID3v2ExtraMetaAPIC  *apic = NULL;
412
+    ID3v2ExtraMeta *new_extra = NULL;
413
+    int64_t               end = avio_tell(pb) + taglen;
414
+
415
+    if (taglen <= 4)
416
+        goto fail;
417
+
418
+    new_extra = av_mallocz(sizeof(*new_extra));
419
+    apic      = av_mallocz(sizeof(*apic));
420
+    if (!new_extra || !apic)
421
+        goto fail;
422
+
423
+    enc = avio_r8(pb);
424
+    taglen--;
425
+
426
+    /* mimetype */
427
+    taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));
428
+    while (mime->id != CODEC_ID_NONE) {
429
+        if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
430
+            id = mime->id;
431
+            break;
432
+        }
433
+        mime++;
434
+    }
435
+    if (id == CODEC_ID_NONE) {
436
+        av_log(s, AV_LOG_WARNING, "Unknown attached picture mimetype: %s, skipping.\n", mimetype);
437
+        goto fail;
438
+    }
439
+    apic->id = id;
440
+
441
+    /* picture type */
442
+    pic_type = avio_r8(pb);
443
+    taglen--;
444
+    if (pic_type < 0 || pic_type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) {
445
+        av_log(s, AV_LOG_WARNING, "Unknown attached picture type %d.\n", pic_type);
446
+        pic_type = 0;
447
+    }
448
+    apic->type = ff_id3v2_picture_types[pic_type];
449
+
450
+    /* description and picture data */
451
+    if (decode_str(s, pb, enc, &apic->description, &taglen) < 0) {
452
+        av_log(s, AV_LOG_ERROR, "Error decoding attached picture description.\n");
453
+        goto fail;
454
+    }
455
+
456
+    apic->len   = taglen;
457
+    apic->data  = av_malloc(taglen);
458
+    if (!apic->data || avio_read(pb, apic->data, taglen) != taglen)
459
+        goto fail;
460
+
461
+    new_extra->tag    = "APIC";
462
+    new_extra->data   = apic;
463
+    new_extra->next   = *extra_meta;
464
+    *extra_meta       = new_extra;
465
+
466
+    return;
467
+
468
+fail:
469
+    if (apic)
470
+        free_apic(apic);
471
+    av_freep(&new_extra);
472
+    avio_seek(pb, end, SEEK_SET);
473
+}
474
+
397 475
 typedef struct ID3v2EMFunc {
398 476
     const char *tag3;
399 477
     const char *tag4;
... ...
@@ -403,6 +514,7 @@ typedef struct ID3v2EMFunc {
403 403
 
404 404
 static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {
405 405
     { "GEO", "GEOB", read_geobtag, free_geobtag },
406
+    { "PIC", "APIC", read_apic,    free_apic },
406 407
     { NULL }
407 408
 };
408 409
 
... ...
@@ -620,7 +732,7 @@ seek:
620 620
     return;
621 621
 }
622 622
 
623
-void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
623
+void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
624 624
 {
625 625
     int len, ret;
626 626
     uint8_t buf[ID3v2_HEADER_SIZE];
... ...
@@ -651,11 +763,6 @@ void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **e
651 651
     merge_date(&s->metadata);
652 652
 }
653 653
 
654
-void ff_id3v2_read(AVFormatContext *s, const char *magic)
655
-{
656
-    ff_id3v2_read_all(s, magic, NULL);
657
-}
658
-
659 654
 void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
660 655
 {
661 656
     ID3v2ExtraMeta *current = *extra_meta, *next;
... ...
@@ -669,3 +776,37 @@ void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
669 669
         current = next;
670 670
     }
671 671
 }
672
+
673
+int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
674
+{
675
+    ID3v2ExtraMeta *cur;
676
+
677
+    for (cur = *extra_meta; cur; cur = cur->next) {
678
+        ID3v2ExtraMetaAPIC *apic;
679
+        AVStream *st;
680
+
681
+        if (strcmp(cur->tag, "APIC"))
682
+            continue;
683
+        apic = cur->data;
684
+
685
+        if (!(st = avformat_new_stream(s, NULL)))
686
+            return AVERROR(ENOMEM);
687
+
688
+        st->disposition      |= AV_DISPOSITION_ATTACHED_PIC;
689
+        st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
690
+        st->codec->codec_id   = apic->id;
691
+        av_dict_set(&st->metadata, "title",   apic->description, 0);
692
+        av_dict_set(&st->metadata, "comment", apic->type, 0);
693
+
694
+        av_init_packet(&st->attached_pic);
695
+        st->attached_pic.data         = apic->data;
696
+        st->attached_pic.size         = apic->len;
697
+        st->attached_pic.destruct     = av_destruct_packet;
698
+        st->attached_pic.stream_index = st->index;
699
+
700
+        apic->data = NULL;
701
+        apic->len  = 0;
702
+    }
703
+
704
+    return 0;
705
+}
... ...
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include <stdint.h>
26 26
 #include "avformat.h"
27
+#include "internal.h"
27 28
 #include "metadata.h"
28 29
 
29 30
 #define ID3v2_HEADER_SIZE 10
... ...
@@ -45,6 +46,12 @@ enum ID3v2Encoding {
45 45
     ID3v2_ENCODING_UTF8     = 3,
46 46
 };
47 47
 
48
+typedef struct ID3v2EncContext {
49
+    int      version;       ///< ID3v2 minor version, either 3 or 4
50
+    int64_t size_pos;       ///< offset of the tag total size
51
+    int          len;       ///< size of the tag written so far
52
+} ID3v2EncContext;
53
+
48 54
 typedef struct ID3v2ExtraMeta {
49 55
     const char *tag;
50 56
     void *data;
... ...
@@ -59,6 +66,14 @@ typedef struct ID3v2ExtraMetaGEOB {
59 59
     uint8_t *data;
60 60
 } ID3v2ExtraMetaGEOB;
61 61
 
62
+typedef struct ID3v2ExtraMetaAPIC {
63
+    uint8_t     *data;
64
+    int          len;
65
+    const char  *type;
66
+    uint8_t     *description;
67
+    enum CodecID id;
68
+} ID3v2ExtraMetaAPIC;
69
+
62 70
 /**
63 71
  * Detect ID3v2 Header.
64 72
  * @param buf   must be ID3v2_HEADER_SIZE byte long
... ...
@@ -75,24 +90,40 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic);
75 75
 int ff_id3v2_tag_len(const uint8_t *buf);
76 76
 
77 77
 /**
78
- * Read an ID3v2 tag (text tags only)
78
+ * Read an ID3v2 tag, including supported extra metadata
79
+ * @param extra_meta If not NULL, extra metadata is parsed into a list of
80
+ * ID3v2ExtraMeta structs and *extra_meta points to the head of the list
79 81
  */
80
-void ff_id3v2_read(AVFormatContext *s, const char *magic);
82
+void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
81 83
 
82 84
 /**
83
- * Read an ID3v2 tag, including supported extra metadata (currently only GEOB)
84
- * @param extra_meta If not NULL, extra metadata is parsed into a list of
85
- * ID3v2ExtraMeta structs and *extra_meta points to the head of the list
85
+ * Initialize an ID3v2 tag.
86
+ */
87
+void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version,
88
+                    const char *magic);
89
+
90
+/**
91
+ * Convert and write all global metadata from s into an ID3v2 tag.
92
+ */
93
+int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3);
94
+
95
+/**
96
+ * Write an attached picture from pkt into an ID3v2 tag.
97
+ */
98
+int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt);
99
+
100
+/**
101
+ * Finalize an opened ID3v2 tag.
86 102
  */
87
-void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
103
+void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb);
88 104
 
89 105
 /**
90
- * Write an ID3v2 tag.
106
+ * Write an ID3v2 tag containing all global metadata from s.
91 107
  * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4
92 108
  * @param magic magic bytes to identify the header
93 109
  * If in doubt, use ID3v2_DEFAULT_MAGIC.
94 110
  */
95
-int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *magic);
111
+int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic);
96 112
 
97 113
 /**
98 114
  * Free memory allocated parsing special (non-text) metadata.
... ...
@@ -100,6 +131,12 @@ int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *mag
100 100
  */
101 101
 void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta);
102 102
 
103
+/**
104
+ * Create a stream for each APIC (attached picture) extracted from the
105
+ * ID3v2 header.
106
+ */
107
+int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta);
108
+
103 109
 extern const AVMetadataConv ff_id3v2_34_metadata_conv[];
104 110
 extern const AVMetadataConv ff_id3v2_4_metadata_conv[];
105 111
 
... ...
@@ -120,4 +157,8 @@ extern const char ff_id3v2_4_tags[][4];
120 120
  */
121 121
 extern const char ff_id3v2_3_tags[][4];
122 122
 
123
+extern const CodecMime ff_id3v2_mime_tags[];
124
+
125
+extern const char *ff_id3v2_picture_types[21];
126
+
123 127
 #endif /* AVFORMAT_ID3V2_H */
... ...
@@ -19,6 +19,8 @@
19 19
  */
20 20
 
21 21
 #include <stdint.h>
22
+#include <string.h>
23
+
22 24
 #include "libavutil/avstring.h"
23 25
 #include "libavutil/dict.h"
24 26
 #include "libavutil/intreadwrite.h"
... ...
@@ -26,12 +28,12 @@
26 26
 #include "avio.h"
27 27
 #include "id3v2.h"
28 28
 
29
-static void id3v2_put_size(AVFormatContext *s, int size)
29
+static void id3v2_put_size(AVIOContext *pb, int size)
30 30
 {
31
-    avio_w8(s->pb, size >> 21 & 0x7f);
32
-    avio_w8(s->pb, size >> 14 & 0x7f);
33
-    avio_w8(s->pb, size >> 7  & 0x7f);
34
-    avio_w8(s->pb, size       & 0x7f);
31
+    avio_w8(pb, size >> 21 & 0x7f);
32
+    avio_w8(pb, size >> 14 & 0x7f);
33
+    avio_w8(pb, size >> 7  & 0x7f);
34
+    avio_w8(pb, size       & 0x7f);
35 35
 }
36 36
 
37 37
 static int string_is_ascii(const uint8_t *str)
... ...
@@ -40,17 +42,30 @@ static int string_is_ascii(const uint8_t *str)
40 40
     return !*str;
41 41
 }
42 42
 
43
+static void id3v2_encode_string(AVIOContext *pb, const uint8_t *str,
44
+                               enum ID3v2Encoding enc)
45
+{
46
+    int (*put)(AVIOContext*, const char*);
47
+
48
+    if (enc == ID3v2_ENCODING_UTF16BOM) {
49
+        avio_wl16(pb, 0xFEFF);      /* BOM */
50
+        put = avio_put_str16le;
51
+    } else
52
+        put = avio_put_str;
53
+
54
+    put(pb, str);
55
+}
56
+
43 57
 /**
44 58
  * Write a text frame with one (normal frames) or two (TXXX frames) strings
45 59
  * according to encoding (only UTF-8 or UTF-16+BOM supported).
46 60
  * @return number of bytes written or a negative error code.
47 61
  */
48
-static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2,
62
+static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *str1, const char *str2,
49 63
                           uint32_t tag, enum ID3v2Encoding enc)
50 64
 {
51 65
     int len;
52 66
     uint8_t *pb;
53
-    int (*put)(AVIOContext*, const char*);
54 67
     AVIOContext *dyn_buf;
55 68
     if (avio_open_dyn_buf(&dyn_buf) < 0)
56 69
         return AVERROR(ENOMEM);
... ...
@@ -62,28 +77,26 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2
62 62
         enc = ID3v2_ENCODING_ISO8859;
63 63
 
64 64
     avio_w8(dyn_buf, enc);
65
-    if (enc == ID3v2_ENCODING_UTF16BOM) {
66
-        avio_wl16(dyn_buf, 0xFEFF);      /* BOM */
67
-        put = avio_put_str16le;
68
-    } else
69
-        put = avio_put_str;
70
-
71
-    put(dyn_buf, str1);
65
+    id3v2_encode_string(dyn_buf, str1, enc);
72 66
     if (str2)
73
-        put(dyn_buf, str2);
67
+        id3v2_encode_string(dyn_buf, str2, enc);
74 68
     len = avio_close_dyn_buf(dyn_buf, &pb);
75 69
 
76
-    avio_wb32(s->pb, tag);
77
-    id3v2_put_size(s, len);
78
-    avio_wb16(s->pb, 0);
79
-    avio_write(s->pb, pb, len);
70
+    avio_wb32(avioc, tag);
71
+    /* ID3v2.3 frame size is not synchsafe */
72
+    if (id3->version == 3)
73
+        avio_wb32(avioc, len);
74
+    else
75
+        id3v2_put_size(avioc, len);
76
+    avio_wb16(avioc, 0);
77
+    avio_write(avioc, pb, len);
80 78
 
81 79
     av_freep(&pb);
82 80
     return len + ID3v2_HEADER_SIZE;
83 81
 }
84 82
 
85
-static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const char table[][4],
86
-                                 enum ID3v2Encoding enc)
83
+static int id3v2_check_write_tag(ID3v2EncContext *id3, AVIOContext *pb, AVDictionaryEntry *t,
84
+                                 const char table[][4], enum ID3v2Encoding enc)
87 85
 {
88 86
     uint32_t tag;
89 87
     int i;
... ...
@@ -93,7 +106,7 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const
93 93
     tag = AV_RB32(t->key);
94 94
     for (i = 0; *table[i]; i++)
95 95
         if (tag == AV_RB32(table[i]))
96
-            return id3v2_put_ttag(s, t->value, NULL, tag, enc);
96
+            return id3v2_put_ttag(id3, pb, t->value, NULL, tag, enc);
97 97
     return -1;
98 98
 }
99 99
 
... ...
@@ -135,52 +148,137 @@ static void id3v2_3_metadata_split_date(AVDictionary **pm)
135 135
     *pm = dst;
136 136
 }
137 137
 
138
-int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version,
139
-                   const char *magic)
138
+void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version,
139
+                    const char *magic)
140 140
 {
141
-    int64_t size_pos, cur_pos;
142
-    AVDictionaryEntry *t = NULL;
141
+    id3->version = id3v2_version;
143 142
 
144
-    int totlen = 0, enc = id3v2_version == 3 ? ID3v2_ENCODING_UTF16BOM :
145
-                                               ID3v2_ENCODING_UTF8;
146
-
147
-
148
-    avio_wb32(s->pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version));
149
-    avio_w8(s->pb, 0);
150
-    avio_w8(s->pb, 0); /* flags */
143
+    avio_wb32(pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version));
144
+    avio_w8(pb, 0);
145
+    avio_w8(pb, 0); /* flags */
151 146
 
152 147
     /* reserve space for size */
153
-    size_pos = avio_tell(s->pb);
154
-    avio_wb32(s->pb, 0);
148
+    id3->size_pos = avio_tell(pb);
149
+    avio_wb32(pb, 0);
150
+}
151
+
152
+int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
153
+{
154
+    AVDictionaryEntry *t = NULL;
155
+    int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM :
156
+                                  ID3v2_ENCODING_UTF8;
155 157
 
156 158
     ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL);
157
-    if (id3v2_version == 3)
159
+    if (id3->version == 3)
158 160
         id3v2_3_metadata_split_date(&s->metadata);
159
-    else if (id3v2_version == 4)
161
+    else if (id3->version == 4)
160 162
         ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);
161 163
 
162 164
     while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
163 165
         int ret;
164 166
 
165
-        if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) {
166
-            totlen += ret;
167
+        if ((ret = id3v2_check_write_tag(id3, s->pb, t, ff_id3v2_tags, enc)) > 0) {
168
+            id3->len += ret;
167 169
             continue;
168 170
         }
169
-        if ((ret = id3v2_check_write_tag(s, t, id3v2_version == 3 ?
171
+        if ((ret = id3v2_check_write_tag(id3, s->pb, t, id3->version == 3 ?
170 172
                                                ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {
171
-            totlen += ret;
173
+            id3->len += ret;
172 174
             continue;
173 175
         }
174 176
 
175 177
         /* unknown tag, write as TXXX frame */
176
-        if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
178
+        if ((ret = id3v2_put_ttag(id3, s->pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
177 179
             return ret;
178
-        totlen += ret;
180
+        id3->len += ret;
179 181
     }
180 182
 
181
-    cur_pos = avio_tell(s->pb);
182
-    avio_seek(s->pb, size_pos, SEEK_SET);
183
-    id3v2_put_size(s, totlen);
184
-    avio_seek(s->pb, cur_pos, SEEK_SET);
183
+    return 0;
184
+}
185
+
186
+int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
187
+{
188
+    AVStream *st = s->streams[pkt->stream_index];
189
+    AVDictionaryEntry *e;
190
+
191
+    AVIOContext *dyn_buf;
192
+    uint8_t     *buf;
193
+    const CodecMime *mime = ff_id3v2_mime_tags;
194
+    const char  *mimetype = NULL, *desc = "";
195
+    int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM :
196
+                                  ID3v2_ENCODING_UTF8;
197
+    int i, len, type = 0;
198
+
199
+    /* get the mimetype*/
200
+    while (mime->id != CODEC_ID_NONE) {
201
+        if (mime->id == st->codec->codec_id) {
202
+            mimetype = mime->str;
203
+            break;
204
+        }
205
+        mime++;
206
+    }
207
+    if (!mimetype) {
208
+        av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
209
+               "write an attached picture.\n", st->index);
210
+        return AVERROR(EINVAL);
211
+    }
212
+
213
+    /* get the picture type */
214
+    e = av_dict_get(st->metadata, "comment", NULL, 0);
215
+    for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
216
+        if (strstr(ff_id3v2_picture_types[i], e->value) == ff_id3v2_picture_types[i]) {
217
+            type = i;
218
+            break;
219
+        }
220
+    }
221
+
222
+    /* get the description */
223
+    if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
224
+        desc = e->value;
225
+
226
+    /* start writing */
227
+    if (avio_open_dyn_buf(&dyn_buf) < 0)
228
+        return AVERROR(ENOMEM);
229
+
230
+    avio_w8(dyn_buf, enc);
231
+    avio_put_str(dyn_buf, mimetype);
232
+    avio_w8(dyn_buf, type);
233
+    id3v2_encode_string(dyn_buf, desc, enc);
234
+    avio_write(dyn_buf, pkt->data, pkt->size);
235
+    len = avio_close_dyn_buf(dyn_buf, &buf);
236
+
237
+    avio_wb32(s->pb, MKBETAG('A', 'P', 'I', 'C'));
238
+    if (id3->version == 3)
239
+        avio_wb32(s->pb, len);
240
+    else
241
+        id3v2_put_size(s->pb, len);
242
+    avio_wb16(s->pb, 0);
243
+    avio_write(s->pb, buf, len);
244
+    av_freep(&buf);
245
+
246
+    id3->len += len + ID3v2_HEADER_SIZE;
247
+
248
+    return 0;
249
+}
250
+
251
+void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb)
252
+{
253
+    int64_t cur_pos = avio_tell(pb);
254
+    avio_seek(pb, id3->size_pos, SEEK_SET);
255
+    id3v2_put_size(pb, id3->len);
256
+    avio_seek(pb, cur_pos, SEEK_SET);
257
+}
258
+
259
+int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version,
260
+                          const char *magic)
261
+{
262
+    ID3v2EncContext id3 = { 0 };
263
+    int ret;
264
+
265
+    ff_id3v2_start(&id3, s->pb, id3v2_version, magic);
266
+    if ((ret = ff_id3v2_write_metadata(s, &id3)) < 0)
267
+        return ret;
268
+    ff_id3v2_finish(&id3, s->pb);
269
+
185 270
     return 0;
186 271
 }
... ...
@@ -37,6 +37,11 @@ typedef struct AVCodecTag {
37 37
     unsigned int tag;
38 38
 } AVCodecTag;
39 39
 
40
+typedef struct CodecMime{
41
+    char str[32];
42
+    enum CodecID id;
43
+} CodecMime;
44
+
40 45
 #ifdef __GNUC__
41 46
 #define dynarray_add(tab, nb_ptr, elem)\
42 47
 do {\
... ...
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include "libavcodec/avcodec.h"
26 26
 #include "metadata.h"
27
+#include "internal.h"
27 28
 
28 29
 /* EBML version supported */
29 30
 #define EBML_VERSION 1
... ...
@@ -250,11 +251,6 @@ typedef struct CodecTags{
250 250
     enum CodecID id;
251 251
 }CodecTags;
252 252
 
253
-typedef struct CodecMime{
254
-    char str[32];
255
-    enum CodecID id;
256
-}CodecMime;
257
-
258 253
 /* max. depth in the EBML tree structure */
259 254
 #define EBML_MAX_DEPTH 16
260 255
 
... ...
@@ -1223,6 +1223,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
1223 1223
         if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
1224 1224
             unsigned int color_depth, len;
1225 1225
             int color_greyscale;
1226
+            int color_table_id;
1226 1227
 
1227 1228
             st->codec->codec_id = id;
1228 1229
             avio_rb16(pb); /* version */
... ...
@@ -1250,9 +1251,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
1250 1250
                 st->codec->codec_tag=MKTAG('I', '4', '2', '0');
1251 1251
 
1252 1252
             st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */
1253
-            st->codec->color_table_id = avio_rb16(pb); /* colortable id */
1253
+            color_table_id = avio_rb16(pb); /* colortable id */
1254 1254
             av_dlog(c->fc, "depth %d, ctab id %d\n",
1255
-                   st->codec->bits_per_coded_sample, st->codec->color_table_id);
1255
+                   st->codec->bits_per_coded_sample, color_table_id);
1256 1256
             /* figure out the palette situation */
1257 1257
             color_depth = st->codec->bits_per_coded_sample & 0x1F;
1258 1258
             color_greyscale = st->codec->bits_per_coded_sample & 0x20;
... ...
@@ -1282,7 +1283,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
1282 1282
                         if (color_index < 0)
1283 1283
                             color_index = 0;
1284 1284
                     }
1285
-                } else if (st->codec->color_table_id) {
1285
+                } else if (color_table_id) {
1286 1286
                     const uint8_t *color_table;
1287 1287
                     /* if flag bit 3 is set, use the default palette */
1288 1288
                     color_count = 1 << color_depth;
... ...
@@ -84,6 +84,7 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
84 84
 
85 85
 typedef struct MP3Context {
86 86
     const AVClass *class;
87
+    ID3v2EncContext id3;
87 88
     int id3v2_version;
88 89
     int write_id3v1;
89 90
     int64_t frames_offset;
... ...
@@ -93,60 +94,15 @@ typedef struct MP3Context {
93 93
     uint32_t seen;
94 94
     uint32_t pos;
95 95
     uint64_t bag[VBR_NUM_BAGS];
96
-} MP3Context;
97
-
98
-static int mp2_write_trailer(struct AVFormatContext *s)
99
-{
100
-    uint8_t buf[ID3v1_TAG_SIZE];
101
-    MP3Context *mp3 = s->priv_data;
102
-
103
-    /* write the id3v1 tag */
104
-    if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) {
105
-        avio_write(s->pb, buf, ID3v1_TAG_SIZE);
106
-    }
107 96
 
108
-    /* write number of frames */
109
-    if (mp3 && mp3->frames_offset) {
110
-        avio_seek(s->pb, mp3->frames_offset, SEEK_SET);
111
-        avio_wb32(s->pb, s->streams[0]->nb_frames);
112
-        avio_seek(s->pb, 0, SEEK_END);
113
-    }
114
-
115
-    avio_flush(s->pb);
116
-
117
-    return 0;
118
-}
119
-
120
-#if CONFIG_MP2_MUXER
121
-AVOutputFormat ff_mp2_muxer = {
122
-    .name              = "mp2",
123
-    .long_name         = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
124
-    .mime_type         = "audio/x-mpeg",
125
-    .extensions        = "mp2,m2a",
126
-    .audio_codec       = CODEC_ID_MP2,
127
-    .video_codec       = CODEC_ID_NONE,
128
-    .write_packet      = ff_raw_write_packet,
129
-    .write_trailer     = mp2_write_trailer,
130
-    .flags             = AVFMT_NOTIMESTAMPS,
131
-};
132
-#endif
133
-
134
-#if CONFIG_MP3_MUXER
135
-
136
-static const AVOption options[] = {
137
-    { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
138
-      offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
139
-    { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
140
-      offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
141
-    { NULL },
142
-};
97
+    /* index of the audio stream */
98
+    int audio_stream_idx;
99
+    /* number of attached pictures we still need to write */
100
+    int pics_to_write;
143 101
 
144
-static const AVClass mp3_muxer_class = {
145
-    .class_name     = "MP3 muxer",
146
-    .item_name      = av_default_item_name,
147
-    .option         = options,
148
-    .version        = LIBAVUTIL_VERSION_INT,
149
-};
102
+    /* audio packets are queued here until we get all the attached pictures */
103
+    AVPacketList *queue, *queue_end;
104
+} MP3Context;
150 105
 
151 106
 static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
152 107
 
... ...
@@ -155,8 +111,8 @@ static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
155 155
  */
156 156
 static int mp3_write_xing(AVFormatContext *s)
157 157
 {
158
-    AVCodecContext   *codec = s->streams[0]->codec;
159 158
     MP3Context       *mp3 = s->priv_data;
159
+    AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec;
160 160
     int              bitrate_idx;
161 161
     int              best_bitrate_idx = -1;
162 162
     int              best_bitrate_error= INT_MAX;
... ...
@@ -166,6 +122,9 @@ static int mp3_write_xing(AVFormatContext *s)
166 166
     int              srate_idx, i, channels;
167 167
     int              needed;
168 168
 
169
+    if (!s->pb->seekable)
170
+        return 0;
171
+
169 172
     for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++)
170 173
         if (avpriv_mpa_freq_tab[i] == codec->sample_rate) {
171 174
             srate_idx = i;
... ...
@@ -295,26 +254,7 @@ static void mp3_fix_xing(AVFormatContext *s)
295 295
     avio_seek(s->pb, 0, SEEK_END);
296 296
 }
297 297
 
298
-/**
299
- * Write an ID3v2 header at beginning of stream
300
- */
301
-
302
-static int mp3_write_header(struct AVFormatContext *s)
303
-{
304
-    MP3Context  *mp3 = s->priv_data;
305
-    int ret;
306
-
307
-    ret = ff_id3v2_write(s, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC);
308
-    if (ret < 0)
309
-        return ret;
310
-
311
-    if (s->pb->seekable)
312
-        mp3_write_xing(s);
313
-
314
-    return 0;
315
-}
316
-
317
-static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
298
+static int mp3_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
318 299
 {
319 300
     if (! pkt || ! pkt->data || pkt->size < 4)
320 301
         return ff_raw_write_packet(s, pkt);
... ...
@@ -350,6 +290,175 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
350 350
     }
351 351
 }
352 352
 
353
+static int mp3_queue_flush(AVFormatContext *s)
354
+{
355
+    MP3Context *mp3 = s->priv_data;
356
+    AVPacketList *pktl;
357
+    int ret = 0, write = 1;
358
+
359
+    ff_id3v2_finish(&mp3->id3, s->pb);
360
+    mp3_write_xing(s);
361
+
362
+    while ((pktl = mp3->queue)) {
363
+        if (write && (ret = mp3_write_packet_internal(s, &pktl->pkt)) < 0)
364
+            write = 0;
365
+        av_free_packet(&pktl->pkt);
366
+        mp3->queue = pktl->next;
367
+        av_freep(&pktl);
368
+    }
369
+    mp3->queue_end = NULL;
370
+    return ret;
371
+}
372
+
373
+static int mp2_write_trailer(struct AVFormatContext *s)
374
+{
375
+    uint8_t buf[ID3v1_TAG_SIZE];
376
+    MP3Context *mp3 = s->priv_data;
377
+
378
+    if (mp3 && mp3->pics_to_write) {
379
+        av_log(s, AV_LOG_WARNING, "No packets were sent for some of the "
380
+               "attached pictures.\n");
381
+        mp3_queue_flush(s);
382
+    }
383
+
384
+    /* write the id3v1 tag */
385
+    if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) {
386
+        avio_write(s->pb, buf, ID3v1_TAG_SIZE);
387
+    }
388
+
389
+    /* write number of frames */
390
+    if (mp3 && mp3->frames_offset) {
391
+        avio_seek(s->pb, mp3->frames_offset, SEEK_SET);
392
+        avio_wb32(s->pb, s->streams[mp3->audio_stream_idx]->nb_frames);
393
+        avio_seek(s->pb, 0, SEEK_END);
394
+    }
395
+
396
+    avio_flush(s->pb);
397
+
398
+    return 0;
399
+}
400
+
401
+#if CONFIG_MP2_MUXER
402
+AVOutputFormat ff_mp2_muxer = {
403
+    .name              = "mp2",
404
+    .long_name         = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
405
+    .mime_type         = "audio/x-mpeg",
406
+    .extensions        = "mp2,m2a",
407
+    .audio_codec       = CODEC_ID_MP2,
408
+    .video_codec       = CODEC_ID_NONE,
409
+    .write_packet      = ff_raw_write_packet,
410
+    .write_trailer     = mp2_write_trailer,
411
+    .flags             = AVFMT_NOTIMESTAMPS,
412
+};
413
+#endif
414
+
415
+#if CONFIG_MP3_MUXER
416
+
417
+static const AVOption options[] = {
418
+    { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
419
+      offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
420
+    { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
421
+      offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
422
+    { NULL },
423
+};
424
+
425
+static const AVClass mp3_muxer_class = {
426
+    .class_name     = "MP3 muxer",
427
+    .item_name      = av_default_item_name,
428
+    .option         = options,
429
+    .version        = LIBAVUTIL_VERSION_INT,
430
+};
431
+
432
+static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
433
+{
434
+    MP3Context *mp3 = s->priv_data;
435
+
436
+    if (pkt->stream_index == mp3->audio_stream_idx) {
437
+        if (mp3->pics_to_write) {
438
+            /* buffer audio packets until we get all the pictures */
439
+            AVPacketList *pktl = av_mallocz(sizeof(*pktl));
440
+            if (!pktl)
441
+                return AVERROR(ENOMEM);
442
+
443
+            pktl->pkt     = *pkt;
444
+            pkt->destruct = NULL;
445
+
446
+            if (mp3->queue_end)
447
+                mp3->queue_end->next = pktl;
448
+            else
449
+                mp3->queue = pktl;
450
+            mp3->queue_end = pktl;
451
+        } else
452
+            return mp3_write_packet_internal(s, pkt);
453
+    } else {
454
+        int ret;
455
+
456
+        /* warn only once for each stream */
457
+        if (s->streams[pkt->stream_index]->nb_frames == 1) {
458
+            av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d,"
459
+                   " ignoring.\n", pkt->stream_index);
460
+        }
461
+        if (!mp3->pics_to_write || s->streams[pkt->stream_index]->nb_frames >= 1)
462
+            return 0;
463
+
464
+        if ((ret = ff_id3v2_write_apic(s, &mp3->id3, pkt)) < 0)
465
+            return ret;
466
+        mp3->pics_to_write--;
467
+
468
+        /* flush the buffered audio packets */
469
+        if (!mp3->pics_to_write &&
470
+            (ret = mp3_queue_flush(s)) < 0)
471
+            return ret;
472
+    }
473
+
474
+    return 0;
475
+}
476
+
477
+/**
478
+ * Write an ID3v2 header at beginning of stream
479
+ */
480
+
481
+static int mp3_write_header(struct AVFormatContext *s)
482
+{
483
+    MP3Context  *mp3 = s->priv_data;
484
+    int ret, i;
485
+
486
+    /* check the streams -- we want exactly one audio and arbitrary number of
487
+     * video (attached pictures) */
488
+    mp3->audio_stream_idx = -1;
489
+    for (i = 0; i < s->nb_streams; i++) {
490
+        AVStream *st = s->streams[i];
491
+        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
492
+            if (mp3->audio_stream_idx >= 0 || st->codec->codec_id != CODEC_ID_MP3) {
493
+                av_log(s, AV_LOG_ERROR, "Invalid audio stream. Exactly one MP3 "
494
+                       "audio stream is required.\n");
495
+                return AVERROR(EINVAL);
496
+            }
497
+            mp3->audio_stream_idx = i;
498
+        } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) {
499
+            av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in MP3.\n");
500
+            return AVERROR(EINVAL);
501
+        }
502
+    }
503
+    if (mp3->audio_stream_idx < 0) {
504
+        av_log(s, AV_LOG_ERROR, "No audio stream present.\n");
505
+        return AVERROR(EINVAL);
506
+    }
507
+    mp3->pics_to_write = s->nb_streams - 1;
508
+
509
+    ff_id3v2_start(&mp3->id3, s->pb, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC);
510
+    ret = ff_id3v2_write_metadata(s, &mp3->id3);
511
+    if (ret < 0)
512
+        return ret;
513
+
514
+    if (!mp3->pics_to_write) {
515
+        ff_id3v2_finish(&mp3->id3, s->pb);
516
+        mp3_write_xing(s);
517
+    }
518
+
519
+    return 0;
520
+}
521
+
353 522
 static int mp3_write_trailer(AVFormatContext *s)
354 523
 {
355 524
     MP3Context  *mp3 = s->priv_data;
... ...
@@ -371,7 +480,7 @@ AVOutputFormat ff_mp3_muxer = {
371 371
     .extensions        = "mp3",
372 372
     .priv_data_size    = sizeof(MP3Context),
373 373
     .audio_codec       = CODEC_ID_MP3,
374
-    .video_codec       = CODEC_ID_NONE,
374
+    .video_codec       = CODEC_ID_PNG,
375 375
     .write_header      = mp3_write_header,
376 376
     .write_packet      = mp3_write_packet,
377 377
     .write_trailer     = mp3_write_trailer,
... ...
@@ -270,7 +270,7 @@ static int oma_read_header(AVFormatContext *s)
270 270
     ID3v2ExtraMeta *extra_meta = NULL;
271 271
     OMAContext *oc = s->priv_data;
272 272
 
273
-    ff_id3v2_read_all(s, ID3v2_EA3_MAGIC, &extra_meta);
273
+    ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta);
274 274
     ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
275 275
     if (ret < EA3_HEADER_SIZE)
276 276
         return -1;
... ...
@@ -49,7 +49,7 @@ static av_cold int oma_write_header(AVFormatContext *s)
49 49
     }
50 50
 
51 51
     /* Metadata; OpenMG does not support ID3v2.4 */
52
-    ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC);
52
+    ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
53 53
 
54 54
     ffio_wfourcc(s->pb, "EA3\0");
55 55
     avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
... ...
@@ -299,4 +299,5 @@ AVInputFormat ff_str_demuxer = {
299 299
     .read_header    = str_read_header,
300 300
     .read_packet    = str_read_packet,
301 301
     .read_close     = str_read_close,
302
+    .flags          = AVFMT_NO_BYTE_SEEK,
302 303
 };
... ...
@@ -112,7 +112,7 @@ static int rtp_write_header(AVFormatContext *s1)
112 112
 
113 113
     if (s->max_packet_size) {
114 114
         if (s1->pb->max_packet_size)
115
-            s->max_packet_size = FFMIN(s->max_payload_size,
115
+            s->max_packet_size = FFMIN(s->max_packet_size,
116 116
                                        s1->pb->max_packet_size);
117 117
     } else
118 118
         s->max_packet_size = s1->pb->max_packet_size;
... ...
@@ -113,7 +113,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
113 113
             vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
114 114
             vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb));
115 115
             avpriv_set_pts_info(vst, 16, 256, swf->frame_rate);
116
-            vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
117 116
             len -= 8;
118 117
         } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) {
119 118
             /* streaming found */
... ...
@@ -186,7 +185,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
186 186
                 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
187 187
                 vst->codec->codec_id = CODEC_ID_MJPEG;
188 188
                 avpriv_set_pts_info(vst, 64, 256, swf->frame_rate);
189
-                vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
190 189
                 st = vst;
191 190
             }
192 191
             avio_rl16(pb); /* BITMAP_ID */
... ...
@@ -545,11 +545,29 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o
545 545
     return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);
546 546
 }
547 547
 
548
+static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
549
+                               AVPacketList **plast_pktl){
550
+    AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
551
+    if (!pktl)
552
+        return NULL;
553
+
554
+    if (*packet_buffer)
555
+        (*plast_pktl)->next = pktl;
556
+    else
557
+        *packet_buffer = pktl;
558
+
559
+    /* add the packet in the buffered packet list */
560
+    *plast_pktl = pktl;
561
+    pktl->pkt= *pkt;
562
+    return &pktl->pkt;
563
+}
564
+
548 565
 int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
549 566
 {
550 567
     AVFormatContext *s = *ps;
551
-    int ret = 0;
568
+    int i, ret = 0;
552 569
     AVDictionary *tmp = NULL;
570
+    ID3v2ExtraMeta *id3v2_extra_meta = NULL;
553 571
 
554 572
     if (!s && !(s = avformat_alloc_context()))
555 573
         return AVERROR(ENOMEM);
... ...
@@ -592,12 +610,25 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
592 592
 
593 593
     /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */
594 594
     if (s->pb)
595
-        ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
595
+        ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
596 596
 
597 597
     if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)
598 598
         if ((ret = s->iformat->read_header(s)) < 0)
599 599
             goto fail;
600 600
 
601
+    if (id3v2_extra_meta &&
602
+        (ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
603
+        goto fail;
604
+    ff_id3v2_free_extra_meta(&id3v2_extra_meta);
605
+
606
+    /* queue attached pictures */
607
+    for (i = 0; i < s->nb_streams; i++)
608
+        if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) {
609
+            AVPacket copy = s->streams[i]->attached_pic;
610
+            copy.destruct = NULL;
611
+            add_to_pktbuf(&s->raw_packet_buffer, &copy, &s->raw_packet_buffer_end);
612
+        }
613
+
601 614
     if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
602 615
         s->data_offset = avio_tell(s->pb);
603 616
 
... ...
@@ -611,6 +642,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
611 611
     return 0;
612 612
 
613 613
 fail:
614
+    ff_id3v2_free_extra_meta(&id3v2_extra_meta);
614 615
     av_dict_free(&tmp);
615 616
     if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))
616 617
         avio_close(s->pb);
... ...
@@ -621,23 +653,6 @@ fail:
621 621
 
622 622
 /*******************************************************/
623 623
 
624
-static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
625
-                               AVPacketList **plast_pktl){
626
-    AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
627
-    if (!pktl)
628
-        return NULL;
629
-
630
-    if (*packet_buffer)
631
-        (*plast_pktl)->next = pktl;
632
-    else
633
-        *packet_buffer = pktl;
634
-
635
-    /* add the packet in the buffered packet list */
636
-    *plast_pktl = pktl;
637
-    pktl->pkt= *pkt;
638
-    return &pktl->pkt;
639
-}
640
-
641 624
 int av_read_packet(AVFormatContext *s, AVPacket *pkt)
642 625
 {
643 626
     int ret, i;
... ...
@@ -2722,6 +2737,8 @@ void avformat_free_context(AVFormatContext *s)
2722 2722
             av_parser_close(st->parser);
2723 2723
             av_free_packet(&st->cur_pkt);
2724 2724
         }
2725
+        if (st->attached_pic.data)
2726
+            av_free_packet(&st->attached_pic);
2725 2727
         av_dict_free(&st->metadata);
2726 2728
         av_freep(&st->index_entries);
2727 2729
         av_freep(&st->codec->extradata);
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33
-#define LIBAVFORMAT_VERSION_MINOR  1
33
+#define LIBAVFORMAT_VERSION_MINOR  2
34 34
 #define LIBAVFORMAT_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
... ...
@@ -220,12 +220,12 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
220 220
     int ret;
221 221
     int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
222 222
 
223
-    pkt->pos          = avio_tell(s->pb);
224
-    pkt->stream_index = 0;
225
-
226 223
     if (av_new_packet(pkt, size+2) < 0)
227 224
         return AVERROR(EIO);
228 225
 
226
+    pkt->pos          = avio_tell(s->pb);
227
+    pkt->stream_index = 0;
228
+
229 229
     pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
230 230
     pkt->data[1] = c->last_frame_bits;
231 231
     ret = avio_read(s->pb, pkt->data+2, size);
... ...
@@ -1046,7 +1046,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
1046 1046
     c->vLumBufSize= c->vLumFilterSize;
1047 1047
     c->vChrBufSize= c->vChrFilterSize;
1048 1048
     for (i=0; i<dstH; i++) {
1049
-        int chrI= (int64_t)i*c->chrDstH / dstH;
1049
+        int chrI = (int64_t) i * c->chrDstH / dstH;
1050 1050
         int nextSlice= FFMAX(c->vLumFilterPos[i   ] + c->vLumFilterSize - 1,
1051 1051
                            ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));
1052 1052
 
... ...
@@ -38,13 +38,13 @@ fi
38 38
 
39 39
 if [ -n "$do_mpeg2_ivlc_qprd" ]; then
40 40
 # mpeg2 encoding intra vlc qprd
41
-do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +qprd+mv0 -intra_vlc 1 -cmp 2 -subcmp 2 -mbd rd -vcodec mpeg2video -f mpeg2video"
41
+do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +mv0 -mpv_flags +qp_rd -intra_vlc 1 -cmp 2 -subcmp 2 -mbd rd -vcodec mpeg2video -f mpeg2video"
42 42
 do_video_decoding
43 43
 fi
44 44
 
45 45
 if [ -n "$do_mpeg2_422" ]; then
46 46
 #mpeg2 4:2:2 encoding
47
-do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +qprd+mv0+ildct+ilme -intra_vlc 1 -mbd rd -vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video"
47
+do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +mv0+ildct+ilme -mpv_flags +qp_rd -intra_vlc 1 -mbd rd -vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video"
48 48
 do_video_decoding
49 49
 fi
50 50
 
... ...
@@ -143,7 +143,7 @@ do_video_decoding
143 143
 fi
144 144
 
145 145
 if [ -n "$do_mpeg4_qprd" ]; then
146
-do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd -an -vcodec mpeg4"
146
+do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+mv0 -mpv_flags +qp_rd -cmp 2 -subcmp 2 -mbd rd -an -vcodec mpeg4"
147 147
 do_video_decoding
148 148
 fi
149 149
 
... ...
@@ -10,5 +10,8 @@ fate-cdxl-pal8: CMD = framecrc -i $(SAMPLES)/cdxl/maku.cdxl -pix_fmt rgb24 -fram
10 10
 FATE_CDXL += fate-cdxl-pal8-small
11 11
 fate-cdxl-pal8-small: CMD = framecrc -i $(SAMPLES)/cdxl/fruit.cdxl -an -pix_fmt rgb24 -frames:v 46
12 12
 
13
+FATE_CDXL += fate-cdxl-bitline-ham6
14
+fate-cdxl-bitline-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/bitline.cdxl -frames:v 10
15
+
13 16
 FATE_TESTS += $(FATE_CDXL)
14 17
 fate-cdxl: $(FATE_CDXL)
... ...
@@ -33,6 +33,11 @@ fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-confo
33 33
 fate-mp3-float-conf-si_block: CMP = stddev
34 34
 fate-mp3-float-conf-si_block: REF = $(SAMPLES)/mp3-conformance/si_block.pcm
35 35
 
36
+FATE_MP3 += fate-mp3-float-extra_overread
37
+fate-mp3-float-extra_overread: CMD = pcm -c:a mp3float -i $(SAMPLES)/mpegaudio/extra_overread.mp3
38
+fate-mp3-float-extra_overread: CMP = stddev
39
+fate-mp3-float-extra_overread: REF = $(SAMPLES)/mpegaudio/extra_overread.pcm
40
+
36 41
 FATE_TESTS += $(FATE_MP3)
37 42
 fate-mp3: $(FATE_MP3)
38 43
 $(FATE_MP3): CMP = stddev
... ...
@@ -143,7 +143,7 @@ FATE_VIDEO += fate-mpeg2-field-enc
143 143
 fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an
144 144
 
145 145
 FATE_VIDEO += fate-nuv
146
-fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv
146
+fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv -an
147 147
 
148 148
 FATE_VIDEO += fate-qpeg
149 149
 fate-qpeg: CMD = framecrc -i $(SAMPLES)/qpeg/Clock.avi -an -pix_fmt rgb24
150 150
new file mode 100644
... ...
@@ -0,0 +1,11 @@
0
+#tb 0: 12/601
1
+0,          0,          0,        1,    63180, 0xcda82c16
2
+0,          1,          1,        1,    63180, 0xa6097bf9
3
+0,          2,          2,        1,    63180, 0x4c2fb091
4
+0,          3,          3,        1,    63180, 0xc597db00
5
+0,          4,          4,        1,    63180, 0xfa581ccd
6
+0,          5,          5,        1,    63180, 0x3e51498f
7
+0,          6,          6,        1,    63180, 0xe3495396
8
+0,          7,          7,        1,    63180, 0x425f5f02
9
+0,          8,          8,        1,    63180, 0x6077465f
10
+0,          9,          9,        1,    63180, 0x923ba29c
... ...
@@ -1,29 +1,10 @@
1 1
 #tb 0: 100/2997
2
-#tb 1: 1/44100
3
-1,          0,          0,     1024,     4096, 0x00000000
4
-1,       1024,       1024,     1024,     4096, 0x4dfae7a6
5
-1,       2048,       2048,     1024,     4096, 0x3fd9f5c6
6
-1,       3072,       3072,     1024,     4096, 0x7b86e310
7
-1,       4096,       4096,     1024,     4096, 0x611cece5
8
-1,       5120,       5120,     1024,     4096, 0xb7d8e872
9 2
 0,          4,          4,        1,   460800, 0x54aedafe
10
-1,       6144,       6144,     1024,     4096, 0x072ef72b
11
-1,       7168,       7168,     1024,     4096, 0xb3560144
12 3
 0,          5,          5,        1,   460800, 0xb7aa8b56
13
-1,       8192,       8192,     1024,     4096, 0x0a3d119e
14 4
 0,          6,          6,        1,   460800, 0x283ea3b5
15
-1,       9216,       9216,     1024,     4096, 0xbe391aa4
16
-1,      10240,      10240,     1024,     4096, 0x28f7c6e5
17 5
 0,          7,          7,        1,   460800, 0x283ea3b5
18
-1,      11264,      11264,     1024,     4096, 0xca9d9df2
19 6
 0,          8,          8,        1,   460800, 0x10e577de
20
-1,      12288,      12288,     1024,     4096, 0x5c6b95a9
21 7
 0,          9,          9,        1,   460800, 0x4e091ee2
22
-1,      13312,      13312,     1024,     4096, 0x0bdfc0bf
23
-1,      14336,      14336,     1024,     4096, 0xd95a9277
24 8
 0,         10,         10,        1,   460800, 0x2ea88828
25
-1,      15360,      15360,     1024,     4096, 0xae2bef2c
26 9
 0,         11,         11,        1,   460800, 0x4b7f4df0
27
-1,      16384,      16384,     1024,     4096, 0xbf031e83
28
-1,      17408,      17408,     1024,     4096, 0x4c83e2d1
29 10
 0,         12,         12,        1,   460800, 0xa57f20d0
... ...
@@ -1,3 +1,3 @@
1
-4ef091d638bb20b8eaef5b3a0d6f97b7 *./tests/data/lavf/lavf.ffm
1
+8ce2ea9a73a1187647df7bf3c8e1b8fd *./tests/data/lavf/lavf.ffm
2 2
 376832 ./tests/data/lavf/lavf.ffm
3 3
 ./tests/data/lavf/lavf.ffm CRC=0xf361ed74
... ...
@@ -1,4 +1,4 @@
1
-40e7637e04991dbe9a23fe109f95bfc8 *./tests/data/vsynth1/prores_kostya.mov
1
+f8fe98b7f9bb66857c81dbca409a9037 *./tests/data/vsynth1/prores_kostya.mov
2 2
 3858901 ./tests/data/vsynth1/prores_kostya.mov
3 3
 0a4153637d0cc0a88a8bcbf04cfaf8c6 *./tests/data/prores_kostya.vsynth1.out.yuv
4 4
 stddev:    3.17 PSNR: 38.09 MAXDIFF:   39 bytes:  7603200/  7603200
... ...
@@ -1,4 +1,4 @@
1
-ed8b8a94da049518af8f95c5da736e57 *./tests/data/vsynth2/prores_kostya.mov
1
+26adb18726c08dde23bc4bee2eb591e2 *./tests/data/vsynth2/prores_kostya.mov
2 2
 3884586 ./tests/data/vsynth2/prores_kostya.mov
3 3
 ca2f6c1162635dedfa468c90f1fdc0ef *./tests/data/prores_kostya.vsynth2.out.yuv
4 4
 stddev:    0.92 PSNR: 48.77 MAXDIFF:   10 bytes:  7603200/  7603200