mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
g723_1: convert to new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
c21e1492e3
commit
182866e9e4
@ -37,7 +37,7 @@ static int g723_1_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
|
|||||||
int next = END_NOT_FOUND;
|
int next = END_NOT_FOUND;
|
||||||
|
|
||||||
if (buf_size > 0)
|
if (buf_size > 0)
|
||||||
next = frame_size[buf[0] & 3] * FFMAX(1, avctx->channels);
|
next = frame_size[buf[0] & 3] * FFMAX(1, avctx->ch_layout.nb_channels);
|
||||||
|
|
||||||
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
|
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
|
||||||
*poutbuf = NULL;
|
*poutbuf = NULL;
|
||||||
|
@ -117,12 +117,12 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
|
|||||||
G723_1_Context *s = avctx->priv_data;
|
G723_1_Context *s = avctx->priv_data;
|
||||||
|
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
|
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
|
||||||
if (avctx->channels < 1 || avctx->channels > 2) {
|
if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels);
|
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n",
|
||||||
|
avctx->ch_layout.nb_channels);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
|
||||||
for (int ch = 0; ch < avctx->channels; ch++) {
|
|
||||||
G723_1_ChannelContext *p = &s->ch[ch];
|
G723_1_ChannelContext *p = &s->ch[ch];
|
||||||
|
|
||||||
p->pf_gain = 1 << 12;
|
p->pf_gain = 1 << 12;
|
||||||
@ -932,6 +932,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
const uint8_t *buf = avpkt->data;
|
const uint8_t *buf = avpkt->data;
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
int dec_mode = buf[0] & 3;
|
int dec_mode = buf[0] & 3;
|
||||||
|
int channels = avctx->ch_layout.nb_channels;
|
||||||
|
|
||||||
PPFParam ppf[SUBFRAMES];
|
PPFParam ppf[SUBFRAMES];
|
||||||
int16_t cur_lsp[LPC_ORDER];
|
int16_t cur_lsp[LPC_ORDER];
|
||||||
@ -940,7 +941,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
int16_t *out;
|
int16_t *out;
|
||||||
int bad_frame = 0, i, j, ret;
|
int bad_frame = 0, i, j, ret;
|
||||||
|
|
||||||
if (buf_size < frame_size[dec_mode] * avctx->channels) {
|
if (buf_size < frame_size[dec_mode] * channels) {
|
||||||
if (buf_size)
|
if (buf_size)
|
||||||
av_log(avctx, AV_LOG_WARNING,
|
av_log(avctx, AV_LOG_WARNING,
|
||||||
"Expected %d bytes, got %d - skipping packet\n",
|
"Expected %d bytes, got %d - skipping packet\n",
|
||||||
@ -953,12 +954,12 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (int ch = 0; ch < avctx->channels; ch++) {
|
for (int ch = 0; ch < channels; ch++) {
|
||||||
G723_1_ChannelContext *p = &s->ch[ch];
|
G723_1_ChannelContext *p = &s->ch[ch];
|
||||||
int16_t *audio = p->audio;
|
int16_t *audio = p->audio;
|
||||||
|
|
||||||
if (unpack_bitstream(p, buf + ch * (buf_size / avctx->channels),
|
if (unpack_bitstream(p, buf + ch * (buf_size / channels),
|
||||||
buf_size / avctx->channels) < 0) {
|
buf_size / channels) < 0) {
|
||||||
bad_frame = 1;
|
bad_frame = 1;
|
||||||
if (p->past_frame_type == ACTIVE_FRAME)
|
if (p->past_frame_type == ACTIVE_FRAME)
|
||||||
p->cur_frame_type = ACTIVE_FRAME;
|
p->cur_frame_type = ACTIVE_FRAME;
|
||||||
@ -1090,7 +1091,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
|
|
||||||
*got_frame_ptr = 1;
|
*got_frame_ptr = 1;
|
||||||
|
|
||||||
return frame_size[dec_mode] * avctx->channels;
|
return frame_size[dec_mode] * channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(G723_1_Context, x)
|
#define OFFSET(x) offsetof(G723_1_Context, x)
|
||||||
|
@ -99,11 +99,6 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx)
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avctx->channels != 1) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (avctx->bit_rate == 6300) {
|
if (avctx->bit_rate == 6300) {
|
||||||
p->cur_rate = RATE_6300;
|
p->cur_rate = RATE_6300;
|
||||||
} else if (avctx->bit_rate == 5300) {
|
} else if (avctx->bit_rate == 5300) {
|
||||||
@ -1256,5 +1251,8 @@ const AVCodec ff_g723_1_encoder = {
|
|||||||
.sample_fmts = (const enum AVSampleFormat[]) {
|
.sample_fmts = (const enum AVSampleFormat[]) {
|
||||||
AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
|
AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
|
||||||
},
|
},
|
||||||
|
.ch_layouts = (const AVChannelLayout[]){
|
||||||
|
AV_CHANNEL_LAYOUT_MONO, { 0 }
|
||||||
|
},
|
||||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user