You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +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:
		
				
					committed by
					
						 James Almer
						James Almer
					
				
			
			
				
	
			
			
			
						parent
						
							c21e1492e3
						
					
				
				
					commit
					182866e9e4
				
			| @@ -37,7 +37,7 @@ static int g723_1_parse(AVCodecParserContext *s1, AVCodecContext *avctx, | ||||
|     int next = END_NOT_FOUND; | ||||
|  | ||||
|     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) { | ||||
|         *poutbuf      = NULL; | ||||
|   | ||||
| @@ -117,12 +117,12 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx) | ||||
|     G723_1_Context *s = avctx->priv_data; | ||||
|  | ||||
|     avctx->sample_fmt     = AV_SAMPLE_FMT_S16P; | ||||
|     if (avctx->channels < 1 || avctx->channels > 2) { | ||||
|         av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels); | ||||
|     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->ch_layout.nb_channels); | ||||
|         return AVERROR(EINVAL); | ||||
|     } | ||||
|     avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; | ||||
|     for (int ch = 0; ch < avctx->channels; ch++) { | ||||
|     for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { | ||||
|         G723_1_ChannelContext *p = &s->ch[ch]; | ||||
|  | ||||
|         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; | ||||
|     int buf_size       = avpkt->size; | ||||
|     int dec_mode       = buf[0] & 3; | ||||
|     int channels       = avctx->ch_layout.nb_channels; | ||||
|  | ||||
|     PPFParam ppf[SUBFRAMES]; | ||||
|     int16_t cur_lsp[LPC_ORDER]; | ||||
| @@ -940,7 +941,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, | ||||
|     int16_t *out; | ||||
|     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) | ||||
|             av_log(avctx, AV_LOG_WARNING, | ||||
|                    "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) | ||||
|         return ret; | ||||
|  | ||||
|     for (int ch = 0; ch < avctx->channels; ch++) { | ||||
|     for (int ch = 0; ch < channels; ch++) { | ||||
|         G723_1_ChannelContext *p = &s->ch[ch]; | ||||
|         int16_t *audio = p->audio; | ||||
|  | ||||
|         if (unpack_bitstream(p, buf + ch * (buf_size / avctx->channels), | ||||
|                              buf_size / avctx->channels) < 0) { | ||||
|         if (unpack_bitstream(p, buf + ch * (buf_size / channels), | ||||
|                              buf_size / channels) < 0) { | ||||
|             bad_frame = 1; | ||||
|             if (p->past_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; | ||||
|  | ||||
|     return frame_size[dec_mode] * avctx->channels; | ||||
|     return frame_size[dec_mode] * channels; | ||||
| } | ||||
|  | ||||
| #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); | ||||
|     } | ||||
|  | ||||
|     if (avctx->channels != 1) { | ||||
|         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); | ||||
|         return AVERROR(EINVAL); | ||||
|     } | ||||
|  | ||||
|     if (avctx->bit_rate == 6300) { | ||||
|         p->cur_rate = RATE_6300; | ||||
|     } else if (avctx->bit_rate == 5300) { | ||||
| @@ -1256,5 +1251,8 @@ const AVCodec ff_g723_1_encoder = { | ||||
|     .sample_fmts    = (const enum AVSampleFormat[]) { | ||||
|         AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE | ||||
|     }, | ||||
|     .ch_layouts     = (const AVChannelLayout[]){ | ||||
|         AV_CHANNEL_LAYOUT_MONO, { 0 } | ||||
|     }, | ||||
|     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE, | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user