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;



    if (!os->psize)

        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++) {

            if (os->segments[seg] < 255) {

                int d = opus_duration(last_pkt, os->segments[seg]);

                if (d < 0) {

                    duration = os->granule;

                    break;

                }

                duration += d;

                last_pkt  = next_pkt + os->segments[seg];

            }

            next_pkt += os->segments[seg];

        }

        os->lastpts                 =

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

    }



    os->pduration = opus_duration(packet, os->psize);

    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;



    if (!os->psize)

        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++) {

            if (os->segments[seg] < 255) {

                int d = opus_duration(last_pkt, os->segments[seg]);

                if (d < 0) {

                    duration = os->granule;

                    break;

                }

                duration += d;

                last_pkt  = next_pkt + os->segments[seg];

            }

            next_pkt += os->segments[seg];

        }

        os->lastpts                 =

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

    }



    os->pduration = opus_duration(packet, os->psize);

    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 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;



    if (!VAR_3->psize)

        return AVERROR_INVALIDDATA;



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

        int VAR_5, VAR_8;

        int VAR_7;

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

        uint8_t *next_pkt  = last_pkt;



        VAR_7 = 0;

        VAR_5 = VAR_3->segp;

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

        if (VAR_8 < 0) {

            VAR_3->pflags |= AV_PKT_FLAG_CORRUPT;

            return 0;

        }

        VAR_7 += VAR_8;

        last_pkt = next_pkt =  next_pkt + VAR_3->psize;

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

            if (VAR_3->segments[VAR_5] < 255) {

                int VAR_8 = opus_duration(last_pkt, VAR_3->segments[VAR_5]);

                if (VAR_8 < 0) {

                    VAR_7 = VAR_3->granule;

                    break;

                }

                VAR_7 += VAR_8;

                last_pkt  = next_pkt + VAR_3->segments[VAR_5];

            }

            next_pkt += VAR_3->segments[VAR_5];

        }

        VAR_3->lastpts                 =

        VAR_3->lastdts                 = VAR_3->granule - VAR_7;

    }



    VAR_3->pduration = opus_duration(packet, VAR_3->psize);

    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_8 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; if (!VAR_3->psize)
return AVERROR_INVALIDDATA; if ((!VAR_3->lastpts || VAR_3->lastpts == AV_NOPTS_VALUE) && !(VAR_3->flags & OGG_FLAG_EOS)) { int VAR_5, VAR_8; int VAR_7; uint8_t *last_pkt  = VAR_3->buf + VAR_3->pstart; uint8_t *next_pkt  = last_pkt; VAR_7 = 0; VAR_5 = VAR_3->segp; VAR_8 = opus_duration(last_pkt, VAR_3->psize); if (VAR_8 < 0) { VAR_3->pflags |= AV_PKT_FLAG_CORRUPT; return 0; } VAR_7 += VAR_8; last_pkt = next_pkt =  next_pkt + VAR_3->psize; for (; VAR_5 < VAR_3->nsegs; VAR_5++) { if (VAR_3->segments[VAR_5] < 255) { int VAR_8 = opus_duration(last_pkt, VAR_3->segments[VAR_5]); if (VAR_8 < 0) { VAR_7 = VAR_3->granule; break; } VAR_7 += VAR_8; last_pkt  = next_pkt + VAR_3->segments[VAR_5]; } next_pkt += VAR_3->segments[VAR_5]; } VAR_3->lastpts                 =
VAR_3->lastdts                 = VAR_3->granule - VAR_7; } VAR_3->pduration = opus_duration(packet, VAR_3->psize); 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_8 due to end trimming.\n",
VAR_3->pduration); } } return 0; }