static int decode_thread(void *arg) { /*(1):首先调用av_open_input_file()直接识别文件格式和间接识别媒体格式(媒体格式 是通过av_open_input_file调用av_open_input_stream 再调用ic->iformat->read_header(ic, ap) 来识别的,所以是间接识别媒体格式)。*/ err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap); err = av_find_stream_info(ic); /* open the streams (2):接着调用stream_component_open()查找打开编解码器codec 并启动音频和视频解码线程。*/ for(i = 0; i < ic->nb_streams; i++) { stream_component_open(is, i); } for(;;) { /*(3):再接着解析文件,分离音视频数据包,排序进入队列。*/ ret = av_read_frame(ic, pkt); //将Packet放入对应的队列:audio, video , subtitle if (pkt->stream_index == is->audio_stream) { packet_queue_put(&is->audioq, pkt); } else if (pkt->stream_index == is->video_stream) { packet_queue_put(&is->videoq, pkt); } else if (pkt->stream_index == is->subtitle_stream) { packet_queue_put(&is->subtitleq, pkt); } else { av_free_packet(pkt); } } /* wait until the end */ while (!is->abort_request) { SDL_Delay(100); } /* close each stream */ for(i = 0; i < ic->nb_streams; i++) { stream_component_close(is, i); } av_close_input_file(is->ic); return 0; }