Mercurial > libavformat.hg
comparison mov.c @ 670:856b151f926a libavformat
cleanup
author | michael |
---|---|
date | Mon, 07 Feb 2005 13:50:39 +0000 |
parents | 758929a1744c |
children | 19ae6e841a32 |
comparison
equal
deleted
inserted
replaced
669:ed7ed3588399 | 670:856b151f926a |
---|---|
217 uint8_t *sl_config; | 217 uint8_t *sl_config; |
218 } MOV_esds_t; | 218 } MOV_esds_t; |
219 | 219 |
220 struct MOVParseTableEntry; | 220 struct MOVParseTableEntry; |
221 | 221 |
222 typedef struct Time2Sample{ | |
223 int count; | |
224 int duration; | |
225 }Time2Sample; | |
226 | |
222 typedef struct MOVStreamContext { | 227 typedef struct MOVStreamContext { |
223 int ffindex; /* the ffmpeg stream id */ | 228 int ffindex; /* the ffmpeg stream id */ |
224 int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */ | 229 int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */ |
225 long next_chunk; | 230 long next_chunk; |
226 long chunk_count; | 231 long chunk_count; |
227 int64_t *chunk_offsets; | 232 int64_t *chunk_offsets; |
228 int32_t stts_count; | 233 int stts_count; |
229 uint64_t *stts_data; /* concatenated data from the time-to-sample atom (count|duration) */ | 234 Time2Sample *stts_data; |
230 int32_t edit_count; /* number of 'edit' (elst atom) */ | 235 int edit_count; /* number of 'edit' (elst atom) */ |
231 long sample_to_chunk_sz; | 236 long sample_to_chunk_sz; |
232 MOV_sample_to_chunk_tbl *sample_to_chunk; | 237 MOV_sample_to_chunk_tbl *sample_to_chunk; |
233 long sample_to_chunk_index; | 238 long sample_to_chunk_index; |
234 int sample_to_time_index; | 239 int sample_to_time_index; |
235 long sample_to_time_sample; | 240 long sample_to_time_sample; |
1273 print_atom("stts", atom); | 1278 print_atom("stts", atom); |
1274 | 1279 |
1275 get_byte(pb); /* version */ | 1280 get_byte(pb); /* version */ |
1276 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | 1281 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
1277 entries = get_be32(pb); | 1282 entries = get_be32(pb); |
1278 if(entries >= UINT_MAX / sizeof(uint64_t)) | 1283 if(entries >= UINT_MAX / sizeof(Time2Sample)) |
1279 return -1; | 1284 return -1; |
1280 | 1285 |
1281 c->streams[c->fc->nb_streams-1]->stts_count = entries; | 1286 c->streams[c->fc->nb_streams-1]->stts_count = entries; |
1282 c->streams[c->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(entries * sizeof(uint64_t)); | 1287 c->streams[c->fc->nb_streams-1]->stts_data = av_malloc(entries * sizeof(Time2Sample)); |
1283 | 1288 |
1284 #ifdef DEBUG | 1289 #ifdef DEBUG |
1285 av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); | 1290 av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); |
1286 #endif | 1291 #endif |
1287 for(i=0; i<entries; i++) { | 1292 for(i=0; i<entries; i++) { |
1288 int32_t sample_duration; | 1293 int sample_duration; |
1289 int32_t sample_count; | 1294 int sample_count; |
1290 | 1295 |
1291 sample_count=get_be32(pb); | 1296 sample_count=get_be32(pb); |
1292 sample_duration = get_be32(pb); | 1297 sample_duration = get_be32(pb); |
1293 c->streams[c->fc->nb_streams - 1]->stts_data[i] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration; | 1298 c->streams[c->fc->nb_streams - 1]->stts_data[i].count= sample_count; |
1299 c->streams[c->fc->nb_streams - 1]->stts_data[i].duration= sample_duration; | |
1294 #ifdef DEBUG | 1300 #ifdef DEBUG |
1295 av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); | 1301 av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); |
1296 #endif | 1302 #endif |
1297 duration+=sample_duration*sample_count; | 1303 duration+=sample_duration*sample_count; |
1298 total_sample_count+=sample_count; | 1304 total_sample_count+=sample_count; |
1913 | 1919 |
1914 mov->next_chunk_offset = offset + size; | 1920 mov->next_chunk_offset = offset + size; |
1915 | 1921 |
1916 /* find the corresponding dts */ | 1922 /* find the corresponding dts */ |
1917 if (sc && sc->sample_to_time_index < sc->stts_count && pkt) { | 1923 if (sc && sc->sample_to_time_index < sc->stts_count && pkt) { |
1918 uint32_t count; | 1924 unsigned int count; |
1919 uint64_t dts; | 1925 uint64_t dts; |
1920 uint32_t duration = (uint32_t)(sc->stts_data[sc->sample_to_time_index]&0xffff); | 1926 unsigned int duration = sc->stts_data[sc->sample_to_time_index].duration; |
1921 count = (uint32_t)(sc->stts_data[sc->sample_to_time_index]>>32); | 1927 count = sc->stts_data[sc->sample_to_time_index].count; |
1922 if ((sc->sample_to_time_sample + count) < sc->current_sample) { | 1928 if ((sc->sample_to_time_sample + count) < sc->current_sample) { |
1923 sc->sample_to_time_sample += count; | 1929 sc->sample_to_time_sample += count; |
1924 sc->sample_to_time_time += count*duration; | 1930 sc->sample_to_time_time += count*duration; |
1925 sc->sample_to_time_index ++; | 1931 sc->sample_to_time_index ++; |
1926 duration = (uint32_t)(sc->stts_data[sc->sample_to_time_index]&0xffff); | 1932 duration = sc->stts_data[sc->sample_to_time_index].duration; |
1927 } | 1933 } |
1928 dts = sc->sample_to_time_time + (sc->current_sample-1 - sc->sample_to_time_sample) * duration; | 1934 dts = sc->sample_to_time_time + (sc->current_sample-1 - sc->sample_to_time_sample) * (int64_t)duration; |
1929 dts = av_rescale( dts, | 1935 dts = av_rescale( dts, |
1930 (int64_t)s->streams[sc->ffindex]->time_base.den, | 1936 (int64_t)s->streams[sc->ffindex]->time_base.den, |
1931 (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num ); | 1937 (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num ); |
1932 pkt->dts = dts; | 1938 pkt->dts = dts; |
1933 // audio pts = dts, true for video only in low_latency mode (FIXME a good way to know if we are in a low latency stream ?) | 1939 //do not set pts=dts because u think it might be equal!!!!!!!! |
1934 if (s->streams[sc->ffindex]->codec.codec_type == CODEC_TYPE_AUDIO) | |
1935 pkt->pts = dts; | |
1936 else | |
1937 pkt->pts = AV_NOPTS_VALUE; | |
1938 #ifdef DEBUG | 1940 #ifdef DEBUG |
1939 /* 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" | 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" |
1940 , pkt->stream_index, sc->current_sample-1, (long)pkt->dts | 1942 , pkt->stream_index, sc->current_sample-1, (long)pkt->dts |
1941 , (long)sc->sample_to_time_sample | 1943 , (long)sc->sample_to_time_sample |
1942 , (long)sc->sample_to_time_time | 1944 , (long)sc->sample_to_time_time |
2004 sample = 1; // sample are 0 based in table | 2006 sample = 1; // sample are 0 based in table |
2005 #ifdef DEBUG | 2007 #ifdef DEBUG |
2006 av_log(s, AV_LOG_DEBUG, "Searching for sample_time %li \n", (long)sample_time); | 2008 av_log(s, AV_LOG_DEBUG, "Searching for sample_time %li \n", (long)sample_time); |
2007 #endif | 2009 #endif |
2008 for (i = 0; i < sc->stts_count; i++) { | 2010 for (i = 0; i < sc->stts_count; i++) { |
2009 count = (uint32_t)(sc->stts_data[i]>>32); | 2011 count = sc->stts_data[i].count; |
2010 duration = (uint32_t)(sc->stts_data[i]&0xffff); | 2012 duration = sc->stts_data[i].duration; |
2011 //av_log(s, AV_LOG_DEBUG, "> sample_time %lli \n", (long)sample_time); | 2013 //av_log(s, AV_LOG_DEBUG, "> sample_time %lli \n", (long)sample_time); |
2012 //av_log(s, AV_LOG_DEBUG, "> count=%i duration=%i\n", count, duration); | 2014 //av_log(s, AV_LOG_DEBUG, "> count=%i duration=%i\n", count, duration); |
2013 if ((start_time + count*duration) > sample_time) { | 2015 if ((start_time + count*duration) > sample_time) { |
2014 sample_to_time_time = start_time; | 2016 sample_to_time_time = start_time; |
2015 sample_to_time_index = i; | 2017 sample_to_time_index = i; |
2147 msc->left_in_chunk = msc->sample_to_chunk[msc->sample_to_chunk_index].count - 1; | 2149 msc->left_in_chunk = msc->sample_to_chunk[msc->sample_to_chunk_index].count - 1; |
2148 // Find corresponding position in stts (used later to compute dts) | 2150 // Find corresponding position in stts (used later to compute dts) |
2149 sample = 0; | 2151 sample = 0; |
2150 start_time = 0; | 2152 start_time = 0; |
2151 for (msc->sample_to_time_index = 0; msc->sample_to_time_index < msc->stts_count; msc->sample_to_time_index++) { | 2153 for (msc->sample_to_time_index = 0; msc->sample_to_time_index < msc->stts_count; msc->sample_to_time_index++) { |
2152 count = (uint32_t)(msc->stts_data[msc->sample_to_time_index]>>32); | 2154 count = msc->stts_data[msc->sample_to_time_index].count; |
2153 duration = (uint32_t)(msc->stts_data[msc->sample_to_time_index]&0xffff); | 2155 duration = msc->stts_data[msc->sample_to_time_index].duration; |
2154 if ((sample + count - 1) > msc->current_sample) { | 2156 if ((sample + count - 1) > msc->current_sample) { |
2155 msc->sample_to_time_time = start_time; | 2157 msc->sample_to_time_time = start_time; |
2156 msc->sample_to_time_sample = sample; | 2158 msc->sample_to_time_sample = sample; |
2157 break; | 2159 break; |
2158 } | 2160 } |