void av_close_input_stream(AVFormatContext *s)
{
    int i;
    AVStream *st;
    if (s->cur_st && s->cur_st->parser)
        av_free_packet(&s->cur_pkt);
    if (s->iformat->read_close)
        s->iformat->read_close(s);
    for(i=0;i<s->nb_streams;i++) {
        st = s->streams[i];
        if (st->parser) {
            av_parser_close(st->parser);
        }
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec);
        av_free(st->filename);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
        av_freep(&s->programs[i]->provider_name);
        av_freep(&s->programs[i]->name);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    flush_packet_queue(s);
    av_freep(&s->priv_data);
    av_free(s);
}
['static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h)\n{\n    HTTPContext *rtp_c;\n    char session_id[32];\n    rtp_c = find_rtp_session_with_url(url, h->session_id);\n    if (!rtp_c) {\n        rtsp_reply_error(c, RTSP_STATUS_SESSION);\n        return;\n    }\n    av_strlcpy(session_id, rtp_c->session_id, sizeof(session_id));\n    close_connection(rtp_c);\n    rtsp_reply_header(c, RTSP_STATUS_OK);\n    url_fprintf(c->pb, "Session: %s\\r\\n", session_id);\n    url_fprintf(c->pb, "\\r\\n");\n}', 'static HTTPContext *find_rtp_session_with_url(const char *url,\n                                              const char *session_id)\n{\n    HTTPContext *rtp_c;\n    char path1[1024];\n    const char *path;\n    char buf[1024];\n    int s;\n    rtp_c = find_rtp_session(session_id);\n    if (!rtp_c)\n        return NULL;\n    url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);\n    path = path1;\n    if (*path == \'/\')\n        path++;\n    if(!strcmp(path, rtp_c->stream->filename)) return rtp_c;\n    for(s=0; s<rtp_c->stream->nb_streams; ++s) {\n      snprintf(buf, sizeof(buf), "%s/streamid=%d",\n        rtp_c->stream->filename, s);\n      if(!strncmp(path, buf, sizeof(buf))) {\n        return rtp_c;\n      }\n    }\n    return NULL;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n    size_t len = 0;\n    while (++len < size && *src)\n        *dst++ = *src++;\n    if (len <= size)\n        *dst = 0;\n    return len + strlen(src) - 1;\n}', 'static void close_connection(HTTPContext *c)\n{\n    HTTPContext **cp, *c1;\n    int i, nb_streams;\n    AVFormatContext *ctx;\n    URLContext *h;\n    AVStream *st;\n    cp = &first_http_ctx;\n    while ((*cp) != NULL) {\n        c1 = *cp;\n        if (c1 == c)\n            *cp = c->next;\n        else\n            cp = &c1->next;\n    }\n    for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n        if (c1->rtsp_c == c)\n            c1->rtsp_c = NULL;\n    }\n    if (c->fd >= 0)\n        closesocket(c->fd);\n    if (c->fmt_in) {\n        for(i=0;i<c->fmt_in->nb_streams;i++) {\n            st = c->fmt_in->streams[i];\n            if (st->codec->codec)\n                avcodec_close(st->codec);\n        }\n        av_close_input_file(c->fmt_in);\n    }\n    nb_streams = 0;\n    if (c->stream)\n        nb_streams = c->stream->nb_streams;\n    for(i=0;i<nb_streams;i++) {\n        ctx = c->rtp_ctx[i];\n        if (ctx) {\n            av_write_trailer(ctx);\n            av_free(ctx);\n        }\n        h = c->rtp_handles[i];\n        if (h)\n            url_close(h);\n    }\n    ctx = &c->fmt_ctx;\n    if (!c->last_packet_sent) {\n        if (ctx->oformat) {\n            if (url_open_dyn_buf(&ctx->pb) >= 0) {\n                av_write_trailer(ctx);\n                url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n            }\n        }\n    }\n    for(i=0; i<ctx->nb_streams; i++)\n        av_free(ctx->streams[i]);\n    if (c->stream && !c->post && c->stream->stream_type == STREAM_TYPE_LIVE)\n        current_bandwidth -= c->stream->bandwidth;\n    if (c->state == HTTPSTATE_RECEIVE_DATA && c->stream) {\n        c->stream->feed_opened = 0;\n        close(c->feed_fd);\n    }\n    av_freep(&c->pb_buffer);\n    av_freep(&c->packet_buffer);\n    av_free(c->buffer);\n    av_free(c);\n    nb_connections--;\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n    ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n    av_close_input_stream(s);\n    if (pb)\n        url_fclose(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\n    if (s->cur_st && s->cur_st->parser)\n        av_free_packet(&s->cur_pkt);\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\n    for(i=0;i<s->nb_streams;i++) {\n        st = s->streams[i];\n        if (st->parser) {\n            av_parser_close(st->parser);\n        }\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec);\n        av_free(st->filename);\n        av_free(st);\n    }\n    for(i=s->nb_programs-1; i>=0; i--) {\n        av_freep(&s->programs[i]->provider_name);\n        av_freep(&s->programs[i]->name);\n        av_freep(&s->programs[i]->stream_index);\n        av_freep(&s->programs[i]);\n    }\n    flush_packet_queue(s);\n    av_freep(&s->priv_data);\n    av_free(s);\n}']