static int opus_packet(AVFormatContext *avf, int idx)

{

    struct ogg *ogg              = avf->priv_data;

    struct ogg_stream *os        = &ogg->streams[idx];

    AVStream *st                 = avf->streams[idx];

    struct oggopus_private *priv = os->private;

    uint8_t *packet              = os->buf + os->pstart;

    int ret;



    if (!os->psize)

        return AVERROR_INVALIDDATA;

    if (os->granule > INT64_MAX - UINT32_MAX) {

        av_log(avf, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", os->granule);

        return AVERROR_INVALIDDATA;

    }



    if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {

        int seg, d;

        int duration;

        uint8_t *last_pkt  = os->buf + os->pstart;

        uint8_t *next_pkt  = last_pkt;



        duration = 0;

        seg = os->segp;

        d = opus_duration(last_pkt, os->psize);

        if (d < 0) {

            os->pflags |= AV_PKT_FLAG_CORRUPT;

            return 0;

        }

        duration += d;

        last_pkt = next_pkt =  next_pkt + os->psize;

        for (; seg < os->nsegs; seg++) {

            next_pkt += os->segments[seg];

            if (os->segments[seg] < 255 && next_pkt != last_pkt) {

                int d = opus_duration(last_pkt, next_pkt - last_pkt);

                if (d > 0)

                    duration += d;

                last_pkt = next_pkt;

            }

        }

        os->lastpts                 =

        os->lastdts                 = os->granule - duration;

    }



    if ((ret = opus_duration(packet, os->psize)) < 0)

        return ret;



    os->pduration = ret;

    if (os->lastpts != AV_NOPTS_VALUE) {

        if (st->start_time == AV_NOPTS_VALUE)

            st->start_time = os->lastpts;

        priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;

    }



    priv->cur_dts += os->pduration;

    if ((os->flags & OGG_FLAG_EOS)) {

        int64_t skip = priv->cur_dts - os->granule + priv->pre_skip;

        skip = FFMIN(skip, os->pduration);

        if (skip > 0) {

            os->pduration = skip < os->pduration ? os->pduration - skip : 1;

            os->end_trimming = skip;

            av_log(avf, AV_LOG_DEBUG,

                   "Last packet was truncated to %d due to end trimming.\n",

                   os->pduration);

        }

    }



    return 0;

}

static int opus_packet(AVFormatContext *avf, int idx)

{

    struct ogg *ogg              = avf->priv_data;

    struct ogg_stream *os        = &ogg->streams[idx];

    AVStream *st                 = avf->streams[idx];

    struct oggopus_private *priv = os->private;

    uint8_t *packet              = os->buf + os->pstart;

    int ret;



    if (!os->psize)

        return AVERROR_INVALIDDATA;

    if (os->granule > INT64_MAX - UINT32_MAX) {

        av_log(avf, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", os->granule);

        return AVERROR_INVALIDDATA;

    }



    if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {

        int seg, d;

        int duration;

        uint8_t *last_pkt  = os->buf + os->pstart;

        uint8_t *next_pkt  = last_pkt;



        duration = 0;

        seg = os->segp;

        d = opus_duration(last_pkt, os->psize);

        if (d < 0) {

            os->pflags |= AV_PKT_FLAG_CORRUPT;

            return 0;

        }

        duration += d;

        last_pkt = next_pkt =  next_pkt + os->psize;

        for (; seg < os->nsegs; seg++) {

            next_pkt += os->segments[seg];

            if (os->segments[seg] < 255 && next_pkt != last_pkt) {

                int d = opus_duration(last_pkt, next_pkt - last_pkt);

                if (d > 0)

                    duration += d;

                last_pkt = next_pkt;

            }

        }

        os->lastpts                 =

        os->lastdts                 = os->granule - duration;

    }



    if ((ret = opus_duration(packet, os->psize)) < 0)

        return ret;



    os->pduration = ret;

    if (os->lastpts != AV_NOPTS_VALUE) {

        if (st->start_time == AV_NOPTS_VALUE)

            st->start_time = os->lastpts;

        priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;

    }



    priv->cur_dts += os->pduration;

    if ((os->flags & OGG_FLAG_EOS)) {

        int64_t skip = priv->cur_dts - os->granule + priv->pre_skip;

        skip = FFMIN(skip, os->pduration);

        if (skip > 0) {

            os->pduration = skip < os->pduration ? os->pduration - skip : 1;

            os->end_trimming = skip;

            av_log(avf, AV_LOG_DEBUG,

                   "Last packet was truncated to %d due to end trimming.\n",

                   os->pduration);

        }

    }



    return 0;

}

    if (os->granule > INT64_MAX - UINT32_MAX) {
static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)

{

    struct VAR_2 *VAR_2              = VAR_0->priv_data;

    struct ogg_stream *VAR_3        = &VAR_2->streams[VAR_1];

    AVStream *st                 = VAR_0->streams[VAR_1];

    struct oggopus_private *VAR_4 = VAR_3->private;

    uint8_t *packet              = VAR_3->buf + VAR_3->pstart;

    int VAR_5;



    if (!VAR_3->psize)

        return AVERROR_INVALIDDATA;

    if (VAR_3->granule > INT64_MAX - UINT32_MAX) {

        av_log(VAR_0, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", VAR_3->granule);

        return AVERROR_INVALIDDATA;

    }



    if ((!VAR_3->lastpts || VAR_3->lastpts == AV_NOPTS_VALUE) && !(VAR_3->flags & OGG_FLAG_EOS)) {

        int VAR_6, VAR_9;

        int VAR_8;

        uint8_t *last_pkt  = VAR_3->buf + VAR_3->pstart;

        uint8_t *next_pkt  = last_pkt;



        VAR_8 = 0;

        VAR_6 = VAR_3->segp;

        VAR_9 = opus_duration(last_pkt, VAR_3->psize);

        if (VAR_9 < 0) {

            VAR_3->pflags |= AV_PKT_FLAG_CORRUPT;

            return 0;

        }

        VAR_8 += VAR_9;

        last_pkt = next_pkt =  next_pkt + VAR_3->psize;

        for (; VAR_6 < VAR_3->nsegs; VAR_6++) {

            next_pkt += VAR_3->segments[VAR_6];

            if (VAR_3->segments[VAR_6] < 255 && next_pkt != last_pkt) {

                int VAR_9 = opus_duration(last_pkt, next_pkt - last_pkt);

                if (VAR_9 > 0)

                    VAR_8 += VAR_9;

                last_pkt = next_pkt;

            }

        }

        VAR_3->lastpts                 =

        VAR_3->lastdts                 = VAR_3->granule - VAR_8;

    }



    if ((VAR_5 = opus_duration(packet, VAR_3->psize)) < 0)

        return VAR_5;



    VAR_3->pduration = VAR_5;

    if (VAR_3->lastpts != AV_NOPTS_VALUE) {

        if (st->start_time == AV_NOPTS_VALUE)

            st->start_time = VAR_3->lastpts;

        VAR_4->cur_dts = VAR_3->lastdts = VAR_3->lastpts -= VAR_4->pre_skip;

    }



    VAR_4->cur_dts += VAR_3->pduration;

    if ((VAR_3->flags & OGG_FLAG_EOS)) {

        int64_t skip = VAR_4->cur_dts - VAR_3->granule + VAR_4->pre_skip;

        skip = FFMIN(skip, VAR_3->pduration);

        if (skip > 0) {

            VAR_3->pduration = skip < VAR_3->pduration ? VAR_3->pduration - skip : 1;

            VAR_3->end_trimming = skip;

            av_log(VAR_0, AV_LOG_DEBUG,

                   "Last packet was truncated to %VAR_9 due to end trimming.\n",

                   VAR_3->pduration);

        }

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1)
{ struct VAR_2 *VAR_2              = VAR_0->priv_data; struct ogg_stream *VAR_3        = &VAR_2->streams[VAR_1]; AVStream *st                 = VAR_0->streams[VAR_1]; struct oggopus_private *VAR_4 = VAR_3->private; uint8_t *packet              = VAR_3->buf + VAR_3->pstart; int VAR_5; if (!VAR_3->psize)
return AVERROR_INVALIDDATA; if (VAR_3->granule > INT64_MAX - UINT32_MAX) { av_log(VAR_0, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", VAR_3->granule); return AVERROR_INVALIDDATA; } if ((!VAR_3->lastpts || VAR_3->lastpts == AV_NOPTS_VALUE) && !(VAR_3->flags & OGG_FLAG_EOS)) { int VAR_6, VAR_9; int VAR_8; uint8_t *last_pkt  = VAR_3->buf + VAR_3->pstart; uint8_t *next_pkt  = last_pkt; VAR_8 = 0; VAR_6 = VAR_3->segp; VAR_9 = opus_duration(last_pkt, VAR_3->psize); if (VAR_9 < 0) { VAR_3->pflags |= AV_PKT_FLAG_CORRUPT; return 0; } VAR_8 += VAR_9; last_pkt = next_pkt =  next_pkt + VAR_3->psize; for (; VAR_6 < VAR_3->nsegs; VAR_6++) { next_pkt += VAR_3->segments[VAR_6]; if (VAR_3->segments[VAR_6] < 255 && next_pkt != last_pkt) { int VAR_9 = opus_duration(last_pkt, next_pkt - last_pkt); if (VAR_9 > 0)
VAR_8 += VAR_9; last_pkt = next_pkt; } } VAR_3->lastpts                 =
VAR_3->lastdts                 = VAR_3->granule - VAR_8; } if ((VAR_5 = opus_duration(packet, VAR_3->psize)) < 0)
return VAR_5; VAR_3->pduration = VAR_5; if (VAR_3->lastpts != AV_NOPTS_VALUE) { if (st->start_time == AV_NOPTS_VALUE)
st->start_time = VAR_3->lastpts; VAR_4->cur_dts = VAR_3->lastdts = VAR_3->lastpts -= VAR_4->pre_skip; } VAR_4->cur_dts += VAR_3->pduration; if ((VAR_3->flags & OGG_FLAG_EOS)) { int64_t skip = VAR_4->cur_dts - VAR_3->granule + VAR_4->pre_skip; skip = FFMIN(skip, VAR_3->pduration); if (skip > 0) { VAR_3->pduration = skip < VAR_3->pduration ? VAR_3->pduration - skip : 1; VAR_3->end_trimming = skip; av_log(VAR_0, AV_LOG_DEBUG,
"Last packet was truncated to %VAR_9 due to end trimming.\n",
VAR_3->pduration); } } return 0; }