Wendy Seltzer wrote:
I think I've tracked down the problem here but don't have the C++ know-how to fix it:
Reading the track length of flac files appears to have broken in the big Nov. 26 mythmusic patch. A rollback to CVS from Nov. 25 reads track lengths again (and once they're in the db, they stay there). It looks as though some of the code didn't make it from flacdecoder.cpp into metaioflacvorbiscomment.cpp

Bang on Wendy!

I'd not really noticed the FLAC decoders correct identification of track length and thought it hadn't been implemented, but it's all there.

A simple comment out of a line just before the Metadata constructor would have actually fixed it, but here is a more complete patch that sticks to the structure laid down by the metio base class. Not sure if it'll be needed in the future in this way, but it's probably wise to stick to it just in case.

Having recently upgraded my flac libraries, I had to add in a
#define HAVE_INTTYPES_H to the files that included <FLAC/*.h> for this to compile.


I don't think it will get in the way of the older implementation, but there may be a more correct way fo defining the 64 bit compatibility layer.... (I know very little about this!).

The attached patch contains both the length fix and the insertion of these #defines into three files. Feel free not to apply the #define bits if it's not appropriate (should be trivial to strip out of the patch).

All the best.

Col.

--

+------------------------+
|     Colin Guthrie      |
+------------------------+
|   [EMAIL PROTECTED]  |
| http://colin.guthr.ie/ |
+------------------------+
? flac_compile_fix_length_fix.diff
? make_patch.sh
? metadata.diff.bz2
? test.tar.bz2
? mythmusic/docs
? mythmusic/fix.diff
? mythmusic/kak
? mythmusic/mythmusic.diff
? mythmusic/test
Index: mythmusic/flacdecoder.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/flacdecoder.h,v
retrieving revision 1.6
diff -u -b -B -w -p -r1.6 flacdecoder.h
--- mythmusic/flacdecoder.h	26 Nov 2004 00:13:04 -0000	1.6
+++ mythmusic/flacdecoder.h	29 Dec 2004 11:09:15 -0000
@@ -1,6 +1,7 @@
 #ifndef FLACDECODER_H_
 #define FLACDECODER_H_
 
+#define HAVE_INTTYPES_H
 #include <FLAC/all.h>
 
 #include "decoder.h"
Index: mythmusic/flacencoder.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/flacencoder.h,v
retrieving revision 1.6
diff -u -b -B -w -p -r1.6 flacencoder.h
--- mythmusic/flacencoder.h	26 Nov 2004 00:13:04 -0000	1.6
+++ mythmusic/flacencoder.h	29 Dec 2004 11:09:15 -0000
@@ -3,6 +3,7 @@
 
 #include <qstring.h>
 
+#define HAVE_INTTYPES_H
 #include <FLAC/file_encoder.h>
 
 #include "encoder.h"
Index: mythmusic/metaioflacvorbiscomment.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/metaioflacvorbiscomment.cpp,v
retrieving revision 1.1
diff -u -b -B -w -p -r1.1 metaioflacvorbiscomment.cpp
--- mythmusic/metaioflacvorbiscomment.cpp	26 Nov 2004 09:00:36 -0000	1.1
+++ mythmusic/metaioflacvorbiscomment.cpp	29 Dec 2004 11:09:16 -0000
@@ -139,11 +139,7 @@ Metadata* MetaIOFLACVorbisComment::read(
     FLAC__ASSERT(0 != block);
     FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
 
-    int samplerate = block->data.stream_info.sample_rate;
-    int totalsamples = block->data.stream_info.total_samples;
-    int bytesperms = (samplerate) / 1000;
-
-    length = totalsamples / bytesperms;
+    length = getTrackLength(block);
 
     do {
         block = FLAC__metadata_iterator_get_block(iterator);
@@ -179,8 +175,6 @@ Metadata* MetaIOFLACVorbisComment::read(
     FLAC__metadata_chain_delete(chain);
     FLAC__metadata_iterator_delete(iterator);
 
-    length = getTrackLength(filename);
-
     Metadata *retdata = new Metadata(filename, artist, album, title, genre,
                                      year, tracknum, length);
 
@@ -192,15 +186,59 @@ Metadata* MetaIOFLACVorbisComment::read(
 /*!
  * \brief Find the length of the track (in seconds)
  *
+ * \note This isn't used at present, but may be desired for public access
+ *       at somepoint in the future.
+ *
  * \param filename The filename for which we want to find the length.
  * \returns An integer (signed!) to represent the length in seconds.
  */
 int MetaIOFLACVorbisComment::getTrackLength(QString filename)
 {
-    filename=filename; // -Wall annoyance
+    FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
+    if (!FLAC__metadata_chain_read(chain, filename.local8Bit())
+        || !FLAC__metadata_chain_read(chain, filename.ascii()))
+    {
+        FLAC__metadata_chain_delete(chain); 
     return 0;
 }
 
+    FLAC__StreamMetadata *block = 0;
+    FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
+    
+    FLAC__metadata_iterator_init(iterator, chain);
+
+    block = FLAC__metadata_iterator_get_block(iterator);
+
+    FLAC__ASSERT(0 != block);
+    FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
+
+    int length = getTrackLength(block);
+
+    FLAC__metadata_chain_delete(chain);
+    FLAC__metadata_iterator_delete(iterator);
+
+    return length;
+}
+
+
+//==========================================================================
+/*!
+ * \brief Find the length of the track (in seconds)
+ *
+ * \note The FLAC StreamMetadata block must be asserted FLAC__METADATA_TYPE_STREAMINFO
+ *
+ * \param pBlock Pointer to a FLAC Metadata block 
+ * \returns An integer (signed!) to represent the length in seconds.
+ */
+inline int MetaIOFLACVorbisComment::getTrackLength(FLAC__StreamMetadata* pBlock)
+{
+    if (!pBlock)
+        return 0;
+
+    return pBlock->data.stream_info.total_samples / 
+        (pBlock->data.stream_info.sample_rate / 1000);
+}
+
 
 //==========================================================================
 /*!
Index: mythmusic/metaioflacvorbiscomment.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/metaioflacvorbiscomment.h,v
retrieving revision 1.1
diff -u -b -B -w -p -r1.1 metaioflacvorbiscomment.h
--- mythmusic/metaioflacvorbiscomment.h	26 Nov 2004 09:00:36 -0000	1.1
+++ mythmusic/metaioflacvorbiscomment.h	29 Dec 2004 11:09:16 -0000
@@ -3,9 +3,8 @@
 
 #include "metaio.h"
 
+#define HAVE_INTTYPES_H
 #include <FLAC/all.h>
-// No need to include all the Flac stuff just for the abstract pointer....
-//class FLAC__StreamMetadata;
 
 class MetaIOFLACVorbisComment : public MetaIO
 {
@@ -18,6 +17,7 @@ public:
     
 private:
     int getTrackLength(QString filename);
+    int getTrackLength(FLAC__StreamMetadata* pBlock);
 
     QString getComment(FLAC__StreamMetadata* pBlock, const char* pLabel);
     void setComment(FLAC__StreamMetadata* pBlock, const char* pLabel,
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

Reply via email to