- 论坛徽章:
- 0
|
原帖由 随风缘 于 2008-9-22 13:12 发表 ![]()
在 av_read_frame 函数执行失败的时候调用exit就行了.
我当初也是这么改的,不管用啊
我找到循环读数据的那段,加了两句:
printf("\a\n");
goto fail;
结果一运行就马上退出,什么声音都还没播出
/* this thread gets the stream from the disk or the network */
static int decode_thread(void *arg)
{
。。。
ret = av_read_frame(ic, pkt);
if (ret < 0) {
printf("\a\n");
goto fail;
if (url_ferror(&ic->pb) == 0) {
SDL_Delay(100); /* wait for user event */
continue;
} else
break;
}
。。。
fail:
/* disable interrupting */
global_video_state = NULL;
/* close each stream */
if (is->audio_stream >= 0)
stream_component_close(is, is->audio_stream);
if (is->video_stream >= 0)
stream_component_close(is, is->video_stream);
if (is->subtitle_stream >= 0)
stream_component_close(is, is->subtitle_stream);
if (is->ic) {
av_close_input_file(is->ic);
is->ic = NULL; /* safety */
}
url_set_interrupt_cb(NULL);
if (ret != 0) {
SDL_Event event;
event.type = FF_QUIT_EVENT;
event.user.data1 = is;
SDL_PushEvent(&event);
}
return 0;
} |
把那两句加到continue后,结果和没改过一样,看了下av_read_frame接口函数的说明,返值小于0就是遇到文件尾了啊?
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream. The information is stored as a packet in pkt.
The returned packet is valid until the next av_read_frame() or until av_close_input_file() and must be freed with av_free_packet. For video, the packet contains exactly one frame. For audio, it contains an integer number of frames if each frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames have a variable size (e.g. MPEG audio), then it contains one frame.
pkt->pts, pkt->dts and pkt->duration are always set to correct values in AVStream.timebase units (and guessed if the format cannot provided them). pkt->pts can be AV_NOPTS_VALUE if the video format has B frames, so it is better to rely on pkt->dts if you do not decompress the payload.
Returns: 0 if OK, < 0 if error or end of file. |
|