static int ea_read_packet(AVFormatContext *s,

                          AVPacket *pkt)

{

    EaDemuxContext *ea = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret = 0;

    int packet_read = 0;

    unsigned int chunk_type, chunk_size;

    int key = 0;

    int av_uninit(num_samples);



    while (!packet_read) {

        chunk_type = avio_rl32(pb);

        chunk_size = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8;



        switch (chunk_type) {

        /* audio data */

        case ISNh_TAG:

            /* header chunk also contains data; skip over the header portion*/

            avio_skip(pb, 32);

            chunk_size -= 32;

        case ISNd_TAG:

        case SCDl_TAG:

        case SNDC_TAG:

        case SDEN_TAG:

            if (!ea->audio_codec) {

                avio_skip(pb, chunk_size);

                break;

            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||

                       ea->audio_codec == CODEC_ID_MP3) {

                num_samples = avio_rl32(pb);

                avio_skip(pb, 8);

                chunk_size -= 12;

            }

            ret = av_get_packet(pb, pkt, chunk_size);

            if (ret < 0)

                return ret;

            pkt->stream_index = ea->audio_stream_index;



            switch (ea->audio_codec) {

            case CODEC_ID_ADPCM_EA:

            case CODEC_ID_ADPCM_EA_R1:

            case CODEC_ID_ADPCM_EA_R2:

            case CODEC_ID_ADPCM_IMA_EA_EACS:

                pkt->duration = AV_RL32(pkt->data);

                break;

            case CODEC_ID_ADPCM_EA_R3:

                pkt->duration = AV_RB32(pkt->data);

                break;

            case CODEC_ID_ADPCM_IMA_EA_SEAD:

                pkt->duration = ret * 2 / ea->num_channels;

                break;

            case CODEC_ID_PCM_S16LE_PLANAR:

            case CODEC_ID_MP3:

                pkt->duration = num_samples;

                break;

            default:

                pkt->duration = chunk_size / (ea->bytes * ea->num_channels);

            }



            packet_read = 1;

            break;



        /* ending tag */

        case 0:

        case ISNe_TAG:

        case SCEl_TAG:

        case SEND_TAG:

        case SEEN_TAG:

            ret = AVERROR(EIO);

            packet_read = 1;

            break;



        case MVIh_TAG:

        case kVGT_TAG:

        case pQGT_TAG:

        case TGQs_TAG:

        case MADk_TAG:

            key = AV_PKT_FLAG_KEY;

        case MVIf_TAG:

        case fVGT_TAG:

        case MADm_TAG:

        case MADe_TAG:

            avio_seek(pb, -8, SEEK_CUR);     // include chunk preamble

            chunk_size += 8;

            goto get_video_packet;



        case mTCD_TAG:

            avio_skip(pb, 8);  // skip ea dct header

            chunk_size -= 8;

            goto get_video_packet;



        case MV0K_TAG:

        case MPCh_TAG:

        case pIQT_TAG:

            key = AV_PKT_FLAG_KEY;

        case MV0F_TAG:

get_video_packet:

            ret = av_get_packet(pb, pkt, chunk_size);

            if (ret < 0)

                return ret;

            pkt->stream_index = ea->video_stream_index;

            pkt->flags |= key;

            packet_read = 1;

            break;



        default:

            avio_skip(pb, chunk_size);

            break;

        }

    }



    return ret;

}

static int ea_read_packet(AVFormatContext *s,

                          AVPacket *pkt)

