summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/aac/aac.c64
-rw-r--r--plugins/libmp4ff/mp4atom.c69
-rw-r--r--plugins/libmp4ff/mp4ff.c4
-rw-r--r--plugins/libmp4ff/mp4ff.h2
-rw-r--r--plugins/libmp4ff/mp4ffint.h8
5 files changed, 86 insertions, 61 deletions
diff --git a/plugins/aac/aac.c b/plugins/aac/aac.c
index ae575c8f..c59d3e24 100644
--- a/plugins/aac/aac.c
+++ b/plugins/aac/aac.c
@@ -222,7 +222,7 @@ parse_aac_stream(DB_FILE *fp, int *psamplerate, int *pchannels, float *pduration
}
static int
-mp4_track_get_info(mp4ff_t *mp4, int track, float *duration, int *samplerate, int *channels, int *totalsamples) {
+mp4_track_get_info(mp4ff_t *mp4, int track, float *duration, int *samplerate, int *channels, int *totalsamples, int *mp4framesize) {
int sr = -1;
unsigned char* buff = 0;
unsigned int buff_size = 0;
@@ -251,22 +251,23 @@ mp4_track_get_info(mp4ff_t *mp4, int track, float *duration, int *samplerate, in
*samplerate = srate;
*channels = ch;
samples = (int64_t)mp4ff_num_samples(mp4, track);
- NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration (dec);
- conf->dontUpSampleImplicitSBR = 1;
- NeAACDecSetConfiguration (dec, conf);
- int mp4framesize = mp4ASC.frameLengthFlag == 1 ? 960 : 1024;
- if (mp4ASC.sbr_present_flag == 1) {
- mp4framesize *= 2;
- }
- samples *= mp4framesize;
-
- *duration = (float)samples / (*samplerate);
NeAACDecClose (dec);
+ int i_sample_count = mp4ff_num_samples (mp4, track);
+ int i_sample;
+
+ int64_t total_dur = 0;
+ for( i_sample = 0; i_sample < i_sample_count; i_sample++ )
+ {
+ total_dur += mp4ff_get_sample_duration (mp4, track, i_sample);
+ }
if (totalsamples) {
- *totalsamples = samples;
+ *totalsamples = total_dur * (*samplerate) / mp4ff_time_scale (mp4, track);
+ *mp4framesize = (*totalsamples) / i_sample;
}
+ *duration = total_dur / (float)mp4ff_time_scale (mp4, track);
+
return 0;
error:
if (dec) {
@@ -336,7 +337,7 @@ aac_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
if (mp4ff_get_track_type (info->mp4, i) != TRACK_AUDIO) {
continue;
}
- int res = mp4_track_get_info (info->mp4, i, &duration, &samplerate, &channels, &totalsamples);
+ int res = mp4_track_get_info (info->mp4, i, &duration, &samplerate, &channels, &totalsamples, &info->mp4framesize);
if (res >= 0 && duration > 0) {
info->mp4track = i;
break;
@@ -345,7 +346,7 @@ aac_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
trace ("track: %d\n", info->mp4track);
if (info->mp4track >= 0) {
// prepare decoder
- int res = mp4_track_get_info (info->mp4, info->mp4track, &duration, &samplerate, &channels, &totalsamples);
+ int res = mp4_track_get_info (info->mp4, info->mp4track, &duration, &samplerate, &channels, &totalsamples, &info->mp4framesize);
if (res != 0) {
trace ("aac: mp4_track_get_info(%d) returned error\n", info->mp4track);
return -1;
@@ -360,26 +361,11 @@ aac_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
unsigned int buff_size = 0;
mp4AudioSpecificConfig mp4ASC;
mp4ff_get_decoder_config (info->mp4, info->mp4track, &buff, &buff_size);
- if(buff) {
- int rc = AudioSpecificConfig(buff, buff_size, &mp4ASC);
- if(rc < 0) {
- free (buff);
- return -1;
- }
- }
-
if (NeAACDecInit2(info->dec, buff, buff_size, &srate, &ch) < 0) {
trace ("NeAACDecInit2 returned error\n");
free (buff);
return -1;
}
- if (NeAACDecAudioSpecificConfig(buff, buff_size, &mp4ASC) < 0) {
- return -1;
- }
- info->mp4framesize = mp4ASC.frameLengthFlag == 1 ? 960 : 1024;
- if (mp4ASC.sbr_present_flag == 1) {
- info->mp4framesize *= 2;
- }
if (buff) {
free (buff);
@@ -974,9 +960,24 @@ aac_load_itunes_chapters (mp4ff_t *mp4, /* out */ int *num_chapters, int sampler
int64_t curr_sample = 0;
for( i_sample = 0; i_sample < i_sample_count; i_sample++ )
{
+#if 0
+ const int64_t i_dts = mp4ff_get_track_dts (mp4, j, i_sample);
+ const int64_t i_pts_delta = mp4ff_get_track_pts_delta(mp4, j, i_sample);
+ trace ("i_dts = %lld, i_pts_delta = %lld\n", i_dts, i_pts_delta);
+ const unsigned int i_size = mp4ff_get_track_sample_size(mp4, j, i_sample);
+ if (i_size <= 0) {
+ continue;
+ }
+
+ int64_t i_time_offset = i_dts + max (i_pts_delta, 0);
+#endif
int32_t dur = (int64_t)1000 * mp4ff_get_sample_duration (mp4, j, i_sample) / mp4ff_time_scale (mp4, j); // milliseconds
total_dur += dur;
- trace ("dur: %d (%f min)\n", dur, dur / 1000.f / 60.f);
+#if 0
+ trace ("dur: %d %f min // offs: %lld %f (from currsample: %f)\n", dur, dur / 1000.f / 60.f, i_time_offset, i_time_offset / 1000000.f / 60.f, curr_sample * 1000.f/ samplerate);
+#else
+ trace ("dur: %d %f min\n", dur, dur / 1000.f / 60.f);
+#endif
unsigned char *buffer = NULL;
int buffer_size = 0;
@@ -1117,7 +1118,8 @@ aac_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
if (mp4ff_get_track_type (mp4, i) != TRACK_AUDIO) {
continue;
}
- int res = mp4_track_get_info (mp4, i, &duration, &samplerate, &channels, &totalsamples);
+ int mp4framesize;
+ int res = mp4_track_get_info (mp4, i, &duration, &samplerate, &channels, &totalsamples, &mp4framesize);
if (res >= 0 && duration > 0) {
trace ("aac: found audio track %d (duration=%f, totalsamples=%d)\n", i, duration, totalsamples);
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 <stdio.h>
-#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);