我从rtmp中解码出了音频流,怎么用audioqueue播放呢
PCM实时音频流怎样播放?
我现在有ffmpeg解码出来的pcm实时音频数据,但是不知道应该怎样播放,请教一下怎么用audioqueue播实时音频流呢?想把ffmpeg解码出来的PCM包直接扔给AudioQueue进行播放
int VoiceErrorCode = 0;
av_register_all(); //注册所有可解码类型
AVFormatContext *pInFmtCtx=NULL; //文件格式
AVCodecContext *pInCodecCtx=NULL; //编码格式
if (av_open_input_file(&pInFmtCtx, [voicePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, 0, NULL)!=0) //获取文件格式
printf("av_open_input_file error\n");
if (av_find_stream_info(pInFmtCtx) < 0) //获取文件内音视频流的信息
printf("av_find_stream_info error\n");
unsigned int j;
// Find the first audio stream
int audioStream = -1;
for (j=0; j<pInFmtCtx->nb_streams; j++) //找到音频对应的stream
{
if (pInFmtCtx->streams[j]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
{
audioStream = j;
break;
}
}
if (audioStream == -1)
{
printf("input file has no audio stream\n");
return VoiceErrorCode; // Didn't find a audio stream
}
printf("audio stream num: %d\n",audioStream);
pInCodecCtx = pInFmtCtx->streams[audioStream]->codec; //音频的编码上下文
AVCodec *pInCodec = NULL;
pInCodec = avcodec_find_decoder(pInCodecCtx->codec_id); //根据编码ID找到用于解码的结构体
if (pInCodec == NULL)
{
printf("error no Codec found\n");
VoiceErrorCode =-1 ; // Codec not found
}
if(avcodec_open(pInCodecCtx, pInCodec)<0)//将两者结合以便在下面的解码函数中调用pInCodec中的对应解码函数
{
printf("error avcodec_open failed.\n");
VoiceErrorCode= -1; // Could not open codec
}
static AVPacket Packet;
printf(" bit_rate = %d \r\n", pInCodecCtx->bit_rate);
printf(" sample_rate = %d \r\n", pInCodecCtx->sample_rate);
printf(" channels = %d \r\n", pInCodecCtx->channels);
printf(" code_name = %s \r\n", pInCodecCtx->codec->name);
printf(" block_align = %d\n",pInCodecCtx->block_align);