From 60d06c0de7a3185e26e1254f364fbb10e301ceb2 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 2 Sep 2012 22:10:17 +0200 Subject: aac: fixed chapter support and track duration --- plugins/libmp4ff/mp4atom.c | 69 +++++++++++++++++++++++++++------------------ plugins/libmp4ff/mp4ff.c | 4 +++ plugins/libmp4ff/mp4ff.h | 2 ++ plugins/libmp4ff/mp4ffint.h | 8 ++++-- 4 files changed, 53 insertions(+), 30 deletions(-) (limited to 'plugins/libmp4ff') diff --git a/plugins/libmp4ff/mp4atom.c b/plugins/libmp4ff/mp4atom.c index 68454899..aa638c80 100644 --- a/plugins/libmp4ff/mp4atom.c +++ b/plugins/libmp4ff/mp4atom.c @@ -44,8 +44,8 @@ #include "mp4ffint.h" #include -#define trace(...) { fprintf(stderr, __VA_ARGS__); } -//#define trace(fmt,...) +//#define trace(...) { fprintf(stderr, __VA_ARGS__); } +#define trace(fmt,...) #define min(x,y) ((x)<(y)?(x):(y)) #define COPYRIGHT_SYMBOL ((int8_t)0xA9) @@ -845,6 +845,7 @@ int32_t mp4ff_atom_read(mp4ff_t *f, const int32_t size, const uint8_t atom_type) return 0; } +#if 0 int mp4ff_track_create_chunks_index(mp4ff_t *f, mp4ff_track_t *trk) { unsigned int i_chunk; @@ -859,18 +860,19 @@ int mp4ff_track_create_chunks_index(mp4ff_t *f, mp4ff_track_t *trk) return -1; } - int i_chunk_count = trk->stsc_entry_count; + trk->i_chunk_count = trk->stco_entry_count; - trk->chunk_sample_first = malloc (sizeof (int32_t) * i_chunk_count); - trk->chunk_first_dts = malloc (sizeof (int32_t) * i_chunk_count); - trk->chunk_last_dts = malloc (sizeof (int32_t) * i_chunk_count); - trk->p_sample_count_dts = malloc (sizeof (int32_t *) * i_chunk_count); - trk->p_sample_delta_dts = malloc (sizeof (int32_t *) * i_chunk_count); - trk->p_sample_count_pts = malloc (sizeof (int32_t *) * i_chunk_count); - trk->p_sample_offset_pts = malloc (sizeof (int32_t *) * i_chunk_count); + trace ("\033[0;31mchunk count %d\033[37;0m\n", trk->i_chunk_count); + trk->chunk_sample_first = malloc (sizeof (int32_t) * trk->i_chunk_count); + trk->chunk_first_dts = malloc (sizeof (int32_t) * trk->i_chunk_count); + trk->chunk_last_dts = malloc (sizeof (int32_t) * trk->i_chunk_count); + trk->p_sample_count_dts = malloc (sizeof (int32_t *) * trk->i_chunk_count); + trk->p_sample_delta_dts = malloc (sizeof (int32_t *) * trk->i_chunk_count); + trk->p_sample_count_pts = malloc (sizeof (int32_t *) * trk->i_chunk_count); + trk->p_sample_offset_pts = malloc (sizeof (int32_t *) * trk->i_chunk_count); /* first we read chunk offset */ - for( i_chunk = 0; i_chunk < i_chunk_count; i_chunk++ ) + for( i_chunk = 0; i_chunk < trk->i_chunk_count; i_chunk++ ) { // chunk.i_offset = stco_chunk_offset[i_chunk] trk->chunk_first_dts[i_chunk] = 0; @@ -883,7 +885,7 @@ int mp4ff_track_create_chunks_index(mp4ff_t *f, mp4ff_track_t *trk) /* now we read index for SampleEntry( soun vide mp4a mp4v ...) to be used for the sample XXX begin to 1 We construct it begining at the end */ - i_last = i_chunk_count; /* last chunk proceded */ + i_last = trk->i_chunk_count; /* last chunk proceded */ i_index = trk->stsc_entry_count; if( !i_index ) { @@ -891,14 +893,16 @@ int mp4ff_track_create_chunks_index(mp4ff_t *f, mp4ff_track_t *trk) return -1; } trk->chunk_sample_first[0] = 0; - for (int i = 1; i < trk->stts_entry_count; i++) + trace ("\033[0;35mchunk_sample_first[%d]=%d\033[37;0m\n", 0, trk->chunk_sample_first[0]); + for (int i = 1; i < trk->i_chunk_count; i++) { trk->chunk_sample_first[i] = trk->chunk_sample_first[i-1] + - trk->stts_sample_count[i-1]; + trk->stsc_samples_per_chunk[i-1]; + trace ("\033[0;35mchunk_sample_first[%d]=%d\033[37;0m\n", i, trk->chunk_sample_first[i]); } - trace ("track[Id 0x%x] read %d chunks\n", trk->id, i_chunk_count); + trace ("track[Id 0x%x] read %d chunks\n", trk->id, trk->i_chunk_count); return 0; } @@ -934,30 +938,35 @@ int mp4ff_track_create_samples_index (mp4ff_t *f, mp4ff_track_t *trk) i_next_dts = 0; i_index = 0; i_index_sample_used = 0; - for( i_chunk = 0; i_chunk < trk->stsc_entry_count; i_chunk++ ) + for( i_chunk = 0; i_chunk < trk->i_chunk_count; i_chunk++ ) { + trace ("calculating first/last dts for chunk %d\n", i_chunk); int64_t i_entry, i_sample_count, i; /* save first dts */ trk->chunk_first_dts[i_chunk] = i_next_dts; trk->chunk_last_dts[i_chunk] = i_next_dts; + trace ("init %lld\n", i_next_dts); /* count how many entries are needed for this chunk * for p_sample_delta_dts and p_sample_count_dts */ i_sample_count = trk->stsc_samples_per_chunk[i_chunk]; + trace ("init i_sample_count %d\n", i_sample_count); - trace ("calc i_entry for chunk %d\n", i_chunk); i_entry = 0; while( i_sample_count > 0 ) { - trace ("i_entry = %d, i_index = %d, i_sample_count = %d, i_sample_count - stts_sample_count[i_index+i_entry] = %d\n", i_entry, i_index, i_sample_count, i_sample_count - trk->stts_sample_count[i_index+i_entry]); i_sample_count -= trk->stts_sample_count[i_index+i_entry]; + trace ("- i_sample_count %d\n", i_sample_count); /* don't count already used sample in this entry */ - if( i_entry == 0 ) + if( i_entry == 0 ) { i_sample_count += i_index_sample_used; + trace ("+ i_sample_count %d\n", i_sample_count); + } i_entry++; } + trace ("+ i_entry %d\n", i_entry); /* allocate them */ trace ("alloc mem for chunk %d (%d entries, %d samples-per-chunk)\n", i_chunk, i_entry, trk->stsc_samples_per_chunk[i_chunk]); trk->p_sample_count_dts[i_chunk] = calloc( i_entry, sizeof( uint32_t ) ); @@ -1001,11 +1010,9 @@ int mp4ff_track_create_samples_index (mp4ff_t *f, mp4ff_track_t *trk) */ if (trk->ctts_entry_count) { - trace ("CTTS table\n"); - /* Create pts-dts table per chunk */ i_index = 0; i_index_sample_used = 0; - for( i_chunk = 0; i_chunk < trk->stsc_entry_count; i_chunk++ ) + for( i_chunk = 0; i_chunk < trk->i_chunk_count; i_chunk++ ) { int64_t i_entry, i_sample_count, i; @@ -1075,16 +1082,17 @@ int64_t mp4ff_get_track_dts (mp4ff_t *f, int t, int s) mp4ff_track_t *p_track = f->track[t]; // find chunk for the sample int i_chunk = 0; - for (i_chunk = 0; i_chunk < p_track->stts_entry_count; i_chunk++) { - if (p_track->chunk_sample_first[i_chunk] < s) { - fprintf (stderr, "chunk for sample %d: %d\n", s, i_chunk); + for (i_chunk = 0; i_chunk < p_track->i_chunk_count-1; i_chunk++) { + if (p_track->chunk_sample_first[i_chunk+1] > s) { break; } } +// trace ("i_chunk for sample %d: %d (out of %d)\n", s, i_chunk, p_track->i_chunk_count); unsigned int i_index = 0; unsigned int i_sample = s - p_track->chunk_sample_first[i_chunk]; int64_t i_dts = p_track->chunk_first_dts[i_chunk]; + trace ("start dts: %lld (i_sample: %d)\n", i_dts, i_sample); while( i_sample > 0 ) { @@ -1130,17 +1138,21 @@ int64_t mp4ff_get_track_dts (mp4ff_t *f, int t, int s) int64_t mp4ff_get_track_pts_delta(mp4ff_t *f, int t, int i_sample) { mp4ff_track_t *p_track = f->track[t]; + // find chunk for the sample int i_chunk = 0; - for (; i_chunk < p_track->stts_entry_count; i_chunk++) { - if (i_sample > p_track->chunk_sample_first[i_chunk]) { + for (i_chunk = 0; i_chunk < p_track->i_chunk_count-1; i_chunk++) { + if (p_track->chunk_sample_first[i_chunk+1] > i_sample) { break; } } +// trace ("i_chunk for sample %d: %d (out of %d)\n", i_sample, i_chunk, p_track->i_chunk_count); unsigned int i_index = 0; i_sample = i_sample - p_track->chunk_sample_first[i_chunk]; - if( p_track->p_sample_count_pts[i_chunk] == NULL || p_track->p_sample_offset_pts[i_chunk] == NULL ) + if( p_track->p_sample_count_pts[i_chunk] == NULL || p_track->p_sample_offset_pts[i_chunk] == NULL ) { + trace ("pts info not found :(\n"); return -1; + } for( i_index = 0;; i_index++ ) { @@ -1202,3 +1214,4 @@ int mp4ff_get_track_sample_size(mp4ff_t *f, int t, int s) return i_size; #endif } +#endif diff --git a/plugins/libmp4ff/mp4ff.c b/plugins/libmp4ff/mp4ff.c index 41e0b391..2b396ec0 100644 --- a/plugins/libmp4ff/mp4ff.c +++ b/plugins/libmp4ff/mp4ff.c @@ -63,6 +63,7 @@ mp4ff_t *mp4ff_open_read_metaonly(mp4ff_callback_t *f) } void mp4ff_track_free (mp4ff_track_t *trk) { +#if 0 if (trk->chunk_sample_first) { free (trk->chunk_sample_first); } @@ -96,6 +97,7 @@ void mp4ff_track_free (mp4ff_track_t *trk) { } free (trk->p_sample_offset_pts); } +#endif free (trk); } @@ -216,6 +218,7 @@ int32_t parse_sub_atoms(mp4ff_t *f, const uint64_t total_size,int meta_only) } else { mp4ff_atom_read(f, (uint32_t)size, atom_type); } +#if 0 if (atom_type == ATOM_TRAK) { trace ("mp4ff_track_create_chunks_index\n"); @@ -223,6 +226,7 @@ int32_t parse_sub_atoms(mp4ff_t *f, const uint64_t total_size,int meta_only) trace ("mp4ff_track_create_samples_index\n"); mp4ff_track_create_samples_index (f, f->track[f->total_tracks-1]); } +#endif } return 0; diff --git a/plugins/libmp4ff/mp4ff.h b/plugins/libmp4ff/mp4ff.h index 801bf6fe..b47bcb8e 100644 --- a/plugins/libmp4ff/mp4ff.h +++ b/plugins/libmp4ff/mp4ff.h @@ -107,9 +107,11 @@ int32_t mp4ff_chapters_get_num_items (mp4ff_t *f); const char *mp4ff_chapters_get_item (mp4ff_t *f, int i); int32_t mp4ff_chap_get_num_tracks (mp4ff_t *f); int32_t mp4ff_chap_get_track_id (mp4ff_t *f, int t); +#if 0 int64_t mp4ff_get_track_dts (mp4ff_t *f, int t, int s); int64_t mp4ff_get_track_pts_delta(mp4ff_t *f, int t, int s); int mp4ff_get_track_sample_size(mp4ff_t *f, int t, int s); +#endif int32_t mp4ff_meta_update(mp4ff_callback_t *f,const mp4ff_metadata_t * data); diff --git a/plugins/libmp4ff/mp4ffint.h b/plugins/libmp4ff/mp4ffint.h index 971ef9cc..e0d335b2 100644 --- a/plugins/libmp4ff/mp4ffint.h +++ b/plugins/libmp4ff/mp4ffint.h @@ -190,11 +190,13 @@ typedef struct int32_t *stts_sample_count; int32_t *stts_sample_delta; +#if 0 +// experimental support for indexing chunks samples based on VLC code /* chunk index generated in mp4ff_create_chunks_index */ - // i_chunk_count = stsc_entry_count // chunk->i_sample_count = stsc_samples_per_chunk[i_chunk] // chunk->i_sample_description_index = stsc_sample_desc_index[chunk] // trk->p_sample_size[i_sample] = stsz_sample_size ? stsz_sample_size : stsz_table[i_sample] + int32_t i_chunk_count; // stco_entry_count int32_t *chunk_sample_first; int32_t *chunk_first_dts; int32_t *chunk_last_dts; @@ -202,7 +204,7 @@ typedef struct int32_t **p_sample_delta_dts; int32_t **p_sample_count_pts; int32_t **p_sample_offset_pts; - +#endif /* stsc */ int32_t stsc_entry_count; int32_t *stsc_first_chunk; @@ -369,8 +371,10 @@ mp4ff_t *mp4ff_open_edit(mp4ff_callback_t *f); #endif void mp4ff_close(mp4ff_t *ff); //void mp4ff_track_add(mp4ff_t *f); +#if 0 int mp4ff_track_create_chunks_index(mp4ff_t *f, mp4ff_track_t *trk); int mp4ff_track_create_samples_index (mp4ff_t *f, mp4ff_track_t *trk); +#endif int32_t parse_sub_atoms(mp4ff_t *f, const uint64_t total_size,int meta_only); int32_t parse_atoms(mp4ff_t *f,int meta_only); -- cgit v1.2.3