Lines Matching defs:alac
26 * @see http://crazney.net/programs/itunes/alac.html
30 * the end of an 'alac' stsd atom and has the following format:
33 * 32bit tag ("alac")
105 static int rice_decompress(ALACContext *alac, int32_t *output_buffer,
109 unsigned int history = alac->rice_initial_history;
116 if(get_bits_left(&alac->gb) <= 0)
121 k = FFMIN(k, alac->rice_limit);
122 x = decode_scalar(&alac->gb, k, bps);
140 k = FFMIN(k, alac->rice_limit);
141 block_size = decode_scalar(&alac->gb, k, 16);
145 av_log(alac->avctx, AV_LOG_ERROR,
262 ALACContext *alac = avctx->priv_data;
267 skip_bits(&alac->gb, 4); /* element instance tag */
268 skip_bits(&alac->gb, 12); /* unused header bits */
271 has_size = get_bits1(&alac->gb);
273 alac->extra_bits = get_bits(&alac->gb, 2) << 3;
274 bps = alac->sample_size - alac->extra_bits + channels - 1;
281 is_compressed = !get_bits1(&alac->gb);
284 output_samples = get_bits_long(&alac->gb, 32);
286 output_samples = alac->max_samples_per_frame;
287 if (!output_samples || output_samples > alac->max_samples_per_frame) {
292 if (!alac->nb_samples) {
298 } else if (output_samples != alac->nb_samples) {
300 output_samples, alac->nb_samples);
303 alac->nb_samples = output_samples;
304 if (alac->direct_output) {
306 alac->output_samples_buffer[ch] = (int32_t *)frame->extended_data[ch_index + ch];
316 decorr_shift = get_bits(&alac->gb, 8);
317 decorr_left_weight = get_bits(&alac->gb, 8);
320 prediction_type[ch] = get_bits(&alac->gb, 4);
321 lpc_quant[ch] = get_bits(&alac->gb, 4);
322 rice_history_mult[ch] = get_bits(&alac->gb, 3);
323 lpc_order[ch] = get_bits(&alac->gb, 5);
325 if (lpc_order[ch] >= alac->max_samples_per_frame)
330 lpc_coefs[ch][i] = get_sbits(&alac->gb, 16);
333 if (alac->extra_bits) {
334 for (i = 0; i < alac->nb_samples; i++) {
335 if(get_bits_left(&alac->gb) <= 0)
338 alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);
342 int ret=rice_decompress(alac, alac->predict_error_buffer[ch],
343 alac->nb_samples, bps,
344 rice_history_mult[ch] * alac->rice_history_mult / 4);
357 lpc_prediction(alac->predict_error_buffer[ch],
358 alac->predict_error_buffer[ch],
359 alac->nb_samples, bps, NULL, 31, 0);
364 lpc_prediction(alac->predict_error_buffer[ch],
365 alac->output_samples_buffer[ch], alac->nb_samples,
370 for (i = 0; i < alac->nb_samples; i++) {
371 if(get_bits_left(&alac->gb) <= 0)
374 alac->output_samples_buffer[ch][i] =
375 get_sbits_long(&alac->gb, alac->sample_size);
378 alac->extra_bits = 0;
384 decorrelate_stereo(alac->output_samples_buffer, alac->nb_samples,
388 if (alac->extra_bits) {
389 append_extra_bits(alac->output_samples_buffer, alac->extra_bits_buffer,
390 alac->extra_bits, channels, alac->nb_samples);
394 switch(alac->sample_size) {
398 for (i = 0; i < alac->nb_samples; i++)
399 *outbuffer++ = alac->output_samples_buffer[ch][i];
404 for (i = 0; i < alac->nb_samples; i++)
405 alac->output_samples_buffer[ch][i] <<= 8;
410 switch(alac->sample_size) {
413 for (i = 0; i < alac->nb_samples; i++) {
415 *outbuffer++ = alac->output_samples_buffer[ch][i];
416 outbuffer += alac->channels - channels;
422 for (i = 0; i < alac->nb_samples; i++) {
424 *outbuffer++ = alac->output_samples_buffer[ch][i] << 8;
425 outbuffer += alac->channels - channels;
431 for (i = 0; i < alac->nb_samples; i++) {
433 *outbuffer++ = alac->output_samples_buffer[ch][i];
434 outbuffer += alac->channels - channels;
447 ALACContext *alac = avctx->priv_data;
453 if ((ret = init_get_bits8(&alac->gb, avpkt->data, avpkt->size)) < 0)
457 alac->nb_samples = 0;
459 while (get_bits_left(&alac->gb) >= 3) {
460 element = get_bits(&alac->gb, 3);
471 if (ch + channels > alac->channels ||
472 ff_alac_channel_layout_offsets[alac->channels - 1][ch] + channels > alac->channels) {
478 ff_alac_channel_layout_offsets[alac->channels - 1][ch],
480 if (ret < 0 && get_bits_left(&alac->gb))
490 if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {
492 avpkt->size * 8 - get_bits_count(&alac->gb));
495 if (alac->channels == ch)
505 ALACContext *alac = avctx->priv_data;
508 for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
509 av_freep(&alac->predict_error_buffer[ch]);
510 if (!alac->direct_output)
511 av_freep(&alac->output_samples_buffer[ch]);
512 av_freep(&alac->extra_bits_buffer[ch]);
518 static int allocate_buffers(ALACContext *alac)
521 int buf_size = alac->max_samples_per_frame * sizeof(int32_t);
523 for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
524 FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
527 alac->direct_output = alac->sample_size > 16 && av_sample_fmt_is_planar(alac->avctx->sample_fmt);
528 if (!alac->direct_output) {
529 FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
533 FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
538 alac_decode_close(alac->avctx);
542 static int alac_set_info(ALACContext *alac)
546 bytestream2_init(&gb, alac->avctx->extradata,
547 alac->avctx->extradata_size);
549 bytestream2_skipu(&gb, 12); // size:4, alac:4, version:4
551 alac->max_samples_per_frame = bytestream2_get_be32u(&gb);
552 if (!alac->max_samples_per_frame ||
553 alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) {
554 av_log(alac->avctx, AV_LOG_ERROR,
556 alac->max_samples_per_frame);
560 alac->sample_size = bytestream2_get_byteu(&gb);
561 alac->rice_history_mult = bytestream2_get_byteu(&gb);
562 alac->rice_initial_history = bytestream2_get_byteu(&gb);
563 alac->rice_limit = bytestream2_get_byteu(&gb);
564 alac->channels = bytestream2_get_byteu(&gb);
577 ALACContext *alac = avctx->priv_data;
578 alac->avctx = avctx;
581 if (alac->avctx->extradata_size < ALAC_EXTRADATA_SIZE) {
585 if (alac_set_info(alac)) {
591 switch (alac->sample_size) {
597 default: avpriv_request_sample(avctx, "Sample depth %d", alac->sample_size);
600 avctx->bits_per_raw_sample = alac->sample_size;
602 if (alac->channels < 1) {
604 alac->channels = avctx->channels;
606 if (alac->channels > ALAC_MAX_CHANNELS)
607 alac->channels = avctx->channels;
609 avctx->channels = alac->channels;
616 avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1];
618 if ((ret = allocate_buffers(alac)) < 0) {
628 ALACContext *alac = avctx->priv_data;
629 alac->avctx = avctx;
630 return allocate_buffers(alac);
634 .name = "alac",