]> granicus.if.org Git - taglib/commitdiff
Added TagLib::MP4::PropertyMap::codec()
authorLukáš Lalinský <lukas@oxygene.sk>
Tue, 8 Oct 2013 15:41:09 +0000 (17:41 +0200)
committerLukáš Lalinský <lukas@oxygene.sk>
Tue, 8 Oct 2013 15:41:09 +0000 (17:41 +0200)
NEWS
taglib/mp4/mp4properties.cpp
taglib/mp4/mp4properties.h
tests/test_mp4.cpp

diff --git a/NEWS b/NEWS
index 6f34d8c416ed80d3525494b57ce09aef4a861b74..72d41fbab1b766f0953f36f2e13777b6f1856ffd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ TagLib 1.9.1 (Oct 8, 2013)
  * Fixed constructing String from ByteVector.
  * Fixed compilation on MSVC with the /Zc:wchar_t- option.
  * Fixed detecting of RIFF files with invalid chunk sizes.
+ * Added TagLib::MP4::PropertyMap::codec().
 
 TagLib 1.9 (Oct 6, 2013)
 ========================
index 058cc61cf51ffe7c1f478f92ae47861e81a5374d..5a41c0814ec8c62aa080f6c3221059cfb6d73be2 100644 (file)
@@ -34,7 +34,7 @@ using namespace TagLib;
 class MP4::Properties::PropertiesPrivate
 {
 public:
-  PropertiesPrivate() : length(0), bitrate(0), sampleRate(0), channels(0), bitsPerSample(0), encrypted(false) {}
+  PropertiesPrivate() : length(0), bitrate(0), sampleRate(0), channels(0), bitsPerSample(0), encrypted(false), codec(MP4::Properties::Unknown) {}
 
   int length;
   int bitrate;
@@ -42,6 +42,7 @@ public:
   int channels;
   int bitsPerSample;
   bool encrypted;
+  Codec codec;
 };
 
 MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
@@ -114,6 +115,7 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
   file->seek(atom->offset);
   data = file->readBlock(atom->length);
   if(data.mid(20, 4) == "mp4a") {
+    d->codec         = AAC;
     d->channels      = data.toShort(40U);
     d->bitsPerSample = data.toShort(42U);
     d->sampleRate    = data.toUInt(46U);
@@ -135,10 +137,11 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
   }
   else if (data.mid(20, 4) == "alac") {
     if (atom->length == 88 && data.mid(56, 4) == "alac") {
+      d->codec         = ALAC;
       d->bitsPerSample = data.at(69);
-      d->channels   = data.at(73);
-      d->bitrate    = data.toUInt(80U) / 1000;
-      d->sampleRate = data.toUInt(84U);
+      d->channels      = data.at(73);
+      d->bitrate       = data.toUInt(80U) / 1000;
+      d->sampleRate    = data.toUInt(84U);
     }
   }
 
@@ -189,3 +192,8 @@ MP4::Properties::isEncrypted() const
   return d->encrypted;
 }
 
+MP4::Properties::Codec MP4::Properties::codec() const
+{
+  return d->codec;
+}
+
index 7906824d8f450a04b00d2e8ccde3ff0bfaf7808f..2607c366473fef25084b6ee44d11add7e9295a6c 100644 (file)
@@ -40,6 +40,12 @@ namespace TagLib {
     class TAGLIB_EXPORT Properties : public AudioProperties
     {
     public:
+      enum Codec {
+        Unknown = 0,
+        AAC,
+        ALAC
+      };
+
       Properties(File *file, Atoms *atoms, ReadStyle style = Average);
       virtual ~Properties();
 
@@ -50,6 +56,9 @@ namespace TagLib {
       virtual int bitsPerSample() const;
       bool isEncrypted() const;
 
+      //! Audio codec used in the MP4 file
+      Codec codec() const;
+
     private:
       class PropertiesPrivate;
       PropertiesPrivate *d;
index be7ad2c3c6cf68b54770ce9c11ec5135b1f3e08e..56b60525aa1c9924bdaa33af2e529f9ba2bc038f 100644 (file)
@@ -39,6 +39,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
     CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
     CPPUNIT_ASSERT_EQUAL(16, ((MP4::Properties *)f.audioProperties())->bitsPerSample());
+    CPPUNIT_ASSERT_EQUAL(MP4::Properties::AAC, ((MP4::Properties *)f.audioProperties())->codec());
   }
 
   void testPropertiesALAC()
@@ -49,6 +50,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
     CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
     CPPUNIT_ASSERT_EQUAL(16, ((MP4::Properties *)f.audioProperties())->bitsPerSample());
+    CPPUNIT_ASSERT_EQUAL(MP4::Properties::ALAC, ((MP4::Properties *)f.audioProperties())->codec());
   }
 
   void testCheckValid()