static int fourxm_read_packet(AVFormatContext *s,

                              AVPacket *pkt)

{

    FourxmDemuxContext *fourxm = s->priv_data;

    ByteIOContext *pb = &s->pb;

    unsigned int fourcc_tag;

    unsigned int size, out_size;

    int ret = 0;

    int track_number;

    int packet_read = 0;

    unsigned char header[8];

    int64_t pts_inc;

    int audio_frame_count;



    while (!packet_read) {



        if ((ret = get_buffer(&s->pb, header, 8)) < 0)

            return ret;

        fourcc_tag = LE_32(&header[0]);

        size = LE_32(&header[4]);

        if (url_feof(pb))

            return AVERROR_IO;

        switch (fourcc_tag) {



        case LIST_TAG:

            /* this is a good time to bump the video pts */

            fourxm->video_pts += fourxm->video_pts_inc;



            /* skip the LIST-* tag and move on to the next fourcc */

            get_le32(pb);

            break;



        case ifrm_TAG:

        case pfrm_TAG:

        case cfrm_TAG:{



            /* allocate 8 more bytes than 'size' to account for fourcc

             * and size */

            if (av_new_packet(pkt, size + 8))

                return AVERROR_IO;

            pkt->stream_index = fourxm->video_stream_index;

            pkt->pts = fourxm->video_pts;

            memcpy(pkt->data, header, 8);

            ret = get_buffer(&s->pb, &pkt->data[8], size);



            if (ret < 0)

                av_free_packet(pkt);

            else

                packet_read = 1;

            break;

        }



        case snd__TAG:

            track_number = get_le32(pb);

            out_size= get_le32(pb);

            size-=8;



            if (track_number == fourxm->selected_track) {

                if (av_new_packet(pkt, size))

                    return AVERROR_IO;

                pkt->stream_index = 

                    fourxm->tracks[fourxm->selected_track].stream_index;

                pkt->pts = fourxm->audio_pts;

                ret = get_buffer(&s->pb, pkt->data, size);

                if (ret < 0)

                    av_free_packet(pkt);

                else

                    packet_read = 1;



                /* pts accounting */

                audio_frame_count = size;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    audio_frame_count -= 

                        2 * (fourxm->tracks[fourxm->selected_track].channels);

                audio_frame_count /=

                      fourxm->tracks[fourxm->selected_track].channels;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    audio_frame_count *= 2;

                else 

                    audio_frame_count /=

                    (fourxm->tracks[fourxm->selected_track].bits / 8);

                pts_inc = audio_frame_count;

                pts_inc *= 90000;

                pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;

                fourxm->audio_pts += pts_inc;



            } else {

                url_fseek(pb, size, SEEK_CUR);

            }

            break;



        default:

            url_fseek(pb, size, SEEK_CUR);

            break;

        }

    }

    return ret;

}

static int fourxm_read_packet(AVFormatContext *s,

                              AVPacket *pkt)

{

    FourxmDemuxContext *fourxm = s->priv_data;

    ByteIOContext *pb = &s->pb;

    unsigned int fourcc_tag;

    unsigned int size, out_size;

    int ret = 0;

    int track_number;

    int packet_read = 0;

    unsigned char header[8];

    int64_t pts_inc;

    int audio_frame_count;



    while (!packet_read) {



        if ((ret = get_buffer(&s->pb, header, 8)) < 0)

            return ret;

        fourcc_tag = LE_32(&header[0]);

        size = LE_32(&header[4]);

        if (url_feof(pb))

            return AVERROR_IO;

        switch (fourcc_tag) {



        case LIST_TAG:

            

            fourxm->video_pts += fourxm->video_pts_inc;



            

            get_le32(pb);

            break;



        case ifrm_TAG:

        case pfrm_TAG:

        case cfrm_TAG:{



            



            if (av_new_packet(pkt, size + 8))

                return AVERROR_IO;

            pkt->stream_index = fourxm->video_stream_index;

            pkt->pts = fourxm->video_pts;

            memcpy(pkt->data, header, 8);

            ret = get_buffer(&s->pb, &pkt->data[8], size);



            if (ret < 0)

                av_free_packet(pkt);

            else

                packet_read = 1;

            break;

        }



        case snd__TAG:

            track_number = get_le32(pb);

            out_size= get_le32(pb);

            size-=8;



            if (track_number == fourxm->selected_track) {

                if (av_new_packet(pkt, size))

                    return AVERROR_IO;

                pkt->stream_index = 

                    fourxm->tracks[fourxm->selected_track].stream_index;

                pkt->pts = fourxm->audio_pts;

                ret = get_buffer(&s->pb, pkt->data, size);

                if (ret < 0)

                    av_free_packet(pkt);

                else

                    packet_read = 1;



                

                audio_frame_count = size;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    audio_frame_count -= 

                        2 * (fourxm->tracks[fourxm->selected_track].channels);

                audio_frame_count /=

                      fourxm->tracks[fourxm->selected_track].channels;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    audio_frame_count *= 2;

                else 

                    audio_frame_count /=

                    (fourxm->tracks[fourxm->selected_track].bits / 8);

                pts_inc = audio_frame_count;

                pts_inc *= 90000;

                pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;

                fourxm->audio_pts += pts_inc;



            } else {

                url_fseek(pb, size, SEEK_CUR);

            }

            break;



        default:

            url_fseek(pb, size, SEEK_CUR);

            break;

        }

    }

    return ret;

}

            if (av_new_packet(pkt, size + 8))
static int FUNC_0(AVFormatContext *VAR_0,

                              AVPacket *VAR_1)

