void av_close_input_stream(AVFormatContext *s)
{
    int i;
    AVStream *st;
    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_packet(&st->cur_pkt);
        }
        av_metadata_free(&st->metadata);
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec);
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_free(st->filename);
#endif
        av_free(st->priv_data);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_freep(&s->programs[i]->provider_name);
        av_freep(&s->programs[i]->name);
#endif
        av_metadata_free(&s->programs[i]->metadata);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    av_freep(&s->programs);
    flush_packet_queue(s);
    av_freep(&s->priv_data);
    while(s->nb_chapters--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_free(s->chapters[s->nb_chapters]->title);
#endif
        av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
        av_free(s->chapters[s->nb_chapters]);
    }
    av_freep(&s->chapters);
    av_metadata_free(&s->metadata);
    av_free(s);
}
['static int http_receive_data(HTTPContext *c)\n{\n    HTTPContext *c1;\n    int len, loop_run = 0;\n    while (c->chunked_encoding && !c->chunk_size &&\n           c->buffer_end > c->buffer_ptr) {\n        len = recv(c->fd, c->buffer_ptr, 1, 0);\n        if (len < 0) {\n            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n                ff_neterrno() != FF_NETERROR(EINTR))\n                goto fail;\n            return 0;\n        } else if (len == 0) {\n            goto fail;\n        } else if (c->buffer_ptr - c->buffer >= 2 &&\n                   !memcmp(c->buffer_ptr - 1, "\\r\\n", 2)) {\n            c->chunk_size = strtol(c->buffer, 0, 16);\n            if (c->chunk_size == 0)\n                goto fail;\n            c->buffer_ptr = c->buffer;\n            break;\n        } else if (++loop_run > 10) {\n            goto fail;\n        } else {\n            c->buffer_ptr++;\n        }\n    }\n    if (c->buffer_end > c->buffer_ptr) {\n        len = recv(c->fd, c->buffer_ptr,\n                   FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);\n        if (len < 0) {\n            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n                ff_neterrno() != FF_NETERROR(EINTR))\n                goto fail;\n        } else if (len == 0)\n            goto fail;\n        else {\n            c->chunk_size -= len;\n            c->buffer_ptr += len;\n            c->data_count += len;\n            update_datarate(&c->datarate, c->data_count);\n        }\n    }\n    if (c->buffer_ptr - c->buffer >= 2 && c->data_count > FFM_PACKET_SIZE) {\n        if (c->buffer[0] != \'f\' ||\n            c->buffer[1] != \'m\') {\n            http_log("Feed stream has become desynchronized -- disconnecting\\n");\n            goto fail;\n        }\n    }\n    if (c->buffer_ptr >= c->buffer_end) {\n        FFStream *feed = c->stream;\n        if (c->data_count > FFM_PACKET_SIZE) {\n            lseek(c->feed_fd, feed->feed_write_index, SEEK_SET);\n            if (write(c->feed_fd, c->buffer, FFM_PACKET_SIZE) < 0) {\n                http_log("Error writing to feed file: %s\\n", strerror(errno));\n                goto fail;\n            }\n            feed->feed_write_index += FFM_PACKET_SIZE;\n            if (feed->feed_write_index > c->stream->feed_size)\n                feed->feed_size = feed->feed_write_index;\n            if (c->stream->feed_max_size && feed->feed_write_index >= c->stream->feed_max_size)\n                feed->feed_write_index = FFM_PACKET_SIZE;\n            if (ffm_write_write_index(c->feed_fd, feed->feed_write_index) < 0) {\n                http_log("Error writing index to feed file: %s\\n", strerror(errno));\n                goto fail;\n            }\n            for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n                if (c1->state == HTTPSTATE_WAIT_FEED &&\n                    c1->stream->feed == c->stream->feed)\n                    c1->state = HTTPSTATE_SEND_DATA;\n            }\n        } else {\n            AVFormatContext *s = NULL;\n            ByteIOContext *pb;\n            AVInputFormat *fmt_in;\n            int i;\n            fmt_in = av_find_input_format(feed->fmt->name);\n            if (!fmt_in)\n                goto fail;\n            url_open_buf(&pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);\n            pb->is_streamed = 1;\n            if (av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL) < 0) {\n                av_free(pb);\n                goto fail;\n            }\n            if (s->nb_streams != feed->nb_streams) {\n                av_close_input_stream(s);\n                av_free(pb);\n                http_log("Feed \'%s\' stream number does not match registered feed\\n",\n                         c->stream->feed_filename);\n                goto fail;\n            }\n            for (i = 0; i < s->nb_streams; i++) {\n                AVStream *fst = feed->streams[i];\n                AVStream *st = s->streams[i];\n                avcodec_copy_context(fst->codec, st->codec);\n            }\n            av_close_input_stream(s);\n            av_free(pb);\n        }\n        c->buffer_ptr = c->buffer;\n    }\n    return 0;\n fail:\n    c->stream->feed_opened = 0;\n    close(c->feed_fd);\n    for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n        if (c1->state == HTTPSTATE_WAIT_FEED &&\n            c1->stream->feed == c->stream->feed)\n            c1->state = HTTPSTATE_SEND_DATA_TRAILER;\n    }\n    return -1;\n}', 'int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)\n{\n    if (dest->codec) {\n        av_log(dest, AV_LOG_ERROR,\n               "Tried to copy AVCodecContext %p into already-initialized %p\\n",\n               src, dest);\n        return AVERROR(EINVAL);\n    }\n    memcpy(dest, src, sizeof(*dest));\n    dest->priv_data       = NULL;\n    dest->codec           = NULL;\n    dest->palctrl         = NULL;\n    dest->slice_offset    = NULL;\n    dest->internal_buffer = NULL;\n    dest->hwaccel         = NULL;\n    dest->thread_opaque   = NULL;\n    dest->rc_eq           = NULL;\n    dest->extradata       = NULL;\n    dest->intra_matrix    = NULL;\n    dest->inter_matrix    = NULL;\n    dest->rc_override     = NULL;\n    if (src->rc_eq) {\n        dest->rc_eq = av_strdup(src->rc_eq);\n        if (!dest->rc_eq)\n            return AVERROR(ENOMEM);\n    }\n#define alloc_and_copy_or_fail(obj, size, pad) \\\n    if (src->obj && size > 0) { \\\n        dest->obj = av_malloc(size + pad); \\\n        if (!dest->obj) \\\n            goto fail; \\\n        memcpy(dest->obj, src->obj, size); \\\n        if (pad) \\\n            memset(((uint8_t *) dest->obj) + size, 0, pad); \\\n    }\n    alloc_and_copy_or_fail(extradata,    src->extradata_size,\n                           FF_INPUT_BUFFER_PADDING_SIZE);\n    alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);\n    alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);\n    alloc_and_copy_or_fail(rc_override,  src->rc_override_count * sizeof(*src->rc_override), 0);\n#undef alloc_and_copy_or_fail\n    return 0;\nfail:\n    av_freep(&dest->rc_override);\n    av_freep(&dest->intra_matrix);\n    av_freep(&dest->inter_matrix);\n    av_freep(&dest->extradata);\n    av_freep(&dest->rc_eq);\n    return AVERROR(ENOMEM);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\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            av_free_packet(&st->cur_pkt);\n        }\n        av_metadata_free(&st->metadata);\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec);\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_free(st->filename);\n#endif\n        av_free(st->priv_data);\n        av_free(st);\n    }\n    for(i=s->nb_programs-1; i>=0; i--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_freep(&s->programs[i]->provider_name);\n        av_freep(&s->programs[i]->name);\n#endif\n        av_metadata_free(&s->programs[i]->metadata);\n        av_freep(&s->programs[i]->stream_index);\n        av_freep(&s->programs[i]);\n    }\n    av_freep(&s->programs);\n    flush_packet_queue(s);\n    av_freep(&s->priv_data);\n    while(s->nb_chapters--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_free(s->chapters[s->nb_chapters]->title);\n#endif\n        av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n        av_free(s->chapters[s->nb_chapters]);\n    }\n    av_freep(&s->chapters);\n    av_metadata_free(&s->metadata);\n    av_free(s);\n}']