]> granicus.if.org Git - taglib/commitdiff
Unify some duplicate internal functions.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 22 Dec 2015 02:49:55 +0000 (11:49 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 22 Dec 2015 02:49:55 +0000 (11:49 +0900)
taglib/mpeg/mpegfile.cpp
taglib/mpeg/mpegheader.cpp
taglib/mpeg/mpegutils.h [new file with mode: 0644]

index 67f0b2737467a7f6db9ac76dfd8c90334cb2bb72..af7253fa573ac50ef79aaa7ded36a012a9445e20 100644 (file)
 
 #include "mpegfile.h"
 #include "mpegheader.h"
+#include "mpegutils.h"
 #include "tpropertymap.h"
 
 using namespace TagLib;
 
-namespace
-{
-  /*!
-   * MPEG frames can be recognized by the bit pattern 11111111 111, so the
-   * first byte is easy to check for, however checking to see if the second byte
-   * starts with \e 111 is a bit more tricky, hence these functions.
-   */
-
-  inline bool firstSyncByte(unsigned char byte)
-  {
-    return (byte == 0xFF);
-  }
-
-  inline bool secondSynchByte(unsigned char byte)
-  {
-    return ((byte & 0xE0) == 0xE0);
-  }
-}
-
 namespace
 {
   enum { ID3v2Index = 0, APEIndex = 1, ID3v1Index = 2 };
index 05177f3e79791d7494556d985a8377b35b578eba..01b37705cf0ef2a838f6e402fee0a68635669043 100644 (file)
 #include <tbytevector.h>
 #include <tstring.h>
 #include <tdebug.h>
-#include "trefcounter.h"
+#include <trefcounter.h>
 
 #include "mpegheader.h"
+#include "mpegutils.h"
 
 using namespace TagLib;
 
@@ -170,13 +171,8 @@ void MPEG::Header::parse(const ByteVector &data)
 
   // Check for the MPEG synch bytes.
 
-  if(static_cast<unsigned char>(data[0]) != 0xFF) {
-    debug("MPEG::Header::parse() -- First byte did not match MPEG synch.");
-    return;
-  }
-
-  if((static_cast<unsigned char>(data[1]) & 0xE0) != 0xE0) {
-    debug("MPEG::Header::parse() -- Second byte did not match MPEG synch.");
+  if(!firstSyncByte(data[0]) || !secondSynchByte(data[1])) {
+    debug("MPEG::Header::parse() -- MPEG header did not match MPEG synch.");
     return;
   }
 
diff --git a/taglib/mpeg/mpegutils.h b/taglib/mpeg/mpegutils.h
new file mode 100644 (file)
index 0000000..78cee28
--- /dev/null
@@ -0,0 +1,59 @@
+/***************************************************************************
+    copyright            : (C) 2015 by Tsuda Kageyu
+    email                : tsuda.kageyu@gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU Lesser General Public License version   *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
+ *   02110-1301  USA                                                       *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#ifndef TAGLIB_MPEGUTILS_H
+#define TAGLIB_MPEGUTILS_H
+
+// THIS FILE IS NOT A PART OF THE TAGLIB API
+
+#ifndef DO_NOT_DOCUMENT  // tell Doxygen not to document this header
+
+namespace TagLib
+{
+  namespace MPEG
+  {
+
+    /*!
+     * MPEG frames can be recognized by the bit pattern 11111111 111, so the
+     * first byte is easy to check for, however checking to see if the second byte
+     * starts with \e 111 is a bit more tricky, hence these functions.
+     */
+
+    inline bool firstSyncByte(unsigned char byte)
+    {
+      return (byte == 0xFF);
+    }
+
+    inline bool secondSynchByte(unsigned char byte)
+    {
+      return ((byte & 0xE0) == 0xE0);
+    }
+
+  }
+}
+
+#endif
+
+#endif