//解音频并播放
bool audio_decode(const char*framebuf, int asize)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int out_size, size, len;
uint8_t *outbuf;
uint8_t *inbuf_ptr;
size = asize;
printf("Audio decoding\n");
if(!m_reg)
{
#if 0
av_register_all();
#else
avcodec_init();
register_avcodec(&mpeg4aac_decoder);
register_avcodec(&h263_decoder);
register_avcodec(&mpeg4_decoder);
#endif
m_reg = true;
}
/* find the mpeg audio decoder */
codec = avcodec_find_decoder(CODEC_ID_MPEG4AAC);
if (!codec) {
fprintf(stderr, "codec not found\n");
//exit(1);
return false;
}
c= avcodec_alloc_context();
c->channels = 2;
/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
return false;
}
outbuf = (uint8_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
/* decode until eof */
inbuf_ptr = (uint8_t *)framebuf;
while (size > 0) {
len = avcodec_decode_audio(c, (short *)outbuf, &out_size,
inbuf_ptr, size);
if (len < 0) {
fprintf(stderr, "Error while decoding\n");
exit(1);
}
if (out_size > 0) {
/* if a frame has been decoded, output it */
//just for test
int test;
test = 0;
}
size -= len;
inbuf_ptr += len;
}
free(outbuf);
avcodec_close(c);
av_free(c);
return true;
}
我的平台是Windows mobile 6,执行到avcodec_decode_audio时,模拟器断开连接.有没有高手遇到过这种情况能指教一下?
------解决方案--------------------------------------------------------
模拟器断开连接什么意思,是机器处于假死状态吗?然后连接被挤断?
------解决方案--------------------------------------------------------
mark