X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fsipr.c;h=3f17686a2a9444ef4c487dda23f0918a279f5a37;hb=9f1245eb9620a70feaa00ba745c6c7a56a839556;hp=971d05bde886c538999503150f2a03e24daab03a;hpb=dafcbfe44361b0d3caa22b15bc95e38ba80af7e6;p=ffmpeg diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index 971d05bde88..3f17686a2a9 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -25,11 +25,13 @@ #include #include +#include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" #include "libavutil/mathematics.h" #include "avcodec.h" #define BITSTREAM_READER_LE #include "get_bits.h" -#include "dsputil.h" +#include "internal.h" #include "lsp.h" #include "acelp_vectors.h" @@ -42,7 +44,7 @@ #include "sipr.h" #include "siprdata.h" -typedef struct { +typedef struct SiprModeParam { const char *mode_name; uint16_t bits_per_frame; uint8_t subframe_count; @@ -238,7 +240,7 @@ static void eval_ir(const float *Az, int pitch_lag, float *freq, float tmp1[SUBFR_SIZE+1], tmp2[LP_FILTER_ORDER+1]; int i; - tmp1[0] = 1.; + tmp1[0] = 1.0; for (i = 0; i < LP_FILTER_ORDER; i++) { tmp1[i+1] = Az[i] * ff_pow_0_55[i]; tmp2[i ] = Az[i] * ff_pow_0_7 [i]; @@ -409,9 +411,10 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params, convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response, SUBFR_SIZE); - avg_energy = - (0.01 + ff_scalarproduct_float_c(fixed_vector, fixed_vector, SUBFR_SIZE)) / - SUBFR_SIZE; + avg_energy = (0.01 + avpriv_scalarproduct_float_c(fixed_vector, + fixed_vector, + SUBFR_SIZE)) / + SUBFR_SIZE; ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0]; @@ -452,9 +455,9 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params, if (ctx->mode == MODE_5k0) { for (i = 0; i < subframe_count; i++) { - float energy = ff_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE, - ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE, - SUBFR_SIZE); + float energy = avpriv_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE, + ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE, + SUBFR_SIZE); ff_adaptive_gain_control(&synth[i * SUBFR_SIZE], &synth[i * SUBFR_SIZE], energy, SUBFR_SIZE, 0.9, &ctx->postfilter_agc); @@ -485,8 +488,13 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx) case 29: ctx->mode = MODE_6k5; break; case 37: ctx->mode = MODE_5k0; break; default: - av_log(avctx, AV_LOG_ERROR, "Invalid block_align: %d\n", avctx->block_align); - return AVERROR(EINVAL); + if (avctx->bit_rate > 12200) ctx->mode = MODE_16k; + else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5; + else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5; + else ctx->mode = MODE_5k0; + av_log(avctx, AV_LOG_WARNING, + "Invalid block_align: %d. Mode %s guessed based on bitrate: %d\n", + avctx->block_align, modes[ctx->mode].mode_name, avctx->bit_rate); } av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name); @@ -504,10 +512,9 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx) for (i = 0; i < 4; i++) ctx->energy_history[i] = -14; - avctx->sample_fmt = AV_SAMPLE_FMT_FLT; - - avcodec_get_frame_defaults(&ctx->frame); - avctx->coded_frame = &ctx->frame; + avctx->channels = 1; + avctx->channel_layout = AV_CH_LAYOUT_MONO; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; return 0; } @@ -516,6 +523,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { SiprContext *ctx = avctx->priv_data; + AVFrame *frame = data; const uint8_t *buf=avpkt->data; SiprParameters parm; const SiprModeParam *mode_par = &modes[ctx->mode]; @@ -533,13 +541,13 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - ctx->frame.nb_samples = mode_par->frames_per_packet * subframe_size * - mode_par->subframe_count; - if ((ret = avctx->get_buffer(avctx, &ctx->frame)) < 0) { + frame->nb_samples = mode_par->frames_per_packet * subframe_size * + mode_par->subframe_count; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (float *)ctx->frame.data[0]; + samples = (float *)frame->data[0]; init_get_bits(&gb, buf, mode_par->bits_per_frame); @@ -551,19 +559,18 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *data, samples += subframe_size * mode_par->subframe_count; } - *got_frame_ptr = 1; - *(AVFrame *)data = ctx->frame; + *got_frame_ptr = 1; return mode_par->bits_per_frame >> 3; } AVCodec ff_sipr_decoder = { .name = "sipr", + .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_SIPR, .priv_data_size = sizeof(SiprContext), .init = sipr_decoder_init, .decode = sipr_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"), + .capabilities = AV_CODEC_CAP_DR1, };