本文整理汇总了C++中AudioStream::setChannels方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioStream::setChannels方法的具体用法?C++ AudioStream::setChannels怎么用?C++ AudioStream::setChannels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioStream
的用法示例。
在下文中一共展示了AudioStream::setChannels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decodeFile
AudioStream* LibAvDecoder::decodeFile(char* fileName) throw (Exception){
av_register_all();
AVCodec *codec = NULL;
AVFormatContext *fCtx = NULL;
AVCodecContext *cCtx = NULL;
// Find audio stream
if(avformat_open_input(&fCtx, fileName, NULL, NULL) != 0){
qCritical("Failed to open audio file: %s", fileName);
throw Exception();
}
if(av_find_stream_info(fCtx) < 0){
qCritical("Failed to find stream information in file: %s", fileName);
throw Exception();
}
int audioStream = -1;
for(int i=0; i<(signed)fCtx->nb_streams; i++){
if(fCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO){
audioStream = i;
break;
}
}
if(audioStream == -1){
qCritical("Failed to find an audio stream in file: %s", fileName);
throw Exception();
}
// Determine stream codec
cCtx = fCtx->streams[audioStream]->codec;
codec = avcodec_find_decoder(cCtx->codec_id);
if(codec == NULL){
qCritical("Audio stream has unsupported codec in file: %s", fileName);
throw Exception();
}
if(avcodec_open(cCtx, codec) < 0){
qCritical("Error opening audio codec: %s", codec->long_name);
throw Exception();
}
// Prep buffer
AudioStream *astrm = new AudioStream();
astrm->setFrameRate(cCtx->sample_rate);
astrm->setChannels(cCtx->channels);
// Decode stream
AVPacket avpkt;
av_init_packet(&avpkt);
int bad_pkt_count = 0;
while(av_read_frame(fCtx, &avpkt) == 0){
if(avpkt.stream_index == audioStream)
try{
if(decodePacket(cCtx, &avpkt, astrm) != 0){
qWarning("LibAV: Error while processing packet");
if(bad_pkt_count < 100){
bad_pkt_count++;
}else{
qCritical("100 bad packets, may be DRM or corruption in file: %s", fileName);
throw Exception();
}
}
}catch(Exception& e){
throw e;
}
av_free_packet(&avpkt);
}
avcodec_close(cCtx);
av_close_input_file(fCtx);
return astrm;
}