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

{

    int ret, size;

    int64_t left;

    AVStream *st;

    WAVDemuxContext *wav = s->priv_data;



    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 0 &&

        s->streams[0]->codec->codec_tag == 1) {

        enum AVCodecID codec;

        ret = ff_spdif_probe(s->pb->buffer, s->pb->buf_end - s->pb->buffer,

                             &codec);

        if (ret > AVPROBE_SCORE_EXTENSION) {

            s->streams[0]->codec->codec_id = codec;

            wav->spdif = 1;

        } else {

            wav->spdif = -1;

        }

    }

    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)

        return ff_spdif_read_packet(s, pkt);



    if (wav->smv_data_ofs > 0) {

        int64_t audio_dts, video_dts;

smv_retry:

        audio_dts = s->streams[0]->cur_dts;

        video_dts = s->streams[1]->cur_dts;



        if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) {

            /*We always return a video frame first to get the pixel format first*/

            wav->smv_last_stream = wav->smv_given_first ?

                av_compare_ts(video_dts, s->streams[1]->time_base,

                              audio_dts, s->streams[0]->time_base) > 0 : 0;

            wav->smv_given_first = 1;

        }

        wav->smv_last_stream = !wav->smv_last_stream;

        wav->smv_last_stream |= wav->audio_eof;

        wav->smv_last_stream &= !wav->smv_eof;

        if (wav->smv_last_stream) {

            uint64_t old_pos = avio_tell(s->pb);

            uint64_t new_pos = wav->smv_data_ofs +

                wav->smv_block * wav->smv_block_size;

            if (avio_seek(s->pb, new_pos, SEEK_SET) < 0) {

                ret = AVERROR_EOF;

                goto smv_out;

            }

            size = avio_rl24(s->pb);

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

            if (ret < 0)

                goto smv_out;

            pkt->pos -= 3;

            pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt;

            wav->smv_cur_pt++;

            if (wav->smv_frames_per_jpeg > 0)

                wav->smv_cur_pt %= wav->smv_frames_per_jpeg;

            if (!wav->smv_cur_pt)

                wav->smv_block++;



            pkt->stream_index = 1;

smv_out:

            avio_seek(s->pb, old_pos, SEEK_SET);

            if (ret == AVERROR_EOF) {

                wav->smv_eof = 1;

                goto smv_retry;

            }

            return ret;

        }

    }



    st = s->streams[0];



    left = wav->data_end - avio_tell(s->pb);

    if (wav->ignore_length)

        left = INT_MAX;

    if (left <= 0) {

        if (CONFIG_W64_DEMUXER && wav->w64)

            left = find_guid(s->pb, ff_w64_guid_data) - 24;

        else

            left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));

        if (left < 0) {

            wav->audio_eof = 1;

            if (wav->smv_data_ofs > 0 && !wav->smv_eof)

                goto smv_retry;

            return AVERROR_EOF;

        }

        wav->data_end = avio_tell(s->pb) + left;

    }



    size = MAX_SIZE;

    if (st->codec->block_align > 1) {

        if (size < st->codec->block_align)

            size = st->codec->block_align;

        size = (size / st->codec->block_align) * st->codec->block_align;

    }

    size = FFMIN(size, left);

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

    if (ret < 0)

        return ret;

    pkt->stream_index = 0;



    return ret;

}

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

