static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)

{

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

    //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;

    int entries, i;

    int64_t duration=0;

    int64_t total_sample_count=0;



    print_atom("stts", atom);



    get_byte(pb); /* version */

    get_byte(pb); get_byte(pb); get_byte(pb); /* flags */

    entries = get_be32(pb);



    c->streams[c->fc->nb_streams-1]->stts_count = entries;

    c->streams[c->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(entries * sizeof(uint64_t));



#ifdef DEBUG

av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);

#endif

    for(i=0; i<entries; i++) {

        int32_t sample_duration;

        int32_t sample_count;



        sample_count=get_be32(pb);

        sample_duration = get_be32(pb);

        c->streams[c->fc->nb_streams - 1]->stts_data[i] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration;

#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);

#endif

        duration+=sample_duration*sample_count;

        total_sample_count+=sample_count;



#if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone



        if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {

            st->codec.frame_rate_base = sample_duration ? sample_duration : 1;

            st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale;

#ifdef DEBUG

            av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);

#endif

        }

#endif

    }



    /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/

    if(duration>0)

    {

        av_reduce(

            &st->codec.frame_rate, 

            &st->codec.frame_rate_base, 

            c->streams[c->fc->nb_streams-1]->time_scale * total_sample_count,

            duration,

            INT_MAX

        );



#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,c->streams[c->fc->nb_streams-1]->time_scale);

#endif

    }

    else

    {

        st->codec.frame_rate_base = 1;

        st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale;

    }

    return 0;

}

static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)

{

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

    

    int entries, i;

    int64_t duration=0;

    int64_t total_sample_count=0;



    print_atom("stts", atom);



    get_byte(pb); 

    get_byte(pb); get_byte(pb); get_byte(pb); 

    entries = get_be32(pb);



    c->streams[c->fc->nb_streams-1]->stts_count = entries;

    c->streams[c->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(entries * sizeof(uint64_t));



#ifdef DEBUG

av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);

#endif

    for(i=0; i<entries; i++) {

        int32_t sample_duration;

        int32_t sample_count;



        sample_count=get_be32(pb);

        sample_duration = get_be32(pb);

        c->streams[c->fc->nb_streams - 1]->stts_data[i] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration;

#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);

#endif

        duration+=sample_duration*sample_count;

        total_sample_count+=sample_count;



#if 0 



        if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {

            st->codec.frame_rate_base = sample_duration ? sample_duration : 1;

            st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale;

#ifdef DEBUG

            av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);

#endif

        }

#endif

    }



    

    if(duration>0)

    {

        av_reduce(

            &st->codec.frame_rate, 

            &st->codec.frame_rate_base, 

            c->streams[c->fc->nb_streams-1]->time_scale * total_sample_count,

            duration,

            INT_MAX

        );



#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,c->streams[c->fc->nb_streams-1]->time_scale);

#endif

    }

    else

    {

        st->codec.frame_rate_base = 1;

        st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale;

    }

    return 0;

}

    int entries, i;     int entries, i;     int entries, i;     int entries, i;     int entries, i;
static int FUNC_0(MOVContext *VAR_0, ByteIOContext *VAR_1, MOV_atom_t VAR_2)

{

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

    

    int VAR_3, VAR_4;

    int64_t duration=0;

    int64_t total_sample_count=0;



    print_atom("stts", VAR_2);



    get_byte(VAR_1); 

    get_byte(VAR_1); get_byte(VAR_1); get_byte(VAR_1); 

    VAR_3 = get_be32(VAR_1);



    VAR_0->streams[VAR_0->fc->nb_streams-1]->stts_count = VAR_3;

    VAR_0->streams[VAR_0->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(VAR_3 * sizeof(uint64_t));



#ifdef DEBUG

av_log(NULL, AV_LOG_DEBUG, "track[%VAR_4].stts.VAR_3 = %VAR_4\n", VAR_0->fc->nb_streams-1, VAR_3);

#endif

    for(VAR_4=0; VAR_4<VAR_3; VAR_4++) {

        int32_t sample_duration;

        int32_t sample_count;



        sample_count=get_be32(VAR_1);

        sample_duration = get_be32(VAR_1);

        VAR_0->streams[VAR_0->fc->nb_streams - 1]->stts_data[VAR_4] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration;

#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);

#endif

        duration+=sample_duration*sample_count;

        total_sample_count+=sample_count;



#if 0 



        if (!VAR_4 && st->codec.codec_type==CODEC_TYPE_VIDEO) {

            st->codec.frame_rate_base = sample_duration ? sample_duration : 1;

            st->codec.frame_rate = VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale;

#ifdef DEBUG

            av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %VAR_4 (sd= %VAR_4)\n", st->codec.frame_rate, sample_duration);

#endif

        }

#endif

    }



    

    if(duration>0)

    {

        av_reduce(

            &st->codec.frame_rate, 

            &st->codec.frame_rate_base, 

            VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale * total_sample_count,

            duration,

            INT_MAX

        );



#ifdef DEBUG

        av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %VAR_4 ,tot dur= %VAR_4 timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale);

#endif

    }

    else

    {

        st->codec.frame_rate_base = 1;

        st->codec.frame_rate = VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale;

    }

    return 0;

}

static int FUNC_0(MOVContext *VAR_0, ByteIOContext *VAR_1, MOV_atom_t VAR_2)
{ AVStream *st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1]; int VAR_3, VAR_4; int64_t duration=0; int64_t total_sample_count=0; print_atom("stts", VAR_2); get_byte(VAR_1); get_byte(VAR_1); get_byte(VAR_1); get_byte(VAR_1); VAR_3 = get_be32(VAR_1); VAR_0->streams[VAR_0->fc->nb_streams-1]->stts_count = VAR_3; VAR_0->streams[VAR_0->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(VAR_3 * sizeof(uint64_t)); #ifdef DEBUG
av_log(NULL, AV_LOG_DEBUG, "track[%VAR_4].stts.VAR_3 = %VAR_4\n", VAR_0->fc->nb_streams-1, VAR_3); #endif
for(VAR_4=0; VAR_4<VAR_3; VAR_4++) { int32_t sample_duration; int32_t sample_count; sample_count=get_be32(VAR_1); sample_duration = get_be32(VAR_1); VAR_0->streams[VAR_0->fc->nb_streams - 1]->stts_data[VAR_4] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration; #ifdef DEBUG
av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); #endif
duration+=sample_duration*sample_count; total_sample_count+=sample_count; #if 0
if (!VAR_4 && st->codec.codec_type==CODEC_TYPE_VIDEO) { st->codec.frame_rate_base = sample_duration ? sample_duration : 1; st->codec.frame_rate = VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale; #ifdef DEBUG
av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %VAR_4 (sd= %VAR_4)\n", st->codec.frame_rate, sample_duration); #endif
} #endif
} if(duration>0)
{ av_reduce(
&st->codec.frame_rate,
&st->codec.frame_rate_base,
VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale * total_sample_count,
duration,
INT_MAX
); #ifdef DEBUG
av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %VAR_4 ,tot dur= %VAR_4 timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale); #endif
} else
{ st->codec.frame_rate_base = 1; st->codec.frame_rate = VAR_0->streams[VAR_0->fc->nb_streams-1]->time_scale; } return 0; }