[mythtv] [PATCH] Mythmusic not finding track length for .flac files

Wendy Seltzer wendy at seltzer.com
Wed Dec 29 17:33:50 UTC 2004


At 11:15 AM 12/29/2004 +0000, Colin Guthrie wrote:
>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).

Thanks for the quick response Colin!  Works here.

--Wendy



>All the best.
>
>Col.
>
>--
>
>+------------------------+
>|     Colin Guthrie      |
>+------------------------+
>|   myth at colin.guthr.ie  |
>| 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 at mythtv.org
>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

--
Wendy Seltzer -- wendy at seltzer.com
Staff Attorney, Electronic Frontier Foundation
Fellow, Berkman Center for Internet & Society at Harvard Law School
http://wendy.seltzer.org/mythtv/
Chilling Effects: http://www.chillingeffects.org/



More information about the mythtv-dev mailing list