if (av_write_packet(&c->fmt_ctx, &pkt))
if (av_write_packet(&c->fmt_ctx, &pkt, 0))
static int http_prepare_data(HTTPContext *c){    int i;    switch(c->state) {    case HTTPSTATE_SEND_DATA_HEADER:        memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));        if (c->stream->feed) {            /* open output stream by using specified codecs */            c->fmt_ctx.format = c->stream->fmt;            c->fmt_ctx.nb_streams = c->stream->nb_streams;            for(i=0;i<c->fmt_ctx.nb_streams;i++) {                AVStream *st;                st = av_mallocz(sizeof(AVStream));                c->fmt_ctx.streams[i] = st;                memcpy(st, c->stream->streams[i], sizeof(AVStream));                st->codec.frame_number = 0; /* XXX: should be done in                                               AVStream, not in codec */                c->got_key_frame[i] = 0;            }        } else {            /* open output stream by using codecs in specified file */            c->fmt_ctx.format = c->stream->fmt;            c->fmt_ctx.nb_streams = c->fmt_in->nb_streams;            for(i=0;i<c->fmt_ctx.nb_streams;i++) {                AVStream *st;                st = av_mallocz(sizeof(AVStream));                c->fmt_ctx.streams[i] = st;                memcpy(st, c->fmt_in->streams[i], sizeof(AVStream));                st->codec.frame_number = 0; /* XXX: should be done in                                               AVStream, not in codec */                c->got_key_frame[i] = 0;            }        }        init_put_byte(&c->fmt_ctx.pb, c->buffer, IOBUFFER_MAX_SIZE,                      1, c, NULL, http_write_packet, NULL);        c->fmt_ctx.pb.is_streamed = 1;        /* prepare header */        c->fmt_ctx.format->write_header(&c->fmt_ctx);        c->state = HTTPSTATE_SEND_DATA;        c->last_packet_sent = 0;        break;    case HTTPSTATE_SEND_DATA:        /* find a new packet */#if 0        fifo_total_size = http_fifo_write_count - c->last_http_fifo_write_count;        if (fifo_total_size >= ((3 * FIFO_MAX_SIZE) / 4)) {            /* overflow : resync. We suppose that wptr is at this               point a pointer to a valid packet */            c->rptr = http_fifo.wptr;            for(i=0;i<c->fmt_ctx.nb_streams;i++) {                c->got_key_frame[i] = 0;            }        }                start_rptr = c->rptr;        if (fifo_read(&http_fifo, (UINT8 *)&hdr, sizeof(hdr), &c->rptr) < 0)            return 0;        payload_size = ntohs(hdr.payload_size);        payload = malloc(payload_size);        if (fifo_read(&http_fifo, payload, payload_size, &c->rptr) < 0) {            /* cannot read all the payload */            free(payload);            c->rptr = start_rptr;            return 0;        }                c->last_http_fifo_write_count = http_fifo_write_count -             fifo_size(&http_fifo, c->rptr);                if (c->stream->stream_type != STREAM_TYPE_MASTER) {            /* test if the packet can be handled by this format */            ret = 0;            for(i=0;i<c->fmt_ctx.nb_streams;i++) {                AVStream *st = c->fmt_ctx.streams[i];                if (test_header(&hdr, &st->codec)) {                    /* only begin sending when got a key frame */                    if (st->codec.key_frame)                        c->got_key_frame[i] = 1;                    if (c->got_key_frame[i]) {                        ret = c->fmt_ctx.format->write_packet(&c->fmt_ctx, i,                                                                   payload, payload_size);                    }                    break;                }            }            if (ret) {                /* must send trailer now */                c->state = HTTPSTATE_SEND_DATA_TRAILER;            }        } else {            /* master case : send everything */            char *q;            q = c->buffer;            memcpy(q, &hdr, sizeof(hdr));            q += sizeof(hdr);            memcpy(q, payload, payload_size);            q += payload_size;            c->buffer_ptr = c->buffer;            c->buffer_end = q;        }        free(payload);#endif        {            AVPacket pkt;            /* read a packet from the input stream */            if (c->stream->feed) {                ffm_set_write_index(c->fmt_in,                                     c->stream->feed->feed_write_index,                                    c->stream->feed->feed_size);            }            if (av_read_packet(c->fmt_in, &pkt) < 0) {                if (c->stream->feed && c->stream->feed->feed_opened) {                    /* if coming from feed, it means we reached the end of the                       ffm file, so must wait for more data */                    c->state = HTTPSTATE_WAIT_FEED;                    return 1; /* state changed */                } else {                    /* must send trailer now because eof or error */                    c->state = HTTPSTATE_SEND_DATA_TRAILER;                }            } else {                /* send it to the appropriate stream */                if (c->stream->feed) {                    /* if coming from a feed, select the right stream */                    for(i=0;i<c->stream->nb_streams;i++) {                        if (c->stream->feed_streams[i] == pkt.stream_index) {                            pkt.stream_index = i;                            goto send_it;                        }                    }                } else {		send_it:                    if (av_write_packet(&c->fmt_ctx, &pkt))			c->state = HTTPSTATE_SEND_DATA_TRAILER;                }                                av_free_packet(&pkt);            }        }        break;    default:    case HTTPSTATE_SEND_DATA_TRAILER:        /* last packet test ? */        if (c->last_packet_sent)            return -1;        /* prepare header */        c->fmt_ctx.format->write_trailer(&c->fmt_ctx);        c->last_packet_sent = 1;        break;    }    return 0;}