static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int ret;



    st = av_new_stream(c->fc, c->fc->nb_streams);

    if (!st) return AVERROR(ENOMEM);

    sc = av_mallocz(sizeof(MOVStreamContext));

    if (!sc) return AVERROR(ENOMEM);



    st->priv_data = sc;

    st->codec->codec_type = CODEC_TYPE_DATA;

    sc->ffindex = st->index;



    if ((ret = mov_read_default(c, pb, atom)) < 0)

        return ret;



    /* sanity checks */

    if(sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||

                           (!sc->sample_size && !sc->sample_count))){

        av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",

               st->index);

        sc->sample_count = 0; //ignore track

        return 0;

    }

    if(!sc->time_rate)

        sc->time_rate=1;

    if(!sc->time_scale)

        sc->time_scale= c->time_scale;

    av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);



    if (st->codec->codec_type == CODEC_TYPE_AUDIO &&

        !st->codec->frame_size && sc->stts_count == 1) {

        st->codec->frame_size = av_rescale(sc->stts_data[0].duration,

                                           st->codec->sample_rate, sc->time_scale);

        dprintf(c->fc, "frame size %d\n", st->codec->frame_size);

    }



    if(st->duration != AV_NOPTS_VALUE){

        assert(st->duration % sc->time_rate == 0);

        st->duration /= sc->time_rate;

    }



    mov_build_index(c, st);



    if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {

        if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)

            av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n",

                   st->index, sc->drefs[sc->dref_id-1].path, strerror(errno));

    } else

        sc->pb = c->fc->pb;



    switch (st->codec->codec_id) {

#if CONFIG_H261_DECODER

    case CODEC_ID_H261:

#endif

#if CONFIG_H263_DECODER

    case CODEC_ID_H263:

#endif

#if CONFIG_MPEG4_DECODER

    case CODEC_ID_MPEG4:

#endif

        st->codec->width= 0; /* let decoder init width/height */

        st->codec->height= 0;

        break;

    }



    /* Do not need those anymore. */

    av_freep(&sc->chunk_offsets);

    av_freep(&sc->stsc_data);

    av_freep(&sc->sample_sizes);

    av_freep(&sc->keyframes);

    av_freep(&sc->stts_data);



    return 0;

}

static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int ret;



    st = av_new_stream(c->fc, c->fc->nb_streams);

    if (!st) return AVERROR(ENOMEM);

    sc = av_mallocz(sizeof(MOVStreamContext));

    if (!sc) return AVERROR(ENOMEM);



    st->priv_data = sc;

    st->codec->codec_type = CODEC_TYPE_DATA;

    sc->ffindex = st->index;



    if ((ret = mov_read_default(c, pb, atom)) < 0)

        return ret;



    

    if(sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||

                           (!sc->sample_size && !sc->sample_count))){

        av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",

               st->index);

        sc->sample_count = 0; 

        return 0;

    }

    if(!sc->time_rate)

        sc->time_rate=1;

    if(!sc->time_scale)

        sc->time_scale= c->time_scale;

    av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);



    if (st->codec->codec_type == CODEC_TYPE_AUDIO &&

        !st->codec->frame_size && sc->stts_count == 1) {

        st->codec->frame_size = av_rescale(sc->stts_data[0].duration,

                                           st->codec->sample_rate, sc->time_scale);

        dprintf(c->fc, "frame size %d\n", st->codec->frame_size);

    }



    if(st->duration != AV_NOPTS_VALUE){

        assert(st->duration % sc->time_rate == 0);

        st->duration /= sc->time_rate;

    }



    mov_build_index(c, st);



    if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {

        if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)

            av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n",

                   st->index, sc->drefs[sc->dref_id-1].path, strerror(errno));

    } else

        sc->pb = c->fc->pb;



    switch (st->codec->codec_id) {

#if CONFIG_H261_DECODER

    case CODEC_ID_H261:

#endif

#if CONFIG_H263_DECODER

    case CODEC_ID_H263:

#endif

#if CONFIG_MPEG4_DECODER

    case CODEC_ID_MPEG4:

#endif

        st->codec->width= 0; 

        st->codec->height= 0;

        break;

    }



    

    av_freep(&sc->chunk_offsets);

    av_freep(&sc->stsc_data);

    av_freep(&sc->sample_sizes);

    av_freep(&sc->keyframes);

    av_freep(&sc->stts_data);



    return 0;

}

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

