diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 00bb99ac80741fc50ef8a289719373032f2391eb (patch) | |
tree | 3a5a9bf72f942784b38bf77dd66c534662fab5f2 /kttsd/players/gstplayer | |
download | tdeaccessibility-00bb99ac80741fc50ef8a289719373032f2391eb.tar.gz tdeaccessibility-00bb99ac80741fc50ef8a289719373032f2391eb.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaccessibility@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kttsd/players/gstplayer')
-rw-r--r-- | kttsd/players/gstplayer/Makefile.am | 30 | ||||
-rw-r--r-- | kttsd/players/gstplayer/gstplugin.cpp | 29 | ||||
-rw-r--r-- | kttsd/players/gstplayer/gstreamerplayer.cpp | 258 | ||||
-rw-r--r-- | kttsd/players/gstplayer/gstreamerplayer.h | 76 | ||||
-rw-r--r-- | kttsd/players/gstplayer/kttsd_gstplugin.desktop | 92 |
5 files changed, 485 insertions, 0 deletions
diff --git a/kttsd/players/gstplayer/Makefile.am b/kttsd/players/gstplayer/Makefile.am new file mode 100644 index 0000000..df00c55 --- /dev/null +++ b/kttsd/players/gstplayer/Makefile.am @@ -0,0 +1,30 @@ +# Include paths. INCLUDES is maintained by KDevelop, AM_CPPFLAGS is the preferred variable, +# so keep them synchronized. +INCLUDES = \ + $(GST_CFLAGS) \ + -I$(top_srcdir)/kttsd/libkttsd -I$(top_builddir)/kttsd/libkttsd \ + $(all_includes) + +# Let automoc handle all of the metsource files (moc). +METASOURCES = AUTO + +######################################################################### +# LIBRARY SECTION +######################################################################### +# This is the library that gets installed. It's name is used for all +# of the other Makefile.am variables. +kde_module_LTLIBRARIES = libkttsd_gstplugin.la + +libkttsd_gstplugin_la_SOURCES = \ + gstplugin.cpp \ + gstreamerplayer.cpp +libkttsd_gstplugin_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) $(LDFLAGS_GST) -no-undefined +libkttsd_gstplugin_la_LIBADD = $(top_builddir)/kttsd/libkttsd/libkttsd.la $(LDADD_GST) + +# Header files that should not be installed. +noinst_HEADERS = \ + gstreamerplayer.h + +# This library is installed as a plugin. +services_DATA = kttsd_gstplugin.desktop +servicesdir = $(kde_servicesdir) diff --git a/kttsd/players/gstplayer/gstplugin.cpp b/kttsd/players/gstplayer/gstplugin.cpp new file mode 100644 index 0000000..633bff9 --- /dev/null +++ b/kttsd/players/gstplayer/gstplugin.cpp @@ -0,0 +1,29 @@ +/***************************************************** vim:set ts=4 sw=4 sts=4: + Generating the factories so that GStreamer can be used as and audio plug in. + ------------------- + Copyright: + (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net> + ------------------- + Original author: Gary Cramblitt <garycramblitt@comcast.net> + + 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. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + ******************************************************************************/ + +#include <kgenericfactory.h> + +#include "gstreamerplayer.h" + +K_EXPORT_COMPONENT_FACTORY( libkttsd_gstplugin, KGenericFactory<GStreamerPlayer>("kttsd_gst") ); + diff --git a/kttsd/players/gstplayer/gstreamerplayer.cpp b/kttsd/players/gstplayer/gstreamerplayer.cpp new file mode 100644 index 0000000..64aa1c4 --- /dev/null +++ b/kttsd/players/gstplayer/gstreamerplayer.cpp @@ -0,0 +1,258 @@ +/*************************************************************************** + copyright : (C) 2004 Scott Wheeler + email : wheeler@kde.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. * + * * + ***************************************************************************/ + +// Qt includes. +#include <qfile.h> + +// KDE includes. +#include <kapplication.h> +#include <kconfig.h> +#include <kglobal.h> +#include <kdebug.h> + +// GStreamerPlayer includes. +#include "gstreamerplayer.h" +#include "gstreamerplayer.moc" + +//////////////////////////////////////////////////////////////////////////////// +// public methods +//////////////////////////////////////////////////////////////////////////////// + +GStreamerPlayer::GStreamerPlayer(QObject* parent, const char* name, const QStringList& args) : + Player(parent, name, args), + m_initialized(false), + m_pipeline(0), + m_source(0), + m_decoder(0), + m_volume(0), + m_sink(0) +{ + // readConfig(); + setupPipeline(); +} + +GStreamerPlayer::~GStreamerPlayer() +{ + stop(); + gst_object_unref(GST_OBJECT(m_pipeline)); +} + +//void GStreamerPlayer::play(const FileHandle &file) +void GStreamerPlayer::startPlay(const QString &file) +{ + if(!file.isNull()) { + stop(); + // g_object_set(G_OBJECT(m_source), "location", file.absFilePath().local8Bit().data(), 0); + g_object_set(G_OBJECT(m_source),"location",file.local8Bit().data(),NULL); + } + + gst_element_set_state(m_pipeline, GST_STATE_PLAYING); +} + +void GStreamerPlayer::pause() +{ + gst_element_set_state(m_pipeline, GST_STATE_PAUSED); +} + +void GStreamerPlayer::stop() +{ + gst_element_set_state(m_pipeline, GST_STATE_NULL); +} + +void GStreamerPlayer::setVolume(float volume) +{ + g_object_set(G_OBJECT(m_volume), "volume", volume, NULL); +} + +float GStreamerPlayer::volume() const +{ + gfloat value; + g_object_get(G_OBJECT(m_volume), "volume", &value, NULL); + return value; +} + +bool GStreamerPlayer::playing() const +{ + return gst_element_get_state(m_pipeline) == GST_STATE_PLAYING; +} + +bool GStreamerPlayer::paused() const +{ + return gst_element_get_state(m_pipeline) == GST_STATE_PAUSED; +} + +int GStreamerPlayer::totalTime() const +{ + return time(GST_QUERY_TOTAL) / GST_SECOND; +} + +int GStreamerPlayer::currentTime() const +{ + return time(GST_QUERY_POSITION) / GST_SECOND; +} + +int GStreamerPlayer::position() const +{ + long long total = time(GST_QUERY_TOTAL); + long long current = time(GST_QUERY_POSITION); + return total > 0 ? int((double(current) / double(total)) * double(1000) + 0.5) : 0; +} + +void GStreamerPlayer::seek(int seekTime) +{ + int type = (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH); + gst_element_seek(m_sink, GstSeekType(type), seekTime * GST_SECOND); +} + +void GStreamerPlayer::seekPosition(int position) +{ + long long total = time(GST_QUERY_TOTAL); + if(total > 0) + seek(int(double(position) / double(1000) * double(totalTime()) + 0.5)); +} + +/** + * Returns a list of GStreamer plugins of the specified class. + * @param classname Desired class. Use "Sink/Audio" for sinks. + * @return List of plugin names. + */ +QStringList GStreamerPlayer::getPluginList( const QCString& classname ) +{ + GList * pool_registries = NULL; + GList* registries = NULL; + GList* plugins = NULL; + GList* features = NULL; + QString name; + QStringList results; + + if(!m_initialized) { + int argc = kapp->argc(); + char **argv = kapp->argv(); + gst_init(&argc, &argv); + m_initialized = true; + } + + pool_registries = gst_registry_pool_list (); + registries = pool_registries; + + while ( registries ) { + GstRegistry * registry = GST_REGISTRY ( registries->data ); + plugins = registry->plugins; + + while ( plugins ) { + GstPlugin * plugin = GST_PLUGIN ( plugins->data ); + features = gst_plugin_get_feature_list ( plugin ); + + while ( features ) { + GstPluginFeature * feature = GST_PLUGIN_FEATURE ( features->data ); + + if ( GST_IS_ELEMENT_FACTORY ( feature ) ) { + GstElementFactory * factory = GST_ELEMENT_FACTORY ( feature ); + + if ( g_strrstr ( factory->details.klass, classname ) ) { + name = g_strdup ( GST_OBJECT_NAME ( factory ) ); + if ( name != "artsdsink" ) results << name; + } + } + features = g_list_next ( features ); + } + plugins = g_list_next ( plugins ); + } + registries = g_list_next ( registries ); + } + g_list_free ( pool_registries ); + pool_registries = NULL; + + return results; +} + +bool GStreamerPlayer::requireVersion(uint major, uint minor, uint micro) +{ + guint gmajor, gminor, gmicro; + + if(!m_initialized) { + int argc = kapp->argc(); + char **argv = kapp->argv(); + gst_init(&argc, &argv); + m_initialized = true; + } + + gst_version(&gmajor, &gminor, &gmicro); + // kdDebug() << QString("GStreamerPlayer::requireVersion: You have gstreamer %1.%2.%3 installed.").arg(gmajor).arg(gminor).arg(gmicro) << endl; + if (gmajor > major) return true; + if (gminor > minor) return true; + if (gmicro >= micro) return true; + kdDebug() << QString("GStreamerPlayer::requireVersion: You have gstreamer %1.%2.%3 installed.").arg(gmajor).arg(gminor).arg(gmicro) << endl; + kdDebug() << QString("GStreamerPlayer::requireVersion: This application requires %1.%2.%3 or greater.").arg(major).arg(minor).arg(micro) << endl; + return false; +} + +void GStreamerPlayer::setSinkName(const QString &sinkName) { m_sinkName = sinkName; } + +//////////////////////////////////////////////////////////////////////////////// +// private methods +//////////////////////////////////////////////////////////////////////////////// + +void GStreamerPlayer::readConfig() +{ + KConfigGroup config(KGlobal::config(), "GStreamerPlayer"); + m_sinkName = config.readEntry("SinkName", QString::null); +} + +void GStreamerPlayer::setupPipeline() +{ + if(!m_initialized) { + int argc = kapp->argc(); + char **argv = kapp->argv(); + gst_init(&argc, &argv); + m_initialized = true; + } + + m_pipeline = gst_thread_new("pipeline"); + m_source = gst_element_factory_make("filesrc", "source"); + m_decoder = gst_element_factory_make("spider", "decoder"); + m_volume = gst_element_factory_make("volume", "volume"); + + if(!m_sinkName.isNull()) + m_sink = gst_element_factory_make(m_sinkName.utf8().data(), "sink"); + if (!m_sink) + { + // m_sink = gst_element_factory_make("alsasink", "sink"); + // if(!m_sink) + // m_sink = gst_element_factory_make("osssink", "sink"); + + // Reversing order. OSS seems to work. Alsa sink produces ugly echo of last + // couple of words in each wav file. argh! + // kdDebug() << "GStreamerPlayer::setupPipeline: trying oss sink." << endl; + m_sink = gst_element_factory_make("osssink", "sink"); + if(!m_sink) + { + // kdDebug() << "GStreamerPlayer::setupPipeline: reverting to alsa sink." << endl; + m_sink = gst_element_factory_make("alsasink", "sink"); + } + } + + gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_decoder, m_volume, m_sink, 0); + gst_element_link_many(m_source, m_decoder, m_volume, m_sink, 0); +} + +long long GStreamerPlayer::time(GstQueryType type) const +{ + gint64 ns = 0; + GstFormat format = GST_FORMAT_TIME; + gst_element_query(m_sink, type, &format, &ns); + return ns; +} + +// vim: set et sw=4: diff --git a/kttsd/players/gstplayer/gstreamerplayer.h b/kttsd/players/gstplayer/gstreamerplayer.h new file mode 100644 index 0000000..6a7f1d6 --- /dev/null +++ b/kttsd/players/gstplayer/gstreamerplayer.h @@ -0,0 +1,76 @@ +/*************************************************************************** + copyright : (C) 2004 Scott Wheeler + email : wheeler@kde.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. * + * * + ***************************************************************************/ + +#ifndef GSTREAMERPLAYER_H +#define GSTREAMERPLAYER_H + +#include "config.h" + +#include <glib.h> +extern "C" { +#include <gst/gstversion.h> +} +#include <gst/gst.h> +#include <qstring.h> +#include "player.h" + +class GStreamerPlayer : public Player +{ + Q_OBJECT + +public: + GStreamerPlayer(QObject* parent = 0, const char* name = 0, const QStringList& args=QStringList()); + virtual ~GStreamerPlayer(); + + // virtual void play(const FileHandle &file = FileHandle::null()); + virtual void startPlay(const QString& file); + + virtual void setVolume(float volume = 1.0); + virtual float volume() const; + + virtual bool playing() const; + virtual bool paused() const; + + virtual int totalTime() const; + virtual int currentTime() const; + virtual int position() const; // in this case not really the percent + + virtual void seek(int seekTime); + virtual void seekPosition(int position); + + virtual QStringList getPluginList( const QCString& classname ); + virtual void setSinkName(const QString &sinkName); + + virtual bool requireVersion(uint major, uint minor, uint micro); + + void pause(); + void stop(); + +private: + void readConfig(); + void setupPipeline(); + long long time(GstQueryType type) const; + + QString m_sinkName; + // True once gst_init() has been called. + bool m_initialized; + + GstElement *m_pipeline; + GstElement *m_source; + GstElement *m_decoder; + GstElement *m_volume; + GstElement *m_sink; +}; + +#endif diff --git a/kttsd/players/gstplayer/kttsd_gstplugin.desktop b/kttsd/players/gstplayer/kttsd_gstplugin.desktop new file mode 100644 index 0000000..7646cee --- /dev/null +++ b/kttsd/players/gstplayer/kttsd_gstplugin.desktop @@ -0,0 +1,92 @@ +[Desktop Entry] +Name=KTTSD GStreamer Plugin +Name[br]=Lugent KTTSD GStreamer +Name[bs]=KTTSD GStreamer dodatak +Name[ca]=Connector GStreamer pel KTTSD +Name[cs]=KTTSD GStreamer modul +Name[da]=KTTSD GStreamer-plugin +Name[de]=KTTSD GStreamer-Modul +Name[el]=KTTSD πρόσθετο GStreamer +Name[es]=Complemento KTTSD GStreamer +Name[et]=KTTSD GStreameri plugin +Name[eu]=KTTSD-ren GStreamer plugina +Name[fa]=وصلۀ KTTSD GStreamer +Name[fi]=KTTSD GStreamer-liitännäinen +Name[fr]=Module GStreamer pour KTTSD +Name[ga]=Breiseán KTTSD GStreamer +Name[gl]=Plugin GStreamer de KTTSD +Name[hu]=KTTSD GStreamer-modul +Name[is]=KTTSD GStreamer íforrit +Name[it]=Plugin per GStreamer di KTTSD +Name[ja]=KTTSD GStreamer プラグイン +Name[ka]=KTTSD GStreamer მოდული +Name[km]= កម្មវិធីជំនួយ GStreamer សម្រាប់ KTTSD +Name[mk]=GStreamer-приклучок за KTTSD +Name[ms]=Plugin KTTSD GStreamer +Name[nb]=GStreamer programtillegg for KTTSD +Name[nds]=GStreamer-Moduul för KTTSD +Name[ne]=KTTSD जि स्ट्रिमर प्लगइन +Name[nl]=KTTSD GStreamer-plugin +Name[pa]=KTTSD ਜੀਸਟਰੀਮਰ ਪਲੱਗਿੰਨ +Name[pl]=Wtyczka GStreamer KTTSD +Name[pt]='Plugin' GStreamer do KTTSD +Name[pt_BR]=Plug-in do GStreamer para o KTTSD +Name[ru]=Модуль GStreamer для KTTSD +Name[sk]=Modul KTTSD GStreamer +Name[sl]=Vstavek KTTSD za GStreamer +Name[sr]=GStreamer као прикључак за KTTSD +Name[sr@Latn]=GStreamer kao priključak za KTTSD +Name[sv]=KTTSD-insticksprogram för Gstreamer +Name[ta]=KTTSD GStreamer சொருகுப்பொருள் +Name[tg]=Модули GStreamer барои KTTSD +Name[tr]=KTTSD GStreamer Eklentisi +Name[uk]=Втулок GStreamer для KTTSD +Name[vi]=Trình bổ sung KTTSD GStreamer +Name[zh_TW]=KTTSd GStreamer 外掛程式 +Comment=KTTSD GStreamer audio plugin +Comment[bg]=Аудио приставка на KTTSD за GStreamer +Comment[br]=Lugent klevet GStreamer evit KTTSD +Comment[ca]=Connector d'àudio GStreamer pel KTTSD +Comment[cs]=KTTSD GStreamer zvukový modul +Comment[da]=KTTSD GStreamer lyd-plugin +Comment[de]=KTTSD GStreamer Audio-Modul +Comment[el]=KTTSD πρόσθετο ήχου GStreamer +Comment[es]=Complemento de audio KTTSD GStreamer +Comment[et]=KTTSD GStreameri audioplugin +Comment[eu]=KTTSD-ren GStreamer audio-plugina +Comment[fa]=وصلۀ صوتی KTTSD GStreamer +Comment[fi]=KTTSD GStreamer ääniliitännäinen +Comment[fr]=Module audio GStreamer pour KTTSD +Comment[ga]=Breiseán fuaime GStreamer KTTSD +Comment[gl]=Plugin de áudio GStreamer para KTTSD +Comment[hu]=KTTSD hangmodul a GStreamerhez +Comment[is]=KTTSD GStreamer hljóð íforrit +Comment[it]=Plugin audio per GStreamer di KTTSD +Comment[ja]=KTTSD GStreamer オーディオプラグイン +Comment[ka]=KTTSD GStreamer აუდიო მოდული +Comment[km]=កម្មវិធីជំនួយអូឌីយ៉ូ GStreamer សម្រាប់ KTTSD +Comment[mk]=GStreamer-аудиоприклучок за KTTSD +Comment[ms]=Plugin audio KTTSD GStreamer +Comment[nb]=GStreamer lyd-programtillegg for KTTSD +Comment[nds]=GStreamer-Audiomoduul för KTTSD +Comment[ne]=KTTSD जि स्ट्रिमर अडियो प्लगइन +Comment[nl]=KTTSD GStreamer-audioplugin +Comment[pa]=KTTSD ਜੀਸਟਰੀਮਰ ਆਡੀਓ ਪਲੱਗਿੰਨ +Comment[pl]=Wtyczka dźwięku GStreamer dla KTTSD +Comment[pt]='Plugin' áudio GStreamer do KTTSD +Comment[pt_BR]=Plug-in de áudio do GStreamer para o KTTSD +Comment[ru]=Модуль вывода звука KTTSD через GStreamer +Comment[sk]=Modul KTTSD GStreamer audio +Comment[sl]=Vstavek KTTSD za zvok v GStreamer +Comment[sr]=GStreamer као аудио прикључак за KTTSD +Comment[sr@Latn]=GStreamer kao audio priključak za KTTSD +Comment[sv]=KTTSD-ljudinsticksprogram för Gstreamer +Comment[ta]=KTTSD GStreamer கேட்பொலி சொருகுப்பொருள் +Comment[tg]=Модули барориши овози KTTSD ба воситаи GStreamer +Comment[tr]= KTTSD GStreamer ses eklentisi +Comment[uk]=Звуковий втулок GStreamer для KTTSD +Comment[vi]=Trình bổ sung âm thanh KTTSD GStreamer +Comment[zh_TW]=KTTSd GStreamer 語音外掛程式 +Type=Service +ServiceTypes=KTTSD/AudioPlugin +X-KDE-Library=libkttsd_gstplugin |