* 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
Unified · Split
| @@ -8,6 +8,7 @@ version next: · 7 unmodified lines | ||
| 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 · 12 unmodified lines | ||
| 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: · 16 unmodified lines | ||
| 35 | 36 | 2012-01-24 - xxxxxxx - lavfi 2.60.100 |
| 36 | 37 | Add avfilter_graph_dump. |
| 37 | 38 | |
| 39 | +||||||| merged common ancestors | |
| 40 | +======= | |
| 41 | +2012-xx-xx - xxxxxxx - lavf 54.2.0 - avformat.h | |
| 42 | + Add AVStream.attached_pic and AV_DISPOSITION_ATTACHED_PIC, | |
| 43 | + used for dealing with attached pictures/cover art. | |
| 44 | + | |
| 45 | +>>>>>>> qatar/master | |
| 38 | 46 | 2012-02-25 - c9bca80 - lavu 51.24.0 - error.h |
| 39 | 47 | Add AVERROR_UNKNOWN |
| 40 | 48 | |
| @@ -370,5 +370,39 @@ Wrap around segment index once it reaches @var{limit}. · 369 unmodified lines | ||
| 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]; · 113 unmodified lines | ||
| 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; |
| @@ -454,6 +405,90 @@ static void flush(AVCodecContext *avctx) · 285 unmodified lines | ||
| 454 | 405 | } |
| 455 | 406 | } |
| 456 | 407 | |
| 408 | +/** | |
| 409 | + * Set up channel positions based on a default channel configuration | |
| 410 | + * as specified in table 1.17. | |
| 411 | + * | |
| 412 | + * @return Returns error status. 0 - OK, !0 - error | |
| 413 | + */ | |
| 414 | +static av_cold int set_default_channel_config(AVCodecContext *avctx, | |
| 415 | + uint8_t (*layout_map)[3], | |
| 416 | + int *tags, | |
| 417 | + int channel_config) | |
| 418 | +{ | |
| 419 | + if (channel_config < 1 || channel_config > 7) { | |
| 420 | + av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", | |
| 421 | + channel_config); | |
| 422 | + return -1; | |
| 423 | + } | |
| 424 | + *tags = tags_per_config[channel_config]; | |
| 425 | + memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map)); | |
| 426 | + return 0; | |
| 427 | +} | |
| 428 | + | |
| 429 | +static ChannelElement *get_che(AACContext *ac, int type, int elem_id) | |
| 430 | +{ | |
| 431 | + // For PCE based channel configurations map the channels solely based on tags. | |
| 432 | + if (!ac->m4ac.chan_config) { | |
| 433 | + return ac->tag_che_map[type][elem_id]; | |
| 434 | + } | |
| 435 | + // Allow single CPE stereo files to be signalled with mono configuration. | |
| 436 | + if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) { | |
| 437 | + uint8_t layout_map[MAX_ELEM_ID*4][3]; | |
| 438 | + int layout_map_tags; | |
| 439 | + | |
| 440 | + if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags, | |
| 441 | + 2) < 0) | |
| 442 | + return NULL; | |
| 443 | + if (output_configure(ac, layout_map, layout_map_tags, | |
| 444 | + 2, OC_TRIAL_FRAME) < 0) | |
| 445 | + return NULL; | |
| 446 | + | |
| 447 | + ac->m4ac.chan_config = 2; | |
| 448 | + } | |
| 449 | + // For indexed channel configurations map the channels solely based on position. | |
| 450 | + switch (ac->m4ac.chan_config) { | |
| 451 | + case 7: | |
| 452 | + if (ac->tags_mapped == 3 && type == TYPE_CPE) { | |
| 453 | + ac->tags_mapped++; | |
| 454 | + return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; | |
| 455 | + } | |
| 456 | + case 6: | |
| 457 | + /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1] | |
| 458 | + instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have | |
| 459 | + encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */ | |
| 460 | + if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) { | |
| 461 | + ac->tags_mapped++; | |
| 462 | + return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0]; | |
| 463 | + } | |
| 464 | + case 5: | |
| 465 | + if (ac->tags_mapped == 2 && type == TYPE_CPE) { | |
| 466 | + ac->tags_mapped++; | |
| 467 | + return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1]; | |
| 468 | + } | |
| 469 | + case 4: | |
| 470 | + if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) { | |
| 471 | + ac->tags_mapped++; | |
| 472 | + return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; | |
| 473 | + } | |
| 474 | + case 3: | |
| 475 | + case 2: | |
| 476 | + if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) { | |
| 477 | + ac->tags_mapped++; | |
| 478 | + return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0]; | |
| 479 | + } else if (ac->m4ac.chan_config == 2) { | |
| 480 | + return NULL; | |
| 481 | + } | |
| 482 | + case 1: | |
| 483 | + if (!ac->tags_mapped && type == TYPE_SCE) { | |
| 484 | + ac->tags_mapped++; | |
| 485 | + return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0]; | |
| 486 | + } | |
| 487 | + default: | |
| 488 | + return NULL; | |
| 489 | + } | |
| 490 | +} | |
| 491 | + | |
| 457 | 492 | /** |
| 458 | 493 | * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit. |
| 459 | 494 | * |
| @@ -550,27 +585,6 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, · 90 unmodified lines | ||
| 550 | 585 | return tags; |
| 551 | 586 | } |
| 552 | 587 | |
| 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 | 588 | /** |
| 575 | 589 | * Decode GA "General Audio" specific configuration; reference: table 4.1. |
| 576 | 590 | * |
| @@ -2138,6 +2138,17 @@ static av_cold int validate_options(AC3EncodeContext *s) · 2137 unmodified lines | ||
| 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) · 42 unmodified lines | ||
| 2186 | 2197 | wpf--; |
| 2187 | 2198 | s->frame_size_min = 2 * wpf; |
| 2188 | 2199 | } else { |
| 2200 | + int best_br = 0, best_code = 0, best_diff = INT_MAX; | |
| 2189 | 2201 | for (i = 0; i < 19; i++) { |
| 2190 | − if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) | |
| 2202 | + int br = (ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift) * 1000; | |
| 2203 | + int diff = abs(br - avctx->bit_rate); | |
| 2204 | + if (diff < best_diff) { | |
| 2205 | + best_br = br; | |
| 2206 | + best_code = i; | |
| 2207 | + best_diff = diff; | |
| 2208 | + } | |
| 2209 | + if (!best_diff) | |
| 2191 | 2210 | break; |
| 2192 | 2211 | } |
| 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; | |
| 2212 | + avctx->bit_rate = best_br; | |
| 2213 | + s->frame_size_code = best_code << 1; | |
| 2198 | 2214 | s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; |
| 2199 | 2215 | s->num_blks_code = 0x3; |
| 2200 | 2216 | s->num_blocks = 6; |
| @@ -157,4 +157,5 @@ AVCodec ff_ac3_fixed_encoder = { · 156 unmodified lines | ||
| 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 = { · 154 unmodified lines | ||
| 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 @@ · 19 unmodified lines | ||
| 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[] = { · 52 unmodified lines | ||
| 78 | 79 | {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"}, |
| 79 | 80 | {NULL} |
| 80 | 81 | }; |
| 82 | + | |
| 83 | +static const AVCodecDefault ac3_defaults[] = { | |
| 84 | + { "b", "0" }, | |
| 85 | + { NULL } | |
| 86 | +}; | |
| @@ -200,6 +200,10 @@ static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf, · 199 unmodified lines | ||
| 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, · 741 unmodified lines | ||
| 947 | 951 | buf_out = (float *)p->avframe.data[0]; |
| 948 | 952 | |
| 949 | 953 | p->cur_frame_mode = unpack_bitstream(p, buf, buf_size); |
| 954 | + if (p->cur_frame_mode == NO_DATA) { | |
| 955 | + av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n"); | |
| 956 | + return AVERROR_INVALIDDATA; | |
| 957 | + } | |
| 950 | 958 | if (p->cur_frame_mode == MODE_DTX) { |
| 951 | 959 | av_log_missing_feature(avctx, "dtx mode", 0); |
| 952 | 960 | av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n"); |
| @@ -582,17 +582,19 @@ typedef struct RcOverride{ · 581 unmodified lines | ||
| 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 { · 893 unmodified lines | ||
| 1492 | 1494 | |
| 1493 | 1495 | int b_frame_strategy; |
| 1494 | 1496 | |
| 1497 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 1495 | 1498 | /** |
| 1496 | 1499 | * luma single coefficient elimination threshold |
| 1497 | 1500 | * - encoding: Set by user. |
| 1498 | 1501 | * - decoding: unused |
| 1499 | 1502 | */ |
| 1500 | − int luma_elim_threshold; | |
| 1503 | + attribute_deprecated int luma_elim_threshold; | |
| 1501 | 1504 | |
| 1502 | 1505 | /** |
| 1503 | 1506 | * chroma single coeff elimination threshold |
| 1504 | 1507 | * - encoding: Set by user. |
| 1505 | 1508 | * - decoding: unused |
| 1506 | 1509 | */ |
| 1507 | − int chroma_elim_threshold; | |
| 1510 | + attribute_deprecated int chroma_elim_threshold; | |
| 1511 | +#endif | |
| 1508 | 1512 | |
| 1509 | 1513 | /** |
| 1510 | 1514 | * qscale offset between IP and B-frames |
| @@ -1735,13 +1739,15 @@ typedef struct AVCodecContext { · 224 unmodified lines | ||
| 1735 | 1739 | */ |
| 1736 | 1740 | int inter_quant_bias; |
| 1737 | 1741 | |
| 1742 | +#if FF_API_COLOR_TABLE_ID | |
| 1738 | 1743 | /** |
| 1739 | 1744 | * color table ID |
| 1740 | 1745 | * - encoding: unused |
| 1741 | 1746 | * - decoding: Which clrtable should be used for 8bit RGB images. |
| 1742 | 1747 | * Tables have to be stored somewhere. FIXME |
| 1743 | 1748 | */ |
| 1744 | − int color_table_id; | |
| 1749 | + attribute_deprecated int color_table_id; | |
| 1750 | +#endif | |
| 1745 | 1751 | |
| 1746 | 1752 | /** |
| 1747 | 1753 | * slice flags |
| @@ -1799,19 +1805,19 @@ typedef struct AVCodecContext { · 51 unmodified lines | ||
| 1799 | 1805 | */ |
| 1800 | 1806 | int noise_reduction; |
| 1801 | 1807 | |
| 1808 | +#if FF_API_INTER_THRESHOLD | |
| 1802 | 1809 | /** |
| 1803 | − * | |
| 1804 | − * - encoding: Set by user. | |
| 1805 | − * - decoding: unused | |
| 1810 | + * @deprecated this field is unused | |
| 1806 | 1811 | */ |
| 1807 | − int inter_threshold; | |
| 1812 | + attribute_deprecated int inter_threshold; | |
| 1813 | +#endif | |
| 1808 | 1814 | |
| 1815 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 1809 | 1816 | /** |
| 1810 | − * quantizer noise shaping | |
| 1811 | − * - encoding: Set by user. | |
| 1812 | − * - decoding: unused | |
| 1817 | + * @deprecated use mpegvideo private options instead | |
| 1813 | 1818 | */ |
| 1814 | − int quantizer_noise_shaping; | |
| 1819 | + attribute_deprecated int quantizer_noise_shaping; | |
| 1820 | +#endif | |
| 1815 | 1821 | |
| 1816 | 1822 | /** |
| 1817 | 1823 | * Motion estimation threshold below which no motion estimation is |
| @@ -228,7 +228,7 @@ static av_cold int decode_init(AVCodecContext *avctx) { · 227 unmodified lines | ||
| 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) { · 7 unmodified lines | ||
| 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, · 130 unmodified lines | ||
| 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 = { · 257 unmodified lines | ||
| 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 · 83 unmodified lines | ||
| 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 = { · 4 unmodified lines | ||
| 94 | 96 | .close = ff_MPV_encode_end, |
| 95 | 97 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 96 | 98 | .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), |
| 99 | + .priv_class = &flv_class, | |
| 97 | 100 | }; |
| @@ -321,6 +321,8 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ · 320 unmodified lines | ||
| 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 = { · 4 unmodified lines | ||
| 331 | 333 | .close = ff_MPV_encode_end, |
| 332 | 334 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 333 | 335 | .long_name= NULL_IF_CONFIG_SMALL("H.261"), |
| 336 | + .priv_class = &h261_class, | |
| 334 | 337 | }; |
| @@ -148,7 +148,7 @@ static inline int get_p_cbp(MpegEncContext * s, · 147 unmodified lines | ||
| 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: · 1997 unmodified lines | ||
| 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 @@ · 19 unmodified lines | ||
| 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 @@ · 3 unmodified lines | ||
| 35 | 36 | #undef NDEBUG |
| 36 | 37 | #include <assert.h> |
| 37 | 38 | |
| 39 | +/* Number of samples the user should send in each call. | |
| 40 | + * This value is used because it is the LCD of all possible frame sizes, so | |
| 41 | + * an output packet will always start at the same point as one of the input | |
| 42 | + * packets. | |
| 43 | + */ | |
| 38 | 44 | #define OGGVORBIS_FRAME_SIZE 64 |
| 39 | 45 | |
| 40 | 46 | #define BUFFER_SIZE (1024 * 64) |
| 41 | 47 | |
| 42 | 48 | 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; | |
| 49 | + AVClass *av_class; /**< class for AVOptions */ | |
| 50 | + vorbis_info vi; /**< vorbis_info used during init */ | |
| 51 | + vorbis_dsp_state vd; /**< DSP state used for analysis */ | |
| 52 | + vorbis_block vb; /**< vorbis_block used for analysis */ | |
| 53 | + AVFifoBuffer *pkt_fifo; /**< output packet buffer */ | |
| 54 | + int eof; /**< end-of-file flag */ | |
| 55 | + int dsp_initialized; /**< vd has been initialized */ | |
| 56 | + vorbis_comment vc; /**< VorbisComment info */ | |
| 57 | + ogg_packet op; /**< ogg packet */ | |
| 58 | + double iblock; /**< impulse block bias option */ | |
| 56 | 59 | } OggVorbisContext; |
| 57 | 60 | |
| 58 | 61 | static const AVOption options[] = { |
| 59 | 62 | { "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 | 63 | { NULL } |
| 61 | 64 | }; |
| 65 | + | |
| 66 | +static const AVCodecDefault defaults[] = { | |
| 67 | + { "b", "0" }, | |
| 68 | + { NULL }, | |
| 69 | +}; | |
| 70 | + | |
| 62 | 71 | static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; |
| 63 | 72 | |
| 73 | + | |
| 64 | 74 | static int vorbis_error_to_averror(int ov_err) |
| 65 | 75 | { |
| 66 | 76 | switch (ov_err) { |
| @@ -71,27 +81,34 @@ static int vorbis_error_to_averror(int ov_err) · 4 unmodified lines | ||
| 71 | 81 | } |
| 72 | 82 | } |
| 73 | 83 | |
| 74 | −static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) | |
| 84 | +static av_cold int oggvorbis_init_encoder(vorbis_info *vi, | |
| 85 | + AVCodecContext *avctx) | |
| 75 | 86 | { |
| 76 | − OggVorbisContext *context = avccontext->priv_data; | |
| 87 | + OggVorbisContext *s = avctx->priv_data; | |
| 77 | 88 | double cfreq; |
| 78 | 89 | int ret; |
| 79 | 90 | |
| 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, | |
| 91 | + if (avctx->flags & CODEC_FLAG_QSCALE || !avctx->bit_rate) { | |
| 92 | + /* variable bitrate | |
| 93 | + * NOTE: we use the oggenc range of -1 to 10 for global_quality for | |
| 94 | + * user convenience, but libvorbis uses -0.1 to 1.0. | |
| 95 | + */ | |
| 96 | + float q = avctx->global_quality / (float)FF_QP2LAMBDA; | |
| 97 | + /* default to 3 if the user did not set quality or bitrate */ | |
| 98 | + if (!(avctx->flags & CODEC_FLAG_QSCALE)) | |
| 99 | + q = 3.0; | |
| 100 | + if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels, | |
| 101 | + avctx->sample_rate, | |
| 85 | 102 | q / 10.0))) |
| 86 | 103 | goto error; |
| 87 | 104 | } 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; | |
| 105 | + int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1; | |
| 106 | + int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1; | |
| 90 | 107 | |
| 91 | − /* constant bitrate */ | |
| 92 | − if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels, | |
| 93 | − avccontext->sample_rate, minrate, | |
| 94 | − avccontext->bit_rate, maxrate))) | |
| 108 | + /* average bitrate */ | |
| 109 | + if ((ret = vorbis_encode_setup_managed(vi, avctx->channels, | |
| 110 | + avctx->sample_rate, maxrate, | |
| 111 | + avctx->bit_rate, minrate))) | |
| 95 | 112 | goto error; |
| 96 | 113 | |
| 97 | 114 | /* variable bitrate by estimate, disable slow rate management */ |
| @@ -101,43 +118,44 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco · 3 unmodified lines | ||
| 101 | 118 | } |
| 102 | 119 | |
| 103 | 120 | /* cutoff frequency */ |
| 104 | − if (avccontext->cutoff > 0) { | |
| 105 | − cfreq = avccontext->cutoff / 1000.0; | |
| 121 | + if (avctx->cutoff > 0) { | |
| 122 | + cfreq = avctx->cutoff / 1000.0; | |
| 106 | 123 | if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) |
| 107 | 124 | goto error; /* should not happen */ |
| 108 | 125 | } |
| 109 | 126 | |
| 110 | − if (context->iblock) { | |
| 111 | − if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock))) | |
| 127 | + /* impulse block bias */ | |
| 128 | + if (s->iblock) { | |
| 129 | + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock))) | |
| 112 | 130 | goto error; |
| 113 | 131 | } |
| 114 | 132 | |
| 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) { | |
| 133 | + if (avctx->channels == 3 && | |
| 134 | + avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || | |
| 135 | + avctx->channels == 4 && | |
| 136 | + avctx->channel_layout != AV_CH_LAYOUT_2_2 && | |
| 137 | + avctx->channel_layout != AV_CH_LAYOUT_QUAD || | |
| 138 | + avctx->channels == 5 && | |
| 139 | + avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && | |
| 140 | + avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || | |
| 141 | + avctx->channels == 6 && | |
| 142 | + avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && | |
| 143 | + avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK || | |
| 144 | + avctx->channels == 7 && | |
| 145 | + avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) || | |
| 146 | + avctx->channels == 8 && | |
| 147 | + avctx->channel_layout != AV_CH_LAYOUT_7POINT1) { | |
| 148 | + if (avctx->channel_layout) { | |
| 131 | 149 | 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: " | |
| 150 | + av_get_channel_layout_string(name, sizeof(name), avctx->channels, | |
| 151 | + avctx->channel_layout); | |
| 152 | + av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: " | |
| 135 | 153 | "output stream will have incorrect " |
| 136 | 154 | "channel layout.\n", name); |
| 137 | 155 | } else { |
| 138 | − av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder " | |
| 156 | + av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder " | |
| 139 | 157 | "will use Vorbis channel layout for " |
| 140 | − "%d channels.\n", avccontext->channels); | |
| 158 | + "%d channels.\n", avctx->channels); | |
| 141 | 159 | } |
| 142 | 160 | } |
| 143 | 161 | |
| @@ -155,59 +173,64 @@ static int xiph_len(int l) · 11 unmodified lines | ||
| 155 | 173 | return 1 + l / 255 + l; |
| 156 | 174 | } |
| 157 | 175 | |
| 158 | −static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) | |
| 176 | +static av_cold int oggvorbis_encode_close(AVCodecContext *avctx) | |
| 159 | 177 | { |
| 160 | − OggVorbisContext *context = avccontext->priv_data; | |
| 161 | −/* ogg_packet op ; */ | |
| 178 | + OggVorbisContext *s = avctx->priv_data; | |
| 162 | 179 | |
| 163 | − vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */ | |
| 180 | + /* notify vorbisenc this is EOF */ | |
| 181 | + if (s->dsp_initialized) | |
| 182 | + vorbis_analysis_wrote(&s->vd, 0); | |
| 164 | 183 | |
| 165 | − vorbis_block_clear(&context->vb); | |
| 166 | − vorbis_dsp_clear(&context->vd); | |
| 167 | − vorbis_info_clear(&context->vi); | |
| 184 | + vorbis_block_clear(&s->vb); | |
| 185 | + vorbis_dsp_clear(&s->vd); | |
| 186 | + vorbis_info_clear(&s->vi); | |
| 168 | 187 | |
| 169 | − av_freep(&avccontext->coded_frame); | |
| 170 | − av_freep(&avccontext->extradata); | |
| 188 | + av_fifo_free(s->pkt_fifo); | |
| 189 | + av_freep(&avctx->coded_frame); | |
| 190 | + av_freep(&avctx->extradata); | |
| 171 | 191 | |
| 172 | 192 | return 0; |
| 173 | 193 | } |
| 174 | 194 | |
| 175 | −static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) | |
| 195 | +static av_cold int oggvorbis_encode_init(AVCodecContext *avctx) | |
| 176 | 196 | { |
| 177 | − OggVorbisContext *context = avccontext->priv_data; | |
| 197 | + OggVorbisContext *s = avctx->priv_data; | |
| 178 | 198 | ogg_packet header, header_comm, header_code; |
| 179 | 199 | uint8_t *p; |
| 180 | 200 | unsigned int offset; |
| 181 | 201 | int ret; |
| 182 | 202 | |
| 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"); | |
| 203 | + vorbis_info_init(&s->vi); | |
| 204 | + if ((ret = oggvorbis_init_encoder(&s->vi, avctx))) { | |
| 205 | + av_log(avctx, AV_LOG_ERROR, "encoder setup failed\n"); | |
| 186 | 206 | goto error; |
| 187 | 207 | } |
| 188 | − if ((ret = vorbis_analysis_init(&context->vd, &context->vi))) { | |
| 208 | + if ((ret = vorbis_analysis_init(&s->vd, &s->vi))) { | |
| 209 | + av_log(avctx, AV_LOG_ERROR, "analysis init failed\n"); | |
| 189 | 210 | ret = vorbis_error_to_averror(ret); |
| 190 | 211 | goto error; |
| 191 | 212 | } |
| 192 | − if ((ret = vorbis_block_init(&context->vd, &context->vb))) { | |
| 213 | + s->dsp_initialized = 1; | |
| 214 | + if ((ret = vorbis_block_init(&s->vd, &s->vb))) { | |
| 215 | + av_log(avctx, AV_LOG_ERROR, "dsp init failed\n"); | |
| 193 | 216 | ret = vorbis_error_to_averror(ret); |
| 194 | 217 | goto error; |
| 195 | 218 | } |
| 196 | 219 | |
| 197 | − vorbis_comment_init(&context->vc); | |
| 198 | − vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT); | |
| 220 | + vorbis_comment_init(&s->vc); | |
| 221 | + vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT); | |
| 199 | 222 | |
| 200 | − if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header, | |
| 201 | − &header_comm, &header_code))) { | |
| 223 | + if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm, | |
| 224 | + &header_code))) { | |
| 202 | 225 | ret = vorbis_error_to_averror(ret); |
| 203 | 226 | goto error; |
| 204 | 227 | } |
| 205 | 228 | |
| 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); | |
| 229 | + avctx->extradata_size = 1 + xiph_len(header.bytes) + | |
| 230 | + xiph_len(header_comm.bytes) + | |
| 231 | + header_code.bytes; | |
| 232 | + p = avctx->extradata = av_malloc(avctx->extradata_size + | |
| 233 | + FF_INPUT_BUFFER_PADDING_SIZE); | |
| 211 | 234 | if (!p) { |
| 212 | 235 | ret = AVERROR(ENOMEM); |
| 213 | 236 | goto error; |
| @@ -222,100 +245,107 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) · 8 unmodified lines | ||
| 222 | 245 | offset += header_comm.bytes; |
| 223 | 246 | memcpy(&p[offset], header_code.packet, header_code.bytes); |
| 224 | 247 | offset += header_code.bytes; |
| 225 | − assert(offset == avccontext->extradata_size); | |
| 248 | + assert(offset == avctx->extradata_size); | |
| 226 | 249 | |
| 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); | |
| 250 | + vorbis_comment_clear(&s->vc); | |
| 233 | 251 | |
| 234 | − avccontext->frame_size = OGGVORBIS_FRAME_SIZE; | |
| 252 | + avctx->frame_size = OGGVORBIS_FRAME_SIZE; | |
| 253 | + | |
| 254 | + s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE); | |
| 255 | + if (!s->pkt_fifo) { | |
| 256 | + ret = AVERROR(ENOMEM); | |
| 257 | + goto error; | |
| 258 | + } | |
| 235 | 259 | |
| 236 | − avccontext->coded_frame = avcodec_alloc_frame(); | |
| 237 | − if (!avccontext->coded_frame) { | |
| 260 | + avctx->coded_frame = avcodec_alloc_frame(); | |
| 261 | + if (!avctx->coded_frame) { | |
| 238 | 262 | ret = AVERROR(ENOMEM); |
| 239 | 263 | goto error; |
| 240 | 264 | } |
| 241 | 265 | |
| 242 | 266 | return 0; |
| 243 | 267 | error: |
| 244 | − oggvorbis_encode_close(avccontext); | |
| 268 | + oggvorbis_encode_close(avctx); | |
| 245 | 269 | return ret; |
| 246 | 270 | } |
| 247 | 271 | |
| 248 | −static int oggvorbis_encode_frame(AVCodecContext *avccontext, | |
| 249 | − unsigned char *packets, | |
| 272 | +static int oggvorbis_encode_frame(AVCodecContext *avctx, unsigned char *packets, | |
| 250 | 273 | int buf_size, void *data) |
| 251 | 274 | { |
| 252 | − OggVorbisContext *context = avccontext->priv_data; | |
| 275 | + OggVorbisContext *s = avctx->priv_data; | |
| 253 | 276 | ogg_packet op; |
| 254 | − signed short *audio = data; | |
| 255 | − int l; | |
| 277 | + float *audio = data; | |
| 278 | + int pkt_size, ret; | |
| 256 | 279 | |
| 280 | + /* send samples to libvorbis */ | |
| 257 | 281 | if (data) { |
| 258 | − const int samples = avccontext->frame_size; | |
| 282 | + const int samples = avctx->frame_size; | |
| 259 | 283 | float **buffer; |
| 260 | − int c, channels = context->vi.channels; | |
| 284 | + int c, channels = s->vi.channels; | |
| 261 | 285 | |
| 262 | − buffer = vorbis_analysis_buffer(&context->vd, samples); | |
| 286 | + buffer = vorbis_analysis_buffer(&s->vd, samples); | |
| 263 | 287 | for (c = 0; c < channels; c++) { |
| 288 | + int i; | |
| 264 | 289 | int co = (channels > 8) ? c : |
| 265 | 290 | 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; | |
| 291 | + for (i = 0; i < samples; i++) | |
| 292 | + buffer[c][i] = audio[i * channels + co]; | |
| 293 | + } | |
| 294 | + if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) { | |
| 295 | + av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); | |
| 296 | + return vorbis_error_to_averror(ret); | |
| 268 | 297 | } |
| 269 | − vorbis_analysis_wrote(&context->vd, samples); | |
| 270 | 298 | } else { |
| 271 | − if (!context->eof) | |
| 272 | − vorbis_analysis_wrote(&context->vd, 0); | |
| 273 | − context->eof = 1; | |
| 299 | + if (!s->eof) | |
| 300 | + if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) { | |
| 301 | + av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); | |
| 302 | + return vorbis_error_to_averror(ret); | |
| 303 | + } | |
| 304 | + s->eof = 1; | |
| 274 | 305 | } |
| 275 | 306 | |
| 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); | |
| 307 | + /* retrieve available packets from libvorbis */ | |
| 308 | + while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) { | |
| 309 | + if ((ret = vorbis_analysis(&s->vb, NULL)) < 0) | |
| 310 | + break; | |
| 311 | + if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0) | |
| 312 | + break; | |
| 313 | + | |
| 314 | + /* add any available packets to the output packet buffer */ | |
| 315 | + while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) { | |
| 316 | + if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) { | |
| 317 | + av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n"); | |
| 318 | + return AVERROR_BUG; | |
| 288 | 319 | } |
| 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); | |
| 320 | + av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); | |
| 321 | + av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL); | |
| 322 | + } | |
| 323 | + if (ret < 0) { | |
| 324 | + av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); | |
| 325 | + break; | |
| 294 | 326 | } |
| 295 | 327 | } |
| 328 | + if (ret < 0) { | |
| 329 | + av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); | |
| 330 | + return vorbis_error_to_averror(ret); | |
| 331 | + } | |
| 296 | 332 | |
| 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"); | |
| 333 | + /* output then next packet from the output buffer, if available */ | |
| 334 | + pkt_size = 0; | |
| 335 | + if (av_fifo_size(s->pkt_fifo) >= sizeof(ogg_packet)) { | |
| 336 | + av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); | |
| 337 | + pkt_size = op.bytes; | |
| 338 | + // FIXME: we should use the user-supplied pts and duration | |
| 339 | + avctx->coded_frame->pts = ff_samples_to_time_base(avctx, | |
| 340 | + op.granulepos); | |
| 341 | + if (pkt_size > buf_size) { | |
| 342 | + av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n"); | |
| 309 | 343 | return AVERROR(EINVAL); |
| 310 | 344 | } |
| 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); | |
| 345 | + av_fifo_generic_read(s->pkt_fifo, packets, pkt_size, NULL); | |
| 316 | 346 | } |
| 317 | 347 | |
| 318 | − return l; | |
| 348 | + return pkt_size; | |
| 319 | 349 | } |
| 320 | 350 | |
| 321 | 351 | AVCodec ff_libvorbis_encoder = { |
| @@ -327,7 +357,9 @@ AVCodec ff_libvorbis_encoder = { · 5 unmodified lines | ||
| 327 | 357 | .encode = oggvorbis_encode_frame, |
| 328 | 358 | .close = oggvorbis_encode_close, |
| 329 | 359 | .capabilities = CODEC_CAP_DELAY, |
| 330 | − .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, | |
| 360 | + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, | |
| 361 | + AV_SAMPLE_FMT_NONE }, | |
| 331 | 362 | .long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"), |
| 332 | 363 | .priv_class = &class, |
| 364 | + .defaults = defaults, | |
| 333 | 365 | }; |
| @@ -939,6 +939,7 @@ static void mpeg1_encode_block(MpegEncContext *s, · 938 unmodified lines | ||
| 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[] = { · 1 unmodified line | ||
| 946 | 947 | COMMON_OPTS |
| 947 | 948 | { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, |
| 948 | 949 | { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, |
| 950 | + FF_MPV_COMMON_OPTS | |
| 949 | 951 | { NULL }, |
| 950 | 952 | }; |
| 951 | 953 | |
| @@ -430,7 +430,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], · 429 unmodified lines | ||
| 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) · 893 unmodified lines | ||
| 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 @@ · 30 unmodified lines | ||
| 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 { · 45 unmodified lines | ||
| 82 | 83 | int err_recognition; |
| 83 | 84 | AVCodecContext* avctx; |
| 84 | 85 | MPADSPContext mpadsp; |
| 86 | + DSPContext dsp; | |
| 85 | 87 | AVFrame frame; |
| 86 | 88 | } MPADecodeContext; |
| 87 | 89 | |
| @@ -434,6 +436,7 @@ static av_cold int decode_init(AVCodecContext * avctx) · 346 unmodified lines | ||
| 434 | 436 | s->avctx = avctx; |
| 435 | 437 | |
| 436 | 438 | ff_mpadsp_init(&s->mpadsp); |
| 439 | + ff_dsputil_init(&s->dsp, avctx); | |
| 437 | 440 | |
| 438 | 441 | avctx->sample_fmt= OUT_FMT; |
| 439 | 442 | s->err_recognition = avctx->err_recognition; |
| @@ -1155,6 +1158,9 @@ found2: · 715 unmodified lines | ||
| 1155 | 1158 | /* ms stereo ONLY */ |
| 1156 | 1159 | /* NOTE: the 1/sqrt(2) normalization factor is included in the |
| 1157 | 1160 | global gain */ |
| 1161 | +#if CONFIG_FLOAT | |
| 1162 | + s-> dsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576); | |
| 1163 | +#else | |
| 1158 | 1164 | tab0 = g0->sb_hybrid; |
| 1159 | 1165 | tab1 = g1->sb_hybrid; |
| 1160 | 1166 | for (i = 0; i < 576; i++) { |
| @@ -1163,6 +1169,7 @@ found2: · 2 unmodified lines | ||
| 1163 | 1169 | tab0[i] = tmp0 + tmp1; |
| 1164 | 1170 | tab1[i] = tmp0 - tmp1; |
| 1165 | 1171 | } |
| 1172 | +#endif | |
| 1166 | 1173 | } |
| 1167 | 1174 | } |
| 1168 | 1175 | |
| @@ -38,6 +38,8 @@ · 37 unmodified lines | ||
| 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 { · 651 unmodified lines | ||
| 695 | 697 | int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow); |
| 696 | 698 | int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow); |
| 697 | 699 | void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block); |
| 700 | + | |
| 701 | + int mpv_flags; ///< flags set by private options | |
| 702 | + int quantizer_noise_shaping; | |
| 698 | 703 | } MpegEncContext; |
| 699 | 704 | |
| 700 | 705 | #define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \ |
| @@ -702,6 +707,36 @@ typedef struct MpegEncContext { · 1 unmodified line | ||
| 702 | 707 | &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\ |
| 703 | 708 | : NULL) |
| 704 | 709 | |
| 710 | +/* mpegvideo_enc common options */ | |
| 711 | +#define FF_MPV_FLAG_SKIP_RD 0x0001 | |
| 712 | +#define FF_MPV_FLAG_STRICT_GOP 0x0002 | |
| 713 | +#define FF_MPV_FLAG_QP_RD 0x0004 | |
| 714 | +#define FF_MPV_FLAG_CBP_RD 0x0008 | |
| 715 | + | |
| 716 | +#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x) | |
| 717 | +#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) | |
| 718 | +#define FF_MPV_COMMON_OPTS \ | |
| 719 | +{ "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" },\ | |
| 720 | +{ "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" },\ | |
| 721 | +{ "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\ | |
| 722 | +{ "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" },\ | |
| 723 | +{ "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" },\ | |
| 724 | +{ "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\ | |
| 725 | + FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\ | |
| 726 | +{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\ | |
| 727 | + FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\ | |
| 728 | +{ "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS }, | |
| 729 | + | |
| 730 | +extern const AVOption ff_mpv_generic_options[]; | |
| 731 | + | |
| 732 | +#define FF_MPV_GENERIC_CLASS(name) \ | |
| 733 | +static const AVClass name ## _class = {\ | |
| 734 | + .class_name = #name " encoder",\ | |
| 735 | + .item_name = av_default_item_name,\ | |
| 736 | + .option = ff_mpv_generic_options,\ | |
| 737 | + .version = LIBAVUTIL_VERSION_INT,\ | |
| 738 | +}; | |
| 739 | + | |
| 705 | 740 | void ff_MPV_decode_defaults(MpegEncContext *s); |
| 706 | 741 | int ff_MPV_common_init(MpegEncContext *s); |
| 707 | 742 | void ff_MPV_common_end(MpegEncContext *s); |
| @@ -63,6 +63,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int · 62 unmodified lines | ||
| 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) · 283 unmodified lines | ||
| 352 | 357 | s->flags2 = avctx->flags2; |
| 353 | 358 | s->max_b_frames = avctx->max_b_frames; |
| 354 | 359 | s->codec_id = avctx->codec->id; |
| 355 | − s->luma_elim_threshold = avctx->luma_elim_threshold; | |
| 356 | − s->chroma_elim_threshold = avctx->chroma_elim_threshold; | |
| 360 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 361 | + if (avctx->luma_elim_threshold) | |
| 362 | + s->luma_elim_threshold = avctx->luma_elim_threshold; | |
| 363 | + if (avctx->chroma_elim_threshold) | |
| 364 | + s->chroma_elim_threshold = avctx->chroma_elim_threshold; | |
| 365 | +#endif | |
| 357 | 366 | s->strict_std_compliance = avctx->strict_std_compliance; |
| 358 | 367 | s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0; |
| 359 | 368 | s->mpeg_quant = avctx->mpeg_quant; |
| @@ -373,13 +382,18 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 13 unmodified lines | ||
| 373 | 382 | /* Fixed QSCALE */ |
| 374 | 383 | s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); |
| 375 | 384 | |
| 385 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 386 | + if (s->flags & CODEC_FLAG_QP_RD) | |
| 387 | + s->mpv_flags |= FF_MPV_FLAG_QP_RD; | |
| 388 | +#endif | |
| 389 | + | |
| 376 | 390 | s->adaptive_quant = (s->avctx->lumi_masking || |
| 377 | 391 | s->avctx->dark_masking || |
| 378 | 392 | s->avctx->temporal_cplx_masking || |
| 379 | 393 | s->avctx->spatial_cplx_masking || |
| 380 | 394 | s->avctx->p_masking || |
| 381 | 395 | s->avctx->border_masking || |
| 382 | − (s->flags & CODEC_FLAG_QP_RD)) && | |
| 396 | + (s->mpv_flags & FF_MPV_FLAG_QP_RD)) && | |
| 383 | 397 | !s->fixed_qscale; |
| 384 | 398 | |
| 385 | 399 | s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER); |
| @@ -488,12 +502,17 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 102 unmodified lines | ||
| 488 | 502 | return -1; |
| 489 | 503 | } |
| 490 | 504 | |
| 491 | − if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) { | |
| 505 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 506 | + if (s->flags & CODEC_FLAG_CBP_RD) | |
| 507 | + s->mpv_flags |= FF_MPV_FLAG_CBP_RD; | |
| 508 | +#endif | |
| 509 | + | |
| 510 | + if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) { | |
| 492 | 511 | av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); |
| 493 | 512 | return -1; |
| 494 | 513 | } |
| 495 | 514 | |
| 496 | − if ((s->flags & CODEC_FLAG_QP_RD) && | |
| 515 | + if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && | |
| 497 | 516 | s->avctx->mb_decision != FF_MB_DECISION_RD) { |
| 498 | 517 | av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); |
| 499 | 518 | return -1; |
| @@ -610,6 +629,15 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) · 110 unmodified lines | ||
| 610 | 629 | } |
| 611 | 630 | s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; |
| 612 | 631 | |
| 632 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 633 | + if (avctx->flags2 & CODEC_FLAG2_SKIP_RD) | |
| 634 | + s->mpv_flags |= FF_MPV_FLAG_SKIP_RD; | |
| 635 | + if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP) | |
| 636 | + s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP; | |
| 637 | + if (avctx->quantizer_noise_shaping) | |
| 638 | + s->quantizer_noise_shaping = avctx->quantizer_noise_shaping; | |
| 639 | +#endif | |
| 640 | + | |
| 613 | 641 | switch (avctx->codec->id) { |
| 614 | 642 | case CODEC_ID_MPEG1VIDEO: |
| 615 | 643 | s->out_format = FMT_MPEG1; |
| @@ -1301,7 +1329,7 @@ static int select_input_picture(MpegEncContext *s) · 685 unmodified lines | ||
| 1301 | 1329 | } |
| 1302 | 1330 | |
| 1303 | 1331 | if (s->picture_in_gop_number + b_frames >= s->gop_size) { |
| 1304 | − if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) && | |
| 1332 | + if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && | |
| 1305 | 1333 | s->gop_size > s->picture_in_gop_number) { |
| 1306 | 1334 | b_frames = s->gop_size - s->picture_in_gop_number - 1; |
| 1307 | 1335 | } else { |
| @@ -1726,7 +1754,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 418 unmodified lines | ||
| 1726 | 1754 | s->lambda = s->lambda_table[mb_xy]; |
| 1727 | 1755 | update_qscale(s); |
| 1728 | 1756 | |
| 1729 | − if (!(s->flags & CODEC_FLAG_QP_RD)) { | |
| 1757 | + if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) { | |
| 1730 | 1758 | s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy]; |
| 1731 | 1759 | s->dquant = s->qscale - last_qp; |
| 1732 | 1760 | |
| @@ -1746,7 +1774,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 13 unmodified lines | ||
| 1746 | 1774 | } |
| 1747 | 1775 | } |
| 1748 | 1776 | ff_set_qscale(s, last_qp + s->dquant); |
| 1749 | − } else if (s->flags & CODEC_FLAG_QP_RD) | |
| 1777 | + } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD) | |
| 1750 | 1778 | ff_set_qscale(s, s->qscale + s->dquant); |
| 1751 | 1779 | |
| 1752 | 1780 | wrap_y = s->linesize; |
| @@ -1934,7 +1962,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 181 unmodified lines | ||
| 1934 | 1962 | } |
| 1935 | 1963 | } |
| 1936 | 1964 | |
| 1937 | − if (s->avctx->quantizer_noise_shaping) { | |
| 1965 | + if (s->quantizer_noise_shaping) { | |
| 1938 | 1966 | if (!skip_dct[0]) |
| 1939 | 1967 | get_visual_weight(weight[0], ptr_y , wrap_y); |
| 1940 | 1968 | if (!skip_dct[1]) |
| @@ -1975,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 34 unmodified lines | ||
| 1975 | 2003 | } else |
| 1976 | 2004 | s->block_last_index[i] = -1; |
| 1977 | 2005 | } |
| 1978 | − if (s->avctx->quantizer_noise_shaping) { | |
| 2006 | + if (s->quantizer_noise_shaping) { | |
| 1979 | 2007 | for (i = 0; i < mb_block_count; i++) { |
| 1980 | 2008 | if (!skip_dct[i]) { |
| 1981 | 2009 | s->block_last_index[i] = |
| @@ -1992,7 +2020,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, · 10 unmodified lines | ||
| 1992 | 2020 | for (i = 4; i < mb_block_count; i++) |
| 1993 | 2021 | dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
| 1994 | 2022 | |
| 1995 | − if (s->flags & CODEC_FLAG_CBP_RD) { | |
| 2023 | + if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { | |
| 1996 | 2024 | for (i = 0; i < mb_block_count; i++) { |
| 1997 | 2025 | if (s->block_last_index[i] == -1) |
| 1998 | 2026 | s->coded_score[i] = INT_MAX / 256; |
| @@ -2513,7 +2541,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 514 unmodified lines | ||
| 2513 | 2541 | s->mb_skipped=0; |
| 2514 | 2542 | s->dquant=0; //only for QP_RD |
| 2515 | 2543 | |
| 2516 | − if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD | |
| 2544 | + 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 | 2545 | int next_block=0; |
| 2518 | 2546 | int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
| 2519 | 2547 | |
| @@ -2650,7 +2678,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 130 unmodified lines | ||
| 2650 | 2678 | } |
| 2651 | 2679 | } |
| 2652 | 2680 | |
| 2653 | − if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){ | |
| 2681 | + if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) { | |
| 2654 | 2682 | if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD |
| 2655 | 2683 | const int last_qp= backup_s.qscale; |
| 2656 | 2684 | int qpi, qp, dc[6]; |
| @@ -2715,7 +2743,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ · 58 unmodified lines | ||
| 2715 | 2743 | encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, |
| 2716 | 2744 | &dmin, &next_block, 0, 0); |
| 2717 | 2745 | } |
| 2718 | − if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){ | |
| 2746 | + if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) { | |
| 2719 | 2747 | int coded=0; |
| 2720 | 2748 | for(i=0; i<6; i++) |
| 2721 | 2749 | coded |= s->block_last_index[i]; |
| @@ -3755,7 +3783,7 @@ STOP_TIMER("init rem[]") · 1033 unmodified lines | ||
| 3755 | 3783 | #ifdef REFINE_STATS |
| 3756 | 3784 | {START_TIMER |
| 3757 | 3785 | #endif |
| 3758 | − analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3; | |
| 3786 | + analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3; | |
| 3759 | 3787 | |
| 3760 | 3788 | if(analyze_gradient){ |
| 3761 | 3789 | #ifdef REFINE_STATS |
| @@ -3813,7 +3841,7 @@ STOP_TIMER("dct")} · 51 unmodified lines | ||
| 3813 | 3841 | const int level= block[j]; |
| 3814 | 3842 | int change, old_coeff; |
| 3815 | 3843 | |
| 3816 | − if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1) | |
| 3844 | + if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1) | |
| 3817 | 3845 | break; |
| 3818 | 3846 | |
| 3819 | 3847 | if(level){ |
| @@ -3831,7 +3859,7 @@ STOP_TIMER("dct")} · 11 unmodified lines | ||
| 3831 | 3859 | int score, new_coeff, unquant_change; |
| 3832 | 3860 | |
| 3833 | 3861 | score=0; |
| 3834 | − if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level)) | |
| 3862 | + if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level)) | |
| 3835 | 3863 | continue; |
| 3836 | 3864 | |
| 3837 | 3865 | if(new_level){ |
| @@ -4089,6 +4117,7 @@ int ff_dct_quantize_c(MpegEncContext *s, · 251 unmodified lines | ||
| 4089 | 4117 | static const AVOption h263_options[] = { |
| 4090 | 4118 | { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, |
| 4091 | 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 | |
| 4092 | 4121 | { NULL }, |
| 4093 | 4122 | }; |
| 4094 | 4123 | |
| @@ -4117,6 +4146,7 @@ static const AVOption h263p_options[] = { · 22 unmodified lines | ||
| 4117 | 4146 | { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, |
| 4118 | 4147 | { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, |
| 4119 | 4148 | { "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}, |
| 4149 | + FF_MPV_COMMON_OPTS | |
| 4120 | 4150 | { NULL }, |
| 4121 | 4151 | }; |
| 4122 | 4152 | static const AVClass h263p_class = { |
| @@ -4140,6 +4170,8 @@ AVCodec ff_h263p_encoder = { · 17 unmodified lines | ||
| 4140 | 4170 | .priv_class = &h263p_class, |
| 4141 | 4171 | }; |
| 4142 | 4172 | |
| 4173 | +FF_MPV_GENERIC_CLASS(msmpeg4v2) | |
| 4174 | + | |
| 4143 | 4175 | AVCodec ff_msmpeg4v2_encoder = { |
| 4144 | 4176 | .name = "msmpeg4v2", |
| 4145 | 4177 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -4150,8 +4182,11 @@ AVCodec ff_msmpeg4v2_encoder = { · 4 unmodified lines | ||
| 4150 | 4182 | .close = ff_MPV_encode_end, |
| 4151 | 4183 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 4152 | 4184 | .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), |
| 4185 | + .priv_class = &msmpeg4v2_class, | |
| 4153 | 4186 | }; |
| 4154 | 4187 | |
| 4188 | +FF_MPV_GENERIC_CLASS(msmpeg4v3) | |
| 4189 | + | |
| 4155 | 4190 | AVCodec ff_msmpeg4v3_encoder = { |
| 4156 | 4191 | .name = "msmpeg4", |
| 4157 | 4192 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -4162,8 +4197,11 @@ AVCodec ff_msmpeg4v3_encoder = { · 4 unmodified lines | ||
| 4162 | 4197 | .close = ff_MPV_encode_end, |
| 4163 | 4198 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 4164 | 4199 | .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), |
| 4200 | + .priv_class = &msmpeg4v3_class, | |
| 4165 | 4201 | }; |
| 4166 | 4202 | |
| 4203 | +FF_MPV_GENERIC_CLASS(wmv1) | |
| 4204 | + | |
| 4167 | 4205 | AVCodec ff_wmv1_encoder = { |
| 4168 | 4206 | .name = "wmv1", |
| 4169 | 4207 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -4174,4 +4212,5 @@ AVCodec ff_wmv1_encoder = { · 4 unmodified lines | ||
| 4174 | 4212 | .close = ff_MPV_encode_end, |
| 4175 | 4213 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 4176 | 4214 | .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), |
| 4215 | + .priv_class = &wmv1_class, | |
| 4177 | 4216 | }; |
| @@ -98,12 +98,16 @@ static const AVOption options[]={ · 97 unmodified lines | ||
| 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[]={ · 57 unmodified lines | ||
| 167 | 171 | {"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"}, |
| 168 | 172 | {"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 | 173 | {"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"}, |
| 174 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 170 | 175 | {"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 | 176 | {"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}, |
| 177 | +#endif | |
| 172 | 178 | {"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 | 179 | {"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 | 180 | {"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[]={ · 19 unmodified lines | ||
| 194 | 200 | {"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, |
| 195 | 201 | {"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, |
| 196 | 202 | {"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}, | |
| 203 | +{"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}, | |
| 204 | +{"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 | 205 | {"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 | 206 | {"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E}, |
| 201 | 207 | {"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[]={ · 94 unmodified lines | ||
| 296 | 302 | {"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 | 303 | {"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E}, |
| 298 | 304 | {"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E}, |
| 305 | +#if FF_API_COLOR_TABLE_ID | |
| 299 | 306 | {"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, |
| 307 | +#endif | |
| 300 | 308 | {"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E}, |
| 301 | 309 | {"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"}, |
| 302 | 310 | {"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[]={ · 14 unmodified lines | ||
| 317 | 325 | {"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E}, |
| 318 | 326 | {"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, |
| 319 | 327 | {"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}, |
| 328 | +#if FF_API_INTER_THRESHOLD | |
| 320 | 329 | {"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, |
| 330 | +#endif | |
| 321 | 331 | {"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT}, 0, UINT_MAX, V|A|E|D, "flags2"}, |
| 322 | 332 | {"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}, | |
| 333 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 334 | +{"qns", "deprecated, use mpegvideo private options instead", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, | |
| 335 | +#endif | |
| 324 | 336 | {"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"}, |
| 325 | 337 | {"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"}, |
| 326 | 338 | {"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[]={ · 39 unmodified lines | ||
| 366 | 378 | {"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E}, |
| 367 | 379 | {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, |
| 368 | 380 | {"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"}, | |
| 381 | +#if FF_API_MPV_GLOBAL_OPTS | |
| 382 | +{"skiprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"}, | |
| 383 | +#endif | |
| 370 | 384 | {"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 | 385 | {"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E}, |
| 372 | 386 | {"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, · 164 unmodified lines | ||
| 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, · 240 unmodified lines | ||
| 411 | 415 | int data_size, uint16_t *out_ptr, |
| 412 | 416 | int linesize, int mbs_per_slice, |
| 413 | 417 | int blocks_per_mb, int plane_size_factor, |
| 414 | − const int16_t *qmat) | |
| 418 | + const int16_t *qmat, int is_chroma) | |
| 415 | 419 | { |
| 416 | 420 | GetBitContext gb; |
| 417 | 421 | DCTELEM *block_ptr; |
| @@ -431,18 +435,33 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td, · 13 unmodified lines | ||
| 431 | 435 | /* inverse quantization, inverse transform and output */ |
| 432 | 436 | block_ptr = td->blocks; |
| 433 | 437 | |
| 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); | |
| 438 | + if (!is_chroma) { | |
| 439 | + for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) { | |
| 440 | + ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat); | |
| 441 | + block_ptr += 64; | |
| 442 | + if (blocks_per_mb > 2) { | |
| 443 | + ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat); | |
| 444 | + block_ptr += 64; | |
| 445 | + } | |
| 446 | + ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat); | |
| 439 | 447 | block_ptr += 64; |
| 448 | + if (blocks_per_mb > 2) { | |
| 449 | + ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat); | |
| 450 | + block_ptr += 64; | |
| 451 | + } | |
| 440 | 452 | } |
| 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); | |
| 453 | + } else { | |
| 454 | + for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) { | |
| 455 | + ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat); | |
| 456 | + block_ptr += 64; | |
| 457 | + ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat); | |
| 445 | 458 | block_ptr += 64; |
| 459 | + if (blocks_per_mb > 2) { | |
| 460 | + ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat); | |
| 461 | + block_ptr += 64; | |
| 462 | + ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat); | |
| 463 | + block_ptr += 64; | |
| 464 | + } | |
| 446 | 465 | } |
| 447 | 466 | } |
| 448 | 467 | } |
| @@ -523,7 +542,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata) · 74 unmodified lines | ||
| 523 | 542 | (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize + |
| 524 | 543 | (mb_x_pos << 5)), y_linesize, |
| 525 | 544 | mbs_per_slice, 4, slice_width_factor + 2, |
| 526 | − td->qmat_luma_scaled); | |
| 545 | + td->qmat_luma_scaled, 0); | |
| 527 | 546 | |
| 528 | 547 | /* decode U chroma plane */ |
| 529 | 548 | 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) · 1 unmodified line | ||
| 531 | 550 | (mb_x_pos << ctx->mb_chroma_factor)), |
| 532 | 551 | u_linesize, mbs_per_slice, ctx->num_chroma_blocks, |
| 533 | 552 | slice_width_factor + ctx->chroma_factor - 1, |
| 534 | − td->qmat_chroma_scaled); | |
| 553 | + td->qmat_chroma_scaled, 1); | |
| 535 | 554 | |
| 536 | 555 | /* decode V chroma plane */ |
| 537 | 556 | 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) · 2 unmodified lines | ||
| 540 | 559 | (mb_x_pos << ctx->mb_chroma_factor)), |
| 541 | 560 | v_linesize, mbs_per_slice, ctx->num_chroma_blocks, |
| 542 | 561 | slice_width_factor + ctx->chroma_factor - 1, |
| 543 | − td->qmat_chroma_scaled); | |
| 562 | + td->qmat_chroma_scaled, 1); | |
| 544 | 563 | |
| 545 | 564 | return 0; |
| 546 | 565 | } |
| @@ -171,7 +171,7 @@ typedef struct ProresContext { · 170 unmodified lines | ||
| 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, · 11 unmodified lines | ||
| 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, · 157 unmodified lines | ||
| 383 | 396 | |
| 384 | 397 | get_slice_data(ctx, src, pic->linesize[i], xp, yp, |
| 385 | 398 | pwidth, avctx->height, ctx->blocks[0], |
| 386 | − mbs_per_slice, num_cblocks); | |
| 399 | + mbs_per_slice, num_cblocks, is_chroma); | |
| 387 | 400 | sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i], |
| 388 | 401 | mbs_per_slice, ctx->blocks[0], |
| 389 | 402 | num_cblocks, plane_factor, |
| @@ -539,7 +552,7 @@ static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic, · 149 unmodified lines | ||
| 539 | 552 | |
| 540 | 553 | get_slice_data(ctx, src, pic->linesize[i], xp, yp, |
| 541 | 554 | pwidth, avctx->height, ctx->blocks[i], |
| 542 | − mbs_per_slice, num_cblocks[i]); | |
| 555 | + mbs_per_slice, num_cblocks[i], is_chroma[i]); | |
| 543 | 556 | } |
| 544 | 557 | |
| 545 | 558 | for (q = min_quant; q < max_quant + 2; q++) { |
| @@ -676,9 +689,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 130 unmodified lines | ||
| 676 | 689 | bytestream_put_be16 (&buf, avctx->height); |
| 677 | 690 | bytestream_put_byte (&buf, ctx->chroma_factor << 6); // frame flags |
| 678 | 691 | 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 | |
| 692 | + bytestream_put_byte (&buf, avctx->color_primaries); | |
| 693 | + bytestream_put_byte (&buf, avctx->color_trc); | |
| 694 | + bytestream_put_byte (&buf, avctx->colorspace); | |
| 682 | 695 | bytestream_put_byte (&buf, 0x40); // source format and alpha information |
| 683 | 696 | bytestream_put_byte (&buf, 0); // reserved |
| 684 | 697 | bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present |
| @@ -424,7 +424,7 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx) · 423 unmodified lines | ||
| 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) · 182 unmodified lines | ||
| 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) · 11 unmodified lines | ||
| 200 | 202 | |
| 201 | 203 | /* Fill block with 16 colors */ |
| 202 | 204 | case 0x00: |
| 205 | + if (s->size - stream_ptr < 16) | |
| 206 | + return; | |
| 203 | 207 | block_ptr = row_ptr + pixel_ptr; |
| 204 | 208 | for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
| 205 | 209 | for (pixel_x = 0; pixel_x < 4; pixel_x++){ |
| @@ -56,6 +56,8 @@ void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number) · 55 unmodified lines | ||
| 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 = { · 4 unmodified lines | ||
| 66 | 68 | .close = ff_MPV_encode_end, |
| 67 | 69 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 68 | 70 | .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"), |
| 71 | + .priv_class = &rv10_class, | |
| 69 | 72 | }; |
| @@ -57,6 +57,8 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){ · 56 unmodified lines | ||
| 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 = { · 4 unmodified lines | ||
| 67 | 69 | .close = ff_MPV_encode_end, |
| 68 | 70 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 69 | 71 | .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"), |
| 72 | + .priv_class = &rv20_class, | |
| 70 | 73 | }; |
| @@ -60,5 +60,14 @@ · 59 unmodified lines | ||
| 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) · 483 unmodified lines | ||
| 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, · 56 unmodified lines | ||
| 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, · 76 unmodified lines | ||
| 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, · 14 unmodified lines | ||
| 97 | 101 | vrt_shift = 5; |
| 98 | 102 | s->sub_version = sub_version; |
| 99 | 103 | } else { |
| 100 | − if (!s->sub_version) | |
| 104 | + if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height) | |
| 101 | 105 | return 0; |
| 102 | 106 | |
| 103 | 107 | if (separated_coeff || !s->filter_header) { |
| @@ -26,7 +26,6 @@ · 25 unmodified lines | ||
| 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) · 166 unmodified lines | ||
| 199 | 198 | asf->hdr.flags = avio_rl32(pb); |
| 200 | 199 | asf->hdr.min_pktsize = avio_rl32(pb); |
| 201 | 200 | asf->hdr.max_pktsize = avio_rl32(pb); |
| 201 | + if (asf->hdr.min_pktsize >= (1U<<29)) | |
| 202 | + return AVERROR_INVALIDDATA; | |
| 202 | 203 | asf->hdr.max_bitrate = avio_rl32(pb); |
| 203 | 204 | s->packet_size = asf->hdr.max_pktsize; |
| 204 | 205 | |
| @@ -317,25 +318,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) · 112 unmodified lines | ||
| 317 | 318 | || asf_st->ds_packet_size % asf_st->ds_chunk_size) |
| 318 | 319 | asf_st->ds_span = 0; // disable descrambling |
| 319 | 320 | } |
| 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 | 321 | } else if (type == AVMEDIA_TYPE_VIDEO && |
| 340 | 322 | size - (avio_tell(pb) - pos1 + 24) >= 51) { |
| 341 | 323 | avio_rl32(pb); |
| @@ -612,7 +594,9 @@ static int asf_read_header(AVFormatContext *s) · 270 unmodified lines | ||
| 612 | 594 | if (gsize < 24) |
| 613 | 595 | return -1; |
| 614 | 596 | if (!ff_guidcmp(&g, &ff_asf_file_header)) { |
| 615 | − asf_read_file_properties(s, gsize); | |
| 597 | + int ret = asf_read_file_properties(s, gsize); | |
| 598 | + if (ret < 0) | |
| 599 | + return ret; | |
| 616 | 600 | } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) { |
| 617 | 601 | asf_read_stream_properties(s, gsize); |
| 618 | 602 | } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) { |
| @@ -541,6 +541,13 @@ typedef struct AVIndexEntry { · 540 unmodified lines | ||
| 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 { · 68 unmodified lines | ||
| 615 | 622 | */ |
| 616 | 623 | AVRational avg_frame_rate; |
| 617 | 624 | |
| 625 | + /** | |
| 626 | + * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet | |
| 627 | + * will contain the attached picture. | |
| 628 | + * | |
| 629 | + * decoding: set by libavformat, must not be modified by the caller. | |
| 630 | + * encoding: unused | |
| 631 | + */ | |
| 632 | + AVPacket attached_pic; | |
| 633 | + | |
| 618 | 634 | /***************************************************************** |
| 619 | 635 | * All fields below this line are not part of the public API. They |
| 620 | 636 | * may not be used outside of libavformat and can be changed and |
| @@ -107,6 +107,8 @@ static int dxa_read_header(AVFormatContext *s) · 106 unmodified lines | ||
| 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) · 337 unmodified lines | ||
| 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) · 143 unmodified lines | ||
| 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 @@ · 37 unmodified lines | ||
| 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] = { · 55 unmodified lines | ||
| 99 | 100 | { 0 }, |
| 100 | 101 | }; |
| 101 | 102 | |
| 103 | +const char *ff_id3v2_picture_types[21] = { | |
| 104 | + "Other", | |
| 105 | + "32x32 pixels 'file icon'", | |
| 106 | + "Other file icon", | |
| 107 | + "Cover (front)", | |
| 108 | + "Cover (back)", | |
| 109 | + "Leaflet page", | |
| 110 | + "Media (e.g. label side of CD)", | |
| 111 | + "Lead artist/lead performer/soloist", | |
| 112 | + "Artist/performer", | |
| 113 | + "Conductor", | |
| 114 | + "Band/Orchestra", | |
| 115 | + "Composer", | |
| 116 | + "Lyricist/text writer", | |
| 117 | + "Recording Location", | |
| 118 | + "During recording", | |
| 119 | + "During performance", | |
| 120 | + "Movie/video screen capture", | |
| 121 | + "A bright coloured fish", | |
| 122 | + "Illustration", | |
| 123 | + "Band/artist logotype", | |
| 124 | + "Publisher/Studio logotype", | |
| 125 | +}; | |
| 126 | + | |
| 127 | +const CodecMime ff_id3v2_mime_tags[] = { | |
| 128 | + {"image/gif" , CODEC_ID_GIF}, | |
| 129 | + {"image/jpeg", CODEC_ID_MJPEG}, | |
| 130 | + {"image/png" , CODEC_ID_PNG}, | |
| 131 | + {"image/tiff", CODEC_ID_TIFF}, | |
| 132 | + {"", CODEC_ID_NONE}, | |
| 133 | +}; | |
| 134 | + | |
| 102 | 135 | int ff_id3v2_match(const uint8_t *buf, const char * magic) |
| 103 | 136 | { |
| 104 | 137 | return buf[0] == magic[0] && |
| @@ -394,6 +427,84 @@ finish: · 289 unmodified lines | ||
| 394 | 427 | av_dict_set(m, "date", date, 0); |
| 395 | 428 | } |
| 396 | 429 | |
| 430 | +static void free_apic(void *obj) | |
| 431 | +{ | |
| 432 | + ID3v2ExtraMetaAPIC *apic = obj; | |
| 433 | + av_freep(&apic->data); | |
| 434 | + av_freep(&apic->description); | |
| 435 | + av_freep(&apic); | |
| 436 | +} | |
| 437 | + | |
| 438 | +static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta) | |
| 439 | +{ | |
| 440 | + int enc, pic_type; | |
| 441 | + char mimetype[64]; | |
| 442 | + const CodecMime *mime = ff_id3v2_mime_tags; | |
| 443 | + enum CodecID id = CODEC_ID_NONE; | |
| 444 | + ID3v2ExtraMetaAPIC *apic = NULL; | |
| 445 | + ID3v2ExtraMeta *new_extra = NULL; | |
| 446 | + int64_t end = avio_tell(pb) + taglen; | |
| 447 | + | |
| 448 | + if (taglen <= 4) | |
| 449 | + goto fail; | |
| 450 | + | |
| 451 | + new_extra = av_mallocz(sizeof(*new_extra)); | |
| 452 | + apic = av_mallocz(sizeof(*apic)); | |
| 453 | + if (!new_extra || !apic) | |
| 454 | + goto fail; | |
| 455 | + | |
| 456 | + enc = avio_r8(pb); | |
| 457 | + taglen--; | |
| 458 | + | |
| 459 | + /* mimetype */ | |
| 460 | + taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype)); | |
| 461 | + while (mime->id != CODEC_ID_NONE) { | |
| 462 | + if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { | |
| 463 | + id = mime->id; | |
| 464 | + break; | |
| 465 | + } | |
| 466 | + mime++; | |
| 467 | + } | |
| 468 | + if (id == CODEC_ID_NONE) { | |
| 469 | + av_log(s, AV_LOG_WARNING, "Unknown attached picture mimetype: %s, skipping.\n", mimetype); | |
| 470 | + goto fail; | |
| 471 | + } | |
| 472 | + apic->id = id; | |
| 473 | + | |
| 474 | + /* picture type */ | |
| 475 | + pic_type = avio_r8(pb); | |
| 476 | + taglen--; | |
| 477 | + if (pic_type < 0 || pic_type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types)) { | |
| 478 | + av_log(s, AV_LOG_WARNING, "Unknown attached picture type %d.\n", pic_type); | |
| 479 | + pic_type = 0; | |
| 480 | + } | |
| 481 | + apic->type = ff_id3v2_picture_types[pic_type]; | |
| 482 | + | |
| 483 | + /* description and picture data */ | |
| 484 | + if (decode_str(s, pb, enc, &apic->description, &taglen) < 0) { | |
| 485 | + av_log(s, AV_LOG_ERROR, "Error decoding attached picture description.\n"); | |
| 486 | + goto fail; | |
| 487 | + } | |
| 488 | + | |
| 489 | + apic->len = taglen; | |
| 490 | + apic->data = av_malloc(taglen); | |
| 491 | + if (!apic->data || avio_read(pb, apic->data, taglen) != taglen) | |
| 492 | + goto fail; | |
| 493 | + | |
| 494 | + new_extra->tag = "APIC"; | |
| 495 | + new_extra->data = apic; | |
| 496 | + new_extra->next = *extra_meta; | |
| 497 | + *extra_meta = new_extra; | |
| 498 | + | |
| 499 | + return; | |
| 500 | + | |
| 501 | +fail: | |
| 502 | + if (apic) | |
| 503 | + free_apic(apic); | |
| 504 | + av_freep(&new_extra); | |
| 505 | + avio_seek(pb, end, SEEK_SET); | |
| 506 | +} | |
| 507 | + | |
| 397 | 508 | typedef struct ID3v2EMFunc { |
| 398 | 509 | const char *tag3; |
| 399 | 510 | const char *tag4; |
| @@ -403,6 +514,7 @@ typedef struct ID3v2EMFunc { · 3 unmodified lines | ||
| 403 | 514 | |
| 404 | 515 | static const ID3v2EMFunc id3v2_extra_meta_funcs[] = { |
| 405 | 516 | { "GEO", "GEOB", read_geobtag, free_geobtag }, |
| 517 | + { "PIC", "APIC", read_apic, free_apic }, | |
| 406 | 518 | { NULL } |
| 407 | 519 | }; |
| 408 | 520 | |
| @@ -620,7 +732,7 @@ seek: · 211 unmodified lines | ||
| 620 | 732 | return; |
| 621 | 733 | } |
| 622 | 734 | |
| 623 | −void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta) | |
| 735 | +void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta) | |
| 624 | 736 | { |
| 625 | 737 | int len, ret; |
| 626 | 738 | uint8_t buf[ID3v2_HEADER_SIZE]; |
| @@ -651,11 +763,6 @@ void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **e · 24 unmodified lines | ||
| 651 | 763 | merge_date(&s->metadata); |
| 652 | 764 | } |
| 653 | 765 | |
| 654 | −void ff_id3v2_read(AVFormatContext *s, const char *magic) | |
| 655 | −{ | |
| 656 | − ff_id3v2_read_all(s, magic, NULL); | |
| 657 | −} | |
| 658 | − | |
| 659 | 766 | void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) |
| 660 | 767 | { |
| 661 | 768 | ID3v2ExtraMeta *current = *extra_meta, *next; |
| @@ -669,3 +776,37 @@ void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) · 7 unmodified lines | ||
| 669 | 776 | current = next; |
| 670 | 777 | } |
| 671 | 778 | } |
| 779 | + | |
| 780 | +int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta) | |
| 781 | +{ | |
| 782 | + ID3v2ExtraMeta *cur; | |
| 783 | + | |
| 784 | + for (cur = *extra_meta; cur; cur = cur->next) { | |
| 785 | + ID3v2ExtraMetaAPIC *apic; | |
| 786 | + AVStream *st; | |
| 787 | + | |
| 788 | + if (strcmp(cur->tag, "APIC")) | |
| 789 | + continue; | |
| 790 | + apic = cur->data; | |
| 791 | + | |
| 792 | + if (!(st = avformat_new_stream(s, NULL))) | |
| 793 | + return AVERROR(ENOMEM); | |
| 794 | + | |
| 795 | + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; | |
| 796 | + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 797 | + st->codec->codec_id = apic->id; | |
| 798 | + av_dict_set(&st->metadata, "title", apic->description, 0); | |
| 799 | + av_dict_set(&st->metadata, "comment", apic->type, 0); | |
| 800 | + | |
| 801 | + av_init_packet(&st->attached_pic); | |
| 802 | + st->attached_pic.data = apic->data; | |
| 803 | + st->attached_pic.size = apic->len; | |
| 804 | + st->attached_pic.destruct = av_destruct_packet; | |
| 805 | + st->attached_pic.stream_index = st->index; | |
| 806 | + | |
| 807 | + apic->data = NULL; | |
| 808 | + apic->len = 0; | |
| 809 | + } | |
| 810 | + | |
| 811 | + return 0; | |
| 812 | +} | |
| @@ -24,6 +24,7 @@ · 23 unmodified lines | ||
| 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 { · 15 unmodified lines | ||
| 45 | 46 | ID3v2_ENCODING_UTF8 = 3, |
| 46 | 47 | }; |
| 47 | 48 | |
| 49 | +typedef struct ID3v2EncContext { | |
| 50 | + int version; ///< ID3v2 minor version, either 3 or 4 | |
| 51 | + int64_t size_pos; ///< offset of the tag total size | |
| 52 | + int len; ///< size of the tag written so far | |
| 53 | +} ID3v2EncContext; | |
| 54 | + | |
| 48 | 55 | typedef struct ID3v2ExtraMeta { |
| 49 | 56 | const char *tag; |
| 50 | 57 | void *data; |
| @@ -59,6 +66,14 @@ typedef struct ID3v2ExtraMetaGEOB { · 8 unmodified lines | ||
| 59 | 66 | uint8_t *data; |
| 60 | 67 | } ID3v2ExtraMetaGEOB; |
| 61 | 68 | |
| 69 | +typedef struct ID3v2ExtraMetaAPIC { | |
| 70 | + uint8_t *data; | |
| 71 | + int len; | |
| 72 | + const char *type; | |
| 73 | + uint8_t *description; | |
| 74 | + enum CodecID id; | |
| 75 | +} ID3v2ExtraMetaAPIC; | |
| 76 | + | |
| 62 | 77 | /** |
| 63 | 78 | * Detect ID3v2 Header. |
| 64 | 79 | * @param buf must be ID3v2_HEADER_SIZE byte long |
| @@ -75,24 +90,40 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic); · 10 unmodified lines | ||
| 75 | 90 | int ff_id3v2_tag_len(const uint8_t *buf); |
| 76 | 91 | |
| 77 | 92 | /** |
| 78 | − * Read an ID3v2 tag (text tags only) | |
| 93 | + * Read an ID3v2 tag, including supported extra metadata | |
| 94 | + * @param extra_meta If not NULL, extra metadata is parsed into a list of | |
| 95 | + * ID3v2ExtraMeta structs and *extra_meta points to the head of the list | |
| 79 | 96 | */ |
| 80 | −void ff_id3v2_read(AVFormatContext *s, const char *magic); | |
| 97 | +void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta); | |
| 81 | 98 | |
| 82 | 99 | /** |
| 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 | |
| 100 | + * Initialize an ID3v2 tag. | |
| 101 | + */ | |
| 102 | +void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, | |
| 103 | + const char *magic); | |
| 104 | + | |
| 105 | +/** | |
| 106 | + * Convert and write all global metadata from s into an ID3v2 tag. | |
| 107 | + */ | |
| 108 | +int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3); | |
| 109 | + | |
| 110 | +/** | |
| 111 | + * Write an attached picture from pkt into an ID3v2 tag. | |
| 112 | + */ | |
| 113 | +int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt); | |
| 114 | + | |
| 115 | +/** | |
| 116 | + * Finalize an opened ID3v2 tag. | |
| 86 | 117 | */ |
| 87 | −void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta); | |
| 118 | +void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb); | |
| 88 | 119 | |
| 89 | 120 | /** |
| 90 | − * Write an ID3v2 tag. | |
| 121 | + * Write an ID3v2 tag containing all global metadata from s. | |
| 91 | 122 | * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4 |
| 92 | 123 | * @param magic magic bytes to identify the header |
| 93 | 124 | * If in doubt, use ID3v2_DEFAULT_MAGIC. |
| 94 | 125 | */ |
| 95 | −int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *magic); | |
| 126 | +int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic); | |
| 96 | 127 | |
| 97 | 128 | /** |
| 98 | 129 | * 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 · 1 unmodified line | ||
| 100 | 131 | */ |
| 101 | 132 | void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta); |
| 102 | 133 | |
| 134 | +/** | |
| 135 | + * Create a stream for each APIC (attached picture) extracted from the | |
| 136 | + * ID3v2 header. | |
| 137 | + */ | |
| 138 | +int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta); | |
| 139 | + | |
| 103 | 140 | extern const AVMetadataConv ff_id3v2_34_metadata_conv[]; |
| 104 | 141 | extern const AVMetadataConv ff_id3v2_4_metadata_conv[]; |
| 105 | 142 | |
| @@ -120,4 +157,8 @@ extern const char ff_id3v2_4_tags[][4]; · 14 unmodified lines | ||
| 120 | 157 | */ |
| 121 | 158 | extern const char ff_id3v2_3_tags[][4]; |
| 122 | 159 | |
| 160 | +extern const CodecMime ff_id3v2_mime_tags[]; | |
| 161 | + | |
| 162 | +extern const char *ff_id3v2_picture_types[21]; | |
| 163 | + | |
| 123 | 164 | #endif /* AVFORMAT_ID3V2_H */ |
| @@ -19,6 +19,8 @@ · 18 unmodified lines | ||
| 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 @@ · 1 unmodified line | ||
| 26 | 28 | #include "avio.h" |
| 27 | 29 | #include "id3v2.h" |
| 28 | 30 | |
| 29 | −static void id3v2_put_size(AVFormatContext *s, int size) | |
| 31 | +static void id3v2_put_size(AVIOContext *pb, int size) | |
| 30 | 32 | { |
| 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); | |
| 33 | + avio_w8(pb, size >> 21 & 0x7f); | |
| 34 | + avio_w8(pb, size >> 14 & 0x7f); | |
| 35 | + avio_w8(pb, size >> 7 & 0x7f); | |
| 36 | + avio_w8(pb, size & 0x7f); | |
| 35 | 37 | } |
| 36 | 38 | |
| 37 | 39 | static int string_is_ascii(const uint8_t *str) |
| @@ -40,17 +42,30 @@ static int string_is_ascii(const uint8_t *str) · 2 unmodified lines | ||
| 40 | 42 | return !*str; |
| 41 | 43 | } |
| 42 | 44 | |
| 45 | +static void id3v2_encode_string(AVIOContext *pb, const uint8_t *str, | |
| 46 | + enum ID3v2Encoding enc) | |
| 47 | +{ | |
| 48 | + int (*put)(AVIOContext*, const char*); | |
| 49 | + | |
| 50 | + if (enc == ID3v2_ENCODING_UTF16BOM) { | |
| 51 | + avio_wl16(pb, 0xFEFF); /* BOM */ | |
| 52 | + put = avio_put_str16le; | |
| 53 | + } else | |
| 54 | + put = avio_put_str; | |
| 55 | + | |
| 56 | + put(pb, str); | |
| 57 | +} | |
| 58 | + | |
| 43 | 59 | /** |
| 44 | 60 | * Write a text frame with one (normal frames) or two (TXXX frames) strings |
| 45 | 61 | * according to encoding (only UTF-8 or UTF-16+BOM supported). |
| 46 | 62 | * @return number of bytes written or a negative error code. |
| 47 | 63 | */ |
| 48 | −static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2, | |
| 64 | +static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *str1, const char *str2, | |
| 49 | 65 | uint32_t tag, enum ID3v2Encoding enc) |
| 50 | 66 | { |
| 51 | 67 | int len; |
| 52 | 68 | uint8_t *pb; |
| 53 | − int (*put)(AVIOContext*, const char*); | |
| 54 | 69 | AVIOContext *dyn_buf; |
| 55 | 70 | if (avio_open_dyn_buf(&dyn_buf) < 0) |
| 56 | 71 | return AVERROR(ENOMEM); |
| @@ -62,28 +77,26 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2 · 5 unmodified lines | ||
| 62 | 77 | enc = ID3v2_ENCODING_ISO8859; |
| 63 | 78 | |
| 64 | 79 | 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); | |
| 80 | + id3v2_encode_string(dyn_buf, str1, enc); | |
| 72 | 81 | if (str2) |
| 73 | − put(dyn_buf, str2); | |
| 82 | + id3v2_encode_string(dyn_buf, str2, enc); | |
| 74 | 83 | len = avio_close_dyn_buf(dyn_buf, &pb); |
| 75 | 84 | |
| 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); | |
| 85 | + avio_wb32(avioc, tag); | |
| 86 | + /* ID3v2.3 frame size is not synchsafe */ | |
| 87 | + if (id3->version == 3) | |
| 88 | + avio_wb32(avioc, len); | |
| 89 | + else | |
| 90 | + id3v2_put_size(avioc, len); | |
| 91 | + avio_wb16(avioc, 0); | |
| 92 | + avio_write(avioc, pb, len); | |
| 80 | 93 | |
| 81 | 94 | av_freep(&pb); |
| 82 | 95 | return len + ID3v2_HEADER_SIZE; |
| 83 | 96 | } |
| 84 | 97 | |
| 85 | −static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const char table[][4], | |
| 86 | − enum ID3v2Encoding enc) | |
| 98 | +static int id3v2_check_write_tag(ID3v2EncContext *id3, AVIOContext *pb, AVDictionaryEntry *t, | |
| 99 | + const char table[][4], enum ID3v2Encoding enc) | |
| 87 | 100 | { |
| 88 | 101 | uint32_t tag; |
| 89 | 102 | int i; |
| @@ -93,7 +106,7 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const · 3 unmodified lines | ||
| 93 | 106 | tag = AV_RB32(t->key); |
| 94 | 107 | for (i = 0; *table[i]; i++) |
| 95 | 108 | if (tag == AV_RB32(table[i])) |
| 96 | − return id3v2_put_ttag(s, t->value, NULL, tag, enc); | |
| 109 | + return id3v2_put_ttag(id3, pb, t->value, NULL, tag, enc); | |
| 97 | 110 | return -1; |
| 98 | 111 | } |
| 99 | 112 | |
| @@ -135,52 +148,137 @@ static void id3v2_3_metadata_split_date(AVDictionary **pm) · 35 unmodified lines | ||
| 135 | 148 | *pm = dst; |
| 136 | 149 | } |
| 137 | 150 | |
| 138 | −int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, | |
| 139 | − const char *magic) | |
| 151 | +void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, | |
| 152 | + const char *magic) | |
| 140 | 153 | { |
| 141 | − int64_t size_pos, cur_pos; | |
| 142 | − AVDictionaryEntry *t = NULL; | |
| 154 | + id3->version = id3v2_version; | |
| 143 | 155 | |
| 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 */ | |
| 156 | + avio_wb32(pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version)); | |
| 157 | + avio_w8(pb, 0); | |
| 158 | + avio_w8(pb, 0); /* flags */ | |
| 151 | 159 | |
| 152 | 160 | /* reserve space for size */ |
| 153 | − size_pos = avio_tell(s->pb); | |
| 154 | − avio_wb32(s->pb, 0); | |
| 161 | + id3->size_pos = avio_tell(pb); | |
| 162 | + avio_wb32(pb, 0); | |
| 163 | +} | |
| 164 | + | |
| 165 | +int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3) | |
| 166 | +{ | |
| 167 | + AVDictionaryEntry *t = NULL; | |
| 168 | + int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM : | |
| 169 | + ID3v2_ENCODING_UTF8; | |
| 155 | 170 | |
| 156 | 171 | ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL); |
| 157 | − if (id3v2_version == 3) | |
| 172 | + if (id3->version == 3) | |
| 158 | 173 | id3v2_3_metadata_split_date(&s->metadata); |
| 159 | − else if (id3v2_version == 4) | |
| 174 | + else if (id3->version == 4) | |
| 160 | 175 | ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL); |
| 161 | 176 | |
| 162 | 177 | while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { |
| 163 | 178 | int ret; |
| 164 | 179 | |
| 165 | − if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) { | |
| 166 | − totlen += ret; | |
| 180 | + if ((ret = id3v2_check_write_tag(id3, s->pb, t, ff_id3v2_tags, enc)) > 0) { | |
| 181 | + id3->len += ret; | |
| 167 | 182 | continue; |
| 168 | 183 | } |
| 169 | − if ((ret = id3v2_check_write_tag(s, t, id3v2_version == 3 ? | |
| 184 | + if ((ret = id3v2_check_write_tag(id3, s->pb, t, id3->version == 3 ? | |
| 170 | 185 | ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) { |
| 171 | − totlen += ret; | |
| 186 | + id3->len += ret; | |
| 172 | 187 | continue; |
| 173 | 188 | } |
| 174 | 189 | |
| 175 | 190 | /* unknown tag, write as TXXX frame */ |
| 176 | − if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0) | |
| 191 | + if ((ret = id3v2_put_ttag(id3, s->pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0) | |
| 177 | 192 | return ret; |
| 178 | − totlen += ret; | |
| 193 | + id3->len += ret; | |
| 179 | 194 | } |
| 180 | 195 | |
| 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); | |
| 196 | + return 0; | |
| 197 | +} | |
| 198 | + | |
| 199 | +int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt) | |
| 200 | +{ | |
| 201 | + AVStream *st = s->streams[pkt->stream_index]; | |
| 202 | + AVDictionaryEntry *e; | |
| 203 | + | |
| 204 | + AVIOContext *dyn_buf; | |
| 205 | + uint8_t *buf; | |
| 206 | + const CodecMime *mime = ff_id3v2_mime_tags; | |
| 207 | + const char *mimetype = NULL, *desc = ""; | |
| 208 | + int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM : | |
| 209 | + ID3v2_ENCODING_UTF8; | |
| 210 | + int i, len, type = 0; | |
| 211 | + | |
| 212 | + /* get the mimetype*/ | |
| 213 | + while (mime->id != CODEC_ID_NONE) { | |
| 214 | + if (mime->id == st->codec->codec_id) { | |
| 215 | + mimetype = mime->str; | |
| 216 | + break; | |
| 217 | + } | |
| 218 | + mime++; | |
| 219 | + } | |
| 220 | + if (!mimetype) { | |
| 221 | + av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot " | |
| 222 | + "write an attached picture.\n", st->index); | |
| 223 | + return AVERROR(EINVAL); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /* get the picture type */ | |
| 227 | + e = av_dict_get(st->metadata, "comment", NULL, 0); | |
| 228 | + for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) { | |
| 229 | + if (strstr(ff_id3v2_picture_types[i], e->value) == ff_id3v2_picture_types[i]) { | |
| 230 | + type = i; | |
| 231 | + break; | |
| 232 | + } | |
| 233 | + } | |
| 234 | + | |
| 235 | + /* get the description */ | |
| 236 | + if ((e = av_dict_get(st->metadata, "title", NULL, 0))) | |
| 237 | + desc = e->value; | |
| 238 | + | |
| 239 | + /* start writing */ | |
| 240 | + if (avio_open_dyn_buf(&dyn_buf) < 0) | |
| 241 | + return AVERROR(ENOMEM); | |
| 242 | + | |
| 243 | + avio_w8(dyn_buf, enc); | |
| 244 | + avio_put_str(dyn_buf, mimetype); | |
| 245 | + avio_w8(dyn_buf, type); | |
| 246 | + id3v2_encode_string(dyn_buf, desc, enc); | |
| 247 | + avio_write(dyn_buf, pkt->data, pkt->size); | |
| 248 | + len = avio_close_dyn_buf(dyn_buf, &buf); | |
| 249 | + | |
| 250 | + avio_wb32(s->pb, MKBETAG('A', 'P', 'I', 'C')); | |
| 251 | + if (id3->version == 3) | |
| 252 | + avio_wb32(s->pb, len); | |
| 253 | + else | |
| 254 | + id3v2_put_size(s->pb, len); | |
| 255 | + avio_wb16(s->pb, 0); | |
| 256 | + avio_write(s->pb, buf, len); | |
| 257 | + av_freep(&buf); | |
| 258 | + | |
| 259 | + id3->len += len + ID3v2_HEADER_SIZE; | |
| 260 | + | |
| 261 | + return 0; | |
| 262 | +} | |
| 263 | + | |
| 264 | +void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb) | |
| 265 | +{ | |
| 266 | + int64_t cur_pos = avio_tell(pb); | |
| 267 | + avio_seek(pb, id3->size_pos, SEEK_SET); | |
| 268 | + id3v2_put_size(pb, id3->len); | |
| 269 | + avio_seek(pb, cur_pos, SEEK_SET); | |
| 270 | +} | |
| 271 | + | |
| 272 | +int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, | |
| 273 | + const char *magic) | |
| 274 | +{ | |
| 275 | + ID3v2EncContext id3 = { 0 }; | |
| 276 | + int ret; | |
| 277 | + | |
| 278 | + ff_id3v2_start(&id3, s->pb, id3v2_version, magic); | |
| 279 | + if ((ret = ff_id3v2_write_metadata(s, &id3)) < 0) | |
| 280 | + return ret; | |
| 281 | + ff_id3v2_finish(&id3, s->pb); | |
| 282 | + | |
| 185 | 283 | return 0; |
| 186 | 284 | } |
| @@ -37,6 +37,11 @@ typedef struct AVCodecTag { · 36 unmodified lines | ||
| 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 @@ · 23 unmodified lines | ||
| 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{ · 220 unmodified lines | ||
| 250 | 251 | enum CodecID id; |
| 251 | 252 | }CodecTags; |
| 252 | 253 | |
| 253 | −typedef struct CodecMime{ | |
| 254 | − char str[32]; | |
| 255 | − enum CodecID id; | |
| 256 | −}CodecMime; | |
| 257 | − | |
| 258 | 254 | /* max. depth in the EBML tree structure */ |
| 259 | 255 | #define EBML_MAX_DEPTH 16 |
| 260 | 256 | |
| @@ -1223,6 +1223,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) · 1222 unmodified lines | ||
| 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) · 21 unmodified lines | ||
| 1250 | 1251 | st->codec->codec_tag=MKTAG('I', '4', '2', '0'); |
| 1251 | 1252 | |
| 1252 | 1253 | st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */ |
| 1253 | − st->codec->color_table_id = avio_rb16(pb); /* colortable id */ | |
| 1254 | + color_table_id = avio_rb16(pb); /* colortable id */ | |
| 1254 | 1255 | av_dlog(c->fc, "depth %d, ctab id %d\n", |
| 1255 | − st->codec->bits_per_coded_sample, st->codec->color_table_id); | |
| 1256 | + st->codec->bits_per_coded_sample, color_table_id); | |
| 1256 | 1257 | /* figure out the palette situation */ |
| 1257 | 1258 | color_depth = st->codec->bits_per_coded_sample & 0x1F; |
| 1258 | 1259 | 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) · 23 unmodified lines | ||
| 1282 | 1283 | if (color_index < 0) |
| 1283 | 1284 | color_index = 0; |
| 1284 | 1285 | } |
| 1285 | − } else if (st->codec->color_table_id) { | |
| 1286 | + } else if (color_table_id) { | |
| 1286 | 1287 | const uint8_t *color_table; |
| 1287 | 1288 | /* if flag bit 3 is set, use the default palette */ |
| 1288 | 1289 | color_count = 1 << color_depth; |
| @@ -84,6 +84,7 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) · 83 unmodified lines | ||
| 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 { · 3 unmodified lines | ||
| 93 | 94 | uint32_t seen; |
| 94 | 95 | uint32_t pos; |
| 95 | 96 | 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 | 97 | |
| 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 | −}; | |
| 98 | + /* index of the audio stream */ | |
| 99 | + int audio_stream_idx; | |
| 100 | + /* number of attached pictures we still need to write */ | |
| 101 | + int pics_to_write; | |
| 143 | 102 | |
| 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 | −}; | |
| 103 | + /* audio packets are queued here until we get all the attached pictures */ | |
| 104 | + AVPacketList *queue, *queue_end; | |
| 105 | +} MP3Context; | |
| 150 | 106 | |
| 151 | 107 | static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; |
| 152 | 108 | |
| @@ -155,8 +111,8 @@ static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; · 2 unmodified lines | ||
| 155 | 111 | */ |
| 156 | 112 | static int mp3_write_xing(AVFormatContext *s) |
| 157 | 113 | { |
| 158 | − AVCodecContext *codec = s->streams[0]->codec; | |
| 159 | 114 | MP3Context *mp3 = s->priv_data; |
| 115 | + AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec; | |
| 160 | 116 | int bitrate_idx; |
| 161 | 117 | int best_bitrate_idx = -1; |
| 162 | 118 | int best_bitrate_error= INT_MAX; |
| @@ -166,6 +122,9 @@ static int mp3_write_xing(AVFormatContext *s) · 3 unmodified lines | ||
| 166 | 122 | int srate_idx, i, channels; |
| 167 | 123 | int needed; |
| 168 | 124 | |
| 125 | + if (!s->pb->seekable) | |
| 126 | + return 0; | |
| 127 | + | |
| 169 | 128 | for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++) |
| 170 | 129 | if (avpriv_mpa_freq_tab[i] == codec->sample_rate) { |
| 171 | 130 | srate_idx = i; |
| @@ -295,26 +254,7 @@ static void mp3_fix_xing(AVFormatContext *s) · 123 unmodified lines | ||
| 295 | 254 | avio_seek(s->pb, 0, SEEK_END); |
| 296 | 255 | } |
| 297 | 256 | |
| 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) | |
| 257 | +static int mp3_write_packet_internal(AVFormatContext *s, AVPacket *pkt) | |
| 318 | 258 | { |
| 319 | 259 | if (! pkt || ! pkt->data || pkt->size < 4) |
| 320 | 260 | return ff_raw_write_packet(s, pkt); |
| @@ -350,6 +290,175 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) · 29 unmodified lines | ||
| 350 | 290 | } |
| 351 | 291 | } |
| 352 | 292 | |
| 293 | +static int mp3_queue_flush(AVFormatContext *s) | |
| 294 | +{ | |
| 295 | + MP3Context *mp3 = s->priv_data; | |
| 296 | + AVPacketList *pktl; | |
| 297 | + int ret = 0, write = 1; | |
| 298 | + | |
| 299 | + ff_id3v2_finish(&mp3->id3, s->pb); | |
| 300 | + mp3_write_xing(s); | |
| 301 | + | |
| 302 | + while ((pktl = mp3->queue)) { | |
| 303 | + if (write && (ret = mp3_write_packet_internal(s, &pktl->pkt)) < 0) | |
| 304 | + write = 0; | |
| 305 | + av_free_packet(&pktl->pkt); | |
| 306 | + mp3->queue = pktl->next; | |
| 307 | + av_freep(&pktl); | |
| 308 | + } | |
| 309 | + mp3->queue_end = NULL; | |
| 310 | + return ret; | |
| 311 | +} | |
| 312 | + | |
| 313 | +static int mp2_write_trailer(struct AVFormatContext *s) | |
| 314 | +{ | |
| 315 | + uint8_t buf[ID3v1_TAG_SIZE]; | |
| 316 | + MP3Context *mp3 = s->priv_data; | |
| 317 | + | |
| 318 | + if (mp3 && mp3->pics_to_write) { | |
| 319 | + av_log(s, AV_LOG_WARNING, "No packets were sent for some of the " | |
| 320 | + "attached pictures.\n"); | |
| 321 | + mp3_queue_flush(s); | |
| 322 | + } | |
| 323 | + | |
| 324 | + /* write the id3v1 tag */ | |
| 325 | + if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) { | |
| 326 | + avio_write(s->pb, buf, ID3v1_TAG_SIZE); | |
| 327 | + } | |
| 328 | + | |
| 329 | + /* write number of frames */ | |
| 330 | + if (mp3 && mp3->frames_offset) { | |
| 331 | + avio_seek(s->pb, mp3->frames_offset, SEEK_SET); | |
| 332 | + avio_wb32(s->pb, s->streams[mp3->audio_stream_idx]->nb_frames); | |
| 333 | + avio_seek(s->pb, 0, SEEK_END); | |
| 334 | + } | |
| 335 | + | |
| 336 | + avio_flush(s->pb); | |
| 337 | + | |
| 338 | + return 0; | |
| 339 | +} | |
| 340 | + | |
| 341 | +#if CONFIG_MP2_MUXER | |
| 342 | +AVOutputFormat ff_mp2_muxer = { | |
| 343 | + .name = "mp2", | |
| 344 | + .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"), | |
| 345 | + .mime_type = "audio/x-mpeg", | |
| 346 | + .extensions = "mp2,m2a", | |
| 347 | + .audio_codec = CODEC_ID_MP2, | |
| 348 | + .video_codec = CODEC_ID_NONE, | |
| 349 | + .write_packet = ff_raw_write_packet, | |
| 350 | + .write_trailer = mp2_write_trailer, | |
| 351 | + .flags = AVFMT_NOTIMESTAMPS, | |
| 352 | +}; | |
| 353 | +#endif | |
| 354 | + | |
| 355 | +#if CONFIG_MP3_MUXER | |
| 356 | + | |
| 357 | +static const AVOption options[] = { | |
| 358 | + { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.", | |
| 359 | + offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM}, | |
| 360 | + { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.", | |
| 361 | + offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, | |
| 362 | + { NULL }, | |
| 363 | +}; | |
| 364 | + | |
| 365 | +static const AVClass mp3_muxer_class = { | |
| 366 | + .class_name = "MP3 muxer", | |
| 367 | + .item_name = av_default_item_name, | |
| 368 | + .option = options, | |
| 369 | + .version = LIBAVUTIL_VERSION_INT, | |
| 370 | +}; | |
| 371 | + | |
| 372 | +static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) | |
| 373 | +{ | |
| 374 | + MP3Context *mp3 = s->priv_data; | |
| 375 | + | |
| 376 | + if (pkt->stream_index == mp3->audio_stream_idx) { | |
| 377 | + if (mp3->pics_to_write) { | |
| 378 | + /* buffer audio packets until we get all the pictures */ | |
| 379 | + AVPacketList *pktl = av_mallocz(sizeof(*pktl)); | |
| 380 | + if (!pktl) | |
| 381 | + return AVERROR(ENOMEM); | |
| 382 | + | |
| 383 | + pktl->pkt = *pkt; | |
| 384 | + pkt->destruct = NULL; | |
| 385 | + | |
| 386 | + if (mp3->queue_end) | |
| 387 | + mp3->queue_end->next = pktl; | |
| 388 | + else | |
| 389 | + mp3->queue = pktl; | |
| 390 | + mp3->queue_end = pktl; | |
| 391 | + } else | |
| 392 | + return mp3_write_packet_internal(s, pkt); | |
| 393 | + } else { | |
| 394 | + int ret; | |
| 395 | + | |
| 396 | + /* warn only once for each stream */ | |
| 397 | + if (s->streams[pkt->stream_index]->nb_frames == 1) { | |
| 398 | + av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d," | |
| 399 | + " ignoring.\n", pkt->stream_index); | |
| 400 | + } | |
| 401 | + if (!mp3->pics_to_write || s->streams[pkt->stream_index]->nb_frames >= 1) | |
| 402 | + return 0; | |
| 403 | + | |
| 404 | + if ((ret = ff_id3v2_write_apic(s, &mp3->id3, pkt)) < 0) | |
| 405 | + return ret; | |
| 406 | + mp3->pics_to_write--; | |
| 407 | + | |
| 408 | + /* flush the buffered audio packets */ | |
| 409 | + if (!mp3->pics_to_write && | |
| 410 | + (ret = mp3_queue_flush(s)) < 0) | |
| 411 | + return ret; | |
| 412 | + } | |
| 413 | + | |
| 414 | + return 0; | |
| 415 | +} | |
| 416 | + | |
| 417 | +/** | |
| 418 | + * Write an ID3v2 header at beginning of stream | |
| 419 | + */ | |
| 420 | + | |
| 421 | +static int mp3_write_header(struct AVFormatContext *s) | |
| 422 | +{ | |
| 423 | + MP3Context *mp3 = s->priv_data; | |
| 424 | + int ret, i; | |
| 425 | + | |
| 426 | + /* check the streams -- we want exactly one audio and arbitrary number of | |
| 427 | + * video (attached pictures) */ | |
| 428 | + mp3->audio_stream_idx = -1; | |
| 429 | + for (i = 0; i < s->nb_streams; i++) { | |
| 430 | + AVStream *st = s->streams[i]; | |
| 431 | + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { | |
| 432 | + if (mp3->audio_stream_idx >= 0 || st->codec->codec_id != CODEC_ID_MP3) { | |
| 433 | + av_log(s, AV_LOG_ERROR, "Invalid audio stream. Exactly one MP3 " | |
| 434 | + "audio stream is required.\n"); | |
| 435 | + return AVERROR(EINVAL); | |
| 436 | + } | |
| 437 | + mp3->audio_stream_idx = i; | |
| 438 | + } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) { | |
| 439 | + av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in MP3.\n"); | |
| 440 | + return AVERROR(EINVAL); | |
| 441 | + } | |
| 442 | + } | |
| 443 | + if (mp3->audio_stream_idx < 0) { | |
| 444 | + av_log(s, AV_LOG_ERROR, "No audio stream present.\n"); | |
| 445 | + return AVERROR(EINVAL); | |
| 446 | + } | |
| 447 | + mp3->pics_to_write = s->nb_streams - 1; | |
| 448 | + | |
| 449 | + ff_id3v2_start(&mp3->id3, s->pb, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC); | |
| 450 | + ret = ff_id3v2_write_metadata(s, &mp3->id3); | |
| 451 | + if (ret < 0) | |
| 452 | + return ret; | |
| 453 | + | |
| 454 | + if (!mp3->pics_to_write) { | |
| 455 | + ff_id3v2_finish(&mp3->id3, s->pb); | |
| 456 | + mp3_write_xing(s); | |
| 457 | + } | |
| 458 | + | |
| 459 | + return 0; | |
| 460 | +} | |
| 461 | + | |
| 353 | 462 | static int mp3_write_trailer(AVFormatContext *s) |
| 354 | 463 | { |
| 355 | 464 | MP3Context *mp3 = s->priv_data; |
| @@ -371,7 +480,7 @@ AVOutputFormat ff_mp3_muxer = { · 15 unmodified lines | ||
| 371 | 480 | .extensions = "mp3", |
| 372 | 481 | .priv_data_size = sizeof(MP3Context), |
| 373 | 482 | .audio_codec = CODEC_ID_MP3, |
| 374 | − .video_codec = CODEC_ID_NONE, | |
| 483 | + .video_codec = CODEC_ID_PNG, | |
| 375 | 484 | .write_header = mp3_write_header, |
| 376 | 485 | .write_packet = mp3_write_packet, |
| 377 | 486 | .write_trailer = mp3_write_trailer, |
| @@ -270,7 +270,7 @@ static int oma_read_header(AVFormatContext *s) · 269 unmodified lines | ||
| 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) · 48 unmodified lines | ||
| 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 = { · 298 unmodified lines | ||
| 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) · 111 unmodified lines | ||
| 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) · 112 unmodified lines | ||
| 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) · 66 unmodified lines | ||
| 186 | 185 | vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
| 187 | 186 | vst->codec->codec_id = CODEC_ID_MJPEG; |
| 188 | 187 | avpriv_set_pts_info(vst, 64, 256, swf->frame_rate); |
| 189 | − vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; | |
| 190 | 188 | st = vst; |
| 191 | 189 | } |
| 192 | 190 | avio_rl16(pb); /* BITMAP_ID */ |
| @@ -545,11 +545,29 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o · 544 unmodified lines | ||
| 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 · 36 unmodified lines | ||
| 592 | 610 | |
| 593 | 611 | /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ |
| 594 | 612 | if (s->pb) |
| 595 | − ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC); | |
| 613 | + ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); | |
| 596 | 614 | |
| 597 | 615 | if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header) |
| 598 | 616 | if ((ret = s->iformat->read_header(s)) < 0) |
| 599 | 617 | goto fail; |
| 600 | 618 | |
| 619 | + if (id3v2_extra_meta && | |
| 620 | + (ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0) | |
| 621 | + goto fail; | |
| 622 | + ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
| 623 | + | |
| 624 | + /* queue attached pictures */ | |
| 625 | + for (i = 0; i < s->nb_streams; i++) | |
| 626 | + if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { | |
| 627 | + AVPacket copy = s->streams[i]->attached_pic; | |
| 628 | + copy.destruct = NULL; | |
| 629 | + add_to_pktbuf(&s->raw_packet_buffer, ©, &s->raw_packet_buffer_end); | |
| 630 | + } | |
| 631 | + | |
| 601 | 632 | if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset) |
| 602 | 633 | s->data_offset = avio_tell(s->pb); |
| 603 | 634 | |
| @@ -611,6 +642,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma · 7 unmodified lines | ||
| 611 | 642 | return 0; |
| 612 | 643 | |
| 613 | 644 | fail: |
| 645 | + ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
| 614 | 646 | av_dict_free(&tmp); |
| 615 | 647 | if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) |
| 616 | 648 | avio_close(s->pb); |
| @@ -621,23 +653,6 @@ fail: · 4 unmodified lines | ||
| 621 | 653 | |
| 622 | 654 | /*******************************************************/ |
| 623 | 655 | |
| 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 | 656 | int av_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 642 | 657 | { |
| 643 | 658 | int ret, i; |
| @@ -2722,6 +2737,8 @@ void avformat_free_context(AVFormatContext *s) · 2078 unmodified lines | ||
| 2722 | 2737 | av_parser_close(st->parser); |
| 2723 | 2738 | av_free_packet(&st->cur_pkt); |
| 2724 | 2739 | } |
| 2740 | + if (st->attached_pic.data) | |
| 2741 | + av_free_packet(&st->attached_pic); | |
| 2725 | 2742 | av_dict_free(&st->metadata); |
| 2726 | 2743 | av_freep(&st->index_entries); |
| 2727 | 2744 | av_freep(&st->codec->extradata); |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | ||
| 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) · 219 unmodified lines | ||
| 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) · 1045 unmodified lines | ||
| 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 · 37 unmodified lines | ||
| 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 · 92 unmodified lines | ||
| 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 · 9 unmodified lines | ||
| 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 · 32 unmodified lines | ||
| 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 · 142 unmodified lines | ||
| 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 |
| @@ -0,0 +1,11 @@ | ||
| 1 | +#tb 0: 12/601 | |
| 2 | +0, 0, 0, 1, 63180, 0xcda82c16 | |
| 3 | +0, 1, 1, 1, 63180, 0xa6097bf9 | |
| 4 | +0, 2, 2, 1, 63180, 0x4c2fb091 | |
| 5 | +0, 3, 3, 1, 63180, 0xc597db00 | |
| 6 | +0, 4, 4, 1, 63180, 0xfa581ccd | |
| 7 | +0, 5, 5, 1, 63180, 0x3e51498f | |
| 8 | +0, 6, 6, 1, 63180, 0xe3495396 | |
| 9 | +0, 7, 7, 1, 63180, 0x425f5f02 | |
| 10 | +0, 8, 8, 1, 63180, 0x6077465f | |
| 11 | +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 |