Permalink
Browse files

Merge pull request #1570 from bobo1on1/pulsefallback

Pulsefallback
  • Loading branch information...
2 parents 7e109e4 + ad7817f commit bf20634d6149ea87ee629ac80bcdc26e1394dbb6 @bobo1on1 bobo1on1 committed Oct 15, 2012
@@ -103,6 +103,12 @@ bool CAEFactory::LoadEngine(enum AEEngine engine)
return false;
}
+ if (AE && !AE->CanInit())
+ {
+ delete AE;
+ AE = NULL;
+ }
+
return AE != NULL;
}
@@ -28,6 +28,7 @@
#include "utils/log.h"
#include "settings/Settings.h"
#include <pulse/pulseaudio.h>
+#include <pulse/simple.h>
#include "guilib/LocalizeStrings.h"
/* Static helpers */
@@ -99,6 +100,29 @@ CPulseAE::~CPulseAE()
}
+bool CPulseAE::CanInit()
+{
+ pa_simple *s;
+ pa_sample_spec ss;
+
+ ss.format = PA_SAMPLE_S16NE;
+ ss.channels = 2;
+ ss.rate = 48000;
+
+ //create a pulse client, if this returns NULL, pulseaudio isn't running
+ s = pa_simple_new(NULL, "XBMC-test", PA_STREAM_PLAYBACK, NULL,"test", &ss, NULL, NULL, NULL);
+
+ if (s)
+ {
+ pa_simple_free(s);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
bool CPulseAE::Initialize()
{
m_Volume = g_settings.m_fVolumeLevel;
@@ -42,6 +42,7 @@ class CPulseAE : public IAE
virtual ~CPulseAE();
public:
+ virtual bool CanInit();
virtual bool Initialize ();
virtual void OnSettingsChange(std::string setting);
@@ -52,6 +52,12 @@ class IAE
virtual ~IAE() {}
/**
+ * Returns true when it should be possible to initialize this engine, if it returns false
+ * CAEFactory can possibly fall back to a different one
+ */
+ virtual bool CanInit() { return true; }
+
+ /**
* Initializes the AudioEngine, called by CFactory when it is time to initialize the audio engine.
* Do not call this directly, CApplication will call this when it is ready
*/

0 comments on commit bf20634

Please sign in to comment.