{

    EaDemuxContext *ea = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret = 0;

    int packet_read = 0;

    unsigned int chunk_type, chunk_size;

    int key = 0;

    int av_uninit(num_samples);



    while (!packet_read) {

        chunk_type = avio_rl32(pb);

        chunk_size = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8;



        switch (chunk_type) {

        

        case ISNh_TAG:

            

            avio_skip(pb, 32);

            chunk_size -= 32;

        case ISNd_TAG:

        case SCDl_TAG:

        case SNDC_TAG:

        case SDEN_TAG:

            if (!ea->audio_codec) {

                avio_skip(pb, chunk_size);

                break;

            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||

                       ea->audio_codec == CODEC_ID_MP3) {

                num_samples = avio_rl32(pb);

                avio_skip(pb, 8);

                chunk_size -= 12;

            }

            ret = av_get_packet(pb, pkt, chunk_size);

            if (ret < 0)

                return ret;

            pkt->stream_index = ea->audio_stream_index;



            switch (ea->audio_codec) {

            case CODEC_ID_ADPCM_EA:

            case CODEC_ID_ADPCM_EA_R1:

            case CODEC_ID_ADPCM_EA_R2:

            case CODEC_ID_ADPCM_IMA_EA_EACS:

                pkt->duration = AV_RL32(pkt->data);

                break;

            case CODEC_ID_ADPCM_EA_R3:

                pkt->duration = AV_RB32(pkt->data);

                break;

            case CODEC_ID_ADPCM_IMA_EA_SEAD:

                pkt->duration = ret * 2 / ea->num_channels;

                break;

            case CODEC_ID_PCM_S16LE_PLANAR:

            case CODEC_ID_MP3:

                pkt->duration = num_samples;

                break;

            default:

                pkt->duration = chunk_size / (ea->bytes * ea->num_channels);

            }



            packet_read = 1;

            break;



        

        case 0:

        case ISNe_TAG:

        case SCEl_TAG:

        case SEND_TAG:

        case SEEN_TAG:

            ret = AVERROR(EIO);

            packet_read = 1;

            break;



        case MVIh_TAG:

        case kVGT_TAG:

        case pQGT_TAG:

        case TGQs_TAG:

        case MADk_TAG:

            key = AV_PKT_FLAG_KEY;

        case MVIf_TAG:

        case fVGT_TAG:

        case MADm_TAG:

        case MADe_TAG:

            avio_seek(pb, -8, SEEK_CUR);     

            chunk_size += 8;

            goto get_video_packet;



        case mTCD_TAG:

            avio_skip(pb, 8);  

            chunk_size -= 8;

            goto get_video_packet;



        case MV0K_TAG:

        case MPCh_TAG:

        case pIQT_TAG:

            key = AV_PKT_FLAG_KEY;

        case MV0F_TAG:

get_video_packet:

            ret = av_get_packet(pb, pkt, chunk_size);

            if (ret < 0)

                return ret;

            pkt->stream_index = ea->video_stream_index;

            pkt->flags |= key;

            packet_read = 1;

            break;



        default:

            avio_skip(pb, chunk_size);

            break;

        }

    }



    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0,

                          AVPacket *VAR_1)

