Revision 45a811b5

View differences:

libavformat/mov.c
2001 2001
    MOVFragment *frag = &c->fragment;
2002 2002
    AVStream *st = NULL;
2003 2003
    MOVStreamContext *sc;
2004
    MOVStts *ctts_data;
2004 2005
    uint64_t offset;
2005 2006
    int64_t dts;
2006 2007
    int data_offset = 0;
......
2024 2025
    flags = avio_rb24(pb);
2025 2026
    entries = avio_rb32(pb);
2026 2027
    av_dlog(c->fc, "flags 0x%x entries %d\n", flags, entries);
2027
    if (flags & 0x001) data_offset        = avio_rb32(pb);
2028
    if (flags & 0x004) first_sample_flags = avio_rb32(pb);
2029
    if (flags & 0x800) {
2030
        MOVStts *ctts_data;
2031
        if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
2032
            return -1;
2033
        ctts_data = av_realloc(sc->ctts_data,
2034
                               (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
2028

  
2029
    /* Always assume the presence of composition time offsets.
2030
     * Without this assumption, for instance, we cannot deal with a track in fragmented movies that meet the following.
2031
     *  1) in the initial movie, there are no samples.
2032
     *  2) in the first movie fragment, there is only one sample without composition time offset.
2033
     *  3) in the subsequent movie fragments, there are samples with composition time offset. */
2034
    if (!sc->ctts_count && sc->sample_count)
2035
    {
2036
        /* Complement ctts table if moov atom doesn't have ctts atom. */
2037
        ctts_data = av_malloc(sizeof(*sc->ctts_data));
2035 2038
        if (!ctts_data)
2036 2039
            return AVERROR(ENOMEM);
2037 2040
        sc->ctts_data = ctts_data;
2041
        sc->ctts_data[sc->ctts_count].count = sc->sample_count;
2042
        sc->ctts_data[sc->ctts_count].duration = 0;
2043
        sc->ctts_count++;
2038 2044
    }
2045
    if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
2046
        return -1;
2047
    ctts_data = av_realloc(sc->ctts_data,
2048
                           (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
2049
    if (!ctts_data)
2050
        return AVERROR(ENOMEM);
2051
    sc->ctts_data = ctts_data;
2052

  
2053
    if (flags & 0x001) data_offset        = avio_rb32(pb);
2054
    if (flags & 0x004) first_sample_flags = avio_rb32(pb);
2039 2055
    dts = st->duration;
2040 2056
    offset = frag->base_data_offset + data_offset;
2041 2057
    distance = 0;
......
2049 2065
        if (flags & 0x100) sample_duration = avio_rb32(pb);
2050 2066
        if (flags & 0x200) sample_size     = avio_rb32(pb);
2051 2067
        if (flags & 0x400) sample_flags    = avio_rb32(pb);
2052
        if (flags & 0x800) {
2053
            sc->ctts_data[sc->ctts_count].count = 1;
2054
            sc->ctts_data[sc->ctts_count].duration = avio_rb32(pb);
2055
            sc->ctts_count++;
2056
        }
2068
        sc->ctts_data[sc->ctts_count].count = 1;
2069
        sc->ctts_data[sc->ctts_count].duration = (flags & 0x800) ? avio_rb32(pb) : 0;
2070
        sc->ctts_count++;
2057 2071
        if ((keyframe = st->codec->codec_type == AVMEDIA_TYPE_AUDIO ||
2058 2072
             (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000))
2059 2073
            distance = 0;

Also available in: Unified diff