changeset 738:6ea974a229a8 trunk

[svn] - add read/write support for TLEN frame.
author yaz
date Tue, 27 Feb 2007 04:17:49 -0800
parents eecd54a11610
children 9480fdc511f1
files ChangeLog src/madplug/TODO src/madplug/decoder.c src/madplug/fileinfo.c src/madplug/input.c src/madplug/plugin.c
diffstat 6 files changed, 71 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Feb 27 03:45:34 2007 -0800
+++ b/ChangeLog	Tue Feb 27 04:17:49 2007 -0800
@@ -1,3 +1,11 @@
+2007-02-27 11:45:34 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [1572]
+  - use vfs_buffered_file_new_from_uri for probing.
+  
+  trunk/src/aac/src/libmp4.c |    4 +++-
+  1 file changed, 3 insertions(+), 1 deletion(-)
+
+
 2007-02-27 10:17:56 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [1570]
   - fix configure.ac lrintf check
--- a/src/madplug/TODO	Tue Feb 27 03:45:34 2007 -0800
+++ b/src/madplug/TODO	Tue Feb 27 04:17:49 2007 -0800
@@ -4,7 +4,7 @@
 X frame_name == ID3_FRAME_COMMENT code highly depends on address of strings. strcmp() is safer way.
 X replace copy right notices
 X import title override feature
-x import neno's configure dialog
+X import neno's configure dialog
 X bug fix: press F5 on not yet played stream hangs.
 - tidy up mad_info_t
 - remove pb_mutex ?
@@ -13,3 +13,4 @@
 - utf8 id3v1 writing ?? (it requires modification to libid3tag.)
 X complete tag deletion code
 - stream recording feature ??
+- simplify info/metadata functions
--- a/src/madplug/decoder.c	Tue Feb 27 03:45:34 2007 -0800
+++ b/src/madplug/decoder.c	Tue Feb 27 04:17:49 2007 -0800
@@ -256,7 +256,12 @@
             g_message("size = %d", stream.next_frame - stream.this_frame);
 #endif
 #endif
