* qatar/master: Remove ffmpeg. aacenc: Simplify windowing aacenc: Move saved overlap samples to the beginning of the same buffer as incoming samples. aacenc: Deinterleave input samples before processing. aacenc: Store channel count in AACEncContext. aacenc: Move Q^3/4 calculation to it's own table aacenc: Request normalized float samples instead of converting s16 samples to float. aacpsy: Replace an if with FFMAX in LAME windowing. aacenc: cosmetics, replace 'rd' with 'bits' in codebook_trellis_rate to make it more clear what is being calculated. aacpsy: cosmetics, change a FIXME to a NOTE about subshort comparisons aacenc: cosmetics: move init() and end() to the bottom of the file. aacenc: aac_encode_init() cleanup XWD encoder and decoder vc1: don't read the interpfrm and bfraction elements for interlaced frames mxfdec: fix memleak on mxf_read_close() westwood: split the AUD and VQA demuxers into separate files. Conflicts: .gitignore Changelog Makefile configure doc/ffmpeg.texi ffmpeg.c libavcodec/Makefile libavcodec/aacenc.c libavcodec/allcodecs.c libavcodec/avcodec.h libavcodec/version.h libavformat/Makefile libavformat/img2.c
Unified · Split
| @@ -15,6 +15,7 @@ version next: · 14 unmodified lines | |||
| 15 | - amerge audio filter | 15 | - amerge audio filter |
| 16 | - GSM audio parser | 16 | - GSM audio parser |
| 17 | - SMJPEG muxer | 17 | - SMJPEG muxer |
| 18 | - XWD encoder and decoder | ||
| 18 | - Automatic thread count based on detection number of (available) CPU cores | 19 | - Automatic thread count based on detection number of (available) CPU cores |
| 19 | - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder | 20 | - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder |
| 20 | - ffprobe -show_error option | 21 | - ffprobe -show_error option |
| @@ -399,6 +399,8 @@ following image formats are supported: · 398 unmodified lines | |||
| 399 | @tab YUV, JPEG and some extension is not supported yet. | 399 | @tab YUV, JPEG and some extension is not supported yet. |
| 400 | @item Truevision Targa @tab X @tab X | 400 | @item Truevision Targa @tab X @tab X |
| 401 | @tab Targa (.TGA) image format | 401 | @tab Targa (.TGA) image format |
| 402 | @item XWD @tab X @tab X | ||
| 403 | @tab X Window Dump image format | ||
| 402 | @end multitable | 404 | @end multitable |
| 403 | 405 | ||
| 404 | @code{X} means that encoding (resp. decoding) is supported. | 406 | @code{X} means that encoding (resp. decoding) is supported. |
| @@ -470,6 +470,8 @@ OBJS-$(CONFIG_XBIN_DECODER) += bintext.o cga_data.o · 469 unmodified lines | |||
| 470 | OBJS-$(CONFIG_XL_DECODER) += xl.o | 470 | OBJS-$(CONFIG_XL_DECODER) += xl.o |
| 471 | OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o | 471 | OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o |
| 472 | OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o | 472 | OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o |
| 473 | OBJS-$(CONFIG_XWD_DECODER) += xwddec.o | ||
| 474 | OBJS-$(CONFIG_XWD_ENCODER) += xwdenc.o | ||
| 473 | OBJS-$(CONFIG_Y41P_DECODER) += y41pdec.o | 475 | OBJS-$(CONFIG_Y41P_DECODER) += y41pdec.o |
| 474 | OBJS-$(CONFIG_Y41P_ENCODER) += y41penc.o | 476 | OBJS-$(CONFIG_Y41P_ENCODER) += y41penc.o |
| 475 | OBJS-$(CONFIG_YOP_DECODER) += yop.o | 477 | OBJS-$(CONFIG_YOP_DECODER) += yop.o |
| @@ -110,14 +110,15 @@ static av_always_inline float quantize_and_encode_band_cost_template( · 109 unmodified lines | |||
| 110 | int *bits, int BT_ZERO, int BT_UNSIGNED, | 110 | int *bits, int BT_ZERO, int BT_UNSIGNED, |
| 111 | int BT_PAIR, int BT_ESC) | 111 | int BT_PAIR, int BT_ESC) |
| 112 | { | 112 | { |
| 113 | const float IQ = ff_aac_pow2sf_tab[POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; | 113 | const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512; |
| 114 | const float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; | 114 | const float Q = ff_aac_pow2sf_tab [q_idx]; |
| 115 | const float Q34 = ff_aac_pow34sf_tab[q_idx]; | ||
| 116 | const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; | ||
| 115 | const float CLIPPED_ESCAPE = 165140.0f*IQ; | 117 | const float CLIPPED_ESCAPE = 165140.0f*IQ; |
| 116 | int i, j; | 118 | int i, j; |
| 117 | float cost = 0; | 119 | float cost = 0; |
| 118 | const int dim = BT_PAIR ? 2 : 4; | 120 | const int dim = BT_PAIR ? 2 : 4; |
| 119 | int resbits = 0; | 121 | int resbits = 0; |
| 120 | const float Q34 = sqrtf(Q * sqrtf(Q)); | ||
| 121 | const int range = aac_cb_range[cb]; | 122 | const int range = aac_cb_range[cb]; |
| 122 | const int maxval = aac_cb_maxval[cb]; | 123 | const int maxval = aac_cb_maxval[cb]; |
| 123 | int off; | 124 | int off; |
| @@ -420,7 +421,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 296 unmodified lines | |||
| 420 | const int run_esc = (1 << run_bits) - 1; | 421 | const int run_esc = (1 << run_bits) - 1; |
| 421 | int idx, ppos, count; | 422 | int idx, ppos, count; |
| 422 | int stackrun[120], stackcb[120], stack_len; | 423 | int stackrun[120], stackcb[120], stack_len; |
| 423 | float next_minrd = INFINITY; | 424 | float next_minbits = INFINITY; |
| 424 | int next_mincb = 0; | 425 | int next_mincb = 0; |
| 425 | 426 | ||
| 426 | abs_pow34_v(s->scoefs, sce->coeffs, 1024); | 427 | abs_pow34_v(s->scoefs, sce->coeffs, 1024); |
| @@ -434,7 +435,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 7 unmodified lines | |||
| 434 | size = sce->ics.swb_sizes[swb]; | 435 | size = sce->ics.swb_sizes[swb]; |
| 435 | if (sce->zeroes[win*16 + swb]) { | 436 | if (sce->zeroes[win*16 + swb]) { |
| 436 | float cost_stay_here = path[swb][0].cost; | 437 | float cost_stay_here = path[swb][0].cost; |
| 437 | float cost_get_here = next_minrd + run_bits + 4; | 438 | float cost_get_here = next_minbits + run_bits + 4; |
| 438 | if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run] | 439 | if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run] |
| 439 | != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1]) | 440 | != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1]) |
| 440 | cost_stay_here += run_bits; | 441 | cost_stay_here += run_bits; |
| @@ -447,7 +448,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 6 unmodified lines | |||
| 447 | path[swb+1][0].cost = cost_stay_here; | 448 | path[swb+1][0].cost = cost_stay_here; |
| 448 | path[swb+1][0].run = path[swb][0].run + 1; | 449 | path[swb+1][0].run = path[swb][0].run + 1; |
| 449 | } | 450 | } |
| 450 | next_minrd = path[swb+1][0].cost; | 451 | next_minbits = path[swb+1][0].cost; |
| 451 | next_mincb = 0; | 452 | next_mincb = 0; |
| 452 | for (cb = 1; cb < 12; cb++) { | 453 | for (cb = 1; cb < 12; cb++) { |
| 453 | path[swb+1][cb].cost = 61450; | 454 | path[swb+1][cb].cost = 61450; |
| @@ -455,10 +456,10 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 1 unmodified line | |||
| 455 | path[swb+1][cb].run = 0; | 456 | path[swb+1][cb].run = 0; |
| 456 | } | 457 | } |
| 457 | } else { | 458 | } else { |
| 458 | float minrd = next_minrd; | 459 | float minbits = next_minbits; |
| 459 | int mincb = next_mincb; | 460 | int mincb = next_mincb; |
| 460 | int startcb = sce->band_type[win*16+swb]; | 461 | int startcb = sce->band_type[win*16+swb]; |
| 461 | next_minrd = INFINITY; | 462 | next_minbits = INFINITY; |
| 462 | next_mincb = 0; | 463 | next_mincb = 0; |
| 463 | for (cb = 0; cb < startcb; cb++) { | 464 | for (cb = 0; cb < startcb; cb++) { |
| 464 | path[swb+1][cb].cost = 61450; | 465 | path[swb+1][cb].cost = 61450; |
| @@ -467,15 +468,15 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 2 unmodified lines | |||
| 467 | } | 468 | } |
| 468 | for (cb = startcb; cb < 12; cb++) { | 469 | for (cb = startcb; cb < 12; cb++) { |
| 469 | float cost_stay_here, cost_get_here; | 470 | float cost_stay_here, cost_get_here; |
| 470 | float rd = 0.0f; | 471 | float bits = 0.0f; |
| 471 | for (w = 0; w < group_len; w++) { | 472 | for (w = 0; w < group_len; w++) { |
| 472 | rd += quantize_band_cost(s, sce->coeffs + start + w*128, | 473 | bits += quantize_band_cost(s, sce->coeffs + start + w*128, |
| 473 | s->scoefs + start + w*128, size, | 474 | s->scoefs + start + w*128, size, |
| 474 | sce->sf_idx[(win+w)*16+swb], cb, | 475 | sce->sf_idx[(win+w)*16+swb], cb, |
| 475 | 0, INFINITY, NULL); | 476 | 0, INFINITY, NULL); |
| 476 | } | 477 | } |
| 477 | cost_stay_here = path[swb][cb].cost + rd; | 478 | cost_stay_here = path[swb][cb].cost + bits; |
| 478 | cost_get_here = minrd + rd + run_bits + 4; | 479 | cost_get_here = minbits + bits + run_bits + 4; |
| 479 | if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run] | 480 | if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run] |
| 480 | != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1]) | 481 | != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1]) |
| 481 | cost_stay_here += run_bits; | 482 | cost_stay_here += run_bits; |
| @@ -488,8 +489,8 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 6 unmodified lines | |||
| 488 | path[swb+1][cb].cost = cost_stay_here; | 489 | path[swb+1][cb].cost = cost_stay_here; |
| 489 | path[swb+1][cb].run = path[swb][cb].run + 1; | 490 | path[swb+1][cb].run = path[swb][cb].run + 1; |
| 490 | } | 491 | } |
| 491 | if (path[swb+1][cb].cost < next_minrd) { | 492 | if (path[swb+1][cb].cost < next_minbits) { |
| 492 | next_minrd = path[swb+1][cb].cost; | 493 | next_minbits = path[swb+1][cb].cost; |
| 493 | next_mincb = cb; | 494 | next_mincb = cb; |
| 494 | } | 495 | } |
| 495 | } | 496 | } |
| @@ -46,6 +46,14 @@ · 45 unmodified lines | |||
| 46 | 46 | ||
| 47 | #define AAC_MAX_CHANNELS 6 | 47 | #define AAC_MAX_CHANNELS 6 |
| 48 | 48 | ||
| 49 | #define ERROR_IF(cond, ...) \ | ||
| 50 | if (cond) { \ | ||
| 51 | av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ | ||
| 52 | return AVERROR(EINVAL); \ | ||
| 53 | } | ||
| 54 | |||
| 55 | float ff_aac_pow34sf_tab[428]; | ||
| 56 | |||
| 49 | static const uint8_t swb_size_1024_96[] = { | 57 | static const uint8_t swb_size_1024_96[] = { |
| 50 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, | 58 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, |
| 51 | 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, | 59 | 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, |
| @@ -135,6 +143,18 @@ static const uint8_t aac_chan_configs[6][5] = { · 83 unmodified lines | |||
| 135 | {4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE | 143 | {4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE |
| 136 | }; | 144 | }; |
| 137 | 145 | ||
| 146 | /** | ||
| 147 | * Table to remap channels from Libav's default order to AAC order. | ||
| 148 | */ | ||
| 149 | static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS] = { | ||
| 150 | { 0 }, | ||
| 151 | { 0, 1 }, | ||
| 152 | { 2, 0, 1 }, | ||
| 153 | { 2, 0, 1, 3 }, | ||
| 154 | { 2, 0, 1, 3, 4 }, | ||
| 155 | { 2, 0, 1, 4, 5, 3 }, | ||
| 156 | }; | ||
| 157 | |||
| 138 | /** | 158 | /** |
| 139 | * Make AAC audio config object. | 159 | * Make AAC audio config object. |
| 140 | * @see 1.6.2.1 "Syntax - AudioSpecificConfig" | 160 | * @see 1.6.2.1 "Syntax - AudioSpecificConfig" |
| @@ -147,7 +167,7 @@ static void put_audio_specific_config(AVCodecContext *avctx) · 6 unmodified lines | |||
| 147 | init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8); | 167 | init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8); |
| 148 | put_bits(&pb, 5, 2); //object type - AAC-LC | 168 | put_bits(&pb, 5, 2); //object type - AAC-LC |
| 149 | put_bits(&pb, 4, s->samplerate_index); //sample rate index | 169 | put_bits(&pb, 4, s->samplerate_index); //sample rate index |
| 150 | put_bits(&pb, 4, avctx->channels); | 170 | put_bits(&pb, 4, s->channels); |
| 151 | //GASpecificConfig | 171 | //GASpecificConfig |
| 152 | put_bits(&pb, 1, 0); //frame length - 1024 samples | 172 | put_bits(&pb, 1, 0); //frame length - 1024 samples |
| 153 | put_bits(&pb, 1, 0); //does not depend on core coder | 173 | put_bits(&pb, 1, 0); //does not depend on core coder |
| @@ -160,117 +180,80 @@ static void put_audio_specific_config(AVCodecContext *avctx) · 6 unmodified lines | |||
| 160 | flush_put_bits(&pb); | 180 | flush_put_bits(&pb); |
| 161 | } | 181 | } |
| 162 | 182 | ||
| 163 | static av_cold int aac_encode_init(AVCodecContext *avctx) | 183 | #define WINDOW_FUNC(type) \ |
| 164 | { | 184 | static void apply_ ##type ##_window(DSPContext *dsp, SingleChannelElement *sce, const float *audio) |
| 165 | AACEncContext *s = avctx->priv_data; | ||
| 166 | int i; | ||
| 167 | const uint8_t *sizes[2]; | ||
| 168 | uint8_t grouping[AAC_MAX_CHANNELS]; | ||
| 169 | int lengths[2]; | ||
| 170 | |||
| 171 | avctx->frame_size = 1024; | ||
| 172 | 185 | ||
| 173 | for (i = 0; i < 16; i++) | 186 | WINDOW_FUNC(only_long) |
| 174 | if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) | 187 | { |
| 175 | break; | 188 | const float *lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; |
| 176 | if (i == 16) { | 189 | const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; |
| 177 | av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate); | 190 | float *out = sce->ret; |
| 178 | return -1; | ||
| 179 | } | ||
| 180 | if (avctx->channels > AAC_MAX_CHANNELS) { | ||
| 181 | av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels); | ||
| 182 | return -1; | ||
| 183 | } | ||
| 184 | if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) { | ||
| 185 | av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile); | ||
| 186 | return -1; | ||
| 187 | } | ||
| 188 | if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) { | ||
| 189 | av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); | ||
| 190 | return -1; | ||
| 191 | } | ||
| 192 | s->samplerate_index = i; | ||
| 193 | |||
| 194 | dsputil_init(&s->dsp, avctx); | ||
| 195 | ff_mdct_init(&s->mdct1024, 11, 0, 1.0); | ||
| 196 | ff_mdct_init(&s->mdct128, 8, 0, 1.0); | ||
| 197 | // window init | ||
| 198 | ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); | ||
| 199 | ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); | ||
| 200 | ff_init_ff_sine_windows(10); | ||
| 201 | ff_init_ff_sine_windows(7); | ||
| 202 | |||
| 203 | s->chan_map = aac_chan_configs[avctx->channels-1]; | ||
| 204 | s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); | ||
| 205 | s->cpe = av_mallocz(sizeof(ChannelElement) * s->chan_map[0]); | ||
| 206 | avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE); | ||
| 207 | avctx->extradata_size = 5; | ||
| 208 | put_audio_specific_config(avctx); | ||
| 209 | 191 | ||
| 210 | sizes[0] = swb_size_1024[i]; | 192 | dsp->vector_fmul (out, audio, lwindow, 1024); |
| 211 | sizes[1] = swb_size_128[i]; | 193 | dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024); |
| 212 | lengths[0] = ff_aac_num_swb_1024[i]; | 194 | } |
| 213 | lengths[1] = ff_aac_num_swb_128[i]; | ||
| 214 | for (i = 0; i < s->chan_map[0]; i++) | ||
| 215 | grouping[i] = s->chan_map[i + 1] == TYPE_CPE; | ||
| 216 | ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping); | ||
| 217 | s->psypp = ff_psy_preprocess_init(avctx); | ||
| 218 | s->coder = &ff_aac_coders[s->options.aac_coder]; | ||
| 219 | 195 | ||
| 220 | s->lambda = avctx->global_quality ? avctx->global_quality : 120; | 196 | WINDOW_FUNC(long_start) |
| 197 | { | ||
| 198 | const float *lwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; | ||
| 199 | const float *swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 200 | float *out = sce->ret; | ||
| 201 | |||
| 202 | dsp->vector_fmul(out, audio, lwindow, 1024); | ||
| 203 | memcpy(out + 1024, audio, sizeof(out[0]) * 448); | ||
| 204 | dsp->vector_fmul_reverse(out + 1024 + 448, audio, swindow, 128); | ||
| 205 | memset(out + 1024 + 576, 0, sizeof(out[0]) * 448); | ||
| 206 | } | ||
| 221 | 207 | ||
| 222 | ff_aac_tableinit(); | 208 | WINDOW_FUNC(long_stop) |
| 209 | { | ||
| 210 | const float *lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; | ||
| 211 | const float *swindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 212 | float *out = sce->ret; | ||
| 213 | |||
| 214 | memset(out, 0, sizeof(out[0]) * 448); | ||
| 215 | dsp->vector_fmul(out + 448, audio + 448, swindow, 128); | ||
| 216 | memcpy(out + 576, audio + 576, sizeof(out[0]) * 448); | ||
| 217 | dsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024); | ||
| 218 | } | ||
| 223 | 219 | ||
| 224 | return 0; | 220 | WINDOW_FUNC(eight_short) |
| 221 | { | ||
| 222 | const float *swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 223 | const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 224 | const float *in = audio + 448; | ||
| 225 | float *out = sce->ret; | ||
| 226 | |||
| 227 | for (int w = 0; w < 8; w++) { | ||
| 228 | dsp->vector_fmul (out, in, w ? pwindow : swindow, 128); | ||
| 229 | out += 128; | ||
| 230 | in += 128; | ||
| 231 | dsp->vector_fmul_reverse(out, in, swindow, 128); | ||
| 232 | out += 128; | ||
| 233 | } | ||
| 225 | } | 234 | } |
| 226 | 235 | ||
| 227 | static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s, | 236 | static void (*const apply_window[4])(DSPContext *dsp, SingleChannelElement *sce, const float *audio) = { |
| 228 | SingleChannelElement *sce, short *audio) | 237 | [ONLY_LONG_SEQUENCE] = apply_only_long_window, |
| 238 | [LONG_START_SEQUENCE] = apply_long_start_window, | ||
| 239 | [EIGHT_SHORT_SEQUENCE] = apply_eight_short_window, | ||
| 240 | [LONG_STOP_SEQUENCE] = apply_long_stop_window | ||
| 241 | }; | ||
| 242 | |||
| 243 | static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, | ||
| 244 | float *audio) | ||
| 229 | { | 245 | { |
| 230 | int i, k; | 246 | int i; |
| 231 | const int chans = avctx->channels; | ||
| 232 | const float * lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; | ||
| 233 | const float * swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 234 | const float * pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; | ||
| 235 | float *output = sce->ret; | 247 | float *output = sce->ret; |
| 236 | 248 | ||
| 237 | if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { | 249 | apply_window[sce->ics.window_sequence[0]](&s->dsp, sce, audio); |
| 238 | memcpy(output, sce->saved, sizeof(float)*1024); | 250 | |
| 239 | if (sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE) { | 251 | if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) |
| 240 | memset(output, 0, sizeof(output[0]) * 448); | ||
| 241 | for (i = 448; i < 576; i++) | ||
| 242 | output[i] = sce->saved[i] * pwindow[i - 448]; | ||
| 243 | for (i = 576; i < 704; i++) | ||
| 244 | output[i] = sce->saved[i]; | ||
| 245 | } | ||
| 246 | if (sce->ics.window_sequence[0] != LONG_START_SEQUENCE) { | ||
| 247 | for (i = 0; i < 1024; i++) { | ||
| 248 | output[i+1024] = audio[i * chans] * lwindow[1024 - i - 1]; | ||
| 249 | sce->saved[i] = audio[i * chans] * lwindow[i]; | ||
| 250 | } | ||
| 251 | } else { | ||
| 252 | for (i = 0; i < 448; i++) | ||
| 253 | output[i+1024] = audio[i * chans]; | ||
| 254 | for (; i < 576; i++) | ||
| 255 | output[i+1024] = audio[i * chans] * swindow[576 - i - 1]; | ||
| 256 | memset(output+1024+576, 0, sizeof(output[0]) * 448); | ||
| 257 | for (i = 0; i < 1024; i++) | ||
| 258 | sce->saved[i] = audio[i * chans]; | ||
| 259 | } | ||
| 260 | s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output); | 252 | s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output); |
| 261 | } else { | 253 | else |
| 262 | for (k = 0; k < 1024; k += 128) { | 254 | for (i = 0; i < 1024; i += 128) |
| 263 | for (i = 448 + k; i < 448 + k + 256; i++) | 255 | s->mdct128.mdct_calc(&s->mdct128, sce->coeffs + i, output + i*2); |
| 264 | output[i - 448 - k] = (i < 1024) | 256 | memcpy(audio, audio + 1024, sizeof(audio[0]) * 1024); |
| 265 | ? sce->saved[i] | ||
| 266 | : audio[(i-1024)*chans]; | ||
| 267 | s->dsp.vector_fmul (output, output, k ? swindow : pwindow, 128); | ||
| 268 | s->dsp.vector_fmul_reverse(output+128, output+128, swindow, 128); | ||
| 269 | s->mdct128.mdct_calc(&s->mdct128, sce->coeffs + k, output); | ||
| 270 | } | ||
| 271 | for (i = 0; i < 1024; i++) | ||
| 272 | sce->saved[i] = audio[i * chans]; | ||
| 273 | } | ||
| 274 | } | 257 | } |
| 275 | 258 | ||
| 276 | /** | 259 | /** |
| @@ -488,11 +471,37 @@ static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, · 211 unmodified lines | |||
| 488 | put_bits(&s->pb, 12 - padbits, 0); | 471 | put_bits(&s->pb, 12 - padbits, 0); |
| 489 | } | 472 | } |
| 490 | 473 | ||
| 474 | /* | ||
| 475 | * Deinterleave input samples. | ||
| 476 | * Channels are reordered from Libav's default order to AAC order. | ||
| 477 | */ | ||
| 478 | static void deinterleave_input_samples(AACEncContext *s, | ||
| 479 | const float *samples) | ||
| 480 | { | ||
| 481 | int ch, i; | ||
| 482 | const int sinc = s->channels; | ||
| 483 | const uint8_t *channel_map = aac_chan_maps[sinc - 1]; | ||
| 484 | |||
| 485 | /* deinterleave and remap input samples */ | ||
| 486 | for (ch = 0; ch < sinc; ch++) { | ||
| 487 | const float *sptr = samples + channel_map[ch]; | ||
| 488 | |||
| 489 | /* copy last 1024 samples of previous frame to the start of the current frame */ | ||
| 490 | memcpy(&s->planar_samples[ch][0], &s->planar_samples[ch][1024], 1024 * sizeof(s->planar_samples[0][0])); | ||
| 491 | |||
| 492 | /* deinterleave */ | ||
| 493 | for (i = 1024; i < 1024 * 2; i++) { | ||
| 494 | s->planar_samples[ch][i] = *sptr; | ||
| 495 | sptr += sinc; | ||
| 496 | } | ||
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 491 | static int aac_encode_frame(AVCodecContext *avctx, | 500 | static int aac_encode_frame(AVCodecContext *avctx, |
| 492 | uint8_t *frame, int buf_size, void *data) | 501 | uint8_t *frame, int buf_size, void *data) |
| 493 | { | 502 | { |
| 494 | AACEncContext *s = avctx->priv_data; | 503 | AACEncContext *s = avctx->priv_data; |
| 495 | int16_t *samples = s->samples, *samples2, *la; | 504 | float **samples = s->planar_samples, *samples2, *la, *overlap; |
| 496 | ChannelElement *cpe; | 505 | ChannelElement *cpe; |
| 497 | int i, ch, w, g, chans, tag, start_ch; | 506 | int i, ch, w, g, chans, tag, start_ch; |
| 498 | int chan_el_counter[4]; | 507 | int chan_el_counter[4]; |
| @@ -500,27 +509,15 @@ static int aac_encode_frame(AVCodecContext *avctx, · 1 unmodified line | |||
| 500 | 509 | ||
| 501 | if (s->last_frame) | 510 | if (s->last_frame) |
| 502 | return 0; | 511 | return 0; |
| 512 | |||
| 503 | if (data) { | 513 | if (data) { |
| 504 | if (!s->psypp) { | 514 | deinterleave_input_samples(s, data); |
| 505 | memcpy(s->samples + 1024 * avctx->channels, data, | 515 | if (s->psypp) |
| 506 | 1024 * avctx->channels * sizeof(s->samples[0])); | 516 | ff_psy_preprocess(s->psypp, s->planar_samples, s->channels); |
| 507 | } else { | ||
| 508 | start_ch = 0; | ||
| 509 | samples2 = s->samples + 1024 * avctx->channels; | ||
| 510 | for (i = 0; i < s->chan_map[0]; i++) { | ||
| 511 | tag = s->chan_map[i+1]; | ||
| 512 | chans = tag == TYPE_CPE ? 2 : 1; | ||
| 513 | ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch, | ||
| 514 | samples2 + start_ch, start_ch, chans); | ||
| 515 | start_ch += chans; | ||
| 516 | } | ||
| 517 | } | ||
| 518 | } | 517 | } |
| 519 | if (!avctx->frame_number) { | 518 | |
| 520 | memcpy(s->samples, s->samples + 1024 * avctx->channels, | 519 | if (!avctx->frame_number) |
| 521 | 1024 * avctx->channels * sizeof(s->samples[0])); | ||
| 522 | return 0; | 520 | return 0; |
| 523 | } | ||
| 524 | 521 | ||
| 525 | start_ch = 0; | 522 | start_ch = 0; |
| 526 | for (i = 0; i < s->chan_map[0]; i++) { | 523 | for (i = 0; i < s->chan_map[0]; i++) { |
| @@ -531,8 +528,9 @@ static int aac_encode_frame(AVCodecContext *avctx, · 4 unmodified lines | |||
| 531 | for (ch = 0; ch < chans; ch++) { | 528 | for (ch = 0; ch < chans; ch++) { |
| 532 | IndividualChannelStream *ics = &cpe->ch[ch].ics; | 529 | IndividualChannelStream *ics = &cpe->ch[ch].ics; |
| 533 | int cur_channel = start_ch + ch; | 530 | int cur_channel = start_ch + ch; |
| 534 | samples2 = samples + cur_channel; | 531 | overlap = &samples[cur_channel][0]; |
| 535 | la = samples2 + (448+64) * avctx->channels; | 532 | samples2 = overlap + 1024; |
| 533 | la = samples2 + (448+64); | ||
| 536 | if (!data) | 534 | if (!data) |
| 537 | la = NULL; | 535 | la = NULL; |
| 538 | if (tag == TYPE_LFE) { | 536 | if (tag == TYPE_LFE) { |
| @@ -560,7 +558,7 @@ static int aac_encode_frame(AVCodecContext *avctx, · 21 unmodified lines | |||
| 560 | for (w = 0; w < ics->num_windows; w++) | 558 | for (w = 0; w < ics->num_windows; w++) |
| 561 | ics->group_len[w] = wi[ch].grouping[w]; | 559 | ics->group_len[w] = wi[ch].grouping[w]; |
| 562 | 560 | ||
| 563 | apply_window_and_mdct(avctx, s, &cpe->ch[ch], samples2); | 561 | apply_window_and_mdct(s, &cpe->ch[ch], overlap); |
| 564 | } | 562 | } |
| 565 | start_ch += chans; | 563 | start_ch += chans; |
| 566 | } | 564 | } |
| @@ -626,8 +624,8 @@ static int aac_encode_frame(AVCodecContext *avctx, · 59 unmodified lines | |||
| 626 | } | 624 | } |
| 627 | 625 | ||
| 628 | frame_bits = put_bits_count(&s->pb); | 626 | frame_bits = put_bits_count(&s->pb); |
| 629 | if (frame_bits <= 6144 * avctx->channels - 3) { | 627 | if (frame_bits <= 6144 * s->channels - 3) { |
| 630 | s->psy.bitres.bits = frame_bits / avctx->channels; | 628 | s->psy.bitres.bits = frame_bits / s->channels; |
| 631 | break; | 629 | break; |
| 632 | } | 630 | } |
| 633 | 631 | ||
| @@ -648,8 +646,7 @@ static int aac_encode_frame(AVCodecContext *avctx, · 14 unmodified lines | |||
| 648 | 646 | ||
| 649 | if (!data) | 647 | if (!data) |
| 650 | s->last_frame = 1; | 648 | s->last_frame = 1; |
| 651 | memcpy(s->samples, s->samples + 1024 * avctx->channels, | 649 | |
| 652 | 1024 * avctx->channels * sizeof(s->samples[0])); | ||
| 653 | return put_bits_count(&s->pb)>>3; | 650 | return put_bits_count(&s->pb)>>3; |
| 654 | } | 651 | } |
| 655 | 652 | ||
| @@ -660,12 +657,109 @@ static av_cold int aac_encode_end(AVCodecContext *avctx) · 4 unmodified lines | |||
| 660 | ff_mdct_end(&s->mdct1024); | 657 | ff_mdct_end(&s->mdct1024); |
| 661 | ff_mdct_end(&s->mdct128); | 658 | ff_mdct_end(&s->mdct128); |
| 662 | ff_psy_end(&s->psy); | 659 | ff_psy_end(&s->psy); |
| 663 | ff_psy_preprocess_end(s->psypp); | 660 | if (s->psypp) |
| 664 | av_freep(&s->samples); | 661 | ff_psy_preprocess_end(s->psypp); |
| 662 | av_freep(&s->buffer.samples); | ||
| 665 | av_freep(&s->cpe); | 663 | av_freep(&s->cpe); |
| 666 | return 0; | 664 | return 0; |
| 667 | } | 665 | } |
| 668 | 666 | ||
| 667 | static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) | ||
| 668 | { | ||
| 669 | int ret = 0; | ||
| 670 | |||
| 671 | dsputil_init(&s->dsp, avctx); | ||
| 672 | |||
| 673 | // window init | ||
| 674 | ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); | ||
| 675 | ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); | ||
| 676 | ff_init_ff_sine_windows(10); | ||
| 677 | ff_init_ff_sine_windows(7); | ||
| 678 | |||
| 679 | if (ret = ff_mdct_init(&s->mdct1024, 11, 0, 32768.0)) | ||
| 680 | return ret; | ||
| 681 | if (ret = ff_mdct_init(&s->mdct128, 8, 0, 32768.0)) | ||
| 682 | return ret; | ||
| 683 | |||
| 684 | return 0; | ||
| 685 | } | ||
| 686 | |||
| 687 | static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s) | ||
| 688 | { | ||
| 689 | FF_ALLOCZ_OR_GOTO(avctx, s->buffer.samples, 3 * 1024 * s->channels * sizeof(s->buffer.samples[0]), alloc_fail); | ||
| 690 | FF_ALLOCZ_OR_GOTO(avctx, s->cpe, sizeof(ChannelElement) * s->chan_map[0], alloc_fail); | ||
| 691 | FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 + FF_INPUT_BUFFER_PADDING_SIZE, alloc_fail); | ||
| 692 | |||
| 693 | for(int ch = 0; ch < s->channels; ch++) | ||
| 694 | s->planar_samples[ch] = s->buffer.samples + 3 * 1024 * ch; | ||
| 695 | |||
| 696 | return 0; | ||
| 697 | alloc_fail: | ||
| 698 | return AVERROR(ENOMEM); | ||
| 699 | } | ||
| 700 | |||
| 701 | static av_cold int aac_encode_init(AVCodecContext *avctx) | ||
| 702 | { | ||
| 703 | AACEncContext *s = avctx->priv_data; | ||
| 704 | int i, ret = 0; | ||
| 705 | const uint8_t *sizes[2]; | ||
| 706 | uint8_t grouping[AAC_MAX_CHANNELS]; | ||
| 707 | int lengths[2]; | ||
| 708 | |||
| 709 | avctx->frame_size = 1024; | ||
| 710 | |||
| 711 | for (i = 0; i < 16; i++) | ||
| 712 | if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) | ||
| 713 | break; | ||
| 714 | |||
| 715 | s->channels = avctx->channels; | ||
| 716 | |||
| 717 | ERROR_IF(i == 16, | ||
| 718 | "Unsupported sample rate %d\n", avctx->sample_rate); | ||
| 719 | ERROR_IF(s->channels > AAC_MAX_CHANNELS, | ||
| 720 | "Unsupported number of channels: %d\n", s->channels); | ||
| 721 | ERROR_IF(avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW, | ||
| 722 | "Unsupported profile %d\n", avctx->profile); | ||
| 723 | ERROR_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, | ||
| 724 | "Too many bits per frame requested\n"); | ||
| 725 | |||
| 726 | s->samplerate_index = i; | ||
| 727 | |||
| 728 | s->chan_map = aac_chan_configs[s->channels-1]; | ||
| 729 | |||
| 730 | if (ret = dsp_init(avctx, s)) | ||
| 731 | goto fail; | ||
| 732 | |||
| 733 | if (ret = alloc_buffers(avctx, s)) | ||
| 734 | goto fail; | ||
| 735 | |||
| 736 | avctx->extradata_size = 5; | ||
| 737 | put_audio_specific_config(avctx); | ||
| 738 | |||
| 739 | sizes[0] = swb_size_1024[i]; | ||
| 740 | sizes[1] = swb_size_128[i]; | ||
| 741 | lengths[0] = ff_aac_num_swb_1024[i]; | ||
| 742 | lengths[1] = ff_aac_num_swb_128[i]; | ||
| 743 | for (i = 0; i < s->chan_map[0]; i++) | ||
| 744 | grouping[i] = s->chan_map[i + 1] == TYPE_CPE; | ||
| 745 | if (ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping)) | ||
| 746 | goto fail; | ||
| 747 | s->psypp = ff_psy_preprocess_init(avctx); | ||
| 748 | s->coder = &ff_aac_coders[s->options.aac_coder]; | ||
| 749 | |||
| 750 | s->lambda = avctx->global_quality ? avctx->global_quality : 120; | ||
| 751 | |||
| 752 | ff_aac_tableinit(); | ||
| 753 | |||
| 754 | for (i = 0; i < 428; i++) | ||
| 755 | ff_aac_pow34sf_tab[i] = sqrt(ff_aac_pow2sf_tab[i] * sqrt(ff_aac_pow2sf_tab[i])); | ||
| 756 | |||
| 757 | return 0; | ||
| 758 | fail: | ||
| 759 | aac_encode_end(avctx); | ||
| 760 | return ret; | ||
| 761 | } | ||
| 762 | |||
| 669 | #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | 763 | #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM |
| 670 | static const AVOption aacenc_options[] = { | 764 | static const AVOption aacenc_options[] = { |
| 671 | {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), AV_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"}, | 765 | {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), AV_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"}, |
| @@ -692,7 +786,7 @@ AVCodec ff_aac_encoder = { · 20 unmodified lines | |||
| 692 | .encode = aac_encode_frame, | 786 | .encode = aac_encode_frame, |
| 693 | .close = aac_encode_end, | 787 | .close = aac_encode_end, |
| 694 | .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, | 788 | .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, |
| 695 | .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, | 789 | .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, |
| 696 | .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), | 790 | .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), |
| 697 | .priv_class = &aacenc_class, | 791 | .priv_class = &aacenc_class, |
| 698 | }; | 792 | }; |
| @@ -61,9 +61,10 @@ typedef struct AACEncContext { · 60 unmodified lines | |||
| 61 | FFTContext mdct1024; ///< long (1024 samples) frame transform context | 61 | FFTContext mdct1024; ///< long (1024 samples) frame transform context |
| 62 | FFTContext mdct128; ///< short (128 samples) frame transform context | 62 | FFTContext mdct128; ///< short (128 samples) frame transform context |
| 63 | DSPContext dsp; | 63 | DSPContext dsp; |
| 64 | int16_t *samples; ///< saved preprocessed input | 64 | float *planar_samples[6]; ///< saved preprocessed input |
| 65 | 65 | ||
| 66 | int samplerate_index; ///< MPEG-4 samplerate index | 66 | int samplerate_index; ///< MPEG-4 samplerate index |
| 67 | int channels; ///< channel count | ||
| 67 | const uint8_t *chan_map; ///< channel configuration map | 68 | const uint8_t *chan_map; ///< channel configuration map |
| 68 | 69 | ||
| 69 | ChannelElement *cpe; ///< channel elements | 70 | ChannelElement *cpe; ///< channel elements |
| @@ -75,6 +76,12 @@ typedef struct AACEncContext { · 5 unmodified lines | |||
| 75 | float lambda; | 76 | float lambda; |
| 76 | DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients | 77 | DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients |
| 77 | DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients | 78 | DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients |
| 79 | |||
| 80 | struct { | ||
| 81 | float *samples; | ||
| 82 | } buffer; | ||
| 78 | } AACEncContext; | 83 | } AACEncContext; |
| 79 | 84 | ||
| 85 | extern float ff_aac_pow34sf_tab[428]; | ||
| 86 | |||
| 80 | #endif /* AVCODEC_AACENC_H */ | 87 | #endif /* AVCODEC_AACENC_H */ |
| @@ -400,7 +400,7 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx, · 399 unmodified lines | |||
| 400 | int stay_short = 0; | 400 | int stay_short = 0; |
| 401 | for (i = 0; i < 8; i++) { | 401 | for (i = 0; i < 8; i++) { |
| 402 | for (j = 0; j < 128; j++) { | 402 | for (j = 0; j < 128; j++) { |
| 403 | v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state); | 403 | v = iir_filter(la[i*128+j], pch->iir_state); |
| 404 | sum += v*v; | 404 | sum += v*v; |
| 405 | } | 405 | } |
| 406 | s[i] = sum; | 406 | s[i] = sum; |
| @@ -776,9 +776,8 @@ static void lame_apply_block_type(AacPsyChannel *ctx, FFPsyWindowInfo *wi, int u · 369 unmodified lines | |||
| 776 | ctx->next_window_seq = blocktype; | 776 | ctx->next_window_seq = blocktype; |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, | 779 | static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio, |
| 780 | const int16_t *audio, const int16_t *la, | 780 | const float *la, int channel, int prev_type) |
| 781 | int channel, int prev_type) | ||
| 782 | { | 781 | { |
| 783 | AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; | 782 | AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; |
| 784 | AacPsyChannel *pch = &pctx->ch[channel]; | 783 | AacPsyChannel *pch = &pctx->ch[channel]; |
| @@ -795,20 +794,20 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, · 10 unmodified lines | |||
| 795 | float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; | 794 | float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; |
| 796 | float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; | 795 | float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; |
| 797 | float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 }; | 796 | float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 }; |
| 798 | int chans = ctx->avctx->channels; | 797 | const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN); |
| 799 | const int16_t *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN) * chans; | ||
| 800 | int j, att_sum = 0; | 798 | int j, att_sum = 0; |
| 801 | 799 | ||
| 802 | /* LAME comment: apply high pass filter of fs/4 */ | 800 | /* LAME comment: apply high pass filter of fs/4 */ |
| 803 | for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) { | 801 | for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) { |
| 804 | float sum1, sum2; | 802 | float sum1, sum2; |
| 805 | sum1 = firbuf[(i + ((PSY_LAME_FIR_LEN - 1) / 2)) * chans]; | 803 | sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2]; |
| 806 | sum2 = 0.0; | 804 | sum2 = 0.0; |
| 807 | for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) { | 805 | for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) { |
| 808 | sum1 += psy_fir_coeffs[j] * (firbuf[(i + j) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j) * chans]); | 806 | sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]); |
| 809 | sum2 += psy_fir_coeffs[j + 1] * (firbuf[(i + j + 1) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j - 1) * chans]); | 807 | sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]); |
| 810 | } | 808 | } |
| 811 | hpfsmpl[i] = sum1 + sum2; | 809 | /* NOTE: The LAME psymodel expects it's input in the range -32768 to 32768. Tuning this for normalized floats would be difficult. */ |
| 810 | hpfsmpl[i] = (sum1 + sum2) * 32768.0f; | ||
| 812 | } | 811 | } |
| 813 | 812 | ||
| 814 | /* Calculate the energies of each sub-shortblock */ | 813 | /* Calculate the energies of each sub-shortblock */ |
| @@ -823,16 +822,15 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, · 8 unmodified lines | |||
| 823 | float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS); | 822 | float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS); |
| 824 | float p = 1.0f; | 823 | float p = 1.0f; |
| 825 | for (; pf < pfe; pf++) | 824 | for (; pf < pfe; pf++) |
| 826 | if (p < fabsf(*pf)) | 825 | p = FFMAX(p, fabsf(*pf)); |
| 827 | p = fabsf(*pf); | ||
| 828 | pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p; | 826 | pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p; |
| 829 | energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p; | 827 | energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p; |
| 830 | /* FIXME: The indexes below are [i + 3 - 2] in the LAME source. | 828 | /* NOTE: The indexes below are [i + 3 - 2] in the LAME source. |
| 831 | * Obviously the 3 and 2 have some significance, or this would be just [i + 1] | 829 | * Obviously the 3 and 2 have some significance, or this would be just [i + 1] |
| 832 | * (which is what we use here). What the 3 stands for is ambigious, as it is both | 830 | * (which is what we use here). What the 3 stands for is ambiguous, as it is both |
| 833 | * number of short blocks, and the number of sub-short blocks. | 831 | * number of short blocks, and the number of sub-short blocks. |
| 834 | * It seems that LAME is comparing each sub-block to sub-block + 1 in the | 832 | * It seems that LAME is comparing each sub-block to sub-block + 1 in the |
| 835 | * previous block. | 833 | * previous block. |
| 836 | */ | 834 | */ |
| 837 | if (p > energy_subshort[i + 1]) | 835 | if (p > energy_subshort[i + 1]) |
| 838 | p = p / energy_subshort[i + 1]; | 836 | p = p / energy_subshort[i + 1]; |
| @@ -245,6 +245,7 @@ void avcodec_register_all(void) · 244 unmodified lines | |||
| 245 | REGISTER_DECODER (XAN_WC3, xan_wc3); | 245 | REGISTER_DECODER (XAN_WC3, xan_wc3); |
| 246 | REGISTER_DECODER (XAN_WC4, xan_wc4); | 246 | REGISTER_DECODER (XAN_WC4, xan_wc4); |
| 247 | REGISTER_DECODER (XL, xl); | 247 | REGISTER_DECODER (XL, xl); |
| 248 | REGISTER_ENCDEC (XWD, xwd); | ||
| 248 | REGISTER_ENCDEC (Y41P, y41p); | 249 | REGISTER_ENCDEC (Y41P, y41p); |
| 249 | REGISTER_DECODER (YOP, yop); | 250 | REGISTER_DECODER (YOP, yop); |
| 250 | REGISTER_ENCDEC (YUV4, yuv4); | 251 | REGISTER_ENCDEC (YUV4, yuv4); |
| @@ -255,6 +255,7 @@ enum CodecID { · 254 unmodified lines | |||
| 255 | CODEC_ID_VBLE, | 255 | CODEC_ID_VBLE, |
| 256 | CODEC_ID_DXTORY, | 256 | CODEC_ID_DXTORY, |
| 257 | CODEC_ID_V410, | 257 | CODEC_ID_V410, |
| 258 | CODEC_ID_XWD, | ||
| 258 | CODEC_ID_Y41P = MKBETAG('Y','4','1','P'), | 259 | CODEC_ID_Y41P = MKBETAG('Y','4','1','P'), |
| 259 | CODEC_ID_UTVIDEO = 0x800, | 260 | CODEC_ID_UTVIDEO = 0x800, |
| 260 | CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'), | 261 | CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'), |
| @@ -112,20 +112,15 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av · 111 unmodified lines | |||
| 112 | return ctx; | 112 | return ctx; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, | 115 | void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels) |
| 116 | const int16_t *audio, int16_t *dest, | ||
| 117 | int tag, int channels) | ||
| 118 | { | 116 | { |
| 119 | int ch, i; | 117 | int ch; |
| 118 | int frame_size = ctx->avctx->frame_size; | ||
| 119 | |||
| 120 | if (ctx->fstate) { | 120 | if (ctx->fstate) { |
| 121 | for (ch = 0; ch < channels; ch++) | 121 | for (ch = 0; ch < channels; ch++) |
| 122 | ff_iir_filter(ctx->fcoeffs, ctx->fstate[tag+ch], ctx->avctx->frame_size, | 122 | ff_iir_filter_flt(ctx->fcoeffs, ctx->fstate[ch], frame_size, |
| 123 | audio + ch, ctx->avctx->channels, | 123 | &audio[ch][frame_size], 1, &audio[ch][frame_size], 1); |
| 124 | dest + ch, ctx->avctx->channels); | ||
| 125 | } else { | ||
| 126 | for (ch = 0; ch < channels; ch++) | ||
| 127 | for (i = 0; i < ctx->avctx->frame_size; i++) | ||
| 128 | dest[i*ctx->avctx->channels + ch] = audio[i*ctx->avctx->channels + ch]; | ||
| 129 | } | 124 | } |
| 130 | } | 125 | } |
| 131 | 126 | ||
| @@ -109,7 +109,7 @@ typedef struct FFPsyModel { · 108 unmodified lines | |||
| 109 | * | 109 | * |
| 110 | * @return suggested window information in a structure | 110 | * @return suggested window information in a structure |
| 111 | */ | 111 | */ |
| 112 | FFPsyWindowInfo (*window)(FFPsyContext *ctx, const int16_t *audio, const int16_t *la, int channel, int prev_type); | 112 | FFPsyWindowInfo (*window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type); |
| 113 | 113 | ||
| 114 | /** | 114 | /** |
| 115 | * Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels. | 115 | * Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels. |
| @@ -174,14 +174,10 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av · 58 unmodified lines | |||
| 174 | * Preprocess several channel in audio frame in order to compress it better. | 174 | * Preprocess several channel in audio frame in order to compress it better. |
| 175 | * | 175 | * |
| 176 | * @param ctx preprocessing context | 176 | * @param ctx preprocessing context |
| 177 | * @param audio samples to preprocess | 177 | * @param audio samples to be filtered (in place) |
| 178 | * @param dest place to put filtered samples | 178 | * @param channels number of channel to preprocess |
| 179 | * @param tag channel number | ||
| 180 | * @param channels number of channel to preprocess (some additional work may be done on stereo pair) | ||
| 181 | */ | 179 | */ |
| 182 | void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, | 180 | void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels); |
| 183 | const int16_t *audio, int16_t *dest, | ||
| 184 | int tag, int channels); | ||
| 185 | 181 | ||
| 186 | /** | 182 | /** |
| 187 | * Cleanup audio preprocessing module. | 183 | * Cleanup audio preprocessing module. |
| @@ -918,13 +918,15 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) · 917 unmodified lines | |||
| 918 | } | 918 | } |
| 919 | goto parse_common_info; | 919 | goto parse_common_info; |
| 920 | } | 920 | } |
| 921 | if (v->finterpflag) | 921 | if (v->fcm == PROGRESSIVE) { |
| 922 | v->interpfrm = get_bits1(gb); | 922 | if (v->finterpflag) |
| 923 | if (v->s.pict_type == AV_PICTURE_TYPE_B) { | 923 | v->interpfrm = get_bits1(gb); |
| 924 | v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); | 924 | if (v->s.pict_type == AV_PICTURE_TYPE_B) { |
| 925 | v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; | 925 | v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); |
| 926 | if (v->bfraction == 0) { | 926 | v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; |
| 927 | v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */ | 927 | if (v->bfraction == 0) { |
| 928 | v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */ | ||
| 929 | } | ||
| 928 | } | 930 | } |
| 929 | } | 931 | } |
| 930 | 932 | ||
| @@ -21,8 +21,8 @@ · 20 unmodified lines | |||
| 21 | #define AVCODEC_VERSION_H | 21 | #define AVCODEC_VERSION_H |
| 22 | 22 | ||
| 23 | #define LIBAVCODEC_VERSION_MAJOR 53 | 23 | #define LIBAVCODEC_VERSION_MAJOR 53 |
| 24 | #define LIBAVCODEC_VERSION_MINOR 57 | 24 | #define LIBAVCODEC_VERSION_MINOR 58 |
| 25 | #define LIBAVCODEC_VERSION_MICRO 105 | 25 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 26 | 26 | ||
| 27 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | 27 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| 28 | LIBAVCODEC_VERSION_MINOR, \ | 28 | LIBAVCODEC_VERSION_MINOR, \ |
| @@ -0,0 +1,41 @@ | |||
| 1 | /* | ||
| 2 | * XWD image format | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012 Paul B Mahol | ||
| 5 | * | ||
| 6 | * This file is part of Libav. | ||
| 7 | * | ||
| 8 | * Libav is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * Libav is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with Libav; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #ifndef AVCODEC_XWD_H | ||
| 24 | #define AVCODEC_XWD_H | ||
| 25 | |||
| 26 | #define XWD_VERSION 7 | ||
| 27 | #define XWD_HEADER_SIZE 100 | ||
| 28 | #define XWD_CMAP_SIZE 12 | ||
| 29 | |||
| 30 | #define XWD_XY_BITMAP 0 | ||
| 31 | #define XWD_XY_PIXMAP 1 | ||
| 32 | #define XWD_Z_PIXMAP 2 | ||
| 33 | |||
| 34 | #define XWD_STATIC_GRAY 0 | ||
| 35 | #define XWD_GRAY_SCALE 1 | ||
| 36 | #define XWD_STATIC_COLOR 2 | ||
| 37 | #define XWD_PSEUDO_COLOR 3 | ||
| 38 | #define XWD_TRUE_COLOR 4 | ||
| 39 | #define XWD_DIRECT_COLOR 5 | ||
| 40 | |||
| 41 | #endif /* AVCODEC_XWD_H */ | ||
| @@ -0,0 +1,267 @@ | |||
| 1 | /* | ||
| 2 | * XWD image format | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012 Paul B Mahol | ||
| 5 | * | ||
| 6 | * This file is part of Libav. | ||
| 7 | * | ||
| 8 | * Libav is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * Libav is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with Libav; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "libavutil/imgutils.h" | ||
| 24 | #include "avcodec.h" | ||
| 25 | #include "bytestream.h" | ||
| 26 | #include "xwd.h" | ||
| 27 | |||
| 28 | static av_cold int xwd_decode_init(AVCodecContext *avctx) | ||
| 29 | { | ||
| 30 | avctx->coded_frame = avcodec_alloc_frame(); | ||
| 31 | if (!avctx->coded_frame) | ||
| 32 | return AVERROR(ENOMEM); | ||
| 33 | |||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | static int xwd_decode_frame(AVCodecContext *avctx, void *data, | ||
| 38 | int *data_size, AVPacket *avpkt) | ||
| 39 | { | ||
| 40 | AVFrame *p = avctx->coded_frame; | ||
| 41 | const uint8_t *buf = avpkt->data; | ||
| 42 | int i, ret, buf_size = avpkt->size; | ||
| 43 | uint32_t version, header_size, vclass, ncolors; | ||
| 44 | uint32_t xoffset, be, bpp, lsize, rsize; | ||
| 45 | uint32_t pixformat, pixdepth, bunit, bitorder, bpad; | ||
| 46 | uint32_t rgb[3]; | ||
| 47 | uint8_t *ptr; | ||
| 48 | |||
| 49 | if (buf_size < XWD_HEADER_SIZE) | ||
| 50 | return AVERROR_INVALIDDATA; | ||
| 51 | |||
| 52 | header_size = bytestream_get_be32(&buf); | ||
| 53 | if (buf_size < header_size) | ||
| 54 | return AVERROR_INVALIDDATA; | ||
| 55 | |||
| 56 | version = bytestream_get_be32(&buf); | ||
| 57 | if (version != XWD_VERSION) { | ||
| 58 | av_log(avctx, AV_LOG_ERROR, "unsupported version\n"); | ||
| 59 | return AVERROR_INVALIDDATA; | ||
| 60 | } | ||
| 61 | |||
| 62 | if (header_size < XWD_HEADER_SIZE) { | ||
| 63 | av_log(avctx, AV_LOG_ERROR, "invalid header size\n"); | ||
| 64 | return AVERROR_INVALIDDATA; | ||
| 65 | } | ||
| 66 | |||
| 67 | pixformat = bytestream_get_be32(&buf); | ||
| 68 | pixdepth = bytestream_get_be32(&buf); | ||
| 69 | avctx->width = bytestream_get_be32(&buf); | ||
| 70 | avctx->height = bytestream_get_be32(&buf); | ||
| 71 | xoffset = bytestream_get_be32(&buf); | ||
| 72 | be = bytestream_get_be32(&buf); | ||
| 73 | bunit = bytestream_get_be32(&buf); | ||
| 74 | bitorder = bytestream_get_be32(&buf); | ||
| 75 | bpad = bytestream_get_be32(&buf); | ||
| 76 | bpp = bytestream_get_be32(&buf); | ||
| 77 | lsize = bytestream_get_be32(&buf); | ||
| 78 | vclass = bytestream_get_be32(&buf); | ||
| 79 | rgb[0] = bytestream_get_be32(&buf); | ||
| 80 | rgb[1] = bytestream_get_be32(&buf); | ||
| 81 | rgb[2] = bytestream_get_be32(&buf); | ||
| 82 | buf += 8; | ||
| 83 | ncolors = bytestream_get_be32(&buf); | ||
| 84 | buf += header_size - (XWD_HEADER_SIZE - 20); | ||
| 85 | |||
| 86 | av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n", | ||
| 87 | pixformat, pixdepth, bunit, bitorder, bpad); | ||
| 88 | av_log(avctx, AV_LOG_DEBUG, "vclass %d, ncolors %d, bpp %d, be %d, lsize %d, xoffset %d\n", | ||
| 89 | vclass, ncolors, bpp, be, lsize, xoffset); | ||
| 90 | av_log(avctx, AV_LOG_DEBUG, "red %0x, green %0x, blue %0x\n", rgb[0], rgb[1], rgb[2]); | ||
| 91 | |||
| 92 | if (pixformat > XWD_Z_PIXMAP) { | ||
| 93 | av_log(avctx, AV_LOG_ERROR, "invalid pixmap format\n"); | ||
| 94 | return AVERROR_INVALIDDATA; | ||
| 95 | } | ||
| 96 | |||
| 97 | if (pixdepth == 0 || pixdepth > 32) { | ||
| 98 | av_log(avctx, AV_LOG_ERROR, "invalid pixmap depth\n"); | ||
| 99 | return AVERROR_INVALIDDATA; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (xoffset) { | ||
| 103 | av_log_ask_for_sample(avctx, "unsupported xoffset %d\n", xoffset); | ||
| 104 | return AVERROR_PATCHWELCOME; | ||
| 105 | } | ||
| 106 | |||
| 107 | if (be > 1) { | ||
| 108 | av_log(avctx, AV_LOG_ERROR, "invalid byte order\n"); | ||
| 109 | return AVERROR_INVALIDDATA; | ||
| 110 | } | ||
| 111 | |||
| 112 | if (bitorder > 1) { | ||
| 113 | av_log(avctx, AV_LOG_ERROR, "invalid bitmap bit order\n"); | ||
| 114 | return AVERROR_INVALIDDATA; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (bunit != 8 && bunit != 16 && bunit != 32) { | ||
| 118 | av_log(avctx, AV_LOG_ERROR, "invalid bitmap unit\n"); | ||
| 119 | return AVERROR_INVALIDDATA; | ||
| 120 | } | ||
| 121 | |||
| 122 | if (bpad != 8 && bpad != 16 && bpad != 32) { | ||
| 123 | av_log(avctx, AV_LOG_ERROR, "invalid bitmap scan-line pad\n"); | ||
| 124 | return AVERROR_INVALIDDATA; | ||
| 125 | } | ||
| 126 | |||
| 127 | if (bpp == 0 || bpp > 32) { | ||
| 128 | av_log(avctx, AV_LOG_ERROR, "invalid bits per pixel\n"); | ||
| 129 | return AVERROR_INVALIDDATA; | ||
| 130 | } | ||
| 131 | |||
| 132 | if (ncolors > 256) { | ||
| 133 | av_log(avctx, AV_LOG_ERROR, "invalid number of entries in colormap\n"); | ||
| 134 | return AVERROR_INVALIDDATA; | ||
| 135 | } | ||
| 136 | |||
| 137 | if ((ret = av_image_check_size(avctx->width, avctx->height, 0, NULL)) < 0) | ||
| 138 | return ret; | ||
| 139 | |||
| 140 | rsize = FFALIGN(avctx->width * bpp, bpad) / 8; | ||
| 141 | if (lsize < rsize) { | ||
| 142 | av_log(avctx, AV_LOG_ERROR, "invalid bytes per scan-line\n"); | ||
| 143 | return AVERROR_INVALIDDATA; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (buf_size < header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize) { | ||
| 147 | av_log(avctx, AV_LOG_ERROR, "input buffer too small\n"); | ||
| 148 | return AVERROR_INVALIDDATA; | ||
| 149 | } | ||
| 150 | |||
| 151 | if (pixformat != XWD_Z_PIXMAP) { | ||
| 152 | av_log(avctx, AV_LOG_ERROR, "pixmap format %d unsupported\n", pixformat); | ||
| 153 | return AVERROR_PATCHWELCOME; | ||
| 154 | } | ||
| 155 | |||
| 156 | avctx->pix_fmt = PIX_FMT_NONE; | ||
| 157 | switch (vclass) { | ||
| 158 | case XWD_STATIC_GRAY: | ||
| 159 | case XWD_GRAY_SCALE: | ||
| 160 | if (bpp != 1) | ||
| 161 | return AVERROR_INVALIDDATA; | ||
| 162 | if (pixdepth == 1) | ||
| 163 | avctx->pix_fmt = PIX_FMT_MONOWHITE; | ||
| 164 | break; | ||
| 165 | case XWD_STATIC_COLOR: | ||
| 166 | case XWD_PSEUDO_COLOR: | ||
| 167 | if (bpp == 8) | ||
| 168 | avctx->pix_fmt = PIX_FMT_PAL8; | ||
| 169 | break; | ||
| 170 | case XWD_TRUE_COLOR: | ||
| 171 | case XWD_DIRECT_COLOR: | ||
| 172 | if (bpp != 16 && bpp != 24 && bpp != 32) | ||
| 173 | return AVERROR_INVALIDDATA; | ||
| 174 | if (bpp == 16 && pixdepth == 15) { | ||
| 175 | if (rgb[0] == 0x7C00 && rgb[1] == 0x3E0 && rgb[2] == 0x1F) | ||
| 176 | avctx->pix_fmt = be ? PIX_FMT_RGB555BE : PIX_FMT_RGB555LE; | ||
| 177 | else if (rgb[0] == 0x1F && rgb[1] == 0x3E0 && rgb[2] == 0x7C00) | ||
| 178 | avctx->pix_fmt = be ? PIX_FMT_BGR555BE : PIX_FMT_BGR555LE; | ||
| 179 | } else if (bpp == 16 && pixdepth == 16) { | ||
| 180 | if (rgb[0] == 0xF800 && rgb[1] == 0x7E0 && rgb[2] == 0x1F) | ||
| 181 | avctx->pix_fmt = be ? PIX_FMT_RGB565BE : PIX_FMT_RGB565LE; | ||
| 182 | else if (rgb[0] == 0x1F && rgb[1] == 0x7E0 && rgb[2] == 0xF800) | ||
| 183 | avctx->pix_fmt = be ? PIX_FMT_BGR565BE : PIX_FMT_BGR565LE; | ||
| 184 | } else if (bpp == 24) { | ||
| 185 | if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF) | ||
| 186 | avctx->pix_fmt = be ? PIX_FMT_RGB24 : PIX_FMT_BGR24; | ||
| 187 | else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000) | ||
| 188 | avctx->pix_fmt = be ? PIX_FMT_BGR24 : PIX_FMT_RGB24; | ||
| 189 | } else if (bpp == 32) { | ||
| 190 | if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF) | ||
| 191 | avctx->pix_fmt = be ? PIX_FMT_ARGB : PIX_FMT_BGRA; | ||
| 192 | else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000) | ||
| 193 | avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA; | ||
| 194 | } | ||
| 195 | buf += ncolors * XWD_CMAP_SIZE; | ||
| 196 | break; | ||
| 197 | default: | ||
| 198 | av_log(avctx, AV_LOG_ERROR, "invalid visual class\n"); | ||
| 199 | return AVERROR_INVALIDDATA; | ||
| 200 | } | ||
| 201 | |||
| 202 | if (avctx->pix_fmt == PIX_FMT_NONE) { | ||
| 203 | av_log_ask_for_sample(avctx, "unknown file: bpp %d, pixdepth %d, vclass %d\n", bpp, pixdepth, vclass); | ||
| 204 | return AVERROR_PATCHWELCOME; | ||
| 205 | } | ||
| 206 | |||
| 207 | if (p->data[0]) | ||
| 208 | avctx->release_buffer(avctx, p); | ||
| 209 | |||
| 210 | p->reference = 0; | ||
| 211 | if ((ret = avctx->get_buffer(avctx, p)) < 0) { | ||
| 212 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | ||
| 213 | return ret; | ||
| 214 | } | ||
| 215 | |||
| 216 | p->key_frame = 1; | ||
| 217 | p->pict_type = AV_PICTURE_TYPE_I; | ||
| 218 | |||
| 219 | if (avctx->pix_fmt == PIX_FMT_PAL8) { | ||
| 220 | uint32_t *dst = (uint32_t *)p->data[1]; | ||
| 221 | uint8_t red, green, blue; | ||
| 222 | |||
| 223 | for (i = 0; i < ncolors; i++) { | ||
| 224 | |||
| 225 | buf += 4; // skip colormap entry number | ||
| 226 | red = *buf; buf += 2; | ||
| 227 | green = *buf; buf += 2; | ||
| 228 | blue = *buf; buf += 2; | ||
| 229 | buf += 2; // skip bitmask flag and padding | ||
| 230 | |||
| 231 | dst[i] = red << 16 | green << 8 | blue; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | ptr = p->data[0]; | ||
| 236 | for (i = 0; i < avctx->height; i++) { | ||
| 237 | bytestream_get_buffer(&buf, ptr, rsize); | ||
| 238 | buf += lsize - rsize; | ||
| 239 | ptr += p->linesize[0]; | ||
| 240 | } | ||
| 241 | |||
| 242 | *data_size = sizeof(AVFrame); | ||
| 243 | *(AVFrame *)data = *p; | ||
| 244 | |||
| 245 | return buf_size; | ||
| 246 | } | ||
| 247 | |||
| 248 | static av_cold int xwd_decode_close(AVCodecContext *avctx) | ||
| 249 | { | ||
| 250 | if (avctx->coded_frame->data[0]) | ||
| 251 | avctx->release_buffer(avctx, avctx->coded_frame); | ||
| 252 | |||
| 253 | av_freep(&avctx->coded_frame); | ||
| 254 | |||
| 255 | return 0; | ||
| 256 | } | ||
| 257 | |||
| 258 | AVCodec ff_xwd_decoder = { | ||
| 259 | .name = "xwd", | ||
| 260 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 261 | .id = CODEC_ID_XWD, | ||
| 262 | .init = xwd_decode_init, | ||
| 263 | .close = xwd_decode_close, | ||
| 264 | .decode = xwd_decode_frame, | ||
| 265 | .capabilities = CODEC_CAP_DR1, | ||
| 266 | .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"), | ||
| 267 | }; | ||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* | ||
| 2 | * XWD image format | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012 Paul B Mahol | ||
| 5 | * | ||
| 6 | * This file is part of Libav. | ||
| 7 | * | ||
| 8 | * Libav is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * Libav is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with Libav; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "libavutil/intreadwrite.h" | ||
| 24 | #include "libavutil/pixdesc.h" | ||
| 25 | #include "avcodec.h" | ||
| 26 | #include "bytestream.h" | ||
| 27 | #include "xwd.h" | ||
| 28 | |||
| 29 | #define WINDOW_NAME "lavcxwdenc" | ||
| 30 | #define WINDOW_NAME_SIZE 11 | ||
| 31 | |||
| 32 | static av_cold int xwd_encode_init(AVCodecContext *avctx) | ||
| 33 | { | ||
| 34 | avctx->coded_frame = avcodec_alloc_frame(); | ||
| 35 | if (!avctx->coded_frame) | ||
| 36 | return AVERROR(ENOMEM); | ||
| 37 | |||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf, | ||
| 42 | int buf_size, void *data) | ||
| 43 | { | ||
| 44 | AVFrame *p = data; | ||
| 45 | enum PixelFormat pix_fmt = avctx->pix_fmt; | ||
| 46 | uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; | ||
| 47 | uint32_t rgb[3] = { 0 }; | ||
| 48 | uint32_t header_size; | ||
| 49 | int i, out_size; | ||
| 50 | uint8_t *ptr; | ||
| 51 | |||
| 52 | pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]); | ||
| 53 | if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE) | ||
| 54 | be = 1; | ||
| 55 | switch (pix_fmt) { | ||
| 56 | case PIX_FMT_ARGB: | ||
| 57 | case PIX_FMT_BGRA: | ||
| 58 | case PIX_FMT_RGBA: | ||
| 59 | case PIX_FMT_ABGR: | ||
| 60 | if (pix_fmt == PIX_FMT_ARGB || | ||
| 61 | pix_fmt == PIX_FMT_ABGR) | ||
| 62 | be = 1; | ||
| 63 | if (pix_fmt == PIX_FMT_ABGR || | ||
| 64 | pix_fmt == PIX_FMT_RGBA) { | ||
| 65 | rgb[0] = 0xFF; | ||
| 66 | rgb[1] = 0xFF00; | ||
| 67 | rgb[2] = 0xFF0000; | ||
| 68 | } else { | ||
| 69 | rgb[0] = 0xFF0000; | ||
| 70 | rgb[1] = 0xFF00; | ||
| 71 | rgb[2] = 0xFF; | ||
| 72 | } | ||
| 73 | bpp = 32; | ||
| 74 | pixdepth = 24; | ||
| 75 | vclass = XWD_TRUE_COLOR; | ||
| 76 | bpad = 32; | ||
| 77 | break; | ||
| 78 | case PIX_FMT_BGR24: | ||
| 79 | case PIX_FMT_RGB24: | ||
| 80 | if (pix_fmt == PIX_FMT_RGB24) | ||
| 81 | be = 1; | ||
| 82 | bpp = 24; | ||
| 83 | vclass = XWD_TRUE_COLOR; | ||
| 84 | bpad = 32; | ||
| 85 | rgb[0] = 0xFF0000; | ||
| 86 | rgb[1] = 0xFF00; | ||
| 87 | rgb[2] = 0xFF; | ||
| 88 | break; | ||
| 89 | case PIX_FMT_RGB565LE: | ||
| 90 | case PIX_FMT_RGB565BE: | ||
| 91 | case PIX_FMT_BGR565LE: | ||
| 92 | case PIX_FMT_BGR565BE: | ||
| 93 | if (pix_fmt == PIX_FMT_BGR565LE || | ||
| 94 | pix_fmt == PIX_FMT_BGR565BE) { | ||
| 95 | rgb[0] = 0x1F; | ||
| 96 | rgb[1] = 0x7E0; | ||
| 97 | rgb[2] = 0xF800; | ||
| 98 | } else { | ||
| 99 | rgb[0] = 0xF800; | ||
| 100 | rgb[1] = 0x7E0; | ||
| 101 | rgb[2] = 0x1F; | ||
| 102 | } | ||
| 103 | bpp = 16; | ||
| 104 | vclass = XWD_TRUE_COLOR; | ||
| 105 | bpad = 16; | ||
| 106 | break; | ||
| 107 | case PIX_FMT_RGB555LE: | ||
| 108 | case PIX_FMT_RGB555BE: | ||
| 109 | case PIX_FMT_BGR555LE: | ||
| 110 | case PIX_FMT_BGR555BE: | ||
| 111 | if (pix_fmt == PIX_FMT_BGR555LE || | ||
| 112 | pix_fmt == PIX_FMT_BGR555BE) { | ||
| 113 | rgb[0] = 0x1F; | ||
| 114 | rgb[1] = 0x3E0; | ||
| 115 | rgb[2] = 0x7C00; | ||
| 116 | } else { | ||
| 117 | rgb[0] = 0x7C00; | ||
| 118 | rgb[1] = 0x3E0; | ||
| 119 | rgb[2] = 0x1F; | ||
| 120 | } | ||
| 121 | bpp = 16; | ||
| 122 | vclass = XWD_TRUE_COLOR; | ||
| 123 | bpad = 16; | ||
| 124 | break; | ||
| 125 | case PIX_FMT_RGB8: | ||
| 126 | case PIX_FMT_BGR8: | ||
| 127 | case PIX_FMT_RGB4_BYTE: | ||
| 128 | case PIX_FMT_BGR4_BYTE: | ||
| 129 | case PIX_FMT_PAL8: | ||
| 130 | bpp = 8; | ||
| 131 | vclass = XWD_PSEUDO_COLOR; | ||
| 132 | bpad = 8; | ||
| 133 | ncolors = 256; | ||
| 134 | break; | ||
| 135 | case PIX_FMT_MONOWHITE: | ||
| 136 | bpp = 1; | ||
| 137 | bpad = 8; | ||
| 138 | vclass = XWD_STATIC_GRAY; | ||
| 139 | break; | ||
| 140 | default: | ||
| 141 | av_log(avctx, AV_LOG_INFO, "unsupported pixel format\n"); | ||
| 142 | return AVERROR(EINVAL); | ||
| 143 | } | ||
| 144 | |||
| 145 | lsize = FFALIGN(bpp * avctx->width, bpad) / 8; | ||
| 146 | header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE; | ||
| 147 | out_size = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize; | ||
| 148 | |||
| 149 | if (buf_size < out_size) { | ||
| 150 | av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); | ||
| 151 | return AVERROR(ENOMEM); | ||
| 152 | } | ||
| 153 | |||
| 154 | avctx->coded_frame->key_frame = 1; | ||
| 155 | avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; | ||
| 156 | |||
| 157 | bytestream_put_be32(&buf, header_size); | ||
| 158 | bytestream_put_be32(&buf, XWD_VERSION); // file version | ||
| 159 | bytestream_put_be32(&buf, XWD_Z_PIXMAP); // pixmap format | ||
| 160 | bytestream_put_be32(&buf, pixdepth); // pixmap depth in pixels | ||
| 161 | bytestream_put_be32(&buf, avctx->width); // pixmap width in pixels | ||
| 162 | bytestream_put_be32(&buf, avctx->height); // pixmap height in pixels | ||
| 163 | bytestream_put_be32(&buf, 0); // bitmap x offset | ||
| 164 | bytestream_put_be32(&buf, be); // byte order | ||
| 165 | bytestream_put_be32(&buf, 32); // bitmap unit | ||
| 166 | bytestream_put_be32(&buf, be); // bit-order of image data | ||
| 167 | bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits | ||
| 168 | bytestream_put_be32(&buf, bpp); // bits per pixel | ||
| 169 | bytestream_put_be32(&buf, lsize); // bytes per scan-line | ||
| 170 | bytestream_put_be32(&buf, vclass); // visual class | ||
| 171 | bytestream_put_be32(&buf, rgb[0]); // red mask | ||
| 172 | bytestream_put_be32(&buf, rgb[1]); // green mask | ||
| 173 | bytestream_put_be32(&buf, rgb[2]); // blue mask | ||
| 174 | bytestream_put_be32(&buf, 8); // size of each bitmask in bits | ||
| 175 | bytestream_put_be32(&buf, ncolors); // number of colors | ||
| 176 | bytestream_put_be32(&buf, ncolors); // number of entries in color map | ||
| 177 | bytestream_put_be32(&buf, avctx->width); // window width | ||
| 178 | bytestream_put_be32(&buf, avctx->height); // window height | ||
| 179 | bytestream_put_be32(&buf, 0); // window upper left X coordinate | ||
| 180 | bytestream_put_be32(&buf, 0); // window upper left Y coordinate | ||
| 181 | bytestream_put_be32(&buf, 0); // window border width | ||
| 182 | bytestream_put_buffer(&buf, WINDOW_NAME, WINDOW_NAME_SIZE); | ||
| 183 | |||
| 184 | for (i = 0; i < ncolors; i++) { | ||
| 185 | uint32_t val; | ||
| 186 | uint8_t red, green, blue; | ||
| 187 | |||
| 188 | val = AV_RN32A(p->data[1] + i * 4); | ||
| 189 | red = (val >> 16) & 0xFF; | ||
| 190 | green = (val >> 8) & 0xFF; | ||
| 191 | blue = val & 0xFF; | ||
| 192 | |||
| 193 | bytestream_put_be32(&buf, i); // colormap entry number | ||
| 194 | bytestream_put_be16(&buf, red << 8); | ||
| 195 | bytestream_put_be16(&buf, green << 8); | ||
| 196 | bytestream_put_be16(&buf, blue << 8); | ||
| 197 | bytestream_put_byte(&buf, 0x7); // bitmask flag | ||
| 198 | bytestream_put_byte(&buf, 0); // padding | ||
| 199 | } | ||
| 200 | |||
| 201 | ptr = p->data[0]; | ||
| 202 | for (i = 0; i < avctx->height; i++) { | ||
| 203 | bytestream_put_buffer(&buf, ptr, lsize); | ||
| 204 | ptr += p->linesize[0]; | ||
| 205 | } | ||
| 206 | |||
| 207 | return out_size; | ||
| 208 | } | ||
| 209 | |||
| 210 | static av_cold int xwd_encode_close(AVCodecContext *avctx) | ||
| 211 | { | ||
| 212 | av_freep(&avctx->coded_frame); | ||
| 213 | |||
| 214 | return 0; | ||
| 215 | } | ||
| 216 | |||
| 217 | AVCodec ff_xwd_encoder = { | ||
| 218 | .name = "xwd", | ||
| 219 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 220 | .id = CODEC_ID_XWD, | ||
| 221 | .init = xwd_encode_init, | ||
| 222 | .encode = xwd_encode_frame, | ||
| 223 | .close = xwd_encode_close, | ||
| 224 | .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGRA, | ||
| 225 | PIX_FMT_RGBA, | ||
| 226 | PIX_FMT_ARGB, | ||
| 227 | PIX_FMT_ABGR, | ||
| 228 | PIX_FMT_RGB24, | ||
| 229 | PIX_FMT_BGR24, | ||
| 230 | PIX_FMT_RGB565BE, | ||
| 231 | PIX_FMT_RGB565LE, | ||
| 232 | PIX_FMT_BGR565BE, | ||
| 233 | PIX_FMT_BGR565LE, | ||
| 234 | PIX_FMT_RGB555BE, | ||
| 235 | PIX_FMT_RGB555LE, | ||
| 236 | PIX_FMT_BGR555BE, | ||
| 237 | PIX_FMT_BGR555LE, | ||
| 238 | PIX_FMT_RGB8, | ||
| 239 | PIX_FMT_BGR8, | ||
| 240 | PIX_FMT_RGB4_BYTE, | ||
| 241 | PIX_FMT_BGR4_BYTE, | ||
| 242 | PIX_FMT_PAL8, | ||
| 243 | PIX_FMT_MONOWHITE, | ||
| 244 | PIX_FMT_NONE }, | ||
| 245 | .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"), | ||
| 246 | }; | ||
| @@ -326,8 +326,8 @@ OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o · 325 unmodified lines | |||
| 326 | OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \ | 326 | OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \ |
| 327 | riff.o isom.o avc.o \ | 327 | riff.o isom.o avc.o \ |
| 328 | flacenc_header.o avlanguage.o | 328 | flacenc_header.o avlanguage.o |
| 329 | OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o | 329 | OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o |
| 330 | OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o | 330 | OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o |
| 331 | OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcrypt.o \ | 331 | OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcrypt.o \ |
| 332 | avlanguage.o mpegts.o isom.o riff.o | 332 | avlanguage.o mpegts.o isom.o riff.o |
| 333 | OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o riff.o | 333 | OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o riff.o |
| @@ -91,6 +91,7 @@ static const IdStrMap img_tags[] = { · 90 unmodified lines | |||
| 91 | { CODEC_ID_JPEG2000 , "jpc"}, | 91 | { CODEC_ID_JPEG2000 , "jpc"}, |
| 92 | { CODEC_ID_DPX , "dpx"}, | 92 | { CODEC_ID_DPX , "dpx"}, |
| 93 | { CODEC_ID_PICTOR , "pic"}, | 93 | { CODEC_ID_PICTOR , "pic"}, |
| 94 | { CODEC_ID_XWD , "xwd"}, | ||
| 94 | { CODEC_ID_NONE , NULL} | 95 | { CODEC_ID_NONE , NULL} |
| 95 | }; | 96 | }; |
| 96 | 97 | ||
| @@ -528,7 +529,7 @@ AVOutputFormat ff_image2_muxer = { · 431 unmodified lines | |||
| 528 | .name = "image2", | 529 | .name = "image2", |
| 529 | .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), | 530 | .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), |
| 530 | .extensions = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," | 531 | .extensions = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," |
| 531 | "ppm,sgi,tga,tif,tiff,jp2,j2c", | 532 | "ppm,sgi,tga,tif,tiff,jp2,j2c,xwd", |
| 532 | .priv_data_size = sizeof(VideoData), | 533 | .priv_data_size = sizeof(VideoData), |
| 533 | .video_codec = CODEC_ID_MJPEG, | 534 | .video_codec = CODEC_ID_MJPEG, |
| 534 | .write_header = write_header, | 535 | .write_header = write_header, |
| @@ -0,0 +1,173 @@ | |||
| 1 | /* | ||
| 2 | * Westwood Studios AUD Format Demuxer | ||
| 3 | * Copyright (c) 2003 The ffmpeg Project | ||
| 4 | * | ||
| 5 | * This file is part of Libav. | ||
| 6 | * | ||
| 7 | * Libav is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * Libav is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with Libav; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * Westwood Studios AUD file demuxer | ||
| 25 | * by Mike Melanson (melanson@pcisys.net) | ||
| 26 | * for more information on the Westwood file formats, visit: | ||
| 27 | * http://www.pcisys.net/~melanson/codecs/ | ||
| 28 | * http://www.geocities.com/SiliconValley/8682/aud3.txt | ||
| 29 | * | ||
| 30 | * Implementation note: There is no definite file signature for AUD files. | ||
| 31 | * The demuxer uses a probabilistic strategy for content detection. This | ||
| 32 | * entails performing sanity checks on certain header values in order to | ||
| 33 | * qualify a file. Refer to wsaud_probe() for the precise parameters. | ||
| 34 | */ | ||
| 35 | |||
| 36 | #include "libavutil/intreadwrite.h" | ||
| 37 | #include "avformat.h" | ||
| 38 | #include "internal.h" | ||
| 39 | |||
| 40 | #define AUD_HEADER_SIZE 12 | ||
| 41 | #define AUD_CHUNK_PREAMBLE_SIZE 8 | ||
| 42 | #define AUD_CHUNK_SIGNATURE 0x0000DEAF | ||
| 43 | |||
| 44 | typedef struct WsAudDemuxContext { | ||
| 45 | int audio_samplerate; | ||
| 46 | int audio_channels; | ||
| 47 | int audio_bits; | ||
| 48 | enum CodecID audio_type; | ||
| 49 | int audio_stream_index; | ||
| 50 | int64_t audio_frame_counter; | ||
| 51 | } WsAudDemuxContext; | ||
| 52 | |||
| 53 | static int wsaud_probe(AVProbeData *p) | ||
| 54 | { | ||
| 55 | int field; | ||
| 56 | |||
| 57 | /* Probabilistic content detection strategy: There is no file signature | ||
| 58 | * so perform sanity checks on various header parameters: | ||
| 59 | * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers | ||
| 60 | * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers | ||
| 61 | * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers | ||
| 62 | * first audio chunk signature (32 bits) ==> 1 acceptable number | ||
| 63 | * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 = | ||
| 64 | * 320008 acceptable number combinations. | ||
| 65 | */ | ||
| 66 | |||
| 67 | if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE) | ||
| 68 | return 0; | ||
| 69 | |||
| 70 | /* check sample rate */ | ||
| 71 | field = AV_RL16(&p->buf[0]); | ||
| 72 | if ((field < 8000) || (field > 48000)) | ||
| 73 | return 0; | ||
| 74 | |||
| 75 | /* enforce the rule that the top 6 bits of this flags field are reserved (0); | ||
| 76 | * this might not be true, but enforce it until deemed unnecessary */ | ||
| 77 | if (p->buf[10] & 0xFC) | ||
| 78 | return 0; | ||
| 79 | |||
| 80 | /* note: only check for WS IMA (type 99) right now since there is no | ||
| 81 | * support for type 1 */ | ||
| 82 | if (p->buf[11] != 99) | ||
| 83 | return 0; | ||
| 84 | |||
| 85 | /* read ahead to the first audio chunk and validate the first header signature */ | ||
| 86 | if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE) | ||
| 87 | return 0; | ||
| 88 | |||
| 89 | /* return 1/2 certainty since this file check is a little sketchy */ | ||
| 90 | return AVPROBE_SCORE_MAX / 2; | ||
| 91 | } | ||
| 92 | |||
| 93 | static int wsaud_read_header(AVFormatContext *s, | ||
| 94 | AVFormatParameters *ap) | ||
| 95 | { | ||
| 96 | WsAudDemuxContext *wsaud = s->priv_data; | ||
| 97 | AVIOContext *pb = s->pb; | ||
| 98 | AVStream *st; | ||
| 99 | unsigned char header[AUD_HEADER_SIZE]; | ||
| 100 | |||
| 101 | if (avio_read(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) | ||
| 102 | return AVERROR(EIO); | ||
| 103 | wsaud->audio_samplerate = AV_RL16(&header[0]); | ||
| 104 | if (header[11] == 99) | ||
| 105 | wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS; | ||
| 106 | else | ||
| 107 | return AVERROR_INVALIDDATA; | ||
| 108 | |||
| 109 | /* flag 0 indicates stereo */ | ||
| 110 | wsaud->audio_channels = (header[10] & 0x1) + 1; | ||
| 111 | /* flag 1 indicates 16 bit audio */ | ||
| 112 | wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8; | ||
| 113 | |||
| 114 | /* initialize the audio decoder stream */ | ||
| 115 | st = avformat_new_stream(s, NULL); | ||
| 116 | if (!st) | ||
| 117 | return AVERROR(ENOMEM); | ||
| 118 | avpriv_set_pts_info(st, 33, 1, wsaud->audio_samplerate); | ||
| 119 | st->codec->codec_type = AVMEDIA_TYPE_AUDIO; | ||
| 120 | st->codec->codec_id = wsaud->audio_type; | ||
| 121 | st->codec->codec_tag = 0; /* no tag */ | ||
| 122 | st->codec->channels = wsaud->audio_channels; | ||
| 123 | st->codec->sample_rate = wsaud->audio_samplerate; | ||
| 124 | st->codec->bits_per_coded_sample = wsaud->audio_bits; | ||
| 125 | st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * | ||
| 126 | st->codec->bits_per_coded_sample / 4; | ||
| 127 | st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; | ||
| 128 | |||
| 129 | wsaud->audio_stream_index = st->index; | ||
| 130 | wsaud->audio_frame_counter = 0; | ||
| 131 | |||
| 132 | return 0; | ||
| 133 | } | ||
| 134 | |||
| 135 | static int wsaud_read_packet(AVFormatContext *s, | ||
| 136 | AVPacket *pkt) | ||
| 137 | { | ||
| 138 | WsAudDemuxContext *wsaud = s->priv_data; | ||
| 139 | AVIOContext *pb = s->pb; | ||
| 140 | unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; | ||
| 141 | unsigned int chunk_size; | ||
| 142 | int ret = 0; | ||
| 143 | |||
| 144 | if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != | ||
| 145 | AUD_CHUNK_PREAMBLE_SIZE) | ||
| 146 | return AVERROR(EIO); | ||
| 147 | |||
| 148 | /* validate the chunk */ | ||
| 149 | if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) | ||
| 150 | return AVERROR_INVALIDDATA; | ||
| 151 | |||
| 152 | chunk_size = AV_RL16(&preamble[0]); | ||
| 153 | ret= av_get_packet(pb, pkt, chunk_size); | ||
| 154 | if (ret != chunk_size) | ||
| 155 | return AVERROR(EIO); | ||
| 156 | pkt->stream_index = wsaud->audio_stream_index; | ||
| 157 | pkt->pts = wsaud->audio_frame_counter; | ||
| 158 | pkt->pts /= wsaud->audio_samplerate; | ||
| 159 | |||
| 160 | /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ | ||
| 161 | wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels; | ||
| 162 | |||
| 163 | return ret; | ||
| 164 | } | ||
| 165 | |||
| 166 | AVInputFormat ff_wsaud_demuxer = { | ||
| 167 | .name = "wsaud", | ||
| 168 | .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"), | ||
| 169 | .priv_data_size = sizeof(WsAudDemuxContext), | ||
| 170 | .read_probe = wsaud_probe, | ||
| 171 | .read_header = wsaud_read_header, | ||
| 172 | .read_packet = wsaud_read_packet, | ||
| 173 | }; | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Westwood Studios Multimedia Formats Demuxer (VQA, AUD) | 2 | * Westwood Studios VQA Format Demuxer |
| 3 | * Copyright (c) 2003 The ffmpeg Project | 3 | * Copyright (c) 2003 The ffmpeg Project |
| 4 | * | 4 | * |
| 5 | * This file is part of FFmpeg. | 5 | * This file is part of FFmpeg. |
| @@ -21,26 +21,17 @@ · 15 unmodified lines | |||
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * @file | 23 | * @file |
| 24 | * Westwood Studios VQA & AUD file demuxers | 24 | * Westwood Studios VQA file demuxer |
| 25 | * by Mike Melanson (melanson@pcisys.net) | 25 | * by Mike Melanson (melanson@pcisys.net) |
| 26 | * for more information on the Westwood file formats, visit: | 26 | * for more information on the Westwood file formats, visit: |
| 27 | * http://www.pcisys.net/~melanson/codecs/ | 27 | * http://www.pcisys.net/~melanson/codecs/ |
| 28 | * http://www.geocities.com/SiliconValley/8682/aud3.txt | 28 | * http://www.geocities.com/SiliconValley/8682/aud3.txt |
| 29 | * | ||
| 30 | * Implementation note: There is no definite file signature for AUD files. | ||
| 31 | * The demuxer uses a probabilistic strategy for content detection. This | ||
| 32 | * entails performing sanity checks on certain header values in order to | ||
| 33 | * qualify a file. Refer to wsaud_probe() for the precise parameters. | ||
| 34 | */ | 29 | */ |
| 35 | 30 | ||
| 36 | #include "libavutil/intreadwrite.h" | 31 | #include "libavutil/intreadwrite.h" |
| 37 | #include "avformat.h" | 32 | #include "avformat.h" |
| 38 | #include "internal.h" | 33 | #include "internal.h" |
| 39 | 34 | ||
| 40 | #define AUD_HEADER_SIZE 12 | ||
| 41 | #define AUD_CHUNK_PREAMBLE_SIZE 8 | ||
| 42 | #define AUD_CHUNK_SIGNATURE 0x0000DEAF | ||
| 43 | |||
| 44 | #define FORM_TAG MKBETAG('F', 'O', 'R', 'M') | 35 | #define FORM_TAG MKBETAG('F', 'O', 'R', 'M') |
| 45 | #define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A') | 36 | #define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A') |
| 46 | #define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D') | 37 | #define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D') |
| @@ -63,15 +54,6 @@ · 16 unmodified lines | |||
| 63 | #define VQA_FRAMERATE 15 | 54 | #define VQA_FRAMERATE 15 |
| 64 | #define VQA_PREAMBLE_SIZE 8 | 55 | #define VQA_PREAMBLE_SIZE 8 |
| 65 | 56 | ||
| 66 | typedef struct WsAudDemuxContext { | ||
| 67 | int audio_samplerate; | ||
| 68 | int audio_channels; | ||
| 69 | int audio_bits; | ||
| 70 | enum CodecID audio_type; | ||
| 71 | int audio_stream_index; | ||
| 72 | int64_t audio_frame_counter; | ||
| 73 | } WsAudDemuxContext; | ||
| 74 | |||
| 75 | typedef struct WsVqaDemuxContext { | 57 | typedef struct WsVqaDemuxContext { |
| 76 | int audio_samplerate; | 58 | int audio_samplerate; |
| 77 | int audio_channels; | 59 | int audio_channels; |
| @@ -83,119 +65,6 @@ typedef struct WsVqaDemuxContext { · 5 unmodified lines | |||
| 83 | int64_t audio_frame_counter; | 65 | int64_t audio_frame_counter; |
| 84 | } WsVqaDemuxContext; | 66 | } WsVqaDemuxContext; |
| 85 | 67 | ||
| 86 | static int wsaud_probe(AVProbeData *p) | ||
| 87 | { | ||
| 88 | int field; | ||
| 89 | |||
| 90 | /* Probabilistic content detection strategy: There is no file signature | ||
| 91 | * so perform sanity checks on various header parameters: | ||
| 92 | * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers | ||
| 93 | * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers | ||
| 94 | * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers | ||
| 95 | * first audio chunk signature (32 bits) ==> 1 acceptable number | ||
| 96 | * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 = | ||
| 97 | * 320008 acceptable number combinations. | ||
| 98 | */ | ||
| 99 | |||
| 100 | if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE) | ||
| 101 | return 0; | ||
| 102 | |||
| 103 | /* check sample rate */ | ||
| 104 | field = AV_RL16(&p->buf[0]); | ||
| 105 | if ((field < 8000) || (field > 48000)) | ||
| 106 | return 0; | ||
| 107 | |||
| 108 | /* enforce the rule that the top 6 bits of this flags field are reserved (0); | ||
| 109 | * this might not be true, but enforce it until deemed unnecessary */ | ||
| 110 | if (p->buf[10] & 0xFC) | ||
| 111 | return 0; | ||
| 112 | |||
| 113 | /* note: only check for WS IMA (type 99) right now since there is no | ||
| 114 | * support for type 1 */ | ||
| 115 | if (p->buf[11] != 99) | ||
| 116 | return 0; | ||
| 117 | |||
| 118 | /* read ahead to the first audio chunk and validate the first header signature */ | ||
| 119 | if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE) | ||
| 120 | return 0; | ||
| 121 | |||
| 122 | /* return 1/2 certainty since this file check is a little sketchy */ | ||
| 123 | return AVPROBE_SCORE_MAX / 2; | ||
| 124 | } | ||
| 125 | |||
| 126 | static int wsaud_read_header(AVFormatContext *s, | ||
| 127 | AVFormatParameters *ap) | ||
| 128 | { | ||
| 129 | WsAudDemuxContext *wsaud = s->priv_data; | ||
| 130 | AVIOContext *pb = s->pb; | ||
| 131 | AVStream *st; | ||
| 132 | unsigned char header[AUD_HEADER_SIZE]; | ||
| 133 | |||
| 134 | if (avio_read(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) | ||
| 135 | return AVERROR(EIO); | ||
| 136 | wsaud->audio_samplerate = AV_RL16(&header[0]); | ||
| 137 | if (header[11] == 99) | ||
| 138 | wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS; | ||
| 139 | else | ||
| 140 | return AVERROR_INVALIDDATA; | ||
| 141 | |||
| 142 | /* flag 0 indicates stereo */ | ||
| 143 | wsaud->audio_channels = (header[10] & 0x1) + 1; | ||
| 144 | /* flag 1 indicates 16 bit audio */ | ||
| 145 | wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8; | ||
| 146 | |||
| 147 | /* initialize the audio decoder stream */ | ||
| 148 | st = avformat_new_stream(s, NULL); | ||
| 149 | if (!st) | ||
| 150 | return AVERROR(ENOMEM); | ||
| 151 | avpriv_set_pts_info(st, 33, 1, wsaud->audio_samplerate); | ||
| 152 | st->codec->codec_type = AVMEDIA_TYPE_AUDIO; | ||
| 153 | st->codec->codec_id = wsaud->audio_type; | ||
| 154 | st->codec->codec_tag = 0; /* no tag */ | ||
| 155 | st->codec->channels = wsaud->audio_channels; | ||
| 156 | st->codec->sample_rate = wsaud->audio_samplerate; | ||
| 157 | st->codec->bits_per_coded_sample = wsaud->audio_bits; | ||
| 158 | st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * | ||
| 159 | st->codec->bits_per_coded_sample / 4; | ||
| 160 | st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; | ||
| 161 | |||
| 162 | wsaud->audio_stream_index = st->index; | ||
| 163 | wsaud->audio_frame_counter = 0; | ||
| 164 | |||
| 165 | return 0; | ||
| 166 | } | ||
| 167 | |||
| 168 | static int wsaud_read_packet(AVFormatContext *s, | ||
| 169 | AVPacket *pkt) | ||
| 170 | { | ||
| 171 | WsAudDemuxContext *wsaud = s->priv_data; | ||
| 172 | AVIOContext *pb = s->pb; | ||
| 173 | unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; | ||
| 174 | unsigned int chunk_size; | ||
| 175 | int ret = 0; | ||
| 176 | |||
| 177 | if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != | ||
| 178 | AUD_CHUNK_PREAMBLE_SIZE) | ||
| 179 | return AVERROR(EIO); | ||
| 180 | |||
| 181 | /* validate the chunk */ | ||
| 182 | if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) | ||
| 183 | return AVERROR_INVALIDDATA; | ||
| 184 | |||
| 185 | chunk_size = AV_RL16(&preamble[0]); | ||
| 186 | ret= av_get_packet(pb, pkt, chunk_size); | ||
| 187 | if (ret != chunk_size) | ||
| 188 | return AVERROR(EIO); | ||
| 189 | pkt->stream_index = wsaud->audio_stream_index; | ||
| 190 | pkt->pts = wsaud->audio_frame_counter; | ||
| 191 | pkt->pts /= wsaud->audio_samplerate; | ||
| 192 | |||
| 193 | /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ | ||
| 194 | wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels; | ||
| 195 | |||
| 196 | return ret; | ||
| 197 | } | ||
| 198 | |||
| 199 | static int wsvqa_probe(AVProbeData *p) | 68 | static int wsvqa_probe(AVProbeData *p) |
| 200 | { | 69 | { |
| 201 | /* need 12 bytes to qualify */ | 70 | /* need 12 bytes to qualify */ |
| @@ -367,17 +236,6 @@ static int wsvqa_read_packet(AVFormatContext *s, · 165 unmodified lines | |||
| 367 | return ret; | 236 | return ret; |
| 368 | } | 237 | } |
| 369 | 238 | ||
| 370 | #if CONFIG_WSAUD_DEMUXER | ||
| 371 | AVInputFormat ff_wsaud_demuxer = { | ||
| 372 | .name = "wsaud", | ||
| 373 | .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"), | ||
| 374 | .priv_data_size = sizeof(WsAudDemuxContext), | ||
| 375 | .read_probe = wsaud_probe, | ||
| 376 | .read_header = wsaud_read_header, | ||
| 377 | .read_packet = wsaud_read_packet, | ||
| 378 | }; | ||
| 379 | #endif | ||
| 380 | #if CONFIG_WSVQA_DEMUXER | ||
| 381 | AVInputFormat ff_wsvqa_demuxer = { | 239 | AVInputFormat ff_wsvqa_demuxer = { |
| 382 | .name = "wsvqa", | 240 | .name = "wsvqa", |
| 383 | .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"), | 241 | .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"), |
| @@ -386,4 +244,3 @@ AVInputFormat ff_wsvqa_demuxer = { · 2 unmodified lines | |||
| 386 | .read_header = wsvqa_read_header, | 244 | .read_header = wsvqa_read_header, |
| 387 | .read_packet = wsvqa_read_packet, | 245 | .read_packet = wsvqa_read_packet, |
| 388 | }; | 246 | }; |
| 389 | #endif | ||