summaryrefslogtreecommitdiffstats
path: root/plugins/decoder/ogg
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/decoder/ogg')
-rw-r--r--plugins/decoder/ogg/Makefile.am13
-rw-r--r--plugins/decoder/ogg/configure.in.bot11
-rw-r--r--plugins/decoder/ogg/configure.in.in32
-rw-r--r--plugins/decoder/ogg/k3boggvorbisdecoder.cpp252
-rw-r--r--plugins/decoder/ogg/k3boggvorbisdecoder.h72
-rw-r--r--plugins/decoder/ogg/k3boggvorbisdecoder.plugin9
6 files changed, 389 insertions, 0 deletions
diff --git a/plugins/decoder/ogg/Makefile.am b/plugins/decoder/ogg/Makefile.am
new file mode 100644
index 0000000..6705be2
--- /dev/null
+++ b/plugins/decoder/ogg/Makefile.am
@@ -0,0 +1,13 @@
+AM_CPPFLAGS = -I$(srcdir)/../../../libk3b/plugin -I$(srcdir)/../../../libk3b/core -I$(srcdir)/../../../libk3bdevice $(all_includes)
+
+kde_module_LTLIBRARIES = libk3boggvorbisdecoder.la
+
+libk3boggvorbisdecoder_la_SOURCES = k3boggvorbisdecoder.cpp
+
+libk3boggvorbisdecoder_la_LIBADD = ../../../libk3b/libk3b.la -logg -lvorbis -lvorbisfile
+libk3boggvorbisdecoder_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries)
+
+pluginsdir = $(kde_datadir)/k3b/plugins
+plugins_DATA = k3boggvorbisdecoder.plugin
+
+METASOURCES = AUTO
diff --git a/plugins/decoder/ogg/configure.in.bot b/plugins/decoder/ogg/configure.in.bot
new file mode 100644
index 0000000..b27ab18
--- /dev/null
+++ b/plugins/decoder/ogg/configure.in.bot
@@ -0,0 +1,11 @@
+echo ""
+
+if test x$ogg_vorbis = xyes; then
+ echo "K3b - Ogg Vorbis support: yes"
+else
+ echo "K3b - Ogg Vorbis support: no"
+if test "$ac_cv_use_oggvorbis" = "yes"; then
+ echo "K3b - You are missing the Ogg-Vorbis headers and libraries."
+ echo "K3b - The Ogg Vorbis decoding and encoding plugins won't be compiled."
+fi
+fi
diff --git a/plugins/decoder/ogg/configure.in.in b/plugins/decoder/ogg/configure.in.in
new file mode 100644
index 0000000..69b1b9c
--- /dev/null
+++ b/plugins/decoder/ogg/configure.in.in
@@ -0,0 +1,32 @@
+dnl === Ogg Vorbis Test - Begin ===
+AC_ARG_WITH(
+ oggvorbis,
+ AS_HELP_STRING([--without-oggvorbis], [build K3b without OggVorbis support (default=no)]),
+ [ac_cv_use_oggvorbis=$withval],
+ [ac_cv_use_oggvorbis=yes]
+)
+
+if test "$ac_cv_use_oggvorbis" = "yes"; then
+
+ AC_MSG_CHECKING(for ogg/vorbis headers)
+ ogg_vorbis=no
+ AC_TRY_COMPILE([
+ #include <vorbis/codec.h>
+ #include <vorbis/vorbisfile.h>
+ ],[
+ ],[
+ ogg_vorbis=yes
+ ])
+ AC_MSG_RESULT($ogg_vorbis)
+ if test x$ogg_vorbis = xyes; then
+ dnl we need the ogg_vorbis_lib because otherwise we override LIBS !
+ AC_CHECK_LIB(vorbisfile,ov_open,ogg_vorbis_lib=yes,
+ ogg_vorbis=no,[$all_libraries -lvorbisfile -lvorbis -logg])
+ fi
+ if test x$ogg_vorbis = xyes; then
+ AC_DEFINE(OGG_VORBIS,1,[Define if you have ogg/vorbis installed])
+ fi
+fi
+
+AM_CONDITIONAL(include_OGG, [test x$ogg_vorbis = xyes])
+dnl === Ogg Vorbis Test - End ===
diff --git a/plugins/decoder/ogg/k3boggvorbisdecoder.cpp b/plugins/decoder/ogg/k3boggvorbisdecoder.cpp
new file mode 100644
index 0000000..15ca665
--- /dev/null
+++ b/plugins/decoder/ogg/k3boggvorbisdecoder.cpp
@@ -0,0 +1,252 @@
+/*
+ *
+ * $Id$
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+#include <config.h>
+
+#include "k3boggvorbisdecoder.h"
+
+#include <k3bpluginfactory.h>
+
+#include <qfile.h>
+#include <qstringlist.h>
+
+#include <kurl.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+
+
+K_EXPORT_COMPONENT_FACTORY( libk3boggvorbisdecoder, K3bPluginFactory<K3bOggVorbisDecoderFactory>( "libk3boggvorbisdecoder" ) )
+
+
+class K3bOggVorbisDecoder::Private
+{
+public:
+ Private()
+ : vInfo(0),
+ vComment(0),
+ isOpen(false) {
+ }
+
+ OggVorbis_File oggVorbisFile;
+ vorbis_info* vInfo;
+ vorbis_comment* vComment;
+ bool isOpen;
+};
+
+
+K3bOggVorbisDecoder::K3bOggVorbisDecoder( QObject* parent, const char* name )
+ : K3bAudioDecoder( parent, name )
+{
+ d = new Private();
+}
+
+
+K3bOggVorbisDecoder::~K3bOggVorbisDecoder()
+{
+ delete d;
+}
+
+
+bool K3bOggVorbisDecoder::openOggVorbisFile()
+{
+ if( !d->isOpen ) {
+ FILE* file = fopen( QFile::encodeName(filename()), "r" );
+ if( !file ) {
+ kdDebug() << "(K3bOggVorbisDecoder) Could not open file " << filename() << endl;
+ return false;
+ }
+ else if( ov_open( file, &d->oggVorbisFile, 0, 0 ) ) {
+ kdDebug() << "(K3bOggVorbisDecoder) " << filename()
+ << " seems not to to be an ogg vorbis file." << endl;
+ fclose( file );
+ return false;
+ }
+ }
+
+ d->isOpen = true;
+ return true;
+}
+
+
+bool K3bOggVorbisDecoder::analyseFileInternal( K3b::Msf& frames, int& samplerate, int& ch )
+{
+ cleanup();
+
+ if( openOggVorbisFile() ) {
+ // check length of track
+ double seconds = ov_time_total( &d->oggVorbisFile, -1 );
+ if( seconds == OV_EINVAL ) {
+ kdDebug() << "(K3bOggVorbisDecoder) Could not determine length of file " << filename() << endl;
+ cleanup();
+ return false;
+ }
+ else {
+
+ d->vInfo = ov_info( &d->oggVorbisFile, -1 /* current bitstream */ );
+ d->vComment = ov_comment( &d->oggVorbisFile, -1 );
+
+ // add meta tags
+ for( int i = 0; i < d->vComment->comments; ++i ) {
+ QString comment = QString::fromUtf8( d->vComment->user_comments[i] );
+ QStringList values = QStringList::split( "=", comment );
+ if( values.count() > 1 ) {
+ if( values[0].lower() == "title" )
+ addMetaInfo( META_TITLE, values[1] );
+ else if( values[0].lower() == "artist" )
+ addMetaInfo( META_ARTIST, values[1] );
+ else if( values[0].lower() == "description" )
+ addMetaInfo( META_COMMENT, values[1] );
+ }
+ }
+
+
+ // add technical infos
+ addTechnicalInfo( i18n("Version"), QString::number(d->vInfo->version) );
+ addTechnicalInfo( i18n("Channels"), QString::number(d->vInfo->channels) );
+ addTechnicalInfo( i18n("Sampling Rate"), i18n("%1 Hz").arg(d->vInfo->rate) );
+ if( d->vInfo->bitrate_upper > 0 )
+ addTechnicalInfo( i18n("Bitrate Upper"), i18n( "%1 bps" ).arg(d->vInfo->bitrate_upper) );
+ if( d->vInfo->bitrate_nominal > 0 )
+ addTechnicalInfo( i18n("Bitrate Nominal"), i18n( "%1 bps" ).arg(d->vInfo->bitrate_nominal) );
+ if( d->vInfo->bitrate_lower > 0 )
+ addTechnicalInfo( i18n("Bitrate Lower"), i18n( "%1 bps" ).arg(d->vInfo->bitrate_lower) );
+
+ frames = K3b::Msf::fromSeconds(seconds);
+ samplerate = d->vInfo->rate;
+ ch = d->vInfo->channels;
+
+ cleanup();
+
+ return true;
+ }
+ }
+ else
+ return false;
+}
+
+
+bool K3bOggVorbisDecoder::initDecoderInternal()
+{
+ cleanup();
+ return openOggVorbisFile();
+}
+
+
+int K3bOggVorbisDecoder::decodeInternal( char* data, int maxLen )
+{
+ int bitStream = 0;
+ long bytesRead = ov_read( &d->oggVorbisFile,
+ data,
+ maxLen, // max length to be read
+ 1, // big endian
+ 2, // word size: 16-bit samples
+ 1, // signed
+ &bitStream ); // current bitstream
+
+ if( bitStream != 0 ) {
+ kdDebug() << "(K3bOggVorbisDecoder) bitstream != 0. Multible bitstreams not supported." << endl;
+ return -1;
+ }
+
+ else if( bytesRead == OV_HOLE ) {
+ kdDebug() << "(K3bOggVorbisDecoder) OV_HOLE" << endl;
+ // recursive new try
+ return decodeInternal( data, maxLen );
+ }
+
+ else if( bytesRead < 0 ) {
+ kdDebug() << "(K3bOggVorbisDecoder) Error: " << bytesRead << endl;
+ return -1;
+ }
+
+ else if( bytesRead == 0 ) {
+ kdDebug() << "(K3bOggVorbisDecoder) successfully finished decoding." << endl;
+ return 0;
+ }
+
+ else {
+ return bytesRead;
+ }
+}
+
+
+void K3bOggVorbisDecoder::cleanup()
+{
+ if( d->isOpen )
+ ov_clear( &d->oggVorbisFile );
+ d->isOpen = false;
+ d->vComment = 0;
+ d->vInfo = 0;
+}
+
+
+bool K3bOggVorbisDecoder::seekInternal( const K3b::Msf& pos )
+{
+ return ( ov_pcm_seek( &d->oggVorbisFile, pos.pcmSamples() ) == 0 );
+}
+
+
+QString K3bOggVorbisDecoder::fileType() const
+{
+ return i18n("Ogg-Vorbis");
+}
+
+
+K3bOggVorbisDecoderFactory::K3bOggVorbisDecoderFactory( QObject* parent, const char* name )
+ : K3bAudioDecoderFactory( parent, name )
+{
+}
+
+
+K3bOggVorbisDecoderFactory::~K3bOggVorbisDecoderFactory()
+{
+}
+
+
+K3bAudioDecoder* K3bOggVorbisDecoderFactory::createDecoder( QObject* parent,
+ const char* name ) const
+{
+ return new K3bOggVorbisDecoder( parent, name );
+}
+
+
+bool K3bOggVorbisDecoderFactory::canDecode( const KURL& url )
+{
+ FILE* file = fopen( QFile::encodeName(url.path()), "r" );
+ if( !file ) {
+ kdDebug() << "(K3bOggVorbisDecoder) Could not open file " << url.path() << endl;
+ return false;
+ }
+
+ OggVorbis_File of;
+
+ if( ov_open( file, &of, 0, 0 ) ) {
+ fclose( file );
+ kdDebug() << "(K3bOggVorbisDecoder) not an Ogg-Vorbis file: " << url.path() << endl;
+ return false;
+ }
+
+ ov_clear( &of );
+
+ return true;
+}
+
+
+#include "k3boggvorbisdecoder.moc"
diff --git a/plugins/decoder/ogg/k3boggvorbisdecoder.h b/plugins/decoder/ogg/k3boggvorbisdecoder.h
new file mode 100644
index 0000000..20ae094
--- /dev/null
+++ b/plugins/decoder/ogg/k3boggvorbisdecoder.h
@@ -0,0 +1,72 @@
+/*
+ *
+ * $Id: k3boggvorbisdecoder.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#ifndef _K3B_OGGVORBIS_DECODER_H_
+#define _K3B_OGGVORBIS_DECODER_H_
+
+
+#include <k3baudiodecoder.h>
+
+class KURL;
+
+
+class K3bOggVorbisDecoderFactory : public K3bAudioDecoderFactory
+{
+ Q_OBJECT
+
+ public:
+ K3bOggVorbisDecoderFactory( QObject* parent = 0, const char* name = 0 );
+ ~K3bOggVorbisDecoderFactory();
+
+ bool canDecode( const KURL& filename );
+
+ int pluginSystemVersion() const { return 3; }
+
+ K3bAudioDecoder* createDecoder( QObject* parent = 0,
+ const char* name = 0 ) const;
+};
+
+
+/**
+ *@author Sebastian Trueg
+ */
+class K3bOggVorbisDecoder : public K3bAudioDecoder
+{
+ Q_OBJECT
+
+ public:
+ K3bOggVorbisDecoder( QObject* parent = 0, const char* name = 0 );
+ ~K3bOggVorbisDecoder();
+
+ void cleanup();
+
+ QString fileType() const;
+
+ protected:
+ bool analyseFileInternal( K3b::Msf& frames, int& samplerate, int& ch );
+ bool initDecoderInternal();
+ bool seekInternal( const K3b::Msf& );
+
+ int decodeInternal( char* _data, int maxLen );
+
+ private:
+ bool openOggVorbisFile();
+
+ class Private;
+ Private* d;
+};
+
+#endif
diff --git a/plugins/decoder/ogg/k3boggvorbisdecoder.plugin b/plugins/decoder/ogg/k3boggvorbisdecoder.plugin
new file mode 100644
index 0000000..0f1c48e
--- /dev/null
+++ b/plugins/decoder/ogg/k3boggvorbisdecoder.plugin
@@ -0,0 +1,9 @@
+[K3b Plugin]
+Lib=libk3boggvorbisdecoder
+Group=AudioDecoder
+Name=K3b Ogg Vorbis Decoder
+Author=Sebastian Trueg
+Email=trueg@k3b.org
+Version=3.0
+Comment=Decoding module to decode Ogg Vorbis files
+License=GPL