{

    AVStream *st;

    MOVStreamContext *sc;

    int VAR_3;



    st = av_new_stream(VAR_0->fc, VAR_0->fc->nb_streams);

    if (!st) return AVERROR(ENOMEM);

    sc = av_mallocz(sizeof(MOVStreamContext));

    if (!sc) return AVERROR(ENOMEM);



    st->priv_data = sc;

    st->codec->codec_type = CODEC_TYPE_DATA;

    sc->ffindex = st->index;



    if ((VAR_3 = mov_read_default(VAR_0, VAR_1, VAR_2)) < 0)

        return VAR_3;



    

    if(sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||

                           (!sc->sample_size && !sc->sample_count))){

        av_log(VAR_0->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",

               st->index);

        sc->sample_count = 0; 

        return 0;

    }

    if(!sc->time_rate)

        sc->time_rate=1;

    if(!sc->time_scale)

        sc->time_scale= VAR_0->time_scale;

    av_set_pts_info(st, 64, sc->time_rate, sc->time_scale);



    if (st->codec->codec_type == CODEC_TYPE_AUDIO &&

        !st->codec->frame_size && sc->stts_count == 1) {

        st->codec->frame_size = av_rescale(sc->stts_data[0].duration,

                                           st->codec->sample_rate, sc->time_scale);

        dprintf(VAR_0->fc, "frame size %d\n", st->codec->frame_size);

    }



    if(st->duration != AV_NOPTS_VALUE){

        assert(st->duration % sc->time_rate == 0);

        st->duration /= sc->time_rate;

    }



    mov_build_index(VAR_0, st);



    if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {

        if (url_fopen(&sc->VAR_1, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)

            av_log(VAR_0->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n",

                   st->index, sc->drefs[sc->dref_id-1].path, strerror(errno));

    } else

        sc->VAR_1 = VAR_0->fc->VAR_1;



    switch (st->codec->codec_id) {

#if CONFIG_H261_DECODER

    case CODEC_ID_H261:

#endif

#if CONFIG_H263_DECODER

    case CODEC_ID_H263:

#endif

#if CONFIG_MPEG4_DECODER

    case CODEC_ID_MPEG4:

#endif

        st->codec->width= 0; 

        st->codec->height= 0;

        break;

    }



    

    av_freep(&sc->chunk_offsets);

    av_freep(&sc->stsc_data);

    av_freep(&sc->sample_sizes);

    av_freep(&sc->keyframes);

    av_freep(&sc->stts_data);



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, ByteIOContext *VAR_1, MOVAtom VAR_2)
{ AVStream *st; MOVStreamContext *sc; int VAR_3; st = av_new_stream(VAR_0->fc, VAR_0->fc->nb_streams); if (!st) return AVERROR(ENOMEM); sc = av_mallocz(sizeof(MOVStreamContext)); if (!sc) return AVERROR(ENOMEM); st->priv_data = sc; st->codec->codec_type = CODEC_TYPE_DATA; sc->ffindex = st->index; if ((VAR_3 = mov_read_default(VAR_0, VAR_1, VAR_2)) < 0)
return VAR_3; if(sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||
(!sc->sample_size && !sc->sample_count))){ av_log(VAR_0->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",
st->index); sc->sample_count = 0; return 0; } if(!sc->time_rate)
sc->time_rate=1; if(!sc->time_scale)
sc->time_scale= VAR_0->time_scale; av_set_pts_info(st, 64, sc->time_rate, sc->time_scale); if (st->codec->codec_type == CODEC_TYPE_AUDIO &&
!st->codec->frame_size && sc->stts_count == 1) { st->codec->frame_size = av_rescale(sc->stts_data[0].duration,
st->codec->sample_rate, sc->time_scale); dprintf(VAR_0->fc, "frame size %d\n", st->codec->frame_size); } if(st->duration != AV_NOPTS_VALUE){ assert(st->duration % sc->time_rate == 0); st->duration /= sc->time_rate; } mov_build_index(VAR_0, st); if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { if (url_fopen(&sc->VAR_1, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0)
av_log(VAR_0->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n",
st->index, sc->drefs[sc->dref_id-1].path, strerror(errno)); } else sc->VAR_1 = VAR_0->fc->VAR_1; switch (st->codec->codec_id) { #if CONFIG_H261_DECODER
case CODEC_ID_H261:
#endif
#if CONFIG_H263_DECODER
case CODEC_ID_H263:
#endif
#if CONFIG_MPEG4_DECODER
case CODEC_ID_MPEG4:
#endif
st->codec->width= 0; st->codec->height= 0; break; } av_freep(&sc->chunk_offsets); av_freep(&sc->stsc_data); av_freep(&sc->sample_sizes); av_freep(&sc->keyframes); av_freep(&sc->stts_data); return 0; }