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

{

    struct ogg *ogg;

    struct ogg_stream *os;

    int idx, ret;

    int pstart, psize;

    int64_t fpos, pts, dts;



    if (s->io_repositioned) {

        ogg_reset(s);

        s->io_repositioned = 0;




    //Get an ogg packet

retry:

    do {

        ret = ogg_packet(s, &idx, &pstart, &psize, &fpos);

        if (ret < 0)

            return ret;

    } while (idx < 0 || !s->streams[idx]);



    ogg = s->priv_data;

    os  = ogg->streams + idx;



    // pflags might not be set until after this

    pts = ogg_calc_pts(s, idx, &dts);

    ogg_validate_keyframe(s, idx, pstart, psize);



    if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))

        goto retry;

    os->keyframe_seek = 0;



    //Alloc a pkt

    ret = av_new_packet(pkt, psize);

    if (ret < 0)

        return ret;

    pkt->stream_index = idx;

    memcpy(pkt->data, os->buf + pstart, psize);



    pkt->pts      = pts;

    pkt->dts      = dts;

    pkt->flags    = os->pflags;

    pkt->duration = os->pduration;

    pkt->pos      = fpos;



    if (os->end_trimming) {

        uint8_t *side_data = av_packet_new_side_data(pkt,

                                                     AV_PKT_DATA_SKIP_SAMPLES,

                                                     10);






        AV_WL32(side_data + 4, os->end_trimming);

        os->end_trimming = 0;




    if (os->new_metadata) {

        uint8_t *side_data = av_packet_new_side_data(pkt,

                                                     AV_PKT_DATA_METADATA_UPDATE,

                                                     os->new_metadata_size);






        memcpy(side_data, os->new_metadata, os->new_metadata_size);

        av_freep(&os->new_metadata);

        os->new_metadata_size = 0;




    return psize;

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

{

    struct ogg *ogg;

    struct ogg_stream *os;

    int idx, ret;

    int pstart, psize;

    int64_t fpos, pts, dts;



    if (s->io_repositioned) {

        ogg_reset(s);

        s->io_repositioned = 0;




    

retry:

    do {

        ret = ogg_packet(s, &idx, &pstart, &psize, &fpos);

        if (ret < 0)

            return ret;

    } while (idx < 0 || !s->streams[idx]);



    ogg = s->priv_data;

    os  = ogg->streams + idx;



    

    pts = ogg_calc_pts(s, idx, &dts);

    ogg_validate_keyframe(s, idx, pstart, psize);



    if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))

        goto retry;

    os->keyframe_seek = 0;



    

    ret = av_new_packet(pkt, psize);

    if (ret < 0)

        return ret;

    pkt->stream_index = idx;

    memcpy(pkt->data, os->buf + pstart, psize);



    pkt->pts      = pts;

    pkt->dts      = dts;

    pkt->flags    = os->pflags;

    pkt->duration = os->pduration;

    pkt->pos      = fpos;



    if (os->end_trimming) {

        uint8_t *side_data = av_packet_new_side_data(pkt,

                                                     AV_PKT_DATA_SKIP_SAMPLES,

                                                     10);






        AV_WL32(side_data + 4, os->end_trimming);

        os->end_trimming = 0;




    if (os->new_metadata) {

        uint8_t *side_data = av_packet_new_side_data(pkt,

                                                     AV_PKT_DATA_METADATA_UPDATE,

                                                     os->new_metadata_size);






        memcpy(side_data, os->new_metadata, os->new_metadata_size);

        av_freep(&os->new_metadata);

        os->new_metadata_size = 0;




    return psize;

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

{

    struct VAR_2 *VAR_2;

    struct ogg_stream *VAR_3;

    int VAR_4, VAR_5;

    int VAR_6, VAR_7;

    int64_t fpos, pts, dts;



    if (VAR_0->io_repositioned) {

        ogg_reset(VAR_0);

        VAR_0->io_repositioned = 0;




    

retry:

    do {

        VAR_5 = ogg_packet(VAR_0, &VAR_4, &VAR_6, &VAR_7, &fpos);

        if (VAR_5 < 0)

            return VAR_5;

    } while (VAR_4 < 0 || !VAR_0->streams[VAR_4]);



    VAR_2 = VAR_0->priv_data;

    VAR_3  = VAR_2->streams + VAR_4;



    

    pts = ogg_calc_pts(VAR_0, VAR_4, &dts);

    ogg_validate_keyframe(VAR_0, VAR_4, VAR_6, VAR_7);



    if (VAR_3->keyframe_seek && !(VAR_3->pflags & AV_PKT_FLAG_KEY))

        goto retry;

    VAR_3->keyframe_seek = 0;



    

    VAR_5 = av_new_packet(VAR_1, VAR_7);

    if (VAR_5 < 0)

        return VAR_5;

    VAR_1->stream_index = VAR_4;

    memcpy(VAR_1->data, VAR_3->buf + VAR_6, VAR_7);



    VAR_1->pts      = pts;

    VAR_1->dts      = dts;

    VAR_1->flags    = VAR_3->pflags;

    VAR_1->duration = VAR_3->pduration;

    VAR_1->pos      = fpos;



    if (VAR_3->end_trimming) {

        uint8_t *side_data = av_packet_new_side_data(VAR_1,

                                                     AV_PKT_DATA_SKIP_SAMPLES,

                                                     10);






        AV_WL32(side_data + 4, VAR_3->end_trimming);

        VAR_3->end_trimming = 0;




    if (VAR_3->new_metadata) {

        uint8_t *side_data = av_packet_new_side_data(VAR_1,

                                                     AV_PKT_DATA_METADATA_UPDATE,

                                                     VAR_3->new_metadata_size);






        memcpy(side_data, VAR_3->new_metadata, VAR_3->new_metadata_size);

        av_freep(&VAR_3->new_metadata);

        VAR_3->new_metadata_size = 0;




    return VAR_7;

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ struct VAR_2 *VAR_2; struct ogg_stream *VAR_3; int VAR_4, VAR_5; int VAR_6, VAR_7; int64_t fpos, pts, dts; if (VAR_0->io_repositioned) { ogg_reset(VAR_0); VAR_0->io_repositioned = 0; retry:
do { VAR_5 = ogg_packet(VAR_0, &VAR_4, &VAR_6, &VAR_7, &fpos); if (VAR_5 < 0)
return VAR_5; } while (VAR_4 < 0 || !VAR_0->streams[VAR_4]); VAR_2 = VAR_0->priv_data; VAR_3  = VAR_2->streams + VAR_4; pts = ogg_calc_pts(VAR_0, VAR_4, &dts); ogg_validate_keyframe(VAR_0, VAR_4, VAR_6, VAR_7); if (VAR_3->keyframe_seek && !(VAR_3->pflags & AV_PKT_FLAG_KEY))
goto retry; VAR_3->keyframe_seek = 0; VAR_5 = av_new_packet(VAR_1, VAR_7); if (VAR_5 < 0)
return VAR_5; VAR_1->stream_index = VAR_4; memcpy(VAR_1->data, VAR_3->buf + VAR_6, VAR_7); VAR_1->pts      = pts; VAR_1->dts      = dts; VAR_1->flags    = VAR_3->pflags; VAR_1->duration = VAR_3->pduration; VAR_1->pos      = fpos; if (VAR_3->end_trimming) { uint8_t *side_data = av_packet_new_side_data(VAR_1,
AV_PKT_DATA_SKIP_SAMPLES,
10); AV_WL32(side_data + 4, VAR_3->end_trimming); VAR_3->end_trimming = 0; if (VAR_3->new_metadata) { uint8_t *side_data = av_packet_new_side_data(VAR_1,
AV_PKT_DATA_METADATA_UPDATE,
VAR_3->new_metadata_size); memcpy(side_data, VAR_3->new_metadata, VAR_3->new_metadata_size); av_freep(&VAR_3->new_metadata); VAR_3->new_metadata_size = 0; return VAR_7;