static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int i, j, entries, ctts_count = 0;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    avio_r8(pb); /* version */

    avio_rb24(pb); /* flags */

    entries = avio_rb32(pb);



    av_log(c->fc, AV_LOG_TRACE, "track[%u].ctts.entries = %u\n", c->fc->nb_streams - 1, entries);



    if (!entries)

        return 0;

    if (entries >= UINT_MAX / sizeof(*sc->ctts_data))

        return AVERROR_INVALIDDATA;

    av_freep(&sc->ctts_data);

    sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data));

    if (!sc->ctts_data)

        return AVERROR(ENOMEM);



    for (i = 0; i < entries && !pb->eof_reached; i++) {

        int count    =avio_rb32(pb);

        int duration =avio_rb32(pb);



        if (count <= 0) {

            av_log(c->fc, AV_LOG_TRACE,

                   "ignoring CTTS entry with count=%d duration=%d\n",

                   count, duration);

            continue;

        }



        /* Expand entries such that we have a 1-1 mapping with samples. */

        for (j = 0; j < count; j++)

            add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, 1, duration);



        av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",

                count, duration);



        if (FFNABS(duration) < -(1<<28) && i+2<entries) {

            av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");

            av_freep(&sc->ctts_data);

            sc->ctts_count = 0;

            return 0;

        }



        if (i+2<entries)

            mov_update_dts_shift(sc, duration);

    }



    sc->ctts_count = ctts_count;



    if (pb->eof_reached)

        return AVERROR_EOF;



    av_log(c->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift);



    return 0;

}

static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int i, j, entries, ctts_count = 0;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    avio_r8(pb); 

    avio_rb24(pb); 

    entries = avio_rb32(pb);



    av_log(c->fc, AV_LOG_TRACE, "track[%u].ctts.entries = %u\n", c->fc->nb_streams - 1, entries);



    if (!entries)

        return 0;

    if (entries >= UINT_MAX / sizeof(*sc->ctts_data))

        return AVERROR_INVALIDDATA;

    av_freep(&sc->ctts_data);

    sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, entries * sizeof(*sc->ctts_data));

    if (!sc->ctts_data)

        return AVERROR(ENOMEM);



    for (i = 0; i < entries && !pb->eof_reached; i++) {

        int count    =avio_rb32(pb);

        int duration =avio_rb32(pb);



        if (count <= 0) {

            av_log(c->fc, AV_LOG_TRACE,

                   "ignoring CTTS entry with count=%d duration=%d\n",

                   count, duration);

            continue;

        }



        

        for (j = 0; j < count; j++)

            add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, 1, duration);



        av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",

                count, duration);



        if (FFNABS(duration) < -(1<<28) && i+2<entries) {

            av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");

            av_freep(&sc->ctts_data);

            sc->ctts_count = 0;

            return 0;

        }



        if (i+2<entries)

            mov_update_dts_shift(sc, duration);

    }



    sc->ctts_count = ctts_count;



    if (pb->eof_reached)

        return AVERROR_EOF;



    av_log(c->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift);



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int VAR_3, VAR_4, VAR_5, VAR_6 = 0;



    if (VAR_0->fc->nb_streams < 1)

        return 0;

    st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1];

    sc = st->priv_data;



    avio_r8(VAR_1); 

    avio_rb24(VAR_1); 

    VAR_5 = avio_rb32(VAR_1);



    av_log(VAR_0->fc, AV_LOG_TRACE, "track[%u].ctts.VAR_5 = %u\n", VAR_0->fc->nb_streams - 1, VAR_5);



    if (!VAR_5)

        return 0;

    if (VAR_5 >= UINT_MAX / sizeof(*sc->ctts_data))

        return AVERROR_INVALIDDATA;

    av_freep(&sc->ctts_data);

    sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, VAR_5 * sizeof(*sc->ctts_data));

    if (!sc->ctts_data)

        return AVERROR(ENOMEM);



    for (VAR_3 = 0; VAR_3 < VAR_5 && !VAR_1->eof_reached; VAR_3++) {

        int count    =avio_rb32(VAR_1);

        int duration =avio_rb32(VAR_1);



        if (count <= 0) {

            av_log(VAR_0->fc, AV_LOG_TRACE,

                   "ignoring CTTS entry with count=%d duration=%d\n",

                   count, duration);

            continue;

        }



        

        for (VAR_4 = 0; VAR_4 < count; VAR_4++)

            add_ctts_entry(&sc->ctts_data, &VAR_6, &sc->ctts_allocated_size, 1, duration);



        av_log(VAR_0->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",

                count, duration);



        if (FFNABS(duration) < -(1<<28) && VAR_3+2<VAR_5) {

            av_log(VAR_0->fc, AV_LOG_WARNING, "CTTS invalid\n");

            av_freep(&sc->ctts_data);

            sc->VAR_6 = 0;

            return 0;

        }



        if (VAR_3+2<VAR_5)

            mov_update_dts_shift(sc, duration);

    }



    sc->VAR_6 = VAR_6;



    if (VAR_1->eof_reached)

        return AVERROR_EOF;



    av_log(VAR_0->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift);



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)
{ AVStream *st; MOVStreamContext *sc; unsigned int VAR_3, VAR_4, VAR_5, VAR_6 = 0; if (VAR_0->fc->nb_streams < 1)
return 0; st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1]; sc = st->priv_data; avio_r8(VAR_1); avio_rb24(VAR_1); VAR_5 = avio_rb32(VAR_1); av_log(VAR_0->fc, AV_LOG_TRACE, "track[%u].ctts.VAR_5 = %u\n", VAR_0->fc->nb_streams - 1, VAR_5); if (!VAR_5)
return 0; if (VAR_5 >= UINT_MAX / sizeof(*sc->ctts_data))
return AVERROR_INVALIDDATA; av_freep(&sc->ctts_data); sc->ctts_data = av_fast_realloc(NULL, &sc->ctts_allocated_size, VAR_5 * sizeof(*sc->ctts_data)); if (!sc->ctts_data)
return AVERROR(ENOMEM); for (VAR_3 = 0; VAR_3 < VAR_5 && !VAR_1->eof_reached; VAR_3++) { int count    =avio_rb32(VAR_1); int duration =avio_rb32(VAR_1); if (count <= 0) { av_log(VAR_0->fc, AV_LOG_TRACE,
"ignoring CTTS entry with count=%d duration=%d\n",
count, duration); continue; } for (VAR_4 = 0; VAR_4 < count; VAR_4++) add_ctts_entry(&sc->ctts_data, &VAR_6, &sc->ctts_allocated_size, 1, duration); av_log(VAR_0->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
count, duration); if (FFNABS(duration) < -(1<<28) && VAR_3+2<VAR_5) { av_log(VAR_0->fc, AV_LOG_WARNING, "CTTS invalid\n"); av_freep(&sc->ctts_data); sc->VAR_6 = 0; return 0; } if (VAR_3+2<VAR_5)
mov_update_dts_shift(sc, duration); } sc->VAR_6 = VAR_6; if (VAR_1->eof_reached)
return AVERROR_EOF; av_log(VAR_0->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift); return 0; }