int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
{
    const char *p;
    char tag[128], *q;
    p = info;
    if (*p == '?')
        p++;
    for(;;) {
        q = tag;
        while (*p != '\0' && *p != '=' && *p != '&') {
            if ((q - tag) < sizeof(tag) - 1)
                *q++ = *p;
            p++;
        }
        *q = '\0';
        q = arg;
        if (*p == '=') {
            p++;
            while (*p != '&' && *p != '\0') {
                if ((q - arg) < arg_size - 1) {
                    if (*p == '+')
                        *q++ = ' ';
                    else
                        *q++ = *p;
                }
                p++;
            }
            *q = '\0';
        }
        if (!strcmp(tag, tag1))
            return 1;
        if (*p != '&')
            break;
        p++;
    }
    return 0;
}
['static int http_prepare_data(HTTPContext *c)\n{\n    int i, len, ret;\n    AVFormatContext *ctx;\n    av_freep(&c->pb_buffer);\n    switch(c->state) {\n    case HTTPSTATE_SEND_DATA_HEADER:\n        memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));\n        av_strlcpy(c->fmt_ctx.author, c->stream->author,\n                   sizeof(c->fmt_ctx.author));\n        av_strlcpy(c->fmt_ctx.comment, c->stream->comment,\n                   sizeof(c->fmt_ctx.comment));\n        av_strlcpy(c->fmt_ctx.copyright, c->stream->copyright,\n                   sizeof(c->fmt_ctx.copyright));\n        av_strlcpy(c->fmt_ctx.title, c->stream->title,\n                   sizeof(c->fmt_ctx.title));\n        c->fmt_ctx.oformat = c->stream->fmt;\n        c->fmt_ctx.nb_streams = c->stream->nb_streams;\n        for(i=0;i<c->fmt_ctx.nb_streams;i++) {\n            AVStream *st;\n            AVStream *src;\n            st = av_mallocz(sizeof(AVStream));\n            st->codec= avcodec_alloc_context();\n            c->fmt_ctx.streams[i] = st;\n            if (!c->stream->feed ||\n                c->stream->feed == c->stream)\n                src = c->stream->streams[i];\n            else\n                src = c->stream->feed->streams[c->stream->feed_streams[i]];\n            *st = *src;\n            st->priv_data = 0;\n            st->codec->frame_number = 0;\n            st->codec->coded_frame = &dummy_frame;\n        }\n        c->got_key_frame = 0;\n        if (url_open_dyn_buf(&c->fmt_ctx.pb) < 0) {\n            return -1;\n        }\n        c->fmt_ctx.pb->is_streamed = 1;\n        av_set_parameters(&c->fmt_ctx, NULL);\n        if (av_write_header(&c->fmt_ctx) < 0)\n            return -1;\n        len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);\n        c->buffer_ptr = c->pb_buffer;\n        c->buffer_end = c->pb_buffer + len;\n        c->state = HTTPSTATE_SEND_DATA;\n        c->last_packet_sent = 0;\n        break;\n    case HTTPSTATE_SEND_DATA:\n        {\n            AVPacket pkt;\n            if (c->stream->feed)\n                ffm_set_write_index(c->fmt_in,\n                                    c->stream->feed->feed_write_index,\n                                    c->stream->feed->feed_size);\n            if (c->stream->max_time &&\n                c->stream->max_time + c->start_time - cur_time < 0)\n                c->state = HTTPSTATE_SEND_DATA_TRAILER;\n            else {\n            redo:\n                if (av_read_frame(c->fmt_in, &pkt) < 0) {\n                    if (c->stream->feed && c->stream->feed->feed_opened) {\n                        c->state = HTTPSTATE_WAIT_FEED;\n                        return 1;\n                    } else {\n                        if (c->stream->loop) {\n                            av_close_input_file(c->fmt_in);\n                            c->fmt_in = NULL;\n                            if (open_input_stream(c, "") < 0)\n                                goto no_loop;\n                            goto redo;\n                        } else {\n                        no_loop:\n                            c->state = HTTPSTATE_SEND_DATA_TRAILER;\n                        }\n                    }\n                } else {\n                    if (c->first_pts == AV_NOPTS_VALUE) {\n                        c->first_pts = av_rescale_q(pkt.dts, c->fmt_in->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);\n                        c->start_time = cur_time;\n                    }\n                    if (c->stream->feed) {\n                        if (c->switch_pending) {\n                            c->switch_pending = 0;\n                            for(i=0;i<c->stream->nb_streams;i++) {\n                                if (c->switch_feed_streams[i] == pkt.stream_index)\n                                    if (pkt.flags & PKT_FLAG_KEY)\n                                        do_switch_stream(c, i);\n                                if (c->switch_feed_streams[i] >= 0)\n                                    c->switch_pending = 1;\n                            }\n                        }\n                        for(i=0;i<c->stream->nb_streams;i++) {\n                            if (c->feed_streams[i] == pkt.stream_index) {\n                                pkt.stream_index = i;\n                                if (pkt.flags & PKT_FLAG_KEY)\n                                    c->got_key_frame |= 1 << i;\n                                if (!c->stream->send_on_key ||\n                                    ((c->got_key_frame + 1) >> c->stream->nb_streams))\n                                    goto send_it;\n                            }\n                        }\n                    } else {\n                        AVCodecContext *codec;\n                    send_it:\n                        if (c->is_packetized) {\n                            AVStream *st;\n                            st = c->fmt_in->streams[pkt.stream_index];\n                            c->cur_pts = av_rescale_q(pkt.dts, st->time_base, AV_TIME_BASE_Q);\n                            if (st->start_time != AV_NOPTS_VALUE)\n                                c->cur_pts -= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);\n                            c->cur_frame_duration = av_rescale_q(pkt.duration, st->time_base, AV_TIME_BASE_Q);\n#if 0\n                            printf("index=%d pts=%0.3f duration=%0.6f\\n",\n                                   pkt.stream_index,\n                                   (double)c->cur_pts /\n                                   AV_TIME_BASE,\n                                   (double)c->cur_frame_duration /\n                                   AV_TIME_BASE);\n#endif\n                            c->packet_stream_index = pkt.stream_index;\n                            ctx = c->rtp_ctx[c->packet_stream_index];\n                            if(!ctx) {\n                              av_free_packet(&pkt);\n                              break;\n                            }\n                            codec = ctx->streams[0]->codec;\n                            pkt.stream_index = 0;\n                        } else {\n                            ctx = &c->fmt_ctx;\n                            codec = ctx->streams[pkt.stream_index]->codec;\n                        }\n                        codec->coded_frame->key_frame = ((pkt.flags & PKT_FLAG_KEY) != 0);\n                        if (c->is_packetized) {\n                            int max_packet_size;\n                            if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP)\n                                max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;\n                            else\n                                max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]);\n                            ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size);\n                        } else {\n                            ret = url_open_dyn_buf(&ctx->pb);\n                        }\n                        if (ret < 0) {\n                            return -1;\n                        }\n                        if (pkt.dts != AV_NOPTS_VALUE)\n                            pkt.dts = av_rescale_q(pkt.dts,\n                                c->fmt_in->streams[pkt.stream_index]->time_base,\n                                ctx->streams[pkt.stream_index]->time_base);\n                        if (pkt.pts != AV_NOPTS_VALUE)\n                            pkt.pts = av_rescale_q(pkt.pts,\n                                c->fmt_in->streams[pkt.stream_index]->time_base,\n                                ctx->streams[pkt.stream_index]->time_base);\n                        if (av_write_frame(ctx, &pkt))\n                            c->state = HTTPSTATE_SEND_DATA_TRAILER;\n                        len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n                        c->cur_frame_bytes = len;\n                        c->buffer_ptr = c->pb_buffer;\n                        c->buffer_end = c->pb_buffer + len;\n                        codec->frame_number++;\n                        if (len == 0)\n                            goto redo;\n                    }\n                    av_free_packet(&pkt);\n                }\n            }\n        }\n        break;\n    default:\n    case HTTPSTATE_SEND_DATA_TRAILER:\n        if (c->last_packet_sent || c->is_packetized)\n            return -1;\n        ctx = &c->fmt_ctx;\n        if (url_open_dyn_buf(&ctx->pb) < 0) {\n            return -1;\n        }\n        av_write_trailer(ctx);\n        len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n        c->buffer_ptr = c->pb_buffer;\n        c->buffer_end = c->pb_buffer + len;\n        c->last_packet_sent = 1;\n        break;\n    }\n    return 0;\n}', 'static int open_input_stream(HTTPContext *c, const char *info)\n{\n    char buf[128];\n    char input_filename[1024];\n    AVFormatContext *s;\n    int buf_size, i;\n    int64_t stream_pos;\n    if (c->stream->feed) {\n        strcpy(input_filename, c->stream->feed->feed_filename);\n        buf_size = FFM_PACKET_SIZE;\n        if (find_info_tag(buf, sizeof(buf), "date", info))\n        {\n            stream_pos = parse_date(buf, 0);\n            if (stream_pos == INT64_MIN)\n                return -1;\n        }\n        else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {\n            int prebuffer = strtol(buf, 0, 10);\n            stream_pos = av_gettime() - prebuffer * (int64_t)1000000;\n        } else\n            stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;\n    } else {\n        strcpy(input_filename, c->stream->feed_filename);\n        buf_size = 0;\n        if (find_info_tag(buf, sizeof(buf), "date", info))\n        {\n            stream_pos = parse_date(buf, 1);\n            if (stream_pos == INT64_MIN)\n                return -1;\n        }\n        else\n            stream_pos = 0;\n    }\n    if (input_filename[0] == \'\\0\')\n        return -1;\n#if 0\n    { time_t when = stream_pos / 1000000;\n    http_log("Stream pos = %"PRId64", time=%s", stream_pos, ctime(&when));\n    }\n#endif\n    if (av_open_input_file(&s, input_filename, c->stream->ifmt,\n                           buf_size, c->stream->ap_in) < 0) {\n        http_log("%s not found", input_filename);\n        return -1;\n    }\n    s->flags |= AVFMT_FLAG_GENPTS;\n    c->fmt_in = s;\n    av_find_stream_info(c->fmt_in);\n    for(i=0;i<s->nb_streams;i++)\n        open_parser(s, i);\n    c->pts_stream_index = 0;\n    for(i=0;i<c->stream->nb_streams;i++) {\n        if (c->pts_stream_index == 0 &&\n            c->stream->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {\n            c->pts_stream_index = i;\n        }\n    }\n#if 1\n    if (c->fmt_in->iformat->read_seek)\n        c->fmt_in->iformat->read_seek(c->fmt_in, 0, stream_pos, 0);\n#endif\n    c->start_time = cur_time;\n    c->first_pts = AV_NOPTS_VALUE;\n    return 0;\n}', "int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)\n{\n    const char *p;\n    char tag[128], *q;\n    p = info;\n    if (*p == '?')\n        p++;\n    for(;;) {\n        q = tag;\n        while (*p != '\\0' && *p != '=' && *p != '&') {\n            if ((q - tag) < sizeof(tag) - 1)\n                *q++ = *p;\n            p++;\n        }\n        *q = '\\0';\n        q = arg;\n        if (*p == '=') {\n            p++;\n            while (*p != '&' && *p != '\\0') {\n                if ((q - arg) < arg_size - 1) {\n                    if (*p == '+')\n                        *q++ = ' ';\n                    else\n                        *q++ = *p;\n                }\n                p++;\n            }\n            *q = '\\0';\n        }\n        if (!strcmp(tag, tag1))\n            return 1;\n        if (*p != '&')\n            break;\n        p++;\n    }\n    return 0;\n}"]