{

    int ret, size;

    int64_t left;

    AVStream *st;

    WAVDemuxContext *wav = s->priv_data;



    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 0 &&

        s->streams[0]->codec->codec_tag == 1) {

        enum AVCodecID codec;

        ret = ff_spdif_probe(s->pb->buffer, s->pb->buf_end - s->pb->buffer,

                             &codec);

        if (ret > AVPROBE_SCORE_EXTENSION) {

            s->streams[0]->codec->codec_id = codec;

            wav->spdif = 1;

        } else {

            wav->spdif = -1;

        }

    }

    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)

        return ff_spdif_read_packet(s, pkt);



    if (wav->smv_data_ofs > 0) {

        int64_t audio_dts, video_dts;

smv_retry:

        audio_dts = s->streams[0]->cur_dts;

        video_dts = s->streams[1]->cur_dts;



        if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) {

            

            wav->smv_last_stream = wav->smv_given_first ?

                av_compare_ts(video_dts, s->streams[1]->time_base,

                              audio_dts, s->streams[0]->time_base) > 0 : 0;

            wav->smv_given_first = 1;

        }

        wav->smv_last_stream = !wav->smv_last_stream;

        wav->smv_last_stream |= wav->audio_eof;

        wav->smv_last_stream &= !wav->smv_eof;

        if (wav->smv_last_stream) {

            uint64_t old_pos = avio_tell(s->pb);

            uint64_t new_pos = wav->smv_data_ofs +

                wav->smv_block * wav->smv_block_size;

            if (avio_seek(s->pb, new_pos, SEEK_SET) < 0) {

                ret = AVERROR_EOF;

                goto smv_out;

            }

            size = avio_rl24(s->pb);

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

            if (ret < 0)

                goto smv_out;

            pkt->pos -= 3;

            pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt;

            wav->smv_cur_pt++;

            if (wav->smv_frames_per_jpeg > 0)

                wav->smv_cur_pt %= wav->smv_frames_per_jpeg;

            if (!wav->smv_cur_pt)

                wav->smv_block++;



            pkt->stream_index = 1;

smv_out:

            avio_seek(s->pb, old_pos, SEEK_SET);

            if (ret == AVERROR_EOF) {

                wav->smv_eof = 1;

                goto smv_retry;

            }

            return ret;

        }

    }



    st = s->streams[0];



    left = wav->data_end - avio_tell(s->pb);

    if (wav->ignore_length)

        left = INT_MAX;

    if (left <= 0) {

        if (CONFIG_W64_DEMUXER && wav->w64)

            left = find_guid(s->pb, ff_w64_guid_data) - 24;

        else

            left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));

        if (left < 0) {

            wav->audio_eof = 1;

            if (wav->smv_data_ofs > 0 && !wav->smv_eof)

                goto smv_retry;

            return AVERROR_EOF;

        }

        wav->data_end = avio_tell(s->pb) + left;

    }



    size = MAX_SIZE;

    if (st->codec->block_align > 1) {

        if (size < st->codec->block_align)

            size = st->codec->block_align;

        size = (size / st->codec->block_align) * st->codec->block_align;

    }

    size = FFMIN(size, left);

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

    if (ret < 0)

        return ret;

    pkt->stream_index = 0;



    return ret;

}

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

