[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/taglib
From:       Lukáš Lalinský <lalinsky () gmail ! com>
Date:       2009-10-24 12:17:09
Message-ID: 1256386629.482452.1568.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1039708 by lalinsky:

Proper .oga file handling in FileRef

This fixes a problem introduced in r983337. OGA files are mostly likely going
to be Ogg::FLAC, if applications are following the Xiph recommendation. But
they can be using any Ogg codec, so we must check multiple formats (Sound Juicer
on Ubuntu used to produce .oga files for Ogg Vorbis, I believe it doesn't do that
anymore).


 M  +9 -4      taglib/fileref.cpp  
 M  +18 -0     tests/test_fileref.cpp  


--- trunk/kdesupport/taglib/taglib/fileref.cpp #1039707:1039708
@@ -205,12 +205,17 @@
   int pos = s.rfind(".");
   if(pos != -1) {
     String ext = s.substr(pos + 1).upper();
-    if(ext == "OGG" || ext == "OGA")
-      return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
     if(ext == "MP3")
       return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
-    if(ext == "OGA")
-      return new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
+    if(ext == "OGG")
+      return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
+    if(ext == "OGA") {
+      /* .oga can be any audio in the Ogg container. First try FLAC, then Vorbis. */
+      File *file = new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
+      if (file->isValid())
+        return file;
+      return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
+    }
     if(ext == "FLAC")
       return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
     if(ext == "MPC")
--- trunk/kdesupport/taglib/tests/test_fileref.cpp #1039707:1039708
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <tag.h>
 #include <fileref.h>
+#include <oggflacfile.h>
+#include <vorbisfile.h>
 #include "utils.h"
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -22,6 +24,8 @@
   CPPUNIT_TEST(testSpeex);
   CPPUNIT_TEST(testFLAC);
   CPPUNIT_TEST(testMP3);
+  CPPUNIT_TEST(testOGA_FLAC);
+  CPPUNIT_TEST(testOGA_Vorbis);
 #ifdef TAGLIB_WITH_MP4
   CPPUNIT_TEST(testMP4_1);
   CPPUNIT_TEST(testMP4_2);
@@ -131,6 +135,20 @@
   }
 #endif
 
+  void testOGA_FLAC()
+  {
+      FileRef *f = new FileRef("data/empty_flac.oga");
+      CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) == NULL);
+      CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) != NULL);
+  }
+
+  void testOGA_Vorbis()
+  {
+      FileRef *f = new FileRef("data/empty_vorbis.oga");
+      CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f->file()) != NULL);
+      CPPUNIT_ASSERT(dynamic_cast<Ogg::FLAC::File *>(f->file()) == NULL);
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestFileRef);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic