| 802 | } |
| 803 | |
| 804 | static void close_connection(HTTPContext *c) |
| 805 | { |
| 806 | HTTPContext **cp, *c1; |
| 807 | int i, nb_streams; |
| 808 | AVFormatContext *ctx; |
| 809 | URLContext *h; |
| 810 | AVStream *st; |
| 811 | |
| 812 | /* remove connection from list */ |
| 813 | cp = &first_http_ctx; |
| 814 | while ((*cp) != NULL) { |
| 815 | c1 = *cp; |
| 816 | if (c1 == c) |
| 817 | *cp = c->next; |
| 818 | else |
| 819 | cp = &c1->next; |
| 820 | } |
| 821 | |
| 822 | /* remove references, if any (XXX: do it faster) */ |
| 823 | for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) { |
| 824 | if (c1->rtsp_c == c) |
| 825 | c1->rtsp_c = NULL; |
| 826 | } |
| 827 | |
| 828 | /* remove connection associated resources */ |
| 829 | if (c->fd >= 0) |
| 830 | closesocket(c->fd); |
| 831 | if (c->fmt_in) { |
| 832 | /* close each frame parser */ |
| 833 | for(i=0;i<c->fmt_in->nb_streams;i++) { |
| 834 | st = c->fmt_in->streams[i]; |
| 835 | if (st->codec->codec) |
| 836 | avcodec_close(st->codec); |
| 837 | } |
| 838 | av_close_input_file(c->fmt_in); |
| 839 | } |
| 840 | |
| 841 | /* free RTP output streams if any */ |
| 842 | nb_streams = 0; |
| 843 | if (c->stream) |
| 844 | nb_streams = c->stream->nb_streams; |
| 845 | |
| 846 | for(i=0;i<nb_streams;i++) { |
| 847 | ctx = c->rtp_ctx[i]; |
| 848 | if (ctx) { |
| 849 | av_write_trailer(ctx); |
| 850 | av_metadata_free(&ctx->metadata); |
| 851 | av_free(ctx->streams[0]); |
| 852 | av_free(ctx); |
| 853 | } |
| 854 | h = c->rtp_handles[i]; |
| 855 | if (h) |
| 856 | url_close(h); |
| 857 | } |
| 858 | |
| 859 | ctx = &c->fmt_ctx; |
| 860 | |
| 861 | if (!c->last_packet_sent && c->state == HTTPSTATE_SEND_DATA_TRAILER) { |
no test coverage detected