|
|
|
@@ -301,29 +301,29 @@ static int16_t g726_encode(G726Context* c, int16_t sig) |
|
|
|
static av_cold int g726_encode_init(AVCodecContext *avctx) |
|
|
|
{ |
|
|
|
G726Context* c = avctx->priv_data; |
|
|
|
unsigned int index; |
|
|
|
|
|
|
|
if (avctx->sample_rate <= 0) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; |
|
|
|
|
|
|
|
if (avctx->bit_rate % avctx->sample_rate) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if(avctx->channels != 1){ |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if(index>3){ |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); |
|
|
|
return -1; |
|
|
|
|
|
|
|
if (avctx->bit_rate % avctx->sample_rate) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
} |
|
|
|
c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate; |
|
|
|
if (c->code_size < 2 || c->code_size > 5) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
} |
|
|
|
g726_reset(c, index); |
|
|
|
c->code_size = index+2; |
|
|
|
avctx->bits_per_coded_sample = c->code_size; |
|
|
|
|
|
|
|
g726_reset(c, c->code_size - 2); |
|
|
|
|
|
|
|
avctx->coded_frame = avcodec_alloc_frame(); |
|
|
|
if (!avctx->coded_frame) |
|
|
|
@@ -332,7 +332,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx) |
|
|
|
|
|
|
|
/* select a frame size that will end on a byte boundary and have a size of |
|
|
|
approximately 1024 bytes */ |
|
|
|
avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; |
|
|
|
avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[c->code_size - 2]; |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
@@ -365,25 +365,23 @@ static int g726_encode_frame(AVCodecContext *avctx, |
|
|
|
static av_cold int g726_decode_init(AVCodecContext *avctx) |
|
|
|
{ |
|
|
|
G726Context* c = avctx->priv_data; |
|
|
|
unsigned int index; |
|
|
|
|
|
|
|
if (avctx->sample_rate <= 0) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; |
|
|
|
|
|
|
|
if(avctx->channels != 1){ |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if(index>3){ |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); |
|
|
|
return -1; |
|
|
|
|
|
|
|
c->code_size = avctx->bits_per_coded_sample; |
|
|
|
if (c->code_size < 2 || c->code_size > 5) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
} |
|
|
|
g726_reset(c, index); |
|
|
|
c->code_size = index+2; |
|
|
|
g726_reset(c, c->code_size - 2); |
|
|
|
|
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
|
|
|
|
|
|
|
|