if (url_is_streamed(&s->pb)) {
if (asf->is_streamed) {
static int asf_write_header1(AVFormatContext *s, INT64 file_size, INT64 data_chunk_size){    ASFContext *asf = s->priv_data;    ByteIOContext *pb = &s->pb;    int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;    int has_title;    AVCodecContext *enc;    INT64 header_offset, cur_pos, hpos;    int bit_rate;    has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);    bit_rate = 0;    for(n=0;n<s->nb_streams;n++) {        enc = &s->streams[n]->codec;        bit_rate += enc->bit_rate;    }    if (url_is_streamed(&s->pb)) {        put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */    }    put_guid(pb, &asf_header);    put_le64(pb, 0); /* header length, will be patched after */    put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */    put_byte(pb, 1); /* ??? */    put_byte(pb, 2); /* ??? */        /* file header */    header_offset = url_ftell(pb);    hpos = put_header(pb, &file_header);    put_guid(pb, &my_guid);    put_le64(pb, file_size);    file_time = 0;    put_le64(pb, unix_to_file_time(file_time));    put_le64(pb, asf->nb_packets); /* number of packets */    put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */    put_le64(pb, asf->duration); /* duration (in 100ns units) */    put_le32(pb, 0); /* start time stamp */     put_le32(pb, 0); /* ??? */     put_le32(pb, url_is_streamed(&s->pb) ? 1 : 0); /* ??? */     put_le32(pb, asf->packet_size); /* packet size */    put_le32(pb, asf->packet_size); /* packet size */    put_le32(pb, bit_rate); /* Nominal data rate in bps */    end_header(pb, hpos);    /* unknown headers */    hpos = put_header(pb, &head1_guid);    put_guid(pb, &head2_guid);    put_le32(pb, 6);    put_le16(pb, 0);    end_header(pb, hpos);    /* title and other infos */    if (has_title) {        hpos = put_header(pb, &comment_header);        put_le16(pb, 2 * (strlen(s->title) + 1));        put_le16(pb, 2 * (strlen(s->author) + 1));        put_le16(pb, 2 * (strlen(s->copyright) + 1));        put_le16(pb, 2 * (strlen(s->comment) + 1));        put_le16(pb, 0);        put_str16_nolen(pb, s->title);        put_str16_nolen(pb, s->author);        put_str16_nolen(pb, s->copyright);        put_str16_nolen(pb, s->comment);        end_header(pb, hpos);    }    /* stream headers */    for(n=0;n<s->nb_streams;n++) {        INT64 es_pos;        ASFStream *stream = &asf->streams[n];        enc = &s->streams[n]->codec;        asf->streams[n].num = n + 1;        asf->streams[n].seq = 0;                switch(enc->codec_type) {        case CODEC_TYPE_AUDIO:            wav_extra_size = 0;            extra_size = 18 + wav_extra_size;            extra_size2 = 0;            /* Init the ticker */            ticker_init(&stream->pts_ticker,                        enc->sample_rate,                        1000 * enc->frame_size);            break;        default:        case CODEC_TYPE_VIDEO:            wav_extra_size = 0;            extra_size = 0x33;            extra_size2 = 0;            /* Init the ticker */            ticker_init(&stream->pts_ticker,                        enc->frame_rate,                        1000 * FRAME_RATE_BASE);            break;        }        hpos = put_header(pb, &stream_header);        if (enc->codec_type == CODEC_TYPE_AUDIO) {            put_guid(pb, &audio_stream);            put_guid(pb, &audio_conceal_none);        } else {            put_guid(pb, &video_stream);            put_guid(pb, &video_conceal_none);        }        put_le64(pb, 0); /* ??? */        es_pos = url_ftell(pb);        put_le32(pb, extra_size); /* wav header len */        put_le32(pb, extra_size2); /* additional data len */        put_le16(pb, n + 1); /* stream number */        put_le32(pb, 0); /* ??? */                if (enc->codec_type == CODEC_TYPE_AUDIO) {            /* WAVEFORMATEX header */            int wavsize = put_wav_header(pb, enc);            if (wavsize < 0)                return -1;            if (wavsize != extra_size) {                cur_pos = url_ftell(pb);                url_fseek(pb, es_pos, SEEK_SET);                put_le32(pb, wavsize); /* wav header len */                url_fseek(pb, cur_pos, SEEK_SET);            }        } else {            put_le32(pb, enc->width);            put_le32(pb, enc->height);            put_byte(pb, 2); /* ??? */            put_le16(pb, 40); /* size */            /* BITMAPINFOHEADER header */            put_bmp_header(pb, enc, codec_asf_bmp_tags);        }        end_header(pb, hpos);    }    /* media comments */    hpos = put_header(pb, &codec_comment_header);    put_guid(pb, &codec_comment1_header);    put_le32(pb, s->nb_streams);    for(n=0;n<s->nb_streams;n++) {        AVCodec *p;        enc = &s->streams[n]->codec;        p = avcodec_find_encoder(enc->codec_id);        put_le16(pb, asf->streams[n].num);        put_str16(pb, p ? p->name : enc->codec_name);        put_le16(pb, 0); /* no parameters */        /* id */        if (enc->codec_type == CODEC_TYPE_AUDIO) {            put_le16(pb, 2);            put_le16(pb, codec_get_tag(codec_wav_tags, enc->codec_id));        } else {            put_le16(pb, 4);            put_le32(pb, codec_get_tag(codec_asf_bmp_tags, enc->codec_id));        }    }    end_header(pb, hpos);    /* patch the header size fields */    cur_pos = url_ftell(pb);    header_size = cur_pos - header_offset;    if (url_is_streamed(&s->pb)) {        header_size += 8 + 30 + 50;        url_fseek(pb, header_offset - 10 - 30, SEEK_SET);        put_le16(pb, header_size);        url_fseek(pb, header_offset - 2 - 30, SEEK_SET);        put_le16(pb, header_size);        header_size -= 8 + 30 + 50;    }    header_size += 24 + 6;    url_fseek(pb, header_offset - 14, SEEK_SET);    put_le64(pb, header_size);    url_fseek(pb, cur_pos, SEEK_SET);    /* movie chunk, followed by packets of packet_size */    asf->data_offset = cur_pos;    put_guid(pb, &data_header);    put_le64(pb, data_chunk_size);    put_guid(pb, &my_guid);    put_le64(pb, asf->nb_packets); /* nb packets */    put_byte(pb, 1); /* ??? */    put_byte(pb, 1); /* ??? */    return 0;}