{

    int VAR_2, VAR_3;

    int64_t left;

    AVStream *st;

    WAVDemuxContext *wav = VAR_0->priv_data;



    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 0 &&

        VAR_0->streams[0]->VAR_4->codec_tag == 1) {

        enum AVCodecID VAR_4;

        VAR_2 = ff_spdif_probe(VAR_0->pb->buffer, VAR_0->pb->buf_end - VAR_0->pb->buffer,

                             &VAR_4);

        if (VAR_2 > AVPROBE_SCORE_EXTENSION) {

            VAR_0->streams[0]->VAR_4->codec_id = VAR_4;

            wav->spdif = 1;

        } else {

            wav->spdif = -1;

        }

    }

    if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)

        return ff_spdif_read_packet(VAR_0, VAR_1);



    if (wav->smv_data_ofs > 0) {

        int64_t audio_dts, video_dts;

smv_retry:

        audio_dts = VAR_0->streams[0]->cur_dts;

        video_dts = VAR_0->streams[1]->cur_dts;



        if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) {

            

            wav->smv_last_stream = wav->smv_given_first ?

                av_compare_ts(video_dts, VAR_0->streams[1]->time_base,

                              audio_dts, VAR_0->streams[0]->time_base) > 0 : 0;

            wav->smv_given_first = 1;

        }

        wav->smv_last_stream = !wav->smv_last_stream;

        wav->smv_last_stream |= wav->audio_eof;

        wav->smv_last_stream &= !wav->smv_eof;

        if (wav->smv_last_stream) {

            uint64_t old_pos = avio_tell(VAR_0->pb);

            uint64_t new_pos = wav->smv_data_ofs +

                wav->smv_block * wav->smv_block_size;

            if (avio_seek(VAR_0->pb, new_pos, SEEK_SET) < 0) {

                VAR_2 = AVERROR_EOF;

                goto smv_out;

            }

            VAR_3 = avio_rl24(VAR_0->pb);

            VAR_2  = av_get_packet(VAR_0->pb, VAR_1, VAR_3);

            if (VAR_2 < 0)

                goto smv_out;

            VAR_1->pos -= 3;

            VAR_1->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt;

            wav->smv_cur_pt++;

            if (wav->smv_frames_per_jpeg > 0)

                wav->smv_cur_pt %= wav->smv_frames_per_jpeg;

            if (!wav->smv_cur_pt)

                wav->smv_block++;



            VAR_1->stream_index = 1;

smv_out:

            avio_seek(VAR_0->pb, old_pos, SEEK_SET);

            if (VAR_2 == AVERROR_EOF) {

                wav->smv_eof = 1;

                goto smv_retry;

            }

            return VAR_2;

        }

    }



    st = VAR_0->streams[0];



    left = wav->data_end - avio_tell(VAR_0->pb);

    if (wav->ignore_length)

        left = INT_MAX;

    if (left <= 0) {

        if (CONFIG_W64_DEMUXER && wav->w64)

            left = find_guid(VAR_0->pb, ff_w64_guid_data) - 24;

        else

            left = find_tag(VAR_0->pb, MKTAG('d', 'a', 't', 'a'));

        if (left < 0) {

            wav->audio_eof = 1;

            if (wav->smv_data_ofs > 0 && !wav->smv_eof)

                goto smv_retry;

            return AVERROR_EOF;

        }

        wav->data_end = avio_tell(VAR_0->pb) + left;

    }



    VAR_3 = MAX_SIZE;

    if (st->VAR_4->block_align > 1) {

        if (VAR_3 < st->VAR_4->block_align)

            VAR_3 = st->VAR_4->block_align;

        VAR_3 = (VAR_3 / st->VAR_4->block_align) * st->VAR_4->block_align;

    }

    VAR_3 = FFMIN(VAR_3, left);

    VAR_2  = av_get_packet(VAR_0->pb, VAR_1, VAR_3);

    if (VAR_2 < 0)

        return VAR_2;

    VAR_1->stream_index = 0;



    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ int VAR_2, VAR_3; int64_t left; AVStream *st; WAVDemuxContext *wav = VAR_0->priv_data; if (CONFIG_SPDIF_DEMUXER && wav->spdif == 0 &&
VAR_0->streams[0]->VAR_4->codec_tag == 1) { enum AVCodecID VAR_4; VAR_2 = ff_spdif_probe(VAR_0->pb->buffer, VAR_0->pb->buf_end - VAR_0->pb->buffer,
&VAR_4); if (VAR_2 > AVPROBE_SCORE_EXTENSION) { VAR_0->streams[0]->VAR_4->codec_id = VAR_4; wav->spdif = 1; } else { wav->spdif = -1; } } if (CONFIG_SPDIF_DEMUXER && wav->spdif == 1)
return ff_spdif_read_packet(VAR_0, VAR_1); if (wav->smv_data_ofs > 0) { int64_t audio_dts, video_dts; smv_retry:
audio_dts = VAR_0->streams[0]->cur_dts; video_dts = VAR_0->streams[1]->cur_dts; if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) { wav->smv_last_stream = wav->smv_given_first ?
av_compare_ts(video_dts, VAR_0->streams[1]->time_base,
audio_dts, VAR_0->streams[0]->time_base) > 0 : 0; wav->smv_given_first = 1; } wav->smv_last_stream = !wav->smv_last_stream; wav->smv_last_stream |= wav->audio_eof; wav->smv_last_stream &= !wav->smv_eof; if (wav->smv_last_stream) { uint64_t old_pos = avio_tell(VAR_0->pb); uint64_t new_pos = wav->smv_data_ofs +
wav->smv_block * wav->smv_block_size; if (avio_seek(VAR_0->pb, new_pos, SEEK_SET) < 0) { VAR_2 = AVERROR_EOF; goto smv_out; } VAR_3 = avio_rl24(VAR_0->pb); VAR_2  = av_get_packet(VAR_0->pb, VAR_1, VAR_3); if (VAR_2 < 0)
goto smv_out; VAR_1->pos -= 3; VAR_1->pts = wav->smv_block * wav->smv_frames_per_jpeg + wav->smv_cur_pt; wav->smv_cur_pt++; if (wav->smv_frames_per_jpeg > 0)
wav->smv_cur_pt %= wav->smv_frames_per_jpeg; if (!wav->smv_cur_pt)
wav->smv_block++; VAR_1->stream_index = 1; smv_out:
avio_seek(VAR_0->pb, old_pos, SEEK_SET); if (VAR_2 == AVERROR_EOF) { wav->smv_eof = 1; goto smv_retry; } return VAR_2; } } st = VAR_0->streams[0]; left = wav->data_end - avio_tell(VAR_0->pb); if (wav->ignore_length)
left = INT_MAX; if (left <= 0) { if (CONFIG_W64_DEMUXER && wav->w64)
left = find_guid(VAR_0->pb, ff_w64_guid_data) - 24; else
left = find_tag(VAR_0->pb, MKTAG('d', 'a', 't', 'a')); if (left < 0) { wav->audio_eof = 1; if (wav->smv_data_ofs > 0 && !wav->smv_eof)
goto smv_retry; return AVERROR_EOF; } wav->data_end = avio_tell(VAR_0->pb) + left; } VAR_3 = MAX_SIZE; if (st->VAR_4->block_align > 1) { if (VAR_3 < st->VAR_4->block_align)
VAR_3 = st->VAR_4->block_align; VAR_3 = (VAR_3 / st->VAR_4->block_align) * st->VAR_4->block_align; } VAR_3 = FFMIN(VAR_3, left); VAR_2  = av_get_packet(VAR_0->pb, VAR_1, VAR_3); if (VAR_2 < 0)
return VAR_2; VAR_1->stream_index = 0; return VAR_2; }