-            mad_timer_add(&info->duration, header.duration);
+            if(info->tuple->length == -1)
+                mad_timer_add(&info->duration, header.duration);
+            else {
+                info->duration.seconds = info->tuple->length / 1000;
+                info->duration.fraction = info->tuple->length % 1000;
+            }
             data_used += stream.next_frame - stream.this_frame;
             if (info->frames == 1) {
                 /* most of these *should* remain constant */
@@ -283,7 +288,12 @@
                         has_xing = TRUE;
                         info->vbr = TRUE;   /* otherwise xing header would have been 'Info' */
                         info->frames = info->xing.frames;
-                        mad_timer_multiply(&info->duration, info->frames);
+                        if(info->tuple->length == -1)
+                            mad_timer_multiply(&info->duration, info->frames);
+                        else {
+                            info->duration.seconds = info->tuple->length / 1000;
+                            info->duration.fraction = info->tuple->length % 1000;
+                        }
                         info->bitrate =
                             8.0 * info->xing.bytes /
                             mad_timer_count(info->duration,
@@ -313,9 +323,15 @@
             if (fast && info->frames >= N_AVERAGE_FRAMES) {
                 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES;
                 info->frames = (info->size - tagsize) / frame_size;
-                info->duration.seconds /= N_AVERAGE_FRAMES;
-                info->duration.fraction /= N_AVERAGE_FRAMES;
-                mad_timer_multiply(&info->duration, info->frames);
+                if(info->tuple->length == -1) {
+                    info->duration.seconds /= N_AVERAGE_FRAMES;
+                    info->duration.fraction /= N_AVERAGE_FRAMES;
+                    mad_timer_multiply(&info->duration, info->frames);
+                }
+                else {
+                    info->duration.seconds = info->tuple->length / 1000;
+                    info->duration.fraction = info->tuple->length % 1000;
+                }
 #ifdef DEBUG
                 g_message("using fast playtime calculation");
                 g_message("data used = %d [tagsize=%d framesize=%f]",
--- a/src/madplug/fileinfo.c	Tue Feb 27 03:45:34 2007 -0800
+++ b/src/madplug/fileinfo.c	Tue Feb 27 04:17:49 2007 -0800
@@ -201,6 +201,11 @@
     free(text);
     free(text2);
 
+    // update TLEN frame
+    text = g_strdup_printf("%ld", mad_timer_count(info.duration, MAD_UNITS_MILLISECONDS));
+    update_id3_frame(id3tag, "TLEN", text);
+    free(text);
+
     text = gtk_editable_get_chars(GTK_EDITABLE(comment_entry), 0, -1);
     text2 =
         g_convert(text, strlen(text), encoding, "UTF-8", NULL, NULL, NULL);
--- a/src/madplug/input.c	Tue Feb 27 03:45:34 2007 -0800
+++ b/src/madplug/input.c	Tue Feb 27 04:17:49 2007 -0800
@@ -388,6 +388,18 @@
         string = NULL;
     }
 
+    // length
+    title_input->length = -1;
+    string = input_id3_get_string(info->tag, "TLEN");
+    if (string) {
+        title_input->length = atoi(string);
+#ifdef DEBUG
+        printf("input_read_tag: TLEN = %d\n", title_input->length);
+#endif	
+        g_free(string);
+        string = NULL;
+    }
+
     title_input->file_name = g_strdup(g_basename(info->filename));
     title_input->file_path = g_path_get_dirname(info->filename);
     if ((string = strrchr(title_input->file_name, '.'))) {
@@ -408,13 +420,15 @@
 #ifdef DEBUG
     g_message("f: input_get_info: %s, fast_scan = %s", info->title, fast_scan ? "TRUE" : "FALSE");
 #endif                          /* DEBUG */
+
     input_read_tag(info);
     input_read_replaygain(info);
 
-    /* scan mp3 file, decoding headers unless fast_scan is set */
+    /* scan mp3 file, decoding headers */
     if (scan_file(info, fast_scan) == FALSE) {
         return FALSE;
     }
+
     /* reset the input file to the start */
     vfs_fseek(info->infile, 0, SEEK_SET);
     info->offset = 0;
--- a/src/madplug/plugin.c	Tue Feb 27 03:45:34 2007 -0800
+++ b/src/madplug/plugin.c	Tue Feb 27 04:17:49 2007 -0800
@@ -402,7 +402,10 @@
             *title = strdup(myinfo.tuple->track_name);
         else
             *title = strdup(url);
-        *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
+        if(myinfo.tuple->length == -1)
+            *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
+        else
+            *length = myinfo.tuple->length;
     }
     else {
         *title = strdup(url);
@@ -555,7 +558,17 @@
                 tuple->file_ext = extname(filename);
 
                 // length
-                {
+                tuple->length = -1;
+                string = input_id3_get_string(tag, "TLEN");
+                if (string) {
+                    tuple->length = atoi(string);
+#ifdef DEBUG
+                    printf("get_song_tuple: TLEN = %d\n", tuple->length);
+#endif	
+                    g_free(string);
+                    string = NULL;
+                }
+                else {
                     char *dummy = NULL;
                     int length = 0;
                     audmad_get_song_info(filename, &dummy, &length);
@@ -582,7 +595,7 @@
             }
             id3_file_close(id3file);
         }
-        else {
+        else { // no id3tag
             tuple->file_name = g_path_get_basename(filename);
             tuple->file_path = g_path_get_dirname(filename);
             tuple->file_ext = extname(filename);
@@ -590,8 +603,10 @@
             {
                 char *dummy = NULL;
                 int length = 0;
-                audmad_get_song_info(filename, &dummy, &length);
-                tuple->length = length;
+                if(tuple->length == -1) {
+                    audmad_get_song_info(filename, &dummy, &length);
+                    tuple->length = length;
+                }
                 g_free(dummy);
             }
         }