if (is->audio_stream >= 0) { packet_queue_flush(&is->audioq); } if (is->video_stream >= 0) { packet_queue_flush(&is->videoq); }
static int decode_thread(void *arg){    VideoState *is = arg;    AVFormatContext *ic;    int err, i, ret, video_index, audio_index, use_play;    AVPacket pkt1, *pkt = &pkt1;    AVFormatParameters params, *ap = &params;    video_index = -1;    audio_index = -1;    is->video_stream = -1;    is->audio_stream = -1;    global_video_state = is;    url_set_interrupt_cb(decode_interrupt_cb);    memset(ap, 0, sizeof(*ap));    ap->image_format = image_format;    ap->initial_pause = 1; /* we force a pause when starting an RTSP                              stream */        err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);    if (err < 0) {        print_error(is->filename, err);        ret = -1;        goto fail;    }    is->ic = ic;#ifdef CONFIG_NETWORK    use_play = (ic->iformat == &rtsp_demux);#else    use_play = 0;#endif    if (!use_play) {        err = av_find_stream_info(ic);        if (err < 0) {            fprintf(stderr, "%s: could not find codec parameters\n", is->filename);            ret = -1;            goto fail;        }    }    /* if seeking requested, we execute it */    if (start_time != AV_NOPTS_VALUE) {        int64_t timestamp;        timestamp = start_time;        /* add the stream start time */        if (ic->start_time != AV_NOPTS_VALUE)            timestamp += ic->start_time;        ret = av_seek_frame(ic, -1, timestamp);        if (ret < 0) {            fprintf(stderr, "%s: could not seek to position %0.3f\n",                     is->filename, (double)timestamp / AV_TIME_BASE);        }    }    /* now we can begin to play (RTSP stream only) */    av_read_play(ic);    if (use_play) {        err = av_find_stream_info(ic);        if (err < 0) {            fprintf(stderr, "%s: could not find codec parameters\n", is->filename);            ret = -1;            goto fail;        }    }    for(i = 0; i < ic->nb_streams; i++) {        AVCodecContext *enc = &ic->streams[i]->codec;        switch(enc->codec_type) {        case CODEC_TYPE_AUDIO:            if (audio_index < 0 && !audio_disable)                audio_index = i;            break;        case CODEC_TYPE_VIDEO:            if (video_index < 0 && !video_disable)                video_index = i;            break;        default:            break;        }    }    if (show_status) {        dump_format(ic, 0, is->filename, 0);        dump_stream_info(ic);    }    /* open the streams */    if (audio_index >= 0) {        stream_component_open(is, audio_index);    }    if (video_index >= 0) {        stream_component_open(is, video_index);    } else {        if (!display_disable)            is->show_audio = 1;    }    if (is->video_stream < 0 && is->audio_stream < 0) {        fprintf(stderr, "%s: could not open codecs\n", is->filename);        ret = -1;        goto fail;    }    for(;;) {        if (is->abort_request)            break;#ifdef CONFIG_NETWORK        if (is->paused != is->last_paused) {            is->last_paused = is->paused;            if (is->paused)                av_read_pause(ic);            else                av_read_play(ic);        }        if (is->paused && ic->iformat == &rtsp_demux) {            /* wait 10 ms to avoid trying to get another packet */            /* XXX: horrible */            SDL_Delay(10);            continue;        }#endif        if (is->seek_req) {            /* XXX: must lock decoder threads */            if (is->audio_stream >= 0) {                packet_queue_flush(&is->audioq);            }            if (is->video_stream >= 0) {                packet_queue_flush(&is->videoq);            }            ret = av_seek_frame(is->ic, -1, is->seek_pos);            if (ret < 0) {                fprintf(stderr, "%s: error while seeking\n", is->ic->filename);            }            is->seek_req = 0;        }        /* if the queue are full, no need to read more */        if (is->audioq.size > MAX_AUDIOQ_SIZE ||            is->videoq.size > MAX_VIDEOQ_SIZE) {            /* wait 10 ms */            SDL_Delay(10);            continue;        }        ret = av_read_frame(ic, pkt);        if (ret < 0) {            break;        }        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 {            av_free_packet(pkt);        }    }    /* wait until the end */    while (!is->abort_request) {        SDL_Delay(100);    }    ret = 0; 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->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;}