History

Merge remote-tracking branch 'qatar/master'

* 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

Michael Niedermayer committed 14 years ago

Commit 0bb57f82 parents b955d40 0fec2cb20 files · +1027 −342Browse files

Unified · Split

20 files
  1. Changelog +1 −0
  2. doc/general.texi +2 −0
  3. libavcodec/Makefile +2 −0
  4. libavcodec/aaccoder.c +18 −17
  5. libavcodec/aacenc.c +224 −130
  6. libavcodec/aacenc.h +8 −1
  7. libavcodec/aacpsy.c +16 −18
  8. libavcodec/allcodecs.c +1 −0
  9. libavcodec/avcodec.h +1 −0
  10. libavcodec/psymodel.c +6 −11
  11. libavcodec/psymodel.h +4 −8
  12. libavcodec/vc1.c +9 −7
  13. libavcodec/version.h +2 −2
  14. libavcodec/xwd.h +41 −0
  15. libavcodec/xwddec.c +267 −0
  16. libavcodec/xwdenc.c +246 −0
  17. libavformat/Makefile +2 −2
  18. libavformat/img2.c +2 −1
  19. libavformat/westwood_aud.c +173 −0
  20. libavformat/westwood_vqa.c +2 −145
Changelog+1−0
@@ -15,6 +15,7 @@ version next: · 14 unmodified lines
1515 - amerge audio filter
1616 - GSM audio parser
1717 - SMJPEG muxer
18+- XWD encoder and decoder
1819 - Automatic thread count based on detection number of (available) CPU cores
1920 - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder
2021 - ffprobe -show_error option
doc/general.texi+2−0
@@ -399,6 +399,8 @@ following image formats are supported: · 398 unmodified lines
399399 @tab YUV, JPEG and some extension is not supported yet.
400400 @item Truevision Targa @tab X @tab X
401401 @tab Targa (.TGA) image format
402+@item XWD @tab X @tab X
403+ @tab X Window Dump image format
402404 @end multitable
403405
404406 @code{X} means that encoding (resp. decoding) is supported.
libavcodec/Makefile+2−0
@@ -470,6 +470,8 @@ OBJS-$(CONFIG_XBIN_DECODER) += bintext.o cga_data.o · 469 unmodified lines
470470 OBJS-$(CONFIG_XL_DECODER) += xl.o
471471 OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o
472472 OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o
473+OBJS-$(CONFIG_XWD_DECODER) += xwddec.o
474+OBJS-$(CONFIG_XWD_ENCODER) += xwdenc.o
473475 OBJS-$(CONFIG_Y41P_DECODER) += y41pdec.o
474476 OBJS-$(CONFIG_Y41P_ENCODER) += y41penc.o
475477 OBJS-$(CONFIG_YOP_DECODER) += yop.o
libavcodec/aaccoder.c+18−17
@@ -110,14 +110,15 @@ static av_always_inline float quantize_and_encode_band_cost_template( · 109 unmodified lines
110110 int *bits, int BT_ZERO, int BT_UNSIGNED,
111111 int BT_PAIR, int BT_ESC)
112112 {
113− const float IQ = ff_aac_pow2sf_tab[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];
113+ const int q_idx = 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];
115117 const float CLIPPED_ESCAPE = 165140.0f*IQ;
116118 int i, j;
117119 float cost = 0;
118120 const int dim = BT_PAIR ? 2 : 4;
119121 int resbits = 0;
120− const float Q34 = sqrtf(Q * sqrtf(Q));
121122 const int range = aac_cb_range[cb];
122123 const int maxval = aac_cb_maxval[cb];
123124 int off;
@@ -420,7 +421,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 296 unmodified lines
420421 const int run_esc = (1 << run_bits) - 1;
421422 int idx, ppos, count;
422423 int stackrun[120], stackcb[120], stack_len;
423− float next_minrd = INFINITY;
424+ float next_minbits = INFINITY;
424425 int next_mincb = 0;
425426
426427 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
@@ -434,7 +435,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 7 unmodified lines
434435 size = sce->ics.swb_sizes[swb];
435436 if (sce->zeroes[win*16 + swb]) {
436437 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;
438439 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]
439440 != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])
440441 cost_stay_here += run_bits;
@@ -447,7 +448,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 6 unmodified lines
447448 path[swb+1][0].cost = cost_stay_here;
448449 path[swb+1][0].run = path[swb][0].run + 1;
449450 }
450− next_minrd = path[swb+1][0].cost;
451+ next_minbits = path[swb+1][0].cost;
451452 next_mincb = 0;
452453 for (cb = 1; cb < 12; cb++) {
453454 path[swb+1][cb].cost = 61450;
@@ -455,10 +456,10 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 1 unmodified line
455456 path[swb+1][cb].run = 0;
456457 }
457458 } else {
458− float minrd = next_minrd;
459+ float minbits = next_minbits;
459460 int mincb = next_mincb;
460461 int startcb = sce->band_type[win*16+swb];
461− next_minrd = INFINITY;
462+ next_minbits = INFINITY;
462463 next_mincb = 0;
463464 for (cb = 0; cb < startcb; cb++) {
464465 path[swb+1][cb].cost = 61450;
@@ -467,15 +468,15 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 2 unmodified lines
467468 }
468469 for (cb = startcb; cb < 12; cb++) {
469470 float cost_stay_here, cost_get_here;
470− float rd = 0.0f;
471+ float bits = 0.0f;
471472 for (w = 0; w < group_len; w++) {
472− rd += quantize_band_cost(s, sce->coeffs + start + w*128,
473− s->scoefs + start + w*128, size,
474− sce->sf_idx[(win+w)*16+swb], cb,
475− 0, INFINITY, NULL);
473+ bits += quantize_band_cost(s, sce->coeffs + start + w*128,
474+ s->scoefs + start + w*128, size,
475+ sce->sf_idx[(win+w)*16+swb], cb,
476+ 0, INFINITY, NULL);
476477 }
477− cost_stay_here = path[swb][cb].cost + rd;
478− cost_get_here = minrd + rd + run_bits + 4;
478+ cost_stay_here = path[swb][cb].cost + bits;
479+ cost_get_here = minbits + bits + run_bits + 4;
479480 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
480481 != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
481482 cost_stay_here += run_bits;
@@ -488,8 +489,8 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, · 6 unmodified lines
488489 path[swb+1][cb].cost = cost_stay_here;
489490 path[swb+1][cb].run = path[swb][cb].run + 1;
490491 }
491− if (path[swb+1][cb].cost < next_minrd) {
492− next_minrd = path[swb+1][cb].cost;
492+ if (path[swb+1][cb].cost < next_minbits) {
493+ next_minbits = path[swb+1][cb].cost;
493494 next_mincb = cb;
494495 }
495496 }
libavcodec/aacenc.c+224−130
@@ -46,6 +46,14 @@ · 45 unmodified lines
4646
4747 #define AAC_MAX_CHANNELS 6
4848
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+
4957 static const uint8_t swb_size_1024_96[] = {
5058 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
5159 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
135143 {4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE
136144 };
137145
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+
138158 /**
139159 * Make AAC audio config object.
140160 * @see 1.6.2.1 "Syntax - AudioSpecificConfig"
@@ -147,7 +167,7 @@ static void put_audio_specific_config(AVCodecContext *avctx) · 6 unmodified lines
147167 init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8);
148168 put_bits(&pb, 5, 2); //object type - AAC-LC
149169 put_bits(&pb, 4, s->samplerate_index); //sample rate index
150− put_bits(&pb, 4, avctx->channels);
170+ put_bits(&pb, 4, s->channels);
151171 //GASpecificConfig
152172 put_bits(&pb, 1, 0); //frame length - 1024 samples
153173 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
160180 flush_put_bits(&pb);
161181 }
162182
163−static av_cold int aac_encode_init(AVCodecContext *avctx)
164−{
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;
183+#define WINDOW_FUNC(type) \
184+static void apply_ ##type ##_window(DSPContext *dsp, SingleChannelElement *sce, const float *audio)
172185
173− for (i = 0; i < 16; i++)
174− if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i])
175− break;
176− if (i == 16) {
177− av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate);
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);
186+WINDOW_FUNC(only_long)
187+{
188+ const float *lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;
189+ const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
190+ float *out = sce->ret;
209191
210− sizes[0] = swb_size_1024[i];
211− sizes[1] = swb_size_128[i];
212− lengths[0] = ff_aac_num_swb_1024[i];
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];
192+ dsp->vector_fmul (out, audio, lwindow, 1024);
193+ dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
194+}
219195
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+}
221207
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+}
223219
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+ }
225234 }
226235
227−static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s,
228− SingleChannelElement *sce, short *audio)
236+static void (*const apply_window[4])(DSPContext *dsp, SingleChannelElement *sce, const float *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)
229245 {
230− int i, k;
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;
246+ int i;
235247 float *output = sce->ret;
236248
237− if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
238− memcpy(output, sce->saved, sizeof(float)*1024);
239− if (sce->ics.window_sequence[0] == LONG_STOP_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− }
249+ apply_window[sce->ics.window_sequence[0]](&s->dsp, sce, audio);
250+
251+ if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE)
260252 s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output);
261− } else {
262− for (k = 0; k < 1024; k += 128) {
263− for (i = 448 + k; i < 448 + k + 256; i++)
264− output[i - 448 - k] = (i < 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− }
253+ else
254+ for (i = 0; i < 1024; i += 128)
255+ s->mdct128.mdct_calc(&s->mdct128, sce->coeffs + i, output + i*2);
256+ memcpy(audio, audio + 1024, sizeof(audio[0]) * 1024);
274257 }
275258
276259 /**
@@ -488,11 +471,37 @@ static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, · 211 unmodified lines
488471 put_bits(&s->pb, 12 - padbits, 0);
489472 }
490473
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+
491500 static int aac_encode_frame(AVCodecContext *avctx,
492501 uint8_t *frame, int buf_size, void *data)
493502 {
494503 AACEncContext *s = avctx->priv_data;
495− int16_t *samples = s->samples, *samples2, *la;
504+ float **samples = s->planar_samples, *samples2, *la, *overlap;
496505 ChannelElement *cpe;
497506 int i, ch, w, g, chans, tag, start_ch;
498507 int chan_el_counter[4];
@@ -500,27 +509,15 @@ static int aac_encode_frame(AVCodecContext *avctx, · 1 unmodified line
500509
501510 if (s->last_frame)
502511 return 0;
512+
503513 if (data) {
504− if (!s->psypp) {
505− memcpy(s->samples + 1024 * avctx->channels, data,
506− 1024 * avctx->channels * sizeof(s->samples[0]));
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− }
514+ deinterleave_input_samples(s, data);
515+ if (s->psypp)
516+ ff_psy_preprocess(s->psypp, s->planar_samples, s->channels);
518517 }
519− if (!avctx->frame_number) {
520− memcpy(s->samples, s->samples + 1024 * avctx->channels,
521− 1024 * avctx->channels * sizeof(s->samples[0]));
518+
519+ if (!avctx->frame_number)
522520 return 0;
523− }
524521
525522 start_ch = 0;
526523 for (i = 0; i < s->chan_map[0]; i++) {
@@ -531,8 +528,9 @@ static int aac_encode_frame(AVCodecContext *avctx, · 4 unmodified lines
531528 for (ch = 0; ch < chans; ch++) {
532529 IndividualChannelStream *ics = &cpe->ch[ch].ics;
533530 int cur_channel = start_ch + ch;
534− samples2 = samples + cur_channel;
535− la = samples2 + (448+64) * avctx->channels;
531+ overlap = &samples[cur_channel][0];
532+ samples2 = overlap + 1024;
533+ la = samples2 + (448+64);
536534 if (!data)
537535 la = NULL;
538536 if (tag == TYPE_LFE) {
@@ -560,7 +558,7 @@ static int aac_encode_frame(AVCodecContext *avctx, · 21 unmodified lines
560558 for (w = 0; w < ics->num_windows; w++)
561559 ics->group_len[w] = wi[ch].grouping[w];
562560
563− apply_window_and_mdct(avctx, s, &cpe->ch[ch], samples2);
561+ apply_window_and_mdct(s, &cpe->ch[ch], overlap);
564562 }
565563 start_ch += chans;
566564 }
@@ -626,8 +624,8 @@ static int aac_encode_frame(AVCodecContext *avctx, · 59 unmodified lines
626624 }
627625
628626 frame_bits = put_bits_count(&s->pb);
629− if (frame_bits <= 6144 * avctx->channels - 3) {
630− s->psy.bitres.bits = frame_bits / avctx->channels;
627+ if (frame_bits <= 6144 * s->channels - 3) {
628+ s->psy.bitres.bits = frame_bits / s->channels;
631629 break;
632630 }
633631
@@ -648,8 +646,7 @@ static int aac_encode_frame(AVCodecContext *avctx, · 14 unmodified lines
648646
649647 if (!data)
650648 s->last_frame = 1;
651− memcpy(s->samples, s->samples + 1024 * avctx->channels,
652− 1024 * avctx->channels * sizeof(s->samples[0]));
649+
653650 return put_bits_count(&s->pb)>>3;
654651 }
655652
@@ -660,12 +657,109 @@ static av_cold int aac_encode_end(AVCodecContext *avctx) · 4 unmodified lines
660657 ff_mdct_end(&s->mdct1024);
661658 ff_mdct_end(&s->mdct128);
662659 ff_psy_end(&s->psy);
663− ff_psy_preprocess_end(s->psypp);
664− av_freep(&s->samples);
660+ if (s->psypp)
661+ ff_psy_preprocess_end(s->psypp);
662+ av_freep(&s->buffer.samples);
665663 av_freep(&s->cpe);
666664 return 0;
667665 }
668666
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+
669763 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
670764 static const AVOption aacenc_options[] = {
671765 {"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
692786 .encode = aac_encode_frame,
693787 .close = aac_encode_end,
694788 .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},
696790 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
697791 .priv_class = &aacenc_class,
698792 };
libavcodec/aacenc.h+8−1
@@ -61,9 +61,10 @@ typedef struct AACEncContext { · 60 unmodified lines
6161 FFTContext mdct1024; ///< long (1024 samples) frame transform context
6262 FFTContext mdct128; ///< short (128 samples) frame transform context
6363 DSPContext dsp;
64− int16_t *samples; ///< saved preprocessed input
64+ float *planar_samples[6]; ///< saved preprocessed input
6565
6666 int samplerate_index; ///< MPEG-4 samplerate index
67+ int channels; ///< channel count
6768 const uint8_t *chan_map; ///< channel configuration map
6869
6970 ChannelElement *cpe; ///< channel elements
@@ -75,6 +76,12 @@ typedef struct AACEncContext { · 5 unmodified lines
7576 float lambda;
7677 DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
7778 DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
79+
80+ struct {
81+ float *samples;
82+ } buffer;
7883 } AACEncContext;
7984
85+extern float ff_aac_pow34sf_tab[428];
86+
8087 #endif /* AVCODEC_AACENC_H */
libavcodec/aacpsy.c+16−18
@@ -400,7 +400,7 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx, · 399 unmodified lines
400400 int stay_short = 0;
401401 for (i = 0; i < 8; i++) {
402402 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);
404404 sum += v*v;
405405 }
406406 s[i] = sum;
@@ -776,9 +776,8 @@ static void lame_apply_block_type(AacPsyChannel *ctx, FFPsyWindowInfo *wi, int u · 369 unmodified lines
776776 ctx->next_window_seq = blocktype;
777777 }
778778
779−static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx,
780− const int16_t *audio, const int16_t *la,
781− int channel, int prev_type)
779+static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
780+ const float *la, int channel, int prev_type)
782781 {
783782 AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
784783 AacPsyChannel *pch = &pctx->ch[channel];
@@ -795,20 +794,20 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, · 10 unmodified lines
795794 float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
796795 float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
797796 float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
798− int chans = ctx->avctx->channels;
799− const int16_t *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN) * chans;
797+ const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN);
800798 int j, att_sum = 0;
801799
802800 /* LAME comment: apply high pass filter of fs/4 */
803801 for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) {
804802 float sum1, sum2;
805− sum1 = firbuf[(i + ((PSY_LAME_FIR_LEN - 1) / 2)) * chans];
803+ sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2];
806804 sum2 = 0.0;
807805 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]);
809− sum2 += psy_fir_coeffs[j + 1] * (firbuf[(i + j + 1) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j - 1) * chans]);
806+ sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]);
807+ sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]);
810808 }
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;
812811 }
813812
814813 /* Calculate the energies of each sub-shortblock */
@@ -823,16 +822,15 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, · 8 unmodified lines
823822 float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS);
824823 float p = 1.0f;
825824 for (; pf < pfe; pf++)
826− if (p < fabsf(*pf))
827− p = fabsf(*pf);
825+ p = FFMAX(p, fabsf(*pf));
828826 pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
829827 energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
830− /* FIXME: 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]
832− * (which is what we use here). What the 3 stands for is ambigious, as it is both
833− * 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
835− * previous block.
828+ /* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
829+ * Obviously the 3 and 2 have some significance, or this would be just [i + 1]
830+ * (which is what we use here). What the 3 stands for is ambiguous, as it is both
831+ * number of short blocks, and the number of sub-short blocks.
832+ * It seems that LAME is comparing each sub-block to sub-block + 1 in the
833+ * previous block.
836834 */
837835 if (p > energy_subshort[i + 1])
838836 p = p / energy_subshort[i + 1];
libavcodec/allcodecs.c+1−0
@@ -245,6 +245,7 @@ void avcodec_register_all(void) · 244 unmodified lines
245245 REGISTER_DECODER (XAN_WC3, xan_wc3);
246246 REGISTER_DECODER (XAN_WC4, xan_wc4);
247247 REGISTER_DECODER (XL, xl);
248+ REGISTER_ENCDEC (XWD, xwd);
248249 REGISTER_ENCDEC (Y41P, y41p);
249250 REGISTER_DECODER (YOP, yop);
250251 REGISTER_ENCDEC (YUV4, yuv4);
libavcodec/avcodec.h+1−0
@@ -255,6 +255,7 @@ enum CodecID { · 254 unmodified lines
255255 CODEC_ID_VBLE,
256256 CODEC_ID_DXTORY,
257257 CODEC_ID_V410,
258+ CODEC_ID_XWD,
258259 CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
259260 CODEC_ID_UTVIDEO = 0x800,
260261 CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
libavcodec/psymodel.c+6−11
@@ -112,20 +112,15 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av · 111 unmodified lines
112112 return ctx;
113113 }
114114
115−void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx,
116− const int16_t *audio, int16_t *dest,
117− int tag, int channels)
115+void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
118116 {
119− int ch, i;
117+ int ch;
118+ int frame_size = ctx->avctx->frame_size;
119+
120120 if (ctx->fstate) {
121121 for (ch = 0; ch < channels; ch++)
122− ff_iir_filter(ctx->fcoeffs, ctx->fstate[tag+ch], ctx->avctx->frame_size,
123− audio + ch, ctx->avctx->channels,
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];
122+ ff_iir_filter_flt(ctx->fcoeffs, ctx->fstate[ch], frame_size,
123+ &audio[ch][frame_size], 1, &audio[ch][frame_size], 1);
129124 }
130125 }
131126
libavcodec/psymodel.h+4−8
@@ -109,7 +109,7 @@ typedef struct FFPsyModel { · 108 unmodified lines
109109 *
110110 * @return suggested window information in a structure
111111 */
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);
113113
114114 /**
115115 * 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
174174 * Preprocess several channel in audio frame in order to compress it better.
175175 *
176176 * @param ctx preprocessing context
177− * @param audio samples to preprocess
178− * @param dest place to put filtered samples
179− * @param tag channel number
180− * @param channels number of channel to preprocess (some additional work may be done on stereo pair)
177+ * @param audio samples to be filtered (in place)
178+ * @param channels number of channel to preprocess
181179 */
182−void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx,
183− const int16_t *audio, int16_t *dest,
184− int tag, int channels);
180+void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels);
185181
186182 /**
187183 * Cleanup audio preprocessing module.
libavcodec/vc1.c+9−7
@@ -918,13 +918,15 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) · 917 unmodified lines
918918 }
919919 goto parse_common_info;
920920 }
921− if (v->finterpflag)
922− v->interpfrm = get_bits1(gb);
923− if (v->s.pict_type == AV_PICTURE_TYPE_B) {
924− v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
925− v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
926− if (v->bfraction == 0) {
927− v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
921+ if (v->fcm == PROGRESSIVE) {
922+ if (v->finterpflag)
923+ v->interpfrm = get_bits1(gb);
924+ if (v->s.pict_type == AV_PICTURE_TYPE_B) {
925+ v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
926+ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
927+ if (v->bfraction == 0) {
928+ v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
929+ }
928930 }
929931 }
930932
libavcodec/version.h+2−2
@@ -21,8 +21,8 @@ · 20 unmodified lines
2121 #define AVCODEC_VERSION_H
2222
2323 #define LIBAVCODEC_VERSION_MAJOR 53
24−#define LIBAVCODEC_VERSION_MINOR 57
25−#define LIBAVCODEC_VERSION_MICRO 105
24+#define LIBAVCODEC_VERSION_MINOR 58
25+#define LIBAVCODEC_VERSION_MICRO 100
2626
2727 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
2828 LIBAVCODEC_VERSION_MINOR, \
libavcodec/xwd.h+41−0
@@ -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 */
libavcodec/xwddec.c+267−0
@@ -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+};
libavcodec/xwdenc.c+246−0
@@ -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+};
libavformat/Makefile+2−2
@@ -326,8 +326,8 @@ OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o · 325 unmodified lines
326326 OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \
327327 riff.o isom.o avc.o \
328328 flacenc_header.o avlanguage.o
329−OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o
330−OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o
329+OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
330+OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o
331331 OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcrypt.o \
332332 avlanguage.o mpegts.o isom.o riff.o
333333 OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o riff.o
libavformat/img2.c+2−1
@@ -91,6 +91,7 @@ static const IdStrMap img_tags[] = { · 90 unmodified lines
9191 { CODEC_ID_JPEG2000 , "jpc"},
9292 { CODEC_ID_DPX , "dpx"},
9393 { CODEC_ID_PICTOR , "pic"},
94+ { CODEC_ID_XWD , "xwd"},
9495 { CODEC_ID_NONE , NULL}
9596 };
9697
@@ -528,7 +529,7 @@ AVOutputFormat ff_image2_muxer = { · 431 unmodified lines
528529 .name = "image2",
529530 .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
530531 .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",
532533 .priv_data_size = sizeof(VideoData),
533534 .video_codec = CODEC_ID_MJPEG,
534535 .write_header = write_header,
libavformat/westwood_aud.c+173−0
@@ -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+};
libavformat/westwood_vqa.crenamed from libavformat/westwood.c+2−145
@@ -1,5 +1,5 @@
11 /*
2− * Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
2+ * Westwood Studios VQA Format Demuxer
33 * Copyright (c) 2003 The ffmpeg Project
44 *
55 * This file is part of FFmpeg.
@@ -21,26 +21,17 @@ · 15 unmodified lines
2121
2222 /**
2323 * @file
24− * Westwood Studios VQA & AUD file demuxers
24+ * Westwood Studios VQA file demuxer
2525 * by Mike Melanson (melanson@pcisys.net)
2626 * for more information on the Westwood file formats, visit:
2727 * http://www.pcisys.net/~melanson/codecs/
2828 * 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.
3429 */
3530
3631 #include "libavutil/intreadwrite.h"
3732 #include "avformat.h"
3833 #include "internal.h"
3934
40−#define AUD_HEADER_SIZE 12
41−#define AUD_CHUNK_PREAMBLE_SIZE 8
42−#define AUD_CHUNK_SIGNATURE 0x0000DEAF
43−
4435 #define FORM_TAG MKBETAG('F', 'O', 'R', 'M')
4536 #define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A')
4637 #define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D')
@@ -63,15 +54,6 @@ · 16 unmodified lines
6354 #define VQA_FRAMERATE 15
6455 #define VQA_PREAMBLE_SIZE 8
6556
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−
7557 typedef struct WsVqaDemuxContext {
7658 int audio_samplerate;
7759 int audio_channels;
@@ -83,119 +65,6 @@ typedef struct WsVqaDemuxContext { · 5 unmodified lines
8365 int64_t audio_frame_counter;
8466 } WsVqaDemuxContext;
8567
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−
19968 static int wsvqa_probe(AVProbeData *p)
20069 {
20170 /* need 12 bytes to qualify */
@@ -367,17 +236,6 @@ static int wsvqa_read_packet(AVFormatContext *s, · 165 unmodified lines
367236 return ret;
368237 }
369238
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
381239 AVInputFormat ff_wsvqa_demuxer = {
382240 .name = "wsvqa",
383241 .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
@@ -386,4 +244,3 @@ AVInputFormat ff_wsvqa_demuxer = { · 2 unmodified lines
386244 .read_header = wsvqa_read_header,
387245 .read_packet = wsvqa_read_packet,
388246 };
389−#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t