static void close_connection(HTTPContext *c)

{

    HTTPContext **cp, *c1;

    int i, nb_streams;

    AVFormatContext *ctx;

    URLContext *h;

    AVStream *st;



    /* remove connection from list */

    cp = &first_http_ctx;

    while ((*cp) != NULL) {

        c1 = *cp;

        if (c1 == c) {

            *cp = c->next;

        } else {

            cp = &c1->next;

        }

    }



    /* remove references, if any (XXX: do it faster) */

    for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {

        if (c1->rtsp_c == c)

            c1->rtsp_c = NULL;

    }



    /* remove connection associated resources */

    if (c->fd >= 0)

        close(c->fd);

    if (c->fmt_in) {

        /* close each frame parser */

        for(i=0;i<c->fmt_in->nb_streams;i++) {

            st = c->fmt_in->streams[i];

            if (st->codec->codec) {

                avcodec_close(st->codec);

            }

        }

        av_close_input_file(c->fmt_in);

    }



    /* free RTP output streams if any */

    nb_streams = 0;

    if (c->stream) 

        nb_streams = c->stream->nb_streams;

    

    for(i=0;i<nb_streams;i++) {

        ctx = c->rtp_ctx[i];

        if (ctx) {

            av_write_trailer(ctx);

            av_free(ctx);

        }

        h = c->rtp_handles[i];

        if (h) {

            url_close(h);

        }

    }

    

    ctx = &c->fmt_ctx;



    if (!c->last_packet_sent) {

        if (ctx->oformat) {

            /* prepare header */

            if (url_open_dyn_buf(&ctx->pb) >= 0) {

                av_write_trailer(ctx);

                url_close_dyn_buf(&ctx->pb, &c->pb_buffer);

            }

        }

    }



    for(i=0; i<ctx->nb_streams; i++) 

        av_free(ctx->streams[i]) ; 



    if (c->stream)

        current_bandwidth -= c->stream->bandwidth;

    av_freep(&c->pb_buffer);

    av_freep(&c->packet_buffer);

    av_free(c->buffer);

    av_free(c);

    nb_connections--;

}

static void close_connection(HTTPContext *c)

{

    HTTPContext **cp, *c1;

    int i, nb_streams;

    AVFormatContext *ctx;

    URLContext *h;

    AVStream *st;



    

    cp = &first_http_ctx;

    while ((*cp) != NULL) {

        c1 = *cp;

        if (c1 == c) {

            *cp = c->next;

        } else {

            cp = &c1->next;

        }

    }



    

    for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {

        if (c1->rtsp_c == c)

            c1->rtsp_c = NULL;

    }



    

    if (c->fd >= 0)

        close(c->fd);

    if (c->fmt_in) {

        

        for(i=0;i<c->fmt_in->nb_streams;i++) {

            st = c->fmt_in->streams[i];

            if (st->codec->codec) {

                avcodec_close(st->codec);

            }

        }

        av_close_input_file(c->fmt_in);

    }



    

    nb_streams = 0;

    if (c->stream) 

        nb_streams = c->stream->nb_streams;

    

    for(i=0;i<nb_streams;i++) {

        ctx = c->rtp_ctx[i];

        if (ctx) {

            av_write_trailer(ctx);

            av_free(ctx);

        }

        h = c->rtp_handles[i];

        if (h) {

            url_close(h);

        }

    }

    

    ctx = &c->fmt_ctx;



    if (!c->last_packet_sent) {

        if (ctx->oformat) {

            

            if (url_open_dyn_buf(&ctx->pb) >= 0) {

                av_write_trailer(ctx);

                url_close_dyn_buf(&ctx->pb, &c->pb_buffer);

            }

        }

    }



    for(i=0; i<ctx->nb_streams; i++) 

        av_free(ctx->streams[i]) ; 



    if (c->stream)

        current_bandwidth -= c->stream->bandwidth;

    av_freep(&c->pb_buffer);

    av_freep(&c->packet_buffer);

    av_free(c->buffer);

    av_free(c);

    nb_connections--;

}

static void FUNC_0(HTTPContext *VAR_0)

