future versions (Re: [kde-announce] Announcing KDE 3.2)

Ralf Habacker ralf.habacker at freenet.de
Thu Feb 5 00:57:53 GMT 2004


On Wednesday 04 February 2004 22:56, Waldo Bastian wrote:
>
> I would like to see a KDE 3.3 targeted for late 2004Q3, let's say early
> oktober. In parallel to that I think there should be a KDE 3.3-experimental
> branch where framework technology for KDE 4 can be developed such as the
> atk bridge integration and various freedesktop technologies such as the
> shared mimetypes, DBUS and perhaps a single shared audio API.
                                                                 ^^^^^^^^^^^
I like  to share some experience with recent sound support on windows/cygwin.  
The following stuff is an very incomplete proposal and implementation I had 
written after I encountered sound problems with kdegames for the kde-cygwin 
3.1.4 release. May be this could be used in relation to the above mentioned  
shared audio API. 

- replacing arts with an initial win32 native sound support based on an 
extended KAudioPlayer class proving base sound playing/stopping with volume 
control and mimetype support for the implemented audio formats. 

The main reason for this is that unix domain sockets has very poor performance 
on cygwin/windows and all sound communications goes over this socket type, 
which produces noticable latencies on a recent pc because KAudioPlayer calls 
Knotify through unix domain sockets and Knotify calls arts through additional 
unix domain sockets too. 
Additional using arts which with glib is overkill for simple sound playing or 
system notication and requires too many resources on windows.. 

The initial implementation supports currently the wave format using a self 
written command line wave player, mp3 format with madplay, and ogg with 
ogg123 from the vorbis-tools (found on the linux day 2003 dvd)  

This class is used by KNotify for System Notification and KonqSoundPlayer for 
Soundfile preview. Additional I have patched some games (kolf, Kasteriods, 
kbattleship and others) using KAudioPlayer to see which requirements are 
there. Kolf initial has showed the most latencies (about 200-300ms),  after 
implementing the patch, I've recognized no hearable latencies (<50ms). 

From my experience from this port, unix based os could use sound support 
through KAudioPlayer too, because arts could be completly encapsulated by 
KAudioPlayer. My initial idea was to use KAudioplayer as an os independing 
class for KDE sound support, which may support many different sound systems.  

Append are the used patches for the kde-cygwin 3.1.4 release, which may be 
good as a viewing material.   

kdebase/libkonq/konq_sound.cc
kdelibs/kdecore/kaudioplayer.cpp
kdelibs/kdecore/kaudioplayer.h
kdelibs/arts/knotify.cpp

Cheers

Ralf 



Index: konq_sound.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_sound.cc,v
retrieving revision 1.16.2.1
diff -u -3 -p -B -u -r1.16.2.1 konq_sound.cc
--- konq_sound.cc       18 May 2003 12:36:02 -0000      1.16.2.1
+++ konq_sound.cc       5 Feb 2004 00:47:24 -0000
@@ -18,10 +18,17 @@

 // $Id: konq_sound.cc,v 1.16.2.1 2003/05/18 12:36:02 mueller Exp $

-#include <kartsdispatcher.h>
 #include <kdebug.h>
-#include <kplayobjectfactory.h>
-#include <soundserver.h>
+
+#ifndef __CYGWIN__
+#define USE_ARTS
+#endif
+
+#ifdef USE_ARTS
+#include <arts/kartsdispatcher.h>
+#include <arts/kplayobjectfactory.h>
+#include <arts/soundserver.h>
+

 #include "konq_sound.h"

@@ -102,6 +109,62 @@ void KonqSoundPlayerImpl::stop()
        m_player = 0;
 }

