static int avi_write_idx1(AVFormatContext *s)

{

    AVIOContext *pb = s->pb;

    AVIContext *avi = s->priv_data;

    int64_t idx_chunk;

    int i;

    char tag[5];



    if (pb->seekable) {

        AVIStream *avist;

        AVIIentry *ie = 0, *tie;

        int empty, stream_id = -1;



        idx_chunk = ff_start_tag(pb, "idx1");

        for (i = 0; i < s->nb_streams; i++) {

            avist        = s->streams[i]->priv_data;

            avist->entry = 0;

        }



        do {

            empty = 1;

            for (i = 0; i < s->nb_streams; i++) {

                avist = s->streams[i]->priv_data;

                if (avist->indexes.entry <= avist->entry)

                    continue;



                tie = avi_get_ientry(&avist->indexes, avist->entry);

                if (empty || tie->pos < ie->pos) {

                    ie        = tie;

                    stream_id = i;

                }

                empty = 0;

            }

            if (!empty) {

                avist = s->streams[stream_id]->priv_data;

                avi_stream2fourcc(tag, stream_id,

                                  s->streams[stream_id]->codecpar->codec_type);

                ffio_wfourcc(pb, tag);

                avio_wl32(pb, ie->flags);

                avio_wl32(pb, ie->pos);

                avio_wl32(pb, ie->len);

                avist->entry++;

            }

        } while (!empty);

        ff_end_tag(pb, idx_chunk);



        avi_write_counters(s, avi->riff_id);

    }

    return 0;

}

static int avi_write_idx1(AVFormatContext *s)

{

    AVIOContext *pb = s->pb;

    AVIContext *avi = s->priv_data;

    int64_t idx_chunk;

    int i;

    char tag[5];



    if (pb->seekable) {

        AVIStream *avist;

        AVIIentry *ie = 0, *tie;

        int empty, stream_id = -1;



        idx_chunk = ff_start_tag(pb, "idx1");

        for (i = 0; i < s->nb_streams; i++) {

            avist        = s->streams[i]->priv_data;

            avist->entry = 0;

        }



        do {

            empty = 1;

            for (i = 0; i < s->nb_streams; i++) {

                avist = s->streams[i]->priv_data;

                if (avist->indexes.entry <= avist->entry)

                    continue;



                tie = avi_get_ientry(&avist->indexes, avist->entry);

                if (empty || tie->pos < ie->pos) {

                    ie        = tie;

                    stream_id = i;

                }

                empty = 0;

            }

            if (!empty) {

                avist = s->streams[stream_id]->priv_data;

                avi_stream2fourcc(tag, stream_id,

                                  s->streams[stream_id]->codecpar->codec_type);

                ffio_wfourcc(pb, tag);

                avio_wl32(pb, ie->flags);

                avio_wl32(pb, ie->pos);

                avio_wl32(pb, ie->len);

                avist->entry++;

            }

        } while (!empty);

        ff_end_tag(pb, idx_chunk);



        avi_write_counters(s, avi->riff_id);

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)

{

    AVIOContext *pb = VAR_0->pb;

    AVIContext *avi = VAR_0->priv_data;

    int64_t idx_chunk;

    int VAR_1;

    char VAR_2[5];



    if (pb->seekable) {

        AVIStream *avist;

        AVIIentry *ie = 0, *tie;

        int VAR_3, VAR_4 = -1;



        idx_chunk = ff_start_tag(pb, "idx1");

        for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) {

            avist        = VAR_0->streams[VAR_1]->priv_data;

            avist->entry = 0;

        }



        do {

            VAR_3 = 1;

            for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) {

                avist = VAR_0->streams[VAR_1]->priv_data;

                if (avist->indexes.entry <= avist->entry)

                    continue;



                tie = avi_get_ientry(&avist->indexes, avist->entry);

                if (VAR_3 || tie->pos < ie->pos) {

                    ie        = tie;

                    VAR_4 = VAR_1;

                }

                VAR_3 = 0;

            }

            if (!VAR_3) {

                avist = VAR_0->streams[VAR_4]->priv_data;

                avi_stream2fourcc(VAR_2, VAR_4,

                                  VAR_0->streams[VAR_4]->codecpar->codec_type);

                ffio_wfourcc(pb, VAR_2);

                avio_wl32(pb, ie->flags);

                avio_wl32(pb, ie->pos);

                avio_wl32(pb, ie->len);

                avist->entry++;

            }

        } while (!VAR_3);

        ff_end_tag(pb, idx_chunk);



        avi_write_counters(VAR_0, avi->riff_id);

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ AVIOContext *pb = VAR_0->pb; AVIContext *avi = VAR_0->priv_data; int64_t idx_chunk; int VAR_1; char VAR_2[5]; if (pb->seekable) { AVIStream *avist; AVIIentry *ie = 0, *tie; int VAR_3, VAR_4 = -1; idx_chunk = ff_start_tag(pb, "idx1"); for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) { avist        = VAR_0->streams[VAR_1]->priv_data; avist->entry = 0; } do { VAR_3 = 1; for (VAR_1 = 0; VAR_1 < VAR_0->nb_streams; VAR_1++) { avist = VAR_0->streams[VAR_1]->priv_data; if (avist->indexes.entry <= avist->entry)
continue; tie = avi_get_ientry(&avist->indexes, avist->entry); if (VAR_3 || tie->pos < ie->pos) { ie        = tie; VAR_4 = VAR_1; } VAR_3 = 0; } if (!VAR_3) { avist = VAR_0->streams[VAR_4]->priv_data; avi_stream2fourcc(VAR_2, VAR_4,
VAR_0->streams[VAR_4]->codecpar->codec_type); ffio_wfourcc(pb, VAR_2); avio_wl32(pb, ie->flags); avio_wl32(pb, ie->pos); avio_wl32(pb, ie->len); avist->entry++; } } while (!VAR_3); ff_end_tag(pb, idx_chunk); avi_write_counters(VAR_0, avi->riff_id); } return 0; }