]> granicus.if.org Git - taglib/commitdiff
Added FLAC::Properties::signature()
authorLukáš Lalinský <lalinsky@gmail.com>
Sun, 11 Jul 2010 10:26:35 +0000 (10:26 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Sun, 11 Jul 2010 10:26:35 +0000 (10:26 +0000)
BUG:160172

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1148630 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

NEWS
taglib/flac/flacproperties.cpp
taglib/flac/flacproperties.h
taglib/toolkit/tbytevector.cpp
taglib/toolkit/tbytevector.h
tests/test_bytevector.cpp
tests/test_flac.cpp

diff --git a/NEWS b/NEWS
index 102ecda354736e437b1de41d37746fb0981583cb..6ded56fa5090b05718491f6f34cfd95dfd79260c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ TagLib 1.7
  * Implemented APE::Tag::isEmpty() to check for all APE tags, not just the
    basic ones.
  * Added reading of WAV audio length. (BUG:116033)
+ * Exposed FLAC MD5 signature of the uncompressed audio stream via
+   FLAC::Properties::signature(). (BUG:160172)
+ * Added function ByteVector::toHex() for hex-encoding of byte vectors.
 
 TagLib 1.6.3 (Apr 17, 2010)
 ===========================
index f1370590b02c3e10eadf411b7ee2afb6d01fe247..ab5026efdc9066a553ae216a53f074d443c35f8a 100644 (file)
@@ -52,6 +52,7 @@ public:
   int sampleRate;
   int sampleWidth;
   int channels;
+  ByteVector signature;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -100,6 +101,11 @@ int FLAC::Properties::channels() const
   return d->channels;
 }
 
+ByteVector FLAC::Properties::signature() const
+{
+  return d->signature;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // private members
 ////////////////////////////////////////////////////////////////////////////////
@@ -147,4 +153,6 @@ void FLAC::Properties::read()
   // Real bitrate:
 
   d->bitrate = d->length > 0 ? ((d->streamLength * 8UL) / d->length) / 1000 : 0;
+
+  d->signature = d->data.mid(pos, 32);
 }
index 9ac676643a87d2d4e2835eddf9bad57018414dcf..64613a4ba8f4bccde808ed12cb0e28b23a3f9030 100644 (file)
@@ -77,6 +77,12 @@ namespace TagLib {
        */
       int sampleWidth() const;
 
+      /*!
+       * Returns the MD5 signature of the uncompressed audio stream as read
+          * from the stream info header header.
+       */
+      ByteVector signature() const;
+
     private:
       Properties(const Properties &);
       Properties &operator=(const Properties &);
index 766797764ab025c66c8ee6d1fc228bb7529ef67e..3545e8a93ff9a06aa2d54a60e210ec4979c659a2 100644 (file)
@@ -42,6 +42,8 @@
 #define DATA(x) (&(x->data[0]))
 
 namespace TagLib {
+  static const char hexTable[17] = "0123456789abcdef";
+
   static const uint crcTable[256] = {
     0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
     0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
@@ -653,6 +655,20 @@ ByteVector &ByteVector::operator=(const char *data)
   return *this;
 }
 
+ByteVector ByteVector::toHex() const
+{
+  ByteVector encoded(size() * 2);
+
+  uint j = 0;
+  for(uint i = 0; i < size(); i++) {
+    unsigned char c = d->data[i];
+    encoded[j++] = hexTable[(c >> 4) & 0x0F];
+    encoded[j++] = hexTable[(c     ) & 0x0F];
+  }
+
+  return encoded;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // protected members
 ////////////////////////////////////////////////////////////////////////////////
index 16d42e64ee4311633d84d5bd747feeae8da9cab2..3c997bf39f9b2b53677c252fac6f24aba960d1a5 100644 (file)
@@ -385,6 +385,11 @@ namespace TagLib {
      */
     static ByteVector null;
 
+    /*!
+        * Returns a hex-encoded copy of the byte vector.
+        */
+    ByteVector toHex() const;
+
   protected:
     /*
      * If this ByteVector is being shared via implicit sharing, do a deep copy
index f92fce01739a621627ea89a68701be3e839f46aa..6b4dae3cf8f63c8f4fae992e264a321267625ccd 100644 (file)
@@ -37,6 +37,7 @@ class TestByteVector : public CppUnit::TestFixture
   CPPUNIT_TEST(testFind2);
   CPPUNIT_TEST(testRfind1);
   CPPUNIT_TEST(testRfind2);
+  CPPUNIT_TEST(testToHex);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -173,6 +174,13 @@ public:
     CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS", 12));
   }
 
+  void testToHex()
+  {
+    ByteVector v("\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f", 16);
+
+    CPPUNIT_ASSERT_EQUAL(ByteVector("f0e1d2c3b4a5968778695a4b3c2d1e0f"), v.toHex());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVector);
index 0901c69f71a15b98b3bb8520eada7d21d2ad98ef..990299b2d2605f4669d294d0105fbbda3b89ede6 100644 (file)
@@ -13,11 +13,18 @@ using namespace TagLib;
 class TestFLAC : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE(TestFLAC);
+  CPPUNIT_TEST(testSignature);
   CPPUNIT_TEST(testMultipleCommentBlocks);
   CPPUNIT_TEST_SUITE_END();
 
 public:
 
+  void testSignature()
+  {
+    FLAC::File f("data/no-tags.flac");
+    CPPUNIT_ASSERT_EQUAL(ByteVector("a1b141f766e9849ac3db1030a20a3c77"), f.audioProperties()->signature().toHex());
+  }
+
   void testMultipleCommentBlocks()
   {
     ScopedFileCopy copy("multiple-vc", ".flac");