Shorten updates from Mark Arigo: calculate average bitrate, skip id3v2 tags and remove debugf definition from codec


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7840 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/codecs/libffmpegFLAC/shndec.c b/apps/codecs/libffmpegFLAC/shndec.c
index 7f5f5f4..6dde8f7 100644
--- a/apps/codecs/libffmpegFLAC/shndec.c
+++ b/apps/codecs/libffmpegFLAC/shndec.c
@@ -24,11 +24,6 @@
  *
  */
  
-#include "../codec.h"
-#include "../lib/codeclib.h"
-extern struct codec_api* ci;
-#define DEBUGF ci->debugf
-
 #include "bitstream.h"
 #include "golomb.h"
 #include "shndec.h"
diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c
index c646156..50d7299 100644
--- a/apps/codecs/shorten.c
+++ b/apps/codecs/shorten.c
@@ -78,6 +78,12 @@
     /* Shorten decoder initialization */
     ci->memset(&sc, 0, sizeof(ShortenContext));
 
+    /* Skip id3v2 tags */
+    if (ci->id3->first_frame_offset) {
+        buf = ci->request_buffer(&bytesleft, ci->id3->first_frame_offset);
+        ci->advance_buffer(ci->id3->first_frame_offset);
+    }
+
     /* Read the shorten & wave headers */
     buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
     res = shorten_init(&sc, buf, bytesleft);
@@ -86,9 +92,18 @@
         return CODEC_ERROR;
     }
 
-    ci->configure(DSP_SET_FREQUENCY, (long *)(sc.sample_rate));
     ci->id3->frequency = sc.sample_rate;
-    ci->id3->length = (sc.totalsamples / sc.sample_rate) * 1000;
+    ci->configure(DSP_SET_FREQUENCY, (long *)(sc.sample_rate));
+
+    if (sc.sample_rate) {
+        ci->id3->length = (sc.totalsamples / sc.sample_rate) * 1000;
+    } else {
+        ci->id3->length = 0;
+    }
+
+    if (ci->id3->length) {
+        ci->id3->bitrate = (ci->id3->filesize * 8) / ci->id3->length;
+    }
 
     consumed = sc.gb.index/8;
     ci->advance_buffer(consumed);
@@ -112,7 +127,7 @@
 
         /* Seek to start of track */
         if (ci->seek_time == 1) {
-            if (ci->seek_buffer(sc.header_bits/8)) {
+            if (ci->seek_buffer(sc.header_bits/8 + ci->id3->first_frame_offset)) {
                 sc.bitindex = sc.header_bits - 8*(sc.header_bits/8);
                 ci->set_elapsed(0);
                 ci->seek_complete();
diff --git a/apps/metadata.c b/apps/metadata.c
index d0557b1..5ed16e5 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -1520,6 +1520,16 @@
 
         break;
 
+    case AFMT_SHN:
+        track->id3.vbr = true;
+        track->id3.filesize = filesize(fd);
+        if (!skip_id3v2(fd, &(track->id3)))
+        {
+            return false;
+        }
+        /* TODO: read the id3v2 header if it exists */
+        break;
+
     /* If we don't know how to read the metadata, just store the filename */
     default:
         break;