+
+#else
+// using KAudioPlayer
+
+
+#include <kaudioplayer.h>
+#include "konq_sound.h"
+
+using namespace std;
+
+class KonqSoundPlayerImpl : public KonqSoundPlayer
+{
+public:
+       KonqSoundPlayerImpl();
+       virtual ~KonqSoundPlayerImpl();
+
+       virtual const QStringList &mimeTypes();
+       virtual void play(const QString &fileName);
+       virtual void stop();
+
+private:
+       KAudioPlayer *m_player;
+};
+
+KonqSoundPlayerImpl::KonqSoundPlayerImpl()
+{
+       m_player = new KAudioPlayer("");
+}
+
+KonqSoundPlayerImpl::~KonqSoundPlayerImpl()
+{
+       delete m_player;
+}
+
+void KonqSoundPlayerImpl::play(const QString &fileName)
+{
+       if (m_player)
+               delete m_player;
+       kdDebug(1203) << __FUNCTION__ << fileName << endl;
+       m_player= new KAudioPlayer(fileName);
+       m_player->play();
+}
+
+const QStringList &KonqSoundPlayerImpl::mimeTypes()
+{
+       return m_player->mimeTypes();
+}
+
+void KonqSoundPlayerImpl::stop()
+{
+       kdDebug(1203) << __FUNCTION__ << endl;
+       m_player->stop();
+}
+
+#endif
+
 class KonqSoundFactory : public KLibFactory
 {
 public:


Index: kaudioplayer.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kaudioplayer.cpp,v
retrieving revision 1.5
diff -u -3 -p -B -r1.5 kaudioplayer.cpp
--- kaudioplayer.cpp    18 Jan 2002 17:48:23 -0000      1.5
+++ kaudioplayer.cpp    5 Feb 2004 00:49:18 -0000
@@ -22,12 +22,34 @@

 #include "kaudioplayer.h"
 #include "knotifyclient.h"
+#include "kconfig.h"
+#include "kprocess_ext.h"
+#include "kdebug.h"
+
+// TODO: use arts directly

 class KAudioPlayerPrivate {
 public:
+       bool useExternal;
        QString filename;
-
-       KAudioPlayerPrivate(const QString &filename) : filename(filename) { };
+       QString wavePlayer;
+       QString mp3Player;
+       QString oggPlayer;
+       QStringList mimeTypes;
+       int pid;
+       bool isPlaying;
+       KAudioPlayerPrivate(const QString &filename) : filename(filename), 
pid(0)
+       {
+         KConfig *kc = new KConfig("knotifyrc", false, false);
+       kc->setGroup("Misc");
+       useExternal = kc->readBoolEntry( "Use external player", false );
+       wavePlayer = kc->readPathEntry("Wave Player","kwaveplay");
+       mp3Player = kc->readPathEntry("MP3 Player","madplay");
+       oggPlayer = kc->readPathEntry("Ogg Player","ogg123");
+               mimeTypes << "audio/x-wav";     // .wav
+               mimeTypes << "audio/x-mp3"; // .mp3
+               mimeTypes << "application/x-ogg"; // .ogg
+       }
 };

 KAudioPlayer::KAudioPlayer( const QString& filename,
@@ -49,8 +72,43 @@ void KAudioPlayer::play(const QString &f

 void KAudioPlayer::play()
 {
-       KNotifyClient::userEvent("KAudioPlayer event",
+       if (d->useExternal) {
+               QString a = d->filename.lower().remove("file:");
+               kdDebug() << "KAudioPlayer: playing sound " << a << endl;
+               if (a.findRev(".wav") != -1)
+                       d->pid = KDE::run((d->wavePlayer + " " + a).ascii());
+               else if (a.findRev(".mp3") != -1)
+                       d->pid = KDE::run((d->mp3Player + " " + a).ascii());
+               else if (a.findRev(".ogg") != -1)
+                       d->pid = KDE::run((d->oggPlayer + " " + a).ascii());
+               else {
+                       kdDebug() << "KAudioPlayer: file format of file " << 
d->filename << " not supported" << endl;
+                       return;
+               }
+               kdDebug() << "KAudioPlayer: gotting pid " << d->pid << endl;
+
+       }
+       else
+               KNotifyClient::userEvent("KAudioPlayer event",
                                                        
KNotifyClient::Sound,KNotifyClient::Notification,d->filename);
 }

+const QStringList &KAudioPlayer::mimeTypes()
+{
+       return d->mimeTypes;
+}
+
+void KAudioPlayer::stop()
+{
+       if (d->useExternal) {
+               if (d->pid) {
+                       kdDebug() << "KAudioPlayer: stopping pid " << d->pid 
<< endl;
+                       KDE::kill(d->pid);
+                       d->pid = 0;
+               }
+       }
+       else
+               ;// ???
+}
+
 #include "kaudioplayer.moc"

Index: kaudioplayer.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kaudioplayer.h,v
retrieving revision 1.8
diff -u -3 -p -B -r1.8 kaudioplayer.h
--- kaudioplayer.h      3 Mar 2002 21:20:25 -0000       1.8
+++ kaudioplayer.h      5 Feb 2004 00:50:06 -0000
@@ -62,7 +62,7 @@ public:
         * @param parent A parent QObject for this KAudioPlayer
         * @param name An internal name for this KAudioPlayer
         */
-       KAudioPlayer( const QString& filename,
+       KAudioPlayer( const QString& = QString::null,
                        QObject* parent = 0, const char* name = 0 );

        /**
@@ -78,6 +78,26 @@ public:
         */
        static void play(const QString &filename);

+       /**
+        * set volume for this sound in the range of 0-100 %.
+        *
+        */
+       void setVolume(int left, int right) {}
+
+       void setVolume(int left_right) {}
+
+       /**
+        * get volume for this sound.
+        *
+        */
+       int getVolume(/* channelselect ??? */) {return 0;}
+
+       /**
+        * return supported mime types.
+        *
+        */
+       const QStringList &mimeTypes(void);
+
 public slots:
        /**
         * Play function as slot.
@@ -85,6 +105,13 @@ public slots:
         * Plays the soundfile given to the constructor.
         */
        void play();
+
+       /**
+        * Stop playing a sound as slot.
+        *
+        * stop playing the soundfile given to the constructor.
+        */
+       void stop();
 private:
        KAudioPlayerPrivate *d;
 };

Index: knotify.cpp
===================================================================
RCS file: /home/kde/kdelibs/arts/knotify/knotify.cpp,v
retrieving revision 1.67.2.2
diff -u -3 -p -B -r1.67.2.2 knotify.cpp
--- knotify.cpp 29 Jun 2003 21:42:57 -0000      1.67.2.2
+++ knotify.cpp 5 Feb 2004 00:51:12 -0000
@@ -19,7 +19,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
-
+//#define USE_ARTS
 // C headers
 #include <fcntl.h>
 #include <sys/types.h>
@@ -28,11 +28,13 @@
 // C++ headers
 #include <string>

+#ifdef USE_ARTS
 // aRts headers
 #include <connect.h>
 #include <dispatcher.h>
 #include <flowsystem.h>
 #include <soundserver.h>
+#endif

 // QT headers
 #include <qfile.h>
@@ -71,10 +73,11 @@ public:
     QString externalPlayer;
     KProcess *externalPlayerProc;

+#ifdef USE_ARTS
     Arts::SoundServerV2 soundServer;
     Arts::PlayObjectFactory playObjectFactory;
     QValueList<Arts::PlayObject> playObjects;
-
+#endif
     bool useExternal;
     int volume;
     QTimer *playTimer;
@@ -102,10 +105,10 @@ int main(int argc, char **argv)

     KUniqueApplication app;
     app.disableSessionManagement();
-
+#ifdef USE_ARTS
     // setup mcop communication
     Arts::Dispatcher dispatcher;
-
+#endif
     // start notify service
     KNotify notify;
     app.dcopClient()->setDefaultObject( "Notify" );
@@ -120,7 +123,9 @@ KNotify::KNotify()
     : QObject(), DCOPObject("Notify")
 {
     d = new KNotifyPrivate;
+#ifdef USE_ARTS
     d->soundServer = Arts::SoundServerV2::null();
+#endif
     d->globalEvents = new KConfig("knotify/eventsrc", true, false, "data");
     d->globalConfig = new KConfig("knotify.eventsrc", true, false);
     d->externalPlayerProc = 0;
@@ -136,7 +141,9 @@ KNotify::~KNotify()
 {
     reconfigure();

+#ifdef USE_ARTS
     d->playObjects.clear();
+#endif

     delete d->globalEvents;
     delete d->globalConfig;
@@ -296,7 +303,7 @@ bool KNotify::notifyBySound( const QStri
     if ( soundFile.isEmpty() || isPlaying( soundFile ) )
         return false;

-
+#ifdef USE_ARTS
     // Oh dear! we seem to have lost our connection to artsd!
     if( !external && (d->soundServer.isNull() || d->soundServer.error()) )
         connectSoundServer();
@@ -348,8 +355,9 @@ bool KNotify::notifyBySound( const QStri
             d->playTimer->start( 1000 );

         return true;
-
-    } else if(!d->externalPlayer.isEmpty()) {
+    } else
+#endif
+    if(!d->externalPlayer.isEmpty()) {
         // use an external player to play the sound
         KProcess *proc = d->externalPlayerProc;
         if (!proc)
@@ -359,7 +367,7 @@ bool KNotify::notifyBySound( const QStri
         if (proc->isRunning())
            return false; // Skip
         proc->clearArguments();
-        (*proc) << d->externalPlayer << QFile::encodeName( soundFile );
+        (*proc) << d->externalPlayer << QFile::encodeName( soundFile ); // << 
d->volume;
         proc->start(KProcess::DontCare);
         return true;
     }
@@ -490,6 +498,7 @@ bool KNotify::isGlobal(const QString &ev

 void KNotify::connectSoundServer()
 {
+#ifdef USE_ARTS
     static bool firstTime = true;

     /*
@@ -514,6 +523,7 @@ void KNotify::connectSoundServer()
         
d->playObjectFactory=Arts::Reference("global:Arts_PlayObjectFactory");

     firstTime = false;
+#endif
 }


@@ -526,6 +536,7 @@ void KNotify::setVolume( int volume )

 void KNotify::playTimeout()
 {
+#ifdef USE_ARTS
     for ( QValueList< Arts::PlayObject >::Iterator it = 
d->playObjects.begin();
           it != d->playObjects.end(); )
     {
@@ -535,10 +546,12 @@ void KNotify::playTimeout()
     }
     if ( !d->playObjects.count() )
         d->playTimer->stop();
+#endif
 }

 bool KNotify::isPlaying( const QString& soundFile ) const
 {
+#ifdef USE_ARTS
     // in local encoding, as passed to the PlayObjectFactory
     std::string filename = QFile::encodeName( soundFile ).data();

@@ -548,6 +561,6 @@ bool KNotify::isPlaying( const QString&
         if ( (*it).mediaName() == filename )
             return true;
     }
-
+#endif
     return false;
 }





More information about the kde-core-devel mailing list