{

    EaDemuxContext *ea = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    int VAR_2 = 0;

    int VAR_3 = 0;

    unsigned int VAR_4, VAR_5;

    int VAR_6 = 0;

    int FUNC_1(num_samples);



    while (!VAR_3) {

        VAR_4 = avio_rl32(pb);

        VAR_5 = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8;



        switch (VAR_4) {

        

        case ISNh_TAG:

            

            avio_skip(pb, 32);

            VAR_5 -= 32;

        case ISNd_TAG:

        case SCDl_TAG:

        case SNDC_TAG:

        case SDEN_TAG:

            if (!ea->audio_codec) {

                avio_skip(pb, VAR_5);

                break;

            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||

                       ea->audio_codec == CODEC_ID_MP3) {

                num_samples = avio_rl32(pb);

                avio_skip(pb, 8);

                VAR_5 -= 12;

            }

            VAR_2 = av_get_packet(pb, VAR_1, VAR_5);

            if (VAR_2 < 0)

                return VAR_2;

            VAR_1->stream_index = ea->audio_stream_index;



            switch (ea->audio_codec) {

            case CODEC_ID_ADPCM_EA:

            case CODEC_ID_ADPCM_EA_R1:

            case CODEC_ID_ADPCM_EA_R2:

            case CODEC_ID_ADPCM_IMA_EA_EACS:

                VAR_1->duration = AV_RL32(VAR_1->data);

                break;

            case CODEC_ID_ADPCM_EA_R3:

                VAR_1->duration = AV_RB32(VAR_1->data);

                break;

            case CODEC_ID_ADPCM_IMA_EA_SEAD:

                VAR_1->duration = VAR_2 * 2 / ea->num_channels;

                break;

            case CODEC_ID_PCM_S16LE_PLANAR:

            case CODEC_ID_MP3:

                VAR_1->duration = num_samples;

                break;

            default:

                VAR_1->duration = VAR_5 / (ea->bytes * ea->num_channels);

            }



            VAR_3 = 1;

            break;



        

        case 0:

        case ISNe_TAG:

        case SCEl_TAG:

        case SEND_TAG:

        case SEEN_TAG:

            VAR_2 = AVERROR(EIO);

            VAR_3 = 1;

            break;



        case MVIh_TAG:

        case kVGT_TAG:

        case pQGT_TAG:

        case TGQs_TAG:

        case MADk_TAG:

            VAR_6 = AV_PKT_FLAG_KEY;

        case MVIf_TAG:

        case fVGT_TAG:

        case MADm_TAG:

        case MADe_TAG:

            avio_seek(pb, -8, SEEK_CUR);     

            VAR_5 += 8;

            goto get_video_packet;



        case mTCD_TAG:

            avio_skip(pb, 8);  

            VAR_5 -= 8;

            goto get_video_packet;



        case MV0K_TAG:

        case MPCh_TAG:

        case pIQT_TAG:

            VAR_6 = AV_PKT_FLAG_KEY;

        case MV0F_TAG:

get_video_packet:

            VAR_2 = av_get_packet(pb, VAR_1, VAR_5);

            if (VAR_2 < 0)

                return VAR_2;

            VAR_1->stream_index = ea->video_stream_index;

            VAR_1->flags |= VAR_6;

            VAR_3 = 1;

            break;



        default:

            avio_skip(pb, VAR_5);

            break;

        }

    }



    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0,
AVPacket *VAR_1)
{ EaDemuxContext *ea = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; int VAR_2 = 0; int VAR_3 = 0; unsigned int VAR_4, VAR_5; int VAR_6 = 0; int FUNC_1(num_samples); while (!VAR_3) { VAR_4 = avio_rl32(pb); VAR_5 = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8; switch (VAR_4) { case ISNh_TAG:
avio_skip(pb, 32); VAR_5 -= 32; case ISNd_TAG:
case SCDl_TAG:
case SNDC_TAG:
case SDEN_TAG:
if (!ea->audio_codec) { avio_skip(pb, VAR_5); break; } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR || ea->audio_codec == CODEC_ID_MP3) { num_samples = avio_rl32(pb); avio_skip(pb, 8); VAR_5 -= 12; } VAR_2 = av_get_packet(pb, VAR_1, VAR_5); if (VAR_2 < 0)
return VAR_2; VAR_1->stream_index = ea->audio_stream_index; switch (ea->audio_codec) { case CODEC_ID_ADPCM_EA:
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_IMA_EA_EACS:
VAR_1->duration = AV_RL32(VAR_1->data); break; case CODEC_ID_ADPCM_EA_R3:
VAR_1->duration = AV_RB32(VAR_1->data); break; case CODEC_ID_ADPCM_IMA_EA_SEAD:
VAR_1->duration = VAR_2 * 2 / ea->num_channels; break; case CODEC_ID_PCM_S16LE_PLANAR:
case CODEC_ID_MP3:
VAR_1->duration = num_samples; break; default:
VAR_1->duration = VAR_5 / (ea->bytes * ea->num_channels); } VAR_3 = 1; break; case 0:
case ISNe_TAG:
case SCEl_TAG:
case SEND_TAG:
case SEEN_TAG:
VAR_2 = AVERROR(EIO); VAR_3 = 1; break; case MVIh_TAG:
case kVGT_TAG:
case pQGT_TAG:
case TGQs_TAG:
case MADk_TAG:
VAR_6 = AV_PKT_FLAG_KEY; case MVIf_TAG:
case fVGT_TAG:
case MADm_TAG:
case MADe_TAG:
avio_seek(pb, -8, SEEK_CUR); VAR_5 += 8; goto get_video_packet; case mTCD_TAG:
avio_skip(pb, 8); VAR_5 -= 8; goto get_video_packet; case MV0K_TAG:
case MPCh_TAG:
case pIQT_TAG:
VAR_6 = AV_PKT_FLAG_KEY; case MV0F_TAG:
get_video_packet:
VAR_2 = av_get_packet(pb, VAR_1, VAR_5); if (VAR_2 < 0)
return VAR_2; VAR_1->stream_index = ea->video_stream_index; VAR_1->flags |= VAR_6; VAR_3 = 1; break; default:
avio_skip(pb, VAR_5); break; } } return VAR_2; }