{

    FourxmDemuxContext *fourxm = VAR_0->priv_data;

    ByteIOContext *pb = &VAR_0->pb;

    unsigned int VAR_2;

    unsigned int VAR_3, VAR_4;

    int VAR_5 = 0;

    int VAR_6;

    int VAR_7 = 0;

    unsigned char VAR_8[8];

    int64_t pts_inc;

    int VAR_9;



    while (!VAR_7) {



        if ((VAR_5 = get_buffer(&VAR_0->pb, VAR_8, 8)) < 0)

            return VAR_5;

        VAR_2 = LE_32(&VAR_8[0]);

        VAR_3 = LE_32(&VAR_8[4]);

        if (url_feof(pb))

            return AVERROR_IO;

        switch (VAR_2) {



        case LIST_TAG:

            

            fourxm->video_pts += fourxm->video_pts_inc;



            

            get_le32(pb);

            break;



        case ifrm_TAG:

        case pfrm_TAG:

        case cfrm_TAG:{



            



            if (av_new_packet(VAR_1, VAR_3 + 8))

                return AVERROR_IO;

            VAR_1->stream_index = fourxm->video_stream_index;

            VAR_1->pts = fourxm->video_pts;

            memcpy(VAR_1->data, VAR_8, 8);

            VAR_5 = get_buffer(&VAR_0->pb, &VAR_1->data[8], VAR_3);



            if (VAR_5 < 0)

                av_free_packet(VAR_1);

            else

                VAR_7 = 1;

            break;

        }



        case snd__TAG:

            VAR_6 = get_le32(pb);

            VAR_4= get_le32(pb);

            VAR_3-=8;



            if (VAR_6 == fourxm->selected_track) {

                if (av_new_packet(VAR_1, VAR_3))

                    return AVERROR_IO;

                VAR_1->stream_index = 

                    fourxm->tracks[fourxm->selected_track].stream_index;

                VAR_1->pts = fourxm->audio_pts;

                VAR_5 = get_buffer(&VAR_0->pb, VAR_1->data, VAR_3);

                if (VAR_5 < 0)

                    av_free_packet(VAR_1);

                else

                    VAR_7 = 1;



                

                VAR_9 = VAR_3;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    VAR_9 -= 

                        2 * (fourxm->tracks[fourxm->selected_track].channels);

                VAR_9 /=

                      fourxm->tracks[fourxm->selected_track].channels;

                if (fourxm->tracks[fourxm->selected_track].adpcm)

                    VAR_9 *= 2;

                else 

                    VAR_9 /=

                    (fourxm->tracks[fourxm->selected_track].bits / 8);

                pts_inc = VAR_9;

                pts_inc *= 90000;

                pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;

                fourxm->audio_pts += pts_inc;



            } else {

                url_fseek(pb, VAR_3, SEEK_CUR);

            }

            break;



        default:

            url_fseek(pb, VAR_3, SEEK_CUR);

            break;

        }

    }

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0,
AVPacket *VAR_1)
{ FourxmDemuxContext *fourxm = VAR_0->priv_data; ByteIOContext *pb = &VAR_0->pb; unsigned int VAR_2; unsigned int VAR_3, VAR_4; int VAR_5 = 0; int VAR_6; int VAR_7 = 0; unsigned char VAR_8[8]; int64_t pts_inc; int VAR_9; while (!VAR_7) { if ((VAR_5 = get_buffer(&VAR_0->pb, VAR_8, 8)) < 0)
return VAR_5; VAR_2 = LE_32(&VAR_8[0]); VAR_3 = LE_32(&VAR_8[4]); if (url_feof(pb))
return AVERROR_IO; switch (VAR_2) { case LIST_TAG:
fourxm->video_pts += fourxm->video_pts_inc; get_le32(pb); break; case ifrm_TAG:
case pfrm_TAG:
case cfrm_TAG:{ if (av_new_packet(VAR_1, VAR_3 + 8))
return AVERROR_IO; VAR_1->stream_index = fourxm->video_stream_index; VAR_1->pts = fourxm->video_pts; memcpy(VAR_1->data, VAR_8, 8); VAR_5 = get_buffer(&VAR_0->pb, &VAR_1->data[8], VAR_3); if (VAR_5 < 0)
av_free_packet(VAR_1); else
VAR_7 = 1; break; } case snd__TAG:
VAR_6 = get_le32(pb); VAR_4= get_le32(pb); VAR_3-=8; if (VAR_6 == fourxm->selected_track) { if (av_new_packet(VAR_1, VAR_3))
return AVERROR_IO; VAR_1->stream_index =
fourxm->tracks[fourxm->selected_track].stream_index; VAR_1->pts = fourxm->audio_pts; VAR_5 = get_buffer(&VAR_0->pb, VAR_1->data, VAR_3); if (VAR_5 < 0)
av_free_packet(VAR_1); else
VAR_7 = 1; VAR_9 = VAR_3; if (fourxm->tracks[fourxm->selected_track].adpcm)
VAR_9 -=
2 * (fourxm->tracks[fourxm->selected_track].channels); VAR_9 /=
fourxm->tracks[fourxm->selected_track].channels; if (fourxm->tracks[fourxm->selected_track].adpcm)
VAR_9 *= 2; else
VAR_9 /=
(fourxm->tracks[fourxm->selected_track].bits / 8); pts_inc = VAR_9; pts_inc *= 90000; pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate; fourxm->audio_pts += pts_inc; } else { url_fseek(pb, VAR_3, SEEK_CUR); } break; default:
url_fseek(pb, VAR_3, SEEK_CUR); break; } } return VAR_5; }