X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fsipr.c;h=65440db2244e03704d1ac7fd13e31830d93b7a86;hb=006508032057824a371bec4e629b66f8cbb26c47;hp=20d9da15e6cd7326e97ac0ab46b7bcd3ebc56c8b;hpb=b429440d857e01250666ed1a68c86c77e575b9ee;p=ffmpeg diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index 20d9da15e6c..65440db2244 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -27,7 +27,7 @@ #include "libavutil/mathematics.h" #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "dsputil.h" @@ -487,7 +487,10 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx) 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_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name); @@ -507,20 +510,23 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + avcodec_get_frame_defaults(&ctx->frame); + avctx->coded_frame = &ctx->frame; + return 0; } -static int sipr_decode_frame(AVCodecContext *avctx, void *datap, - int *data_size, AVPacket *avpkt) +static int sipr_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) { SiprContext *ctx = avctx->priv_data; const uint8_t *buf=avpkt->data; SiprParameters parm; const SiprModeParam *mode_par = &modes[ctx->mode]; GetBitContext gb; - float *data = datap; + float *samples; int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE; - int i, out_size; + int i, ret; ctx->avctx = avctx; if (avpkt->size < (mode_par->bits_per_frame >> 3)) { @@ -530,27 +536,27 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap, return -1; } - out_size = mode_par->frames_per_packet * subframe_size * - mode_par->subframe_count * - av_get_bytes_per_sample(avctx->sample_fmt); - if (*data_size < out_size) { - av_log(avctx, AV_LOG_ERROR, - "Error processing packet: output buffer (%d) too small\n", - *data_size); - return -1; + /* 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) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; } + samples = (float *)ctx->frame.data[0]; init_get_bits(&gb, buf, mode_par->bits_per_frame); for (i = 0; i < mode_par->frames_per_packet; i++) { decode_parameters(&parm, &gb, mode_par); - ctx->decode_frame(ctx, &parm, data); + ctx->decode_frame(ctx, &parm, samples); - data += subframe_size * mode_par->subframe_count; + samples += subframe_size * mode_par->subframe_count; } - *data_size = out_size; + *got_frame_ptr = 1; + *(AVFrame *)data = ctx->frame; return mode_par->bits_per_frame >> 3; } @@ -562,5 +568,6 @@ AVCodec ff_sipr_decoder = { .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"), };