static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)

{

    MvContext *mv = avctx->priv_data;

    AVIOContext *pb = avctx->pb;

    AVStream *st = avctx->streams[mv->stream_index];

    const AVIndexEntry *index;

    int frame = mv->frame[mv->stream_index];

    int ret;

    uint64_t pos;



    if (frame < st->nb_index_entries) {

        index = &st->index_entries[frame];

        pos   = avio_tell(pb);

        if (index->pos > pos)

            avio_skip(pb, index->pos - pos);

        else if (index->pos < pos) {

            if (!pb->seekable)

                return AVERROR(EIO);

            ret = avio_seek(pb, index->pos, SEEK_SET);

            if (ret < 0)

                return ret;

        }

        ret = av_get_packet(pb, pkt, index->size);

        if (ret < 0)

            return ret;



        pkt->stream_index = mv->stream_index;

        pkt->pts          = index->timestamp;

        pkt->flags       |= AV_PKT_FLAG_KEY;



        mv->frame[mv->stream_index]++;

        mv->eof_count = 0;

    } else {

        mv->eof_count++;

        if (mv->eof_count >= avctx->nb_streams)

            return AVERROR_EOF;



        // avoid returning 0 without a packet

        return AVERROR(EAGAIN);

    }



    mv->stream_index++;

    if (mv->stream_index >= avctx->nb_streams)

        mv->stream_index = 0;



    return 0;

}

static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)

{

    MvContext *mv = avctx->priv_data;

    AVIOContext *pb = avctx->pb;

    AVStream *st = avctx->streams[mv->stream_index];

    const AVIndexEntry *index;

    int frame = mv->frame[mv->stream_index];

    int ret;

    uint64_t pos;



    if (frame < st->nb_index_entries) {

        index = &st->index_entries[frame];

        pos   = avio_tell(pb);

        if (index->pos > pos)

            avio_skip(pb, index->pos - pos);

        else if (index->pos < pos) {

            if (!pb->seekable)

                return AVERROR(EIO);

            ret = avio_seek(pb, index->pos, SEEK_SET);

            if (ret < 0)

                return ret;

        }

        ret = av_get_packet(pb, pkt, index->size);

        if (ret < 0)

            return ret;



        pkt->stream_index = mv->stream_index;

        pkt->pts          = index->timestamp;

        pkt->flags       |= AV_PKT_FLAG_KEY;



        mv->frame[mv->stream_index]++;

        mv->eof_count = 0;

    } else {

        mv->eof_count++;

        if (mv->eof_count >= avctx->nb_streams)

            return AVERROR_EOF;



        

        return AVERROR(EAGAIN);

    }



    mv->stream_index++;

    if (mv->stream_index >= avctx->nb_streams)

        mv->stream_index = 0;



    return 0;

}

    int ret;
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    MvContext *mv = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    AVStream *st = VAR_0->streams[mv->stream_index];

    const AVIndexEntry *VAR_2;

    int VAR_3 = mv->VAR_3[mv->stream_index];

    int VAR_4;

    uint64_t pos;



    if (VAR_3 < st->nb_index_entries) {

        VAR_2 = &st->index_entries[VAR_3];

        pos   = avio_tell(pb);

        if (VAR_2->pos > pos)

            avio_skip(pb, VAR_2->pos - pos);

        else if (VAR_2->pos < pos) {

            if (!pb->seekable)

                return AVERROR(EIO);

            VAR_4 = avio_seek(pb, VAR_2->pos, SEEK_SET);

            if (VAR_4 < 0)

                return VAR_4;

        }

        VAR_4 = av_get_packet(pb, VAR_1, VAR_2->size);

        if (VAR_4 < 0)

            return VAR_4;



        VAR_1->stream_index = mv->stream_index;

        VAR_1->pts          = VAR_2->timestamp;

        VAR_1->flags       |= AV_PKT_FLAG_KEY;



        mv->VAR_3[mv->stream_index]++;

        mv->eof_count = 0;

    } else {

        mv->eof_count++;

        if (mv->eof_count >= VAR_0->nb_streams)

            return AVERROR_EOF;



        

        return AVERROR(EAGAIN);

    }



    mv->stream_index++;

    if (mv->stream_index >= VAR_0->nb_streams)

        mv->stream_index = 0;



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ MvContext *mv = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; AVStream *st = VAR_0->streams[mv->stream_index]; const AVIndexEntry *VAR_2; int VAR_3 = mv->VAR_3[mv->stream_index]; int VAR_4; uint64_t pos; if (VAR_3 < st->nb_index_entries) { VAR_2 = &st->index_entries[VAR_3]; pos   = avio_tell(pb); if (VAR_2->pos > pos)
avio_skip(pb, VAR_2->pos - pos); else if (VAR_2->pos < pos) { if (!pb->seekable)
return AVERROR(EIO); VAR_4 = avio_seek(pb, VAR_2->pos, SEEK_SET); if (VAR_4 < 0)
return VAR_4; } VAR_4 = av_get_packet(pb, VAR_1, VAR_2->size); if (VAR_4 < 0)
return VAR_4; VAR_1->stream_index = mv->stream_index; VAR_1->pts          = VAR_2->timestamp; VAR_1->flags       |= AV_PKT_FLAG_KEY; mv->VAR_3[mv->stream_index]++; mv->eof_count = 0; } else { mv->eof_count++; if (mv->eof_count >= VAR_0->nb_streams)
return AVERROR_EOF; return AVERROR(EAGAIN); } mv->stream_index++; if (mv->stream_index >= VAR_0->nb_streams)
mv->stream_index = 0; return 0; }