{

    HTTPContext **cp, *c1;

    int VAR_1, VAR_2;

    AVFormatContext *ctx;

    URLContext *h;

    AVStream *st;



    

    cp = &first_http_ctx;

    while ((*cp) != NULL) {

        c1 = *cp;

        if (c1 == VAR_0) {

            *cp = VAR_0->next;

        } else {

            cp = &c1->next;

        }

    }



    

    for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {

        if (c1->rtsp_c == VAR_0)

            c1->rtsp_c = NULL;

    }



    

    if (VAR_0->fd >= 0)

        close(VAR_0->fd);

    if (VAR_0->fmt_in) {

        

        for(VAR_1=0;VAR_1<VAR_0->fmt_in->VAR_2;VAR_1++) {

            st = VAR_0->fmt_in->streams[VAR_1];

            if (st->codec->codec) {

                avcodec_close(st->codec);

            }

        }

        av_close_input_file(VAR_0->fmt_in);

    }



    

    VAR_2 = 0;

    if (VAR_0->stream) 

        VAR_2 = VAR_0->stream->VAR_2;

    

    for(VAR_1=0;VAR_1<VAR_2;VAR_1++) {

        ctx = VAR_0->rtp_ctx[VAR_1];

        if (ctx) {

            av_write_trailer(ctx);

            av_free(ctx);

        }

        h = VAR_0->rtp_handles[VAR_1];

        if (h) {

            url_close(h);

        }

    }

    

    ctx = &VAR_0->fmt_ctx;



    if (!VAR_0->last_packet_sent) {

        if (ctx->oformat) {

            

            if (url_open_dyn_buf(&ctx->pb) >= 0) {

                av_write_trailer(ctx);

                url_close_dyn_buf(&ctx->pb, &VAR_0->pb_buffer);

            }

        }

    }



    for(VAR_1=0; VAR_1<ctx->VAR_2; VAR_1++) 

        av_free(ctx->streams[VAR_1]) ; 



    if (VAR_0->stream)

        current_bandwidth -= VAR_0->stream->bandwidth;

    av_freep(&VAR_0->pb_buffer);

    av_freep(&VAR_0->packet_buffer);

    av_free(VAR_0->buffer);

    av_free(VAR_0);

    nb_connections--;

}

static void FUNC_0(HTTPContext *VAR_0)
{ HTTPContext **cp, *c1; int VAR_1, VAR_2; AVFormatContext *ctx; URLContext *h; AVStream *st; cp = &first_http_ctx; while ((*cp) != NULL) { c1 = *cp; if (c1 == VAR_0) { *cp = VAR_0->next; } else { cp = &c1->next; } } for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) { if (c1->rtsp_c == VAR_0)
c1->rtsp_c = NULL; } if (VAR_0->fd >= 0)
close(VAR_0->fd); if (VAR_0->fmt_in) { for(VAR_1=0;VAR_1<VAR_0->fmt_in->VAR_2;VAR_1++) { st = VAR_0->fmt_in->streams[VAR_1]; if (st->codec->codec) { avcodec_close(st->codec); } } av_close_input_file(VAR_0->fmt_in); } VAR_2 = 0; if (VAR_0->stream)
VAR_2 = VAR_0->stream->VAR_2; for(VAR_1=0;VAR_1<VAR_2;VAR_1++) { ctx = VAR_0->rtp_ctx[VAR_1]; if (ctx) { av_write_trailer(ctx); av_free(ctx); } h = VAR_0->rtp_handles[VAR_1]; if (h) { url_close(h); } } ctx = &VAR_0->fmt_ctx; if (!VAR_0->last_packet_sent) { if (ctx->oformat) { if (url_open_dyn_buf(&ctx->pb) >= 0) { av_write_trailer(ctx); url_close_dyn_buf(&ctx->pb, &VAR_0->pb_buffer); } } } for(VAR_1=0; VAR_1<ctx->VAR_2; VAR_1++) av_free(ctx->streams[VAR_1]) ; if (VAR_0->stream)
current_bandwidth -= VAR_0->stream->bandwidth; av_freep(&VAR_0->pb_buffer); av_freep(&VAR_0->packet_buffer); av_free(VAR_0->buffer); av_free(VAR_0); nb_connections--; }