Index: mozilla/widget/src/gtk2/nsSound.cpp =================================================================== --- mozilla.orig/widget/src/gtk2/nsSound.cpp 2006-07-27 21:24:12.000000000 +0200 +++ mozilla/widget/src/gtk2/nsSound.cpp 2006-07-27 21:40:46.000000000 +0200 @@ -51,9 +51,15 @@ #include "nsNetUtil.h" #include "nsCOMPtr.h" +#include #include +#include +#include +#include #include +#include + #include /* used with esd_open_sound */ static int esdref = -1; @@ -105,8 +111,12 @@ */ if (mInited) return NS_OK; - if (elib) - return NS_OK; + + if(getenv("MOZILLA_AUDIO_HANDLER")) + { + mInited = PR_TRUE; + return NS_OK; + } EsdOpenSoundType EsdOpenSound; @@ -161,6 +171,57 @@ return aStatus; } + char *audio_handler=getenv("MOZILLA_AUDIO_HANDLER"); + if(audio_handler) + { + char err[1024]; + +#define BACKGROUND_AUDIO 1 +#if BACKGROUND_AUDIO + // fork to play audio in background + pid_t p=fork(); + if(p<0) + { + // a fork error? something must be really wrong in your unix + snprintf(err, sizeof(err), "could not fork : %s", strerror(errno)); + NS_WARNING(err); + return NS_ERROR_FAILURE; + } + if(p>0) + { + // reap some old children + typedef std::set childs_t; + static childs_t childs; + childs_t childs_=childs; + for(childs_t::iterator i=childs_.begin(); i!=childs_.end(); ++i) + if(waitpid(*i, NULL, WNOHANG) == *i) + childs.erase(*i); + + childs.insert(p); // add new child + return NS_OK; + } +#endif + + FILE *f=popen(audio_handler, "w"); + if(f) + { + fwrite(data, 1, dataLen, f); + pclose(f); +#if BACKGROUND_AUDIO + _exit(0); // abort the child process +#endif + return NS_OK; + } + snprintf(err, sizeof(err), "could not issue '%s' : %s", audio_handler, strerror(errno)); + NS_WARNING(err); +#if BACKGROUND_AUDIO + _exit(0); // abort the child process +#endif + return NS_ERROR_FAILURE; + } + +#undef BACKGROUND_AUDIO + int fd, mask = 0; unsigned long samples_per_sec=0, avg_bytes_per_sec=0; unsigned long rate=0; @@ -285,7 +346,7 @@ if (!mInited) Init(); - if (!elib) + if (!mInited) return NS_ERROR_FAILURE; nsCOMPtr loader;