g729: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
		
							parent
							
								
									e763a7cf0b
								
							
						
					
					
						commit
						64c64cb451
					
				@ -49,9 +49,9 @@ static int g729_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
 | 
				
			|||||||
        if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
 | 
					        if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
 | 
				
			||||||
            s->block_size++;
 | 
					            s->block_size++;
 | 
				
			||||||
        // channels > 2 is invalid, we pass the packet on unchanged
 | 
					        // channels > 2 is invalid, we pass the packet on unchanged
 | 
				
			||||||
        if (avctx->channels > 2)
 | 
					        if (avctx->ch_layout.nb_channels > 2)
 | 
				
			||||||
            s->block_size = 0;
 | 
					            s->block_size = 0;
 | 
				
			||||||
        s->block_size *= avctx->channels;
 | 
					        s->block_size *= avctx->ch_layout.nb_channels;
 | 
				
			||||||
        s->duration   = avctx->frame_size;
 | 
					        s->duration   = avctx->frame_size;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -350,10 +350,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    G729Context *s = avctx->priv_data;
 | 
					    G729Context *s = avctx->priv_data;
 | 
				
			||||||
    G729ChannelContext *ctx;
 | 
					    G729ChannelContext *ctx;
 | 
				
			||||||
 | 
					    int channels = avctx->ch_layout.nb_channels;
 | 
				
			||||||
    int c,i,k;
 | 
					    int c,i,k;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (avctx->channels < 1 || avctx->channels > 2) {
 | 
					    if (channels < 1 || 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", channels);
 | 
				
			||||||
        return AVERROR(EINVAL);
 | 
					        return AVERROR(EINVAL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
 | 
					    avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
 | 
				
			||||||
@ -362,11 +363,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
 | 
				
			|||||||
    avctx->frame_size = SUBFRAME_SIZE << 1;
 | 
					    avctx->frame_size = SUBFRAME_SIZE << 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ctx =
 | 
					    ctx =
 | 
				
			||||||
    s->channel_context = av_mallocz(sizeof(G729ChannelContext) * avctx->channels);
 | 
					    s->channel_context = av_mallocz(sizeof(G729ChannelContext) * channels);
 | 
				
			||||||
    if (!ctx)
 | 
					    if (!ctx)
 | 
				
			||||||
        return AVERROR(ENOMEM);
 | 
					        return AVERROR(ENOMEM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (c = 0; c < avctx->channels; c++) {
 | 
					    for (c = 0; c < channels; c++) {
 | 
				
			||||||
        ctx->gain_coeff = 16384; // 1.0 in (1.14)
 | 
					        ctx->gain_coeff = 16384; // 1.0 in (1.14)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (k = 0; k < MA_NP + 1; k++) {
 | 
					        for (k = 0; k < MA_NP + 1; k++) {
 | 
				
			||||||
@ -412,6 +413,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
 | 
				
			|||||||
    G729Formats packet_type;
 | 
					    G729Formats packet_type;
 | 
				
			||||||
    G729Context *s = avctx->priv_data;
 | 
					    G729Context *s = avctx->priv_data;
 | 
				
			||||||
    G729ChannelContext *ctx = s->channel_context;
 | 
					    G729ChannelContext *ctx = s->channel_context;
 | 
				
			||||||
 | 
					    int channels = avctx->ch_layout.nb_channels;
 | 
				
			||||||
    int16_t lp[2][11];           // (3.12)
 | 
					    int16_t lp[2][11];           // (3.12)
 | 
				
			||||||
    uint8_t ma_predictor;     ///< switched MA predictor of LSP quantizer
 | 
					    uint8_t ma_predictor;     ///< switched MA predictor of LSP quantizer
 | 
				
			||||||
    uint8_t quantizer_1st;    ///< first stage vector of quantizer
 | 
					    uint8_t quantizer_1st;    ///< first stage vector of quantizer
 | 
				
			||||||
@ -430,14 +432,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
 | 
				
			|||||||
    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 | 
					    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 | 
				
			||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels) == 0) {
 | 
					    if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels) == 0) {
 | 
				
			||||||
        packet_type = FORMAT_G729_8K;
 | 
					        packet_type = FORMAT_G729_8K;
 | 
				
			||||||
        format = &format_g729_8k;
 | 
					        format = &format_g729_8k;
 | 
				
			||||||
        //Reset voice decision
 | 
					        //Reset voice decision
 | 
				
			||||||
        ctx->onset = 0;
 | 
					        ctx->onset = 0;
 | 
				
			||||||
        ctx->voice_decision = DECISION_VOICE;
 | 
					        ctx->voice_decision = DECISION_VOICE;
 | 
				
			||||||
        av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
 | 
					        av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
 | 
				
			||||||
    } else if (buf_size == G729D_6K4_BLOCK_SIZE * avctx->channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
 | 
					    } else if (buf_size == G729D_6K4_BLOCK_SIZE * channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
 | 
				
			||||||
        packet_type = FORMAT_G729D_6K4;
 | 
					        packet_type = FORMAT_G729D_6K4;
 | 
				
			||||||
        format = &format_g729d_6k4;
 | 
					        format = &format_g729d_6k4;
 | 
				
			||||||
        av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
 | 
					        av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
 | 
				
			||||||
@ -446,13 +448,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
 | 
				
			|||||||
        return AVERROR_INVALIDDATA;
 | 
					        return AVERROR_INVALIDDATA;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (c = 0; c < avctx->channels; c++) {
 | 
					    for (c = 0; c < channels; c++) {
 | 
				
			||||||
        int frame_erasure = 0; ///< frame erasure detected during decoding
 | 
					        int frame_erasure = 0; ///< frame erasure detected during decoding
 | 
				
			||||||
        int bad_pitch = 0;     ///< parity check failed
 | 
					        int bad_pitch = 0;     ///< parity check failed
 | 
				
			||||||
        int is_periodic = 0;   ///< whether one of the subframes is declared as periodic or not
 | 
					        int is_periodic = 0;   ///< whether one of the subframes is declared as periodic or not
 | 
				
			||||||
        out_frame = (int16_t*)frame->data[c];
 | 
					        out_frame = (int16_t*)frame->data[c];
 | 
				
			||||||
        if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN) {
 | 
					        if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN) {
 | 
				
			||||||
            if (*buf != ((avctx->channels - 1 - c) * 0x80 | 2))
 | 
					            if (*buf != ((avctx->ch_layout.nb_channels - 1 - c) * 0x80 | 2))
 | 
				
			||||||
                avpriv_request_sample(avctx, "First byte value %x for channel %d", *buf, c);
 | 
					                avpriv_request_sample(avctx, "First byte value %x for channel %d", *buf, c);
 | 
				
			||||||
            buf++;
 | 
					            buf++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -739,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *got_frame_ptr = 1;
 | 
					    *got_frame_ptr = 1;
 | 
				
			||||||
    return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels;
 | 
					    return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static av_cold int decode_close(AVCodecContext *avctx)
 | 
					static av_cold int decode_close(AVCodecContext *avctx)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user