Revision c4ac052b

View differences:

libavformat/mov.c
232 232
    int64_t *chunk_offsets;
233 233
    int stts_count;
234 234
    Time2Sample *stts_data;
235
    int ctts_count;
236
    Time2Sample *ctts_data;
235 237
    int edit_count;             /* number of 'edit' (elst atom) */
236 238
    long sample_to_chunk_sz;
237 239
    MOV_sample_to_chunk_tbl *sample_to_chunk;
......
239 241
    int sample_to_time_index;	 
240 242
    long sample_to_time_sample;	 
241 243
    uint64_t sample_to_time_time;    
244
    int sample_to_ctime_index;
245
    int sample_to_ctime_sample;
242 246
    long sample_size;
243 247
    long sample_count;
244 248
    long *sample_sizes;
......
1338 1342
    return 0;
1339 1343
}
1340 1344

  
1345
static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1346
{
1347
//    AVStream *st = c->fc->streams[c->fc->nb_streams-1];
1348
    //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
1349
    unsigned int i, entries;
1350

  
1351
    print_atom("ctts", atom);
1352

  
1353
    get_byte(pb); /* version */
1354
    get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
1355
    entries = get_be32(pb);
1356
    if(entries >= UINT_MAX / sizeof(Time2Sample))
1357
        return -1;
1358

  
1359
    c->streams[c->fc->nb_streams-1]->ctts_count = entries;
1360
    c->streams[c->fc->nb_streams-1]->ctts_data = av_malloc(entries * sizeof(Time2Sample));
1361

  
1362
// #ifdef DEBUG
1363
av_log(NULL, AV_LOG_DEBUG, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
1364
// #endif
1365
    for(i=0; i<entries; i++) {
1366
        c->streams[c->fc->nb_streams - 1]->ctts_data[i].count= get_be32(pb);
1367
        c->streams[c->fc->nb_streams - 1]->ctts_data[i].duration= get_be32(pb);
1368
    }
1369
    return 0;
1370
}
1371

  
1341 1372
static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1342 1373
{
1343 1374
    AVStream *st;
......
1520 1551
{ MKTAG( 'c', 'o', '6', '4' ), mov_read_stco },
1521 1552
{ MKTAG( 'c', 'p', 'r', 't' ), mov_read_default },
1522 1553
{ MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default },
1523
{ MKTAG( 'c', 't', 't', 's' ), mov_read_leaf }, /* composition time to sample */
1554
{ MKTAG( 'c', 't', 't', 's' ), mov_read_ctts }, /* composition time to sample */
1524 1555
{ MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */
1525 1556
{ MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf },
1526 1557
{ MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf },
......
1597 1628
static void mov_free_stream_context(MOVStreamContext *sc)
1598 1629
{
1599 1630
    if(sc) {
1600
        av_free(sc->chunk_offsets);
1601
        av_free(sc->sample_to_chunk);
1602
        av_free(sc->sample_sizes);
1603
        av_free(sc->keyframes);
1604
        av_free(sc->header_data);
1605
        av_free(sc->stts_data);        
1606
        av_free(sc);
1631
        av_freep(&sc->chunk_offsets);
1632
        av_freep(&sc->sample_to_chunk);
1633
        av_freep(&sc->sample_sizes);
1634
        av_freep(&sc->keyframes);
1635
        av_freep(&sc->header_data);
1636
        av_freep(&sc->stts_data);        
1637
        av_freep(&sc->ctts_data);        
1638
        av_freep(&sc);
1607 1639
    }
1608 1640
}
1609 1641

  
......
1922 1954
    /* find the corresponding dts */	 
1923 1955
    if (sc && sc->sample_to_time_index < sc->stts_count && pkt) {	 
1924 1956
      unsigned int count;
1925
      uint64_t dts;
1957
      uint64_t dts, pts;
1926 1958
      unsigned int duration = sc->stts_data[sc->sample_to_time_index].duration;
1927 1959
      count = sc->stts_data[sc->sample_to_time_index].count;
1928 1960
      if ((sc->sample_to_time_sample + count) < sc->current_sample) {	 
......
1932 1964
        duration = sc->stts_data[sc->sample_to_time_index].duration;
1933 1965
      }	 
1934 1966
      dts = sc->sample_to_time_time + (sc->current_sample-1 - sc->sample_to_time_sample) * (int64_t)duration;
1935
      dts = av_rescale( dts, 	 
1936
                        (int64_t)s->streams[sc->ffindex]->time_base.den, 	 
1937
                        (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num );	 
1938
      pkt->dts = dts;
1939
      //do not set pts=dts because u think it might be equal!!!!!!!!
1940
#ifdef DEBUG 	 
1941
/*    av_log(NULL, AV_LOG_DEBUG, "stream #%d smp #%ld dts = %ld (smp:%ld time:%ld idx:%ld ent:%d count:%ld dur:%ld)\n"	 
1942
      , pkt->stream_index, sc->current_sample-1, (long)pkt->dts	 
1943
      , (long)sc->sample_to_time_sample	 
1944
      , (long)sc->sample_to_time_time	 
1945
      , (long)sc->sample_to_time_index	 
1946
      , (long)sc->stts_count	 
1947
      , count	 
1948
      , duration);*/	 
1949
#endif        	 
1950
    } 
1967
        /* find the corresponding pts */
1968
        if (sc->sample_to_ctime_index < sc->ctts_count) {
1969
            int duration = sc->ctts_data[sc->sample_to_ctime_index].duration;
1970
            int count = sc->ctts_data[sc->sample_to_ctime_index].count;
1971

  
1972
            if ((sc->sample_to_ctime_sample + count) < sc->current_sample) {
1973
                sc->sample_to_ctime_sample += count;
1974
                sc->sample_to_ctime_index ++;
1975
                duration = sc->ctts_data[sc->sample_to_ctime_index].duration;
1976
            }
1977
            pts = dts + duration;
1978
        }else
1979
            pts = dts;
1980
        pkt->pts = av_rescale( pts,
1981
                         (int64_t)s->streams[sc->ffindex]->time_base.den,
1982
                         (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num );
1983
        pkt->dts = av_rescale( dts,
1984
                         (int64_t)s->streams[sc->ffindex]->time_base.den,
1985
                         (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num );
1986
#ifdef DEBUG
1987
    av_log(NULL, AV_LOG_DEBUG, "stream #%d smp #%ld dts = %lld pts = %lld (smp:%ld time:%lld idx:%d ent:%d count:%d dur:%d)\n"
1988
      , pkt->stream_index, sc->current_sample-1, pkt->dts, pkt->pts
1989
      , sc->sample_to_time_sample
1990
      , sc->sample_to_time_time
1991
      , sc->sample_to_time_index
1992
      , sc->stts_count
1993
      , count
1994
      , duration);
1995
#endif
1996
    }
1951 1997

  
1952 1998
    return 0;
1953 1999
}
......
2160 2206
            }	 
2161 2207
            sample += count;	 
2162 2208
            start_time += count * duration;	 
2163
        }        
2209
        }
2210
        sample = 0;
2211
        for (msc->sample_to_ctime_index = 0; msc->sample_to_ctime_index < msc->ctts_count; msc->sample_to_ctime_index++) {
2212
            count = msc->ctts_data[msc->sample_to_ctime_index].count;
2213
            duration = msc->ctts_data[msc->sample_to_ctime_index].duration;
2214
            if ((sample + count - 1) > msc->current_sample) {
2215
                msc->sample_to_ctime_sample = sample;
2216
                break;
2217
            }
2218
            sample += count;
2219
        }       
2164 2220
#ifdef DEBUG        
2165 2221
        av_log(s, AV_LOG_DEBUG, "Next Sample for stream #%i is #%i @%i\n", i, msc->current_sample + 1, msc->sample_to_chunk_index + 1);
2166 2222
#endif        

Also available in: Unified diff