前提条件:首先能解码正常的压缩格式的数据比如:MP3、aac等格式的!
BUG结果:不能解码出WAV格式数据!
原 因:声道数和声道布局不对应 ,所以生成的SwrContext是错误的,进而swr_convert 的时候 格式转换异常!
所 以 在:在获取到AVCodecContext的时候要进行声道数和声道布局数统一处理下。
//avCodecContext 是我的解码器上下文
if (avCodecContext->channels > 0 && avCodecContext->channel_layout == 0) { //有声道数没有声道布局,所以要设置声道布局
avCodecContext->channel_layout = av_get_default_channel_layout(avCodecContext->channels);//设置声道布局
} else if (avCodecContext->channels == 0 && avCodecContext->channel_layout > 0) {//有声道布局没有声道数,所以要设置声道数
avCodecContext->channels = av_get_channel_layout_nb_channels(avCodecContext->channel_layout);
}