static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)

{

    BFIContext *bfi = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret, audio_offset, video_offset, chunk_size, audio_size = 0;

    if (bfi->nframes == 0 || pb->eof_reached) {

        return AVERROR(EIO);




    /* If all previous chunks were completely read, then find a new one... */

    if (!bfi->avflag) {

        uint32_t state = 0;

        while(state != MKTAG('S','A','V','I')){

            if (pb->eof_reached)

                return AVERROR(EIO);

            state = 256*state + avio_r8(pb);


        /* Now that the chunk's location is confirmed, we proceed... */

        chunk_size      = avio_rl32(pb);

        avio_rl32(pb);

        audio_offset    = avio_rl32(pb);

        avio_rl32(pb);

        video_offset    = avio_rl32(pb);

        audio_size      = video_offset - audio_offset;

        bfi->video_size = chunk_size - video_offset;







        //Tossing an audio packet at the audio decoder.

        ret = av_get_packet(pb, pkt, audio_size);

        if (ret < 0)

            return ret;



        pkt->pts          = bfi->audio_frame;

        bfi->audio_frame += ret;

    } else if (bfi->video_size > 0) {



        //Tossing a video packet at the video decoder.

        ret = av_get_packet(pb, pkt, bfi->video_size);

        if (ret < 0)

            return ret;



        pkt->pts          = bfi->video_frame;

        bfi->video_frame += ret / bfi->video_size;



        /* One less frame to read. A cursory decrement. */

        bfi->nframes--;

    } else {

        /* Empty video packet */

        ret = AVERROR(EAGAIN);




    bfi->avflag       = !bfi->avflag;

    pkt->stream_index = bfi->avflag;

    return ret;

static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)

{

    BFIContext *bfi = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret, audio_offset, video_offset, chunk_size, audio_size = 0;

    if (bfi->nframes == 0 || pb->eof_reached) {

        return AVERROR(EIO);




    

    if (!bfi->avflag) {

        uint32_t state = 0;

        while(state != MKTAG('S','A','V','I')){

            if (pb->eof_reached)

                return AVERROR(EIO);

            state = 256*state + avio_r8(pb);


        

        chunk_size      = avio_rl32(pb);

        avio_rl32(pb);

        audio_offset    = avio_rl32(pb);

        avio_rl32(pb);

        video_offset    = avio_rl32(pb);

        audio_size      = video_offset - audio_offset;

        bfi->video_size = chunk_size - video_offset;







        

        ret = av_get_packet(pb, pkt, audio_size);

        if (ret < 0)

            return ret;



        pkt->pts          = bfi->audio_frame;

        bfi->audio_frame += ret;

    } else if (bfi->video_size > 0) {



        

        ret = av_get_packet(pb, pkt, bfi->video_size);

        if (ret < 0)

            return ret;



        pkt->pts          = bfi->video_frame;

        bfi->video_frame += ret / bfi->video_size;



        

        bfi->nframes--;

    } else {

        

        ret = AVERROR(EAGAIN);




    bfi->avflag       = !bfi->avflag;

    pkt->stream_index = bfi->avflag;

    return ret;

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

{

    BFIContext *bfi = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6 = 0;

    if (bfi->nframes == 0 || pb->eof_reached) {

        return AVERROR(EIO);




    

    if (!bfi->avflag) {

        uint32_t state = 0;

        while(state != MKTAG('S','A','V','I')){

            if (pb->eof_reached)

                return AVERROR(EIO);

            state = 256*state + avio_r8(pb);


        

        VAR_5      = avio_rl32(pb);

        avio_rl32(pb);

        VAR_3    = avio_rl32(pb);

        avio_rl32(pb);

        VAR_4    = avio_rl32(pb);

        VAR_6      = VAR_4 - VAR_3;

        bfi->video_size = VAR_5 - VAR_4;







        

        VAR_2 = av_get_packet(pb, VAR_1, VAR_6);

        if (VAR_2 < 0)

            return VAR_2;



        VAR_1->pts          = bfi->audio_frame;

        bfi->audio_frame += VAR_2;

    } else if (bfi->video_size > 0) {



        

        VAR_2 = av_get_packet(pb, VAR_1, bfi->video_size);

        if (VAR_2 < 0)

            return VAR_2;



        VAR_1->pts          = bfi->video_frame;

        bfi->video_frame += VAR_2 / bfi->video_size;



        

        bfi->nframes--;

    } else {

        

        VAR_2 = AVERROR(EAGAIN);




    bfi->avflag       = !bfi->avflag;

    VAR_1->stream_index = bfi->avflag;

    return VAR_2;

static int FUNC_0(AVFormatContext * VAR_0, AVPacket * VAR_1)
{ BFIContext *bfi = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6 = 0; if (bfi->nframes == 0 || pb->eof_reached) { return AVERROR(EIO); if (!bfi->avflag) { uint32_t state = 0; while(state != MKTAG('S','A','V','I')){ if (pb->eof_reached)
return AVERROR(EIO); state = 256*state + avio_r8(pb); VAR_5      = avio_rl32(pb); avio_rl32(pb); VAR_3    = avio_rl32(pb); avio_rl32(pb); VAR_4    = avio_rl32(pb); VAR_6      = VAR_4 - VAR_3; bfi->video_size = VAR_5 - VAR_4; VAR_2 = av_get_packet(pb, VAR_1, VAR_6); if (VAR_2 < 0)
return VAR_2; VAR_1->pts          = bfi->audio_frame; bfi->audio_frame += VAR_2; } else if (bfi->video_size > 0) { VAR_2 = av_get_packet(pb, VAR_1, bfi->video_size); if (VAR_2 < 0)
return VAR_2; VAR_1->pts          = bfi->video_frame; bfi->video_frame += VAR_2 / bfi->video_size; bfi->nframes--; } else { VAR_2 = AVERROR(EAGAIN); bfi->avflag       = !bfi->avflag; VAR_1->stream_index = bfi->avflag; return VAR_2;