Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove unneeded sound modules and cleanup the .pro file

The sound modules weren't used in webappmanager, so can be removed,
plus the references to them in the .pro file.
Also removed references to unused #defines in the .pro file.

When built with Qt5, now includes QtWebkitWidget in the pri files.

Removed reference to serviceinstaller from the device.pri file

Open-webOS-DCO-1.0-Signed-off-by: Roger Stringer <roger.stringer@palm.com>

Change-Id: I2e43da62427722e2953266e56329d1042e439886
  • Loading branch information...
commit cb164ae01334fae7eb6798603524936d251c758f 1 parent a300a29
Roger Stringer authored January 19, 2013
618  Src/sound/SoundPlayer.cpp
... ...
@@ -1,618 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#include "Common.h"
23  
-
24  
-#include "SoundPlayer.h"
25  
-
26  
-#include <map>
27  
-#include <algorithm>
28  
-#include <sys/prctl.h>
29  
-
30  
-#include "HostBase.h"
31  
-#include "SoundPlayerPool.h"
32  
-#include "Utils.h"
33  
-#include "Logging.h"
34  
-
35  
-#define TRACE_DEBUG_THIS_FILE  0
36  
-#define USE_COLOR_PRINTF       1
37  
-
38  
-#if TRACE_DEBUG_THIS_FILE
39  
-	#if USE_COLOR_PRINTF
40  
-		#define COLORESCAPE     "\033["
41  
-		#define RESETCOLOR      COLORESCAPE "0m"
42  
-		#define BOLDCOLOR       COLORESCAPE "1m"
43  
-		#define REDOVERBLACK    COLORESCAPE "1;31m"
44  
-		#define BLUEOVERBLACK   COLORESCAPE "1;34m"
45  
-		#define YELLOWOVERBLACK COLORESCAPE "1;33m"
46  
-	#else
47  
-		#define COLORESCAPE
48  
-		#define RESETCOLOR
49  
-		#define BOLDCOLOR
50  
-		#define REDOVERBLACK
51  
-		#define BLUEOVERBLACK
52  
-		#define YELLOWOVERBLACK
53  
-	#endif
54  
-	#define PRINTF(fmt, args...) printf("%s: " fmt "\n", getTimeStamp(), ## args)
55  
-	#define PRINTF_RED(fmt, args...) printf(REDOVERBLACK "%s: " fmt RESETCOLOR "\n", getTimeStamp(), ## args)
56  
-	#define PRINTF_BLUE(fmt, args...) printf(BLUEOVERBLACK "%s: " fmt RESETCOLOR "\n", getTimeStamp(), ## args)
57  
-	#define PRINTF_YELLOW(fmt, args...) printf(YELLOWOVERBLACK "%s: " fmt RESETCOLOR "\n", getTimeStamp(), ## args)
58  
-	#define PRINTF_BOLD(fmt, args...) printf(BOLDCOLOR "%s: " fmt RESETCOLOR "\n", getTimeStamp(), ## args)
59  
-
60  
-	#define DEBUG PRINTF
61  
-	#define MESSAGE PRINTF_BLUE
62  
-	#define WARNING PRINTF_YELLOW
63  
-	#define CRITICAL PRINTF_RED
64  
-
65  
-static const char * getTimeStamp()
66  
-{
67  
-	static bool sInited = false;
68  
-	static struct timespec		sLogStartSeconds = { 0 };
69  
-	static struct tm			sLogStartTime = { 0 };
70  
-	if (!sInited)
71  
-	{
72  
-		time_t now = ::time(0);
73  
-		::clock_gettime(CLOCK_MONOTONIC, &sLogStartSeconds);
74  
-		::localtime_r(&now, &sLogStartTime);
75  
-		sInited = true;
76  
-	}
77  
-	struct timespec now;
78  
-	::clock_gettime(CLOCK_MONOTONIC, &now);
79  
-	int ms = (now.tv_nsec - sLogStartSeconds.tv_nsec) / 1000000;
80  
-	int sec = sLogStartTime.tm_sec + int (now.tv_sec - sLogStartSeconds.tv_sec);
81  
-	if (ms < 0)
82  
-	{
83  
-		ms += 1000;
84  
-		--sec;
85  
-	}
86  
-	int min = sLogStartTime.tm_min + sec / 60;
87  
-	int hr = sLogStartTime.tm_hour + min / 60;
88  
-	min = min % 60;
89  
-	sec = sec % 60;
90  
-	static char sTimeStamp[128];
91  
-	::sprintf(sTimeStamp, "%02d:%02d:%02d.%03d", hr, min, sec, ms);
92  
-	return sTimeStamp;
93  
-}
94  
-
95  
-#else
96  
-	#define PRINTF(fmt, args...) (void)0
97  
-	#define PRINTF_RED(fmt, args...) (void)0
98  
-	#define PRINTF_BLUE(fmt, args...) (void)0
99  
-	#define PRINTF_YELLOW(fmt, args...) (void)0
100  
-	#define PRINTF_BOLD(fmt, args...) (void)0
101  
-
102  
-	#define DEBUG g_debug
103  
-	#define MESSAGE g_message
104  
-	#define WARNING g_warning
105  
-	#define CRITICAL g_critical
106  
-#endif
107  
-
108  
-int SoundPlayer::m_numInstances = 0;
109  
-int SoundPlayer::m_activityCount = 0;
110  
-
111  
-#ifdef BOOST_NO_EXCEPTIONS
112  
-#include <exception>
113  
-void boost::throw_exception(std::exception const&)
114  
-{ abort(); }	//this function is supposed to never return, so abort() seems appropriate.
115  
-#endif
116  
-
117  
-/**
118  
- * Constructor: register proxy listener
119  
- */
120  
-SoundPlayer::SoundPlayer()
121  
-	: m_serviceHandle(0)
122  
-	, m_retries(0)
123  
-	, m_state(eState_Init)
124  
-	, m_fakeBackupRingtoneCount(0)
125  
-	, m_timer(HostBase::instance()->masterTimer(), this, &SoundPlayer::healthCheck)
126  
-	, m_activityID(0)
127  
-{
128  
-	PRINTF_BLUE("SoundPlayer::SoundPlayer(%d)", getpid());
129  
-	m_mediaPlayerChangeListener = boost::shared_ptr<MediaPlayerChangeListener>(new SoundPlayerMediaPlayerChangeListener(this));
130  
-}
131  
-
132  
-/**
133  
- * Destructor: Stop anything we have going & disconnect proxy listener
134  
- */
135  
-SoundPlayer::~SoundPlayer()
136  
-{
137  
-	PRINTF_BLUE("SoundPlayer::~SoundPlayer(%s)", getStateName());
138  
-	if (m_state == eState_PlayPending || m_state == eState_Playing)
139  
-		stop();
140  
-
141  
-	if (m_player.get()) {
142  
-		m_player->removeMediaPlayerChangeListener(m_mediaPlayerChangeListener);
143  
-		m_player.reset((media::MediaPlayer*) 0);
144  
-	}
145  
-	
146  
-	// Important: Make sure to call this before the service handle destuction
147  
-	if (m_mediaPlayerChangeListener.get())
148  
-		m_mediaPlayerChangeListener.reset((media::MediaPlayerChangeListener*)0);
149  
-
150  
-	if (m_serviceHandle) {
151  
-		LSError lserror;
152  
-		LSErrorInit(&lserror);
153  
-		if (!LSUnregisterPalmService(m_serviceHandle, &lserror)) {
154  
-	        LSErrorPrint (&lserror, stderr);
155  
-	        LSErrorFree (&lserror);
156  
-		}
157  
-
158  
-		m_serviceHandle = 0;
159  
-	}
160  
-}
161  
-
162  
-/**
163  
- * Client request entry point
164  
- */
165  
-void SoundPlayer::play(const std::string& filePath, const std::string& streamClass, bool repeat, int duration)
166  
-{
167  
-	WARNING("SoundPlayer::play(%s): %p: filePath: %s, streamClass: %s, repeat: %d, duration: %d",
168  
-			  getStateName(), this, filePath.c_str(), streamClass.c_str(), repeat, duration);
169  
-
170  
-	if (m_state == eState_Dead)
171  
-	{
172  
-		CRITICAL("SoundPlayer::play(%s): This player can not be reused!", getStateName());
173  
-		return;
174  
-	}
175  
-
176  
-	if (m_state != eState_Init)
177  
-		stop();
178  
-
179  
-	// recycling? move state machine back
180  
-	if (m_state == eState_Finished)
181  
-		setState(eState_Connected);
182  
-
183  
-	m_filePath = filePath;
184  
-	m_streamClass = streamClass;
185  
-	m_audioStreamClass = kAudioStreamMedia;
186  
-
187  
-	if (!m_streamClass.empty())
188  
-	{
189  
-		if (m_streamClass == "ringtones")
190  
-			m_audioStreamClass = kAudioStreamRingtone;
191  
-
192  
-		else if (m_streamClass == "alarm")
193  
-			m_audioStreamClass = kAudioStreamAlarm;
194  
-
195  
-		else if (m_streamClass == "alerts")
196  
-			m_audioStreamClass = kAudioStreamAlert;
197  
-
198  
-		else if (m_streamClass == "notifications")
199  
-			m_audioStreamClass = kAudioStreamNotification;
200  
-
201  
-		else if (m_streamClass == "calendar")
202  
-			m_audioStreamClass = kAudioStreamCalendar;
203  
-
204  
-		else if (m_streamClass == "media")
205  
-			m_audioStreamClass = kAudioStreamMedia;
206  
-
207  
-		else if (m_streamClass == "voicedial")
208  
-			m_audioStreamClass = kAudioStreamVoicedial;
209  
-
210  
-		else if (m_streamClass == "flash")
211  
-			m_audioStreamClass = kAudioStreamFlash;
212  
-
213  
-		else if (m_streamClass == "navigation")
214  
-			m_audioStreamClass = kAudioStreamNavigation;
215  
-
216  
-		else if (m_streamClass == "defaultapp")
217  
-			m_audioStreamClass = kAudioStreamDefaultapp;
218  
-
219  
-		else if (m_streamClass == "feedback")
220  
-			m_audioStreamClass = kAudioStreamFeedback;
221  
-
222  
-		else
223  
-		{
224  
-			WARNING("SoundPlayer::play: unrecognized media class '%s' for '%s'. Will use media class.", streamClass.c_str(), filePath.c_str());
225  
-			m_audioStreamClass = kAudioStreamMedia;
226  
-		}
227  
-	}
228  
-
229  
-	m_repeat = repeat;
230  
-	m_duration = float(duration) / 1000.f;	// integer ms to float seconds
231  
-	checkForNextStep();
232  
-}
233  
-
234  
-/**
235  
- * Client side cancel point. Also used internally.
236  
- */
237  
-void SoundPlayer::stop()
238  
-{
239  
-	PRINTF_BLUE("SoundPlayer::stop(%s)", getStateName());
240  
-	if (m_state == eState_PlayPending || m_state == eState_Playing)
241  
-	{
242  
-		if (VERIFY(m_player))
243  
-		{
244  
-			m_player->pause();
245  
-			m_player->unload();
246  
-		}
247  
-		setState(eState_Closing);
248  
-	}
249  
-	else
250  
-	{	// not sure why we were not playing: don't take chance...
251  
-		WARNING("SoundPlayer::stop(%s): unexpected stop request. Declaring SoundPlayer object dead.", getStateName());
252  
-		setState(eState_Dead);
253  
-	}
254  
-	m_filePath.clear();
255  
-	m_streamClass.clear();
256  
-	m_lastPlayingTime = currentTime();
257  
-	m_fakeBackupRingtoneCount = 0;
258  
-	if (m_activityID)
259  
-	{
260  
-	    gchar *  request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\"}", m_activityID);
261  
-
262  
-	    LSError lserror;
263  
-	    LSErrorInit(&lserror);
264  
-	    bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityEnd", request, NULL, NULL, NULL, &lserror);
265  
-	    if (!activityStartRequestSuccess)
266  
-	    {
267  
-	        CRITICAL("SoundPlayer::stop: activity '%s' End failed", request);
268  
-	        LSErrorPrint (&lserror, stderr);
269  
-	        LSErrorFree (&lserror);
270  
-	    }
271  
-	    else
272  
-	    	DEBUG("SoundPlayer::stop: ended activity '%s'...", request);
273  
-
274  
-	    g_free(request);
275  
-	    m_activityID = 0;
276  
-	}
277  
-}
278  
-
279  
-/**
280  
- * Connect to mediaserver using lunaservice.
281  
- */
282  
-LSPalmService* SoundPlayer::connectToBus()
283  
-{
284  
-	PRINTF_BLUE("SoundPlayer::connectToBus(%s)", getStateName());
285  
-	VERIFY(m_state == eState_Connecting);
286  
-	setState(eState_Connecting);
287  
-
288  
-	if (m_serviceHandle)
289  
-		return m_serviceHandle;
290  
-
291  
-	bool result = true;
292  
-	LSError lserror;
293  
-	LSErrorInit(&lserror);
294  
-
295  
-	result = LSRegisterPalmService(NULL, &m_serviceHandle, &lserror);
296  
-	if (!result)
297  
-	{
298  
-		CRITICAL("SoundPlayer::connectToBus: Could not register SoundPlayer");
299  
-		LSErrorPrint(&lserror, stderr);
300  
-		LSErrorFree(&lserror);
301  
-		// Make next health check fail ASAP...
302  
-		m_lastPlayingTime = 0;
303  
-		return NULL;
304  
-	}
305  
-
306  
-	result = LSGmainAttachPalmService (m_serviceHandle, HostBase::instance()->mainLoop(), &lserror);
307  
-	if (!result)
308  
-	{
309  
-		CRITICAL("SoundPlayer::connectToBus: Could not attach SoundPlayer to main loop");
310  
-		LSErrorPrint(&lserror, stderr);
311  
-		LSErrorFree(&lserror);
312  
-		// Make next health check fail ASAP...
313  
-		m_lastPlayingTime = 0;
314  
-		return NULL;
315  
-	}
316  
-	return m_serviceHandle;
317  
-}
318  
-
319  
-/**
320  
- * This simply loads the media source URI and plays it.
321  
- */
322  
-void SoundPlayer::connected() {
323  
-	PRINTF_BLUE("SoundPlayer::connected(%s): loading '%s', as '%s'", getStateName(), m_filePath.c_str(), m_streamClass.c_str());
324  
-	if (VERIFY(m_state == eState_Connecting))
325  
-		setState(eState_Connected);
326  
-	checkForNextStep();
327  
-}
328  
-
329  
-/**
330  
- * Playback is moving
331  
- */
332  
-void SoundPlayer::currentTimeChanged()
333  
-{
334  
-	if (VERIFY(m_player))
335  
-	{
336  
-		PRINTF_BOLD("SoundPlayer::currentTimeChanged(%s): %f sec", getStateName(), m_player->getCurrentTime());
337  
-		if (m_state == eState_PlayPending || m_state == eState_Playing)
338  
-		{
339  
-			setState(eState_Playing);
340  
-			m_lastPlayingTime = currentTime();
341  
-			if (!m_repeat && m_duration > 0 && m_player->getCurrentTime() >= m_duration)
342  
-				stop();
343  
-		}
344  
-	}
345  
-}
346  
-
347  
-/**
348  
- * The end of the stream has been reached (i.e. we played the entire stream).
349  
- */
350  
-void SoundPlayer::eosChanged()
351  
-{
352  
-    if (VERIFY(m_player) && m_player->getEos()) {
353  
-    	PRINTF_BLUE("SoundPlayer::eosChanged(%s): EOS", getStateName());
354  
-    	if (m_state == eState_PlayPending || m_state == eState_Playing)
355  
-    	{
356  
-			if (m_repeat)
357  
-			{
358  
-				m_player->seek(0);
359  
-				m_player->play();
360  
-			}
361  
-			else
362  
-				stop();
363  
-    	}
364  
-    }
365  
-}
366  
-
367  
-/**
368  
- * The object we are playing was changed.
369  
- */
370  
-void SoundPlayer::sourceChanged()
371  
-{
372  
-	if (!VERIFY(m_player))
373  
-		return;
374  
-	PRINTF_BLUE("SoundPlayer::sourceChanged(%s): '%s'", getStateName(), m_player->getSource().c_str());
375  
-	if (m_player->getSource().empty() && m_state == eState_Closing)
376  
-	{
377  
-		setState(eState_Connected);
378  
-		checkForNextStep();
379  
-	}
380  
-}
381  
-
382  
-/**
383  
- * Errors occur asynchronously.  If an error occurs, this will be called.
384  
- */
385  
-void SoundPlayer::errorChanged()
386  
-{
387  
-	if (!VERIFY(m_player))
388  
-		return;
389  
-    if (m_player->getError() != NO_ERROR)
390  
-    {
391  
-    	CRITICAL("SoundPlayer::errorChanged(%s): %d", getStateName(), m_player->getError());
392  
-    	onError();
393  
-    }
394  
-}
395  
-
396  
-/**
397  
- * Errors occur asynchronously.  If an error occurs, this will be called.
398  
- */
399  
-void SoundPlayer::extendedErrorChanged()
400  
-{
401  
-	if (!VERIFY(m_player))
402  
-		return;
403  
-    if (!m_player->getExtendedError().empty())
404  
-    {
405  
-    	CRITICAL("SoundPlayer::extendedErrorChanged(%s): '%s'", getStateName(), m_player->getExtendedError().c_str());
406  
-    	onError();
407  
-    }
408  
-}
409  
-
410  
-/**
411  
- * In case of error, try again
412  
- */
413  
-void SoundPlayer::onError()
414  
-{
415  
-	if (VERIFY(m_player) && eState_PlayPending && m_retries++ < 3)
416  
-	{
417  
-		m_player->unload();
418  
-		m_player->load(getURI(), m_audioStreamClass);
419  
-		m_player->seek(0);
420  
-		m_player->play();
421  
-	}
422  
-}
423  
-
424  
-/**
425  
- * Set the state of the player
426  
- */
427  
-void SoundPlayer::setState(EState state)
428  
-{
429  
-	// dead is dead...
430  
-	if (m_state != eState_Dead)
431  
-	{
432  
-		if (state != m_state)
433  
-		{
434  
-			if ((state == eState_Dead || state == eState_Finished) && (m_state != eState_Dead && m_state != eState_Finished))
435  
-			{
436  
-				m_timer.stop();
437  
-				SoundPlayerPool::instance()->queueFinishedPlayer(this);
438  
-			}
439  
-		}
440  
-		m_state = state;
441  
-	}
442  
-}
443  
-
444  
-/**
445  
- * Check if we can advance the state machine by loading or playing
446  
- */
447  
-void SoundPlayer::checkForNextStep()
448  
-{
449  
-	if (m_state == eState_Init)
450  
-	{
451  
-		if (!m_filePath.empty() && VERIFY(m_player == 0))
452  
-		{
453  
-			setState(eState_Connecting);
454  
-			startTimer();
455  
-			m_player = media::MediaClient::createLunaMediaPlayer(*this);
456  
-			m_player->addMediaPlayerChangeListener(m_mediaPlayerChangeListener);
457  
-		}
458  
-	}
459  
-	else if (m_state == eState_Connected)
460  
-	{
461  
-		if (m_filePath.empty())
462  
-		{	// if we had any problem, don't recycle this player...
463  
-			if (m_retries == 0)
464  
-				setState(eState_Finished);
465  
-			else
466  
-				setState(eState_Dead);
467  
-		}
468  
-		else if (VERIFY(m_player))
469  
-		{
470  
-			setState(eState_PlayPending);
471  
-			startTimer();
472  
-			m_player->load(getURI(), m_audioStreamClass);
473  
-			m_player->play();
474  
-		}
475  
-	}
476  
-}
477  
-
478  
-/**
479  
- * Simply start the healthCheck timer with a single refresh setting
480  
- * Also start activity if necessary
481  
- */
482  
-void SoundPlayer::startTimer()
483  
-{
484  
-	if (!m_timer.running())
485  
-	{
486  
-		m_timer.start(1000, false);
487  
-		m_activityID = ++m_activityCount;
488  
-
489  
-	    gchar * request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\",\"duration_ms\":60000}", m_activityID);
490  
-
491  
-	    LSError lserror;
492  
-	    LSErrorInit(&lserror);
493  
-	    bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityStart", request, NULL, NULL, NULL, &lserror);
494  
-	    if (!activityStartRequestSuccess)
495  
-	    {
496  
-	    	CRITICAL("SoundPlayer::startTimer: activity '%s' Start failed", request);
497  
-	        LSErrorPrint (&lserror, stderr);
498  
-	        LSErrorFree (&lserror);
499  
-	    }
500  
-	    else
501  
-	    	DEBUG("SoundPlayer::startTimer: booked activity '%s'...", request);
502  
-
503  
-	    g_free(request);
504  
-	}
505  
-	m_lastPlayingTime = currentTime();
506  
-}
507  
-
508  
-static const guint64 cConnectDelay = 8000;
509  
-static const guint64 cLoadDelay = 3000;
510  
-static const guint64 cPlayDelay = 1000;
511  
-static const guint64 cCloseDelay = 2000;
512  
-
513  
-/**
514  
- * Check that we aren't stuck waiting, while loading or playing...
515  
- */
516  
-bool SoundPlayer::healthCheck()
517  
-{
518  
-	DEBUG("SoundPlayer::healthCheck(%s, %llu ms)", getStateName(), currentTime() - m_lastPlayingTime);
519  
-	if (!m_filePath.empty() &&		// we are supposed to play something
520  
-		(	(m_state == eState_Connecting && m_lastPlayingTime + cConnectDelay < currentTime()) ||	// but we can't connect, or
521  
-			(m_state == eState_PlayPending && m_lastPlayingTime + cLoadDelay < currentTime())   ||	// we can't load the file, or
522  
-			(m_state == eState_Playing && m_lastPlayingTime + cPlayDelay < currentTime())))			// we can't play the file
523  
-	{
524  
-		if (m_fakeBackupRingtoneCount == 0)
525  
-		{	// log failure, when it first happens
526  
-			CRITICAL("SoundPlayer::healthCheck(%s): can't play '%s' as %s for %llu ms", getStateName(),
527  
-					m_filePath.c_str(), m_streamClass.c_str(), currentTime() - m_lastPlayingTime);
528  
-			m_retries++;	// we failed to play. Remember this, so that we won't recycle this player.
529  
-		}
530  
-		if (m_audioStreamClass == kAudioStreamRingtone || m_audioStreamClass == kAudioStreamAlarm)
531  
-		{	// back ringtone for ringtones & alarms
532  
-			if (m_fakeBackupRingtoneCount == 0)
533  
-				WARNING("SoundPlayer::healthCheck: using backup ringtone using alert notifications!");
534  
-			// Don't use alarm & ringtone sinks, because they trigger a ringtone vibration, which we are faking here!
535  
-			if ((m_fakeBackupRingtoneCount++ % 5) < 3)
536  
-				SoundPlayerPool::instance()->playFeedback("sysmgr_notification", "palerts");	// let's hope audiod & pulse are ok!
537  
-		}
538  
-		else if (m_audioStreamClass == kAudioStreamNotification)
539  
-		{
540  
-			WARNING("SoundPlayer::healthCheck: using default notification instead!");
541  
-			stop();
542  
-			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "palerts");	// let's hope audiod & pulse are ok!
543  
-		}
544  
-		else if (m_audioStreamClass == kAudioStreamCalendar)
545  
-		{
546  
-			WARNING("SoundPlayer::healthCheck: using default notification instead!");
547  
-			stop();
548  
-			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "pcalendar");	// let's hope audiod & pulse are ok!
549  
-		}
550  
-		else if (m_audioStreamClass == kAudioStreamAlert)
551  
-		{
552  
-			WARNING("SoundPlayer::healthCheck: using default alert instead!");
553  
-			stop();
554  
-			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "palerts");	// let's hope audiod & pulse are ok!
555  
-		}
556  
-	}
557  
-	else if (m_state == eState_Closing && m_lastPlayingTime + cCloseDelay < currentTime())
558  
-	{
559  
-		WARNING("SoundPlayer::healthCheck(%s): can't close for %llu ms. Declaring SoundPlayer object dead.", getStateName(), currentTime() - m_lastPlayingTime);
560  
-		setState(eState_Dead);
561  
-	}
562  
-	else
563  
-	{
564  
-		m_fakeBackupRingtoneCount = 0;
565  
-	}
566  
-
567  
-	return true;	// return true to repeat
568  
-}
569  
-
570  
-/**
571  
- * Return URI based on file name or URI
572  
- */
573  
-string SoundPlayer::getURI()
574  
-{
575  
-	string	uri;
576  
-	if (m_filePath.size() > 0 && m_filePath[0] == '/')
577  
-		uri = "file://" + m_filePath;
578  
-	else
579  
-		uri = m_filePath;
580  
-	return uri;
581  
-}
582  
-
583  
-/**
584  
- * Name of current state for tracing purposes
585  
- */
586  
-const char * SoundPlayer::getStateName()
587  
-{
588  
-	switch (m_state)
589  
-	{
590  
-	case eState_Init:			return "Init";
591  
-	case eState_Connecting:		return "Connecting";
592  
-	case eState_Connected:		return "Connected";
593  
-	case eState_PlayPending:	return "Play Pending";
594  
-	case eState_Playing:		return "Playing";
595  
-	case eState_Closing:		return "Closing";
596  
-	case eState_Finished:		return "Finished";
597  
-	case eState_Dead:			return "Dead";
598  
-	}
599  
-	return "< ??? State ??? >";
600  
-}
601  
-
602  
-/**
603  
- * Current time in ms
604  
- */
605  
-guint64 SoundPlayer::currentTime()
606  
-{
607  
-	struct timespec now;
608  
-	::clock_gettime(CLOCK_MONOTONIC, &now);
609  
-	return guint64(now.tv_sec) * 1000ULL + guint64(now.tv_nsec) / 1000000ULL;
610  
-}
611  
-
612  
-/**
613  
- * Minor utility function
614  
- */
615  
-LSHandle * SoundPlayer::getServiceHandle()
616  
-{
617  
-	return SoundPlayerPool::instance()->m_lsHandle;
618  
-}
173  Src/sound/SoundPlayer.h
... ...
@@ -1,173 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#ifndef SOUNDPLAYER_H
23  
-#define SOUNDPLAYER_H
24  
-
25  
-#include "Common.h"
26  
-
27  
-#include <string>
28  
-#include <list>
29  
-#include <glib.h>
30  
-#include <pthread.h>
31  
-
32  
-#include "sptr.h"
33  
-
34  
-/**
35  
- * these need to be define since qemux86 still uses gcc 4.2.1 
36  
- */
37  
-#define BOOST_NO_TYPEID
38  
-#define BOOST_NO_RTTI
39  
-
40  
-#include <media/LunaConnector.h>
41  
-#include <media/MediaClient.h>
42  
-#include <media/MediaPlayer.h>
43  
-
44  
-#include "Timer.h"
45  
-
46  
-using namespace media;
47  
-using namespace boost;
48  
-using namespace std;
49  
-
50  
-/**
51  
- * Simple media playback class to demonstrate a possible way to connect up to the
52  
- * luna bus and use a MediaPlayer object.
53  
- */
54  
-class SoundPlayer : public RefCounted, public LunaConnector {
55  
-
56  
-	/*
57  
-	 * This listener merely forwards notifications to SoundPlayer object
58  
-	 * Can't use multiple inheritance, because it's refcounted via boost::shared_ptr
59  
-	 */
60  
-	class SoundPlayerMediaPlayerChangeListener : public MediaPlayerChangeListener
61  
-	{
62  
-	public:
63  
-		SoundPlayerMediaPlayerChangeListener(SoundPlayer * player) : m_soundPlayer(player) {}
64  
-
65  
-		void	disconnect()					{ m_soundPlayer = 0; }
66  
-
67  
-		virtual void currentTimeChanged()		{ if (m_soundPlayer) m_soundPlayer->currentTimeChanged(); }
68  
-		virtual void eosChanged()				{ if (m_soundPlayer) m_soundPlayer->eosChanged(); }
69  
-		virtual void sourceChanged()			{ if (m_soundPlayer) m_soundPlayer->sourceChanged(); }
70  
-		virtual void errorChanged()				{ if (m_soundPlayer) m_soundPlayer->errorChanged(); }
71  
-		virtual void extendedErrorChanged()		{ if (m_soundPlayer) m_soundPlayer->extendedErrorChanged(); }
72  
-
73  
-	private:
74  
-		SoundPlayer *	m_soundPlayer;
75  
-	};
76  
-
77  
-	enum EState
78  
-	{
79  
-		// Created, but nothing happened yet
80  
-		eState_Init,
81  
-
82  
-		// Waiting for connection
83  
-		eState_Connecting,
84  
-
85  
-		// Connected, waiting for a request
86  
-		eState_Connected,
87  
-
88  
-		// Play request sent, but not playing yet
89  
-		eState_PlayPending,
90  
-
91  
-		// Playing. Audio is flowing out...
92  
-		eState_Playing,
93  
-
94  
-		// Stop request issued. Waiting for completion
95  
-		eState_Closing,
96  
-
97  
-		// Done: we're all done successfully (you can try to reuse us)
98  
-		eState_Finished,
99  
-
100  
-		// Dead: we're finished (successful or not), and don't try to use us again!
101  
-		eState_Dead
102  
-	};
103  
-
104  
-public:
105  
-
106  
-    /**
107  
-     * Construct a player to play the media content at the given URI.
108  
-     */
109  
-	SoundPlayer();
110  
-	~SoundPlayer();
111  
-
112  
-	void 		play(const std::string& filePath, const std::string& streamClass, bool repeat, int duration);
113  
-	void 		stop();
114  
-
115  
-	bool 		dead() const { return m_state == eState_Dead; }
116  
-
117  
-	static int m_numInstances; // to keep count of number of instantiations
118  
-
119  
-protected:
120  
-
121  
-	/**
122  
-	 * LunaConnector callback methods
123  
-	 */
124  
-
125  
-    virtual LSPalmService *	connectToBus();
126  
-    virtual void 			connected();
127  
-
128  
-    /**
129  
-     * MediaPlayerChangeListener callbacks methods
130  
-     */
131  
-
132  
-	void			currentTimeChanged();
133  
-	void			eosChanged();
134  
-	void			sourceChanged();
135  
-	void			errorChanged();
136  
-	void			extendedErrorChanged();
137  
-
138  
-private:
139  
-	/**
140  
-	 * Internal implementation methods
141  
-	 */
142  
-	bool			healthCheck();
143  
-	void			checkForNextStep();
144  
-	void			setState(EState state);
145  
-	const char *	getStateName();
146  
-	guint64			currentTime();
147  
-	void			startTimer();
148  
-	string			getURI();
149  
-	void			onError();
150  
-
151  
-	LSHandle *		getServiceHandle();
152  
-
153  
-private:
154  
-    shared_ptr<MediaPlayer> m_player;
155  
-	LSPalmService*			m_serviceHandle;
156  
-	string					m_filePath;
157  
-	string					m_streamClass;
158  
-	AudioStreamClass		m_audioStreamClass;
159  
-	bool					m_repeat;
160  
-	int						m_retries;
161  
-	float					m_duration;
162  
-	EState					m_state;
163  
-	guint64					m_lastPlayingTime;
164  
-	int						m_fakeBackupRingtoneCount;
165  
-	boost::shared_ptr<MediaPlayerChangeListener>	m_mediaPlayerChangeListener;
166  
-
167  
-	Timer<SoundPlayer>		m_timer;
168  
-	int						m_activityID;
169  
-
170  
-	static int				m_activityCount;
171  
-};
172  
-
173  
-#endif /* SOUNDPLAYER_H */
46  Src/sound/SoundPlayerDummy.cpp
... ...
@@ -1,46 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#include "Common.h"
23  
-
24  
-#include "SoundPlayerDummy.h"
25  
-
26  
-int SoundPlayer::m_numInstances = 0;
27  
-
28  
-SoundPlayer::SoundPlayer()
29  
-{
30  
-    m_numInstances++;
31  
-}
32  
-
33  
-SoundPlayer::~SoundPlayer()
34  
-{
35  
-    m_numInstances--;
36  
-}
37  
-
38  
-void SoundPlayer::play(const std::string& filePath, const std::string& streamClass, bool repeat, int duration)
39  
-{
40  
-    
41  
-}
42  
-
43  
-void SoundPlayer::stop()
44  
-{
45  
-    
46  
-}
54  Src/sound/SoundPlayerDummy.h
... ...
@@ -1,54 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#ifndef SOUNDPLAYERDUMMY_H
23  
-#define SOUNDPLAYERDUMMY_H
24  
-
25  
-#include "Common.h"
26  
-
27  
-#include <string>
28  
-
29  
-#include "sptr.h"
30  
-
31  
-/**
32  
- * Simple media playback class to demonstrate a possible way to connect up to the
33  
- * luna bus and use a MediaPlayer object.
34  
- */
35  
-class SoundPlayer : public RefCounted
36  
-{
37  
-public:
38  
-
39  
-    /**
40  
-     * Construct a player to play the media content at the given URI.
41  
-     */
42  
-	SoundPlayer();
43  
-	~SoundPlayer();
44  
-
45  
-	void 		play(const std::string& filePath, const std::string& streamClass, bool repeat, int duration);
46  
-	void 		stop();
47  
-
48  
-	bool 		dead() const { return true; }
49  
-
50  
-	static int m_numInstances; // to keep count of number of instantiations
51  
-};	
52  
-
53  
-
54  
-#endif /* SOUNDPLAYERDUMMY_H */
209  Src/sound/SoundPlayerPool.cpp
... ...
@@ -1,209 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#include "Common.h"
23  
-
24  
-#include "SoundPlayerPool.h"
25  
-#include <algorithm>
26  
-#include <cjson/json.h>
27  
-
28  
-#include "HostBase.h"
29  
-#include "Preferences.h"
30  
-
31  
-static SoundPlayerPool* s_instance = 0;
32  
-static const int kMaxPooledPlayers = 0;
33  
-static const int kMaxPlayers = 5;
34  
-
35  
-SoundPlayerPool* SoundPlayerPool::instance()
36  
-{
37  
-    if (!s_instance)
38  
-		new SoundPlayerPool;
39  
-
40  
-	return s_instance;
41  
-}
42  
-
43  
-SoundPlayerPool::SoundPlayerPool()
44  
-	: m_purgeTimer(HostBase::instance()->masterTimer(), this, &SoundPlayerPool::purgeTimerFired)
45  
-{
46  
-    s_instance = this;
47  
-
48  
-	bool ret;
49  
-	LSError error;
50  
-	LSErrorInit(&error);
51  
-
52  
-	ret = LSRegister(NULL, &m_lsHandle, &error);
53  
-	if (!ret) {
54  
-		g_warning("Failed to register handler: %s", error.message);
55  
-		LSErrorFree(&error);
56  
-		return;
57  
-	}
58  
-
59  
-	ret = LSGmainAttach(m_lsHandle, HostBase::instance()->mainLoop(), &error);
60  
-	if (!ret) {
61  
-		g_warning("Failed to attach service to main loop: %s", error.message);
62  
-		LSErrorFree(&error);
63  
-		return;
64  
-	}
65  
-}
66  
-
67  
-SoundPlayerPool::~SoundPlayerPool()
68  
-{
69  
-	s_instance = 0;
70  
-	
71  
-	// no-op    
72  
-}
73  
-
74  
-sptr<SoundPlayer> SoundPlayerPool::play(const std::string& filePath,
75  
-										const std::string& streamClass,
76  
-										bool repeat, int duration)
77  
-{
78  
-	sptr<SoundPlayer> player = getPooledPlayer();
79  
-	if (!player.get()) {
80  
-		if (SoundPlayer::m_numInstances >= kMaxPlayers) {
81  
-			g_warning ("Exceeded maximum instances of sound players %d, ignoring request", kMaxPlayers);
82  
-			return 0;
83  
-            }
84  
-		
85  
-		player = new SoundPlayer;
86  
-	}
87  
-	
88  
-	// Add to list of active players
89  
-	m_activePlayers.push_back(player);
90  
-
91  
-	player->play(filePath, streamClass, repeat, duration);
92  
-
93  
-	return player;
94  
-}
95  
-
96  
-void SoundPlayerPool::stop(sptr<SoundPlayer> player)
97  
-{
98  
-    if (player.get())
99  
-        player->stop();
100  
-
101  
-	// once the player is asynchronously closed, it will add
102  
-	// itself to the pool of dormant clients
103  
-}
104  
-
105  
-void SoundPlayerPool::playFeedback(const std::string& name,
106  
-								   const std::string& sinkName)
107  
-{
108  
-	if (sinkName.empty() && !Preferences::instance()->playFeedbackSounds())
109  
-		return;
110  
-	
111  
-	bool ret;
112  
-	LSError error;
113  
-	LSErrorInit(&error);
114  
-
115  
-	if (!m_lsHandle)
116  
-		return;
117  
-
118  
-	json_object* json = json_object_new_object();
119  
-	json_object_object_add(json, "name", json_object_new_string(name.c_str()));
120  
-
121  
-	if (!sinkName.empty())
122  
-		json_object_object_add(json, "sink", json_object_new_string(sinkName.c_str()));
123  
-
124  
-	ret = LSCall(m_lsHandle, "palm://com.palm.audio/systemsounds/playFeedback",
125  
-				 json_object_to_json_string(json), NULL, NULL, NULL, &error);
126  
-	if (!ret) {
127  
-		g_warning("Failed in playFeedback call: %s", error.message);
128  
-		LSErrorFree(&error);
129  
-	}
130  
-	json_object_put(json);
131  
-}
132  
-
133  
-void SoundPlayerPool::queueFinishedPlayer(sptr<SoundPlayer> player)
134  
-{
135  
-	// Add to list of finished players
136  
-	bool foundInFinishedPlayers = false;
137  
-	for (PlayerList::const_iterator it = m_finishedPlayers.begin();
138  
-		it != m_finishedPlayers.end(); ++it) {
139  
-		if (it->get() == player.get()) {
140  
-			foundInFinishedPlayers = true;
141  
-			break;
142  
-		}
143  
-	}
144  
-
145  
-	if (!foundInFinishedPlayers)
146  
-		m_finishedPlayers.push_back(player);
147  
-
148  
-	// Remove from list of active players
149  
-	for (PlayerList::iterator it = m_activePlayers.begin(); it != m_activePlayers.end(); ++it) {
150  
-		if (it->get() == player.get()) {
151  
-			m_activePlayers.erase(it);
152  
-			break;
153  
-		}
154  
-	}
155  
-		
156  
-	if (!m_purgeTimer.running())
157  
-		m_purgeTimer.start(0);
158  
-}
159  
-
160  
-bool SoundPlayerPool::purgeTimerFired()
161  
-{
162  
-	PlayerList::iterator it;
163  
-	
164  
-	// First delete all dead players
165  
-	it = m_finishedPlayers.begin();
166  
-	while (it != m_finishedPlayers.end()) {
167  
-		
168  
-		if ((*it)->dead())
169  
-			it = m_finishedPlayers.erase(it);
170  
-		else
171  
-			++it;
172  
-	}
173  
-
174  
-	int count = m_finishedPlayers.size();
175  
-	it = m_finishedPlayers.begin();
176  
-	while (it != m_finishedPlayers.end()) {
177  
-
178  
-		if (count <= kMaxPooledPlayers)
179  
-			break;
180  
-
181  
-		it = m_finishedPlayers.erase(it);
182  
-	}
183  
-	
184  
-    return false;
185  
-}
186  
-
187  
-sptr<SoundPlayer> SoundPlayerPool::getPooledPlayer()
188  
-{
189  
-/*	
190  
-	PlayerList::iterator it = m_finishedPlayers.begin();
191  
-	while (it != m_finishedPlayers.end()) {
192  
-
193  
-		sptr<SoundPlayer> player = (*it);
194  
-		// explicitly remove from dormant set
195  
-		it = m_finishedPlayers.erase(it);
196  
-
197  
-		if (player->dead())
198  
-			continue;
199  
-
200  
-		return player;
201  
-	}
202  
-
203  
-	return 0;
204  
-*/
205  
-
206  
-	// No pooling: mediaserver cannot handle back to back playbacks
207  
-	// on the same client very well
208  
-	return 0;
209  
-}
74  Src/sound/SoundPlayerPool.h
... ...
@@ -1,74 +0,0 @@
1  
-/* @@@LICENSE
2  
-*
3  
-*      Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4  
-*
5  
-* Licensed under the Apache License, Version 2.0 (the "License");
6  
-* you may not use this file except in compliance with the License.
7  
-* You may obtain a copy of the License at
8  
-*
9  
-* http://www.apache.org/licenses/LICENSE-2.0
10  
-*
11  
-* Unless required by applicable law or agreed to in writing, software
12  
-* distributed under the License is distributed on an "AS IS" BASIS,
13  
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  
-* See the License for the specific language governing permissions and
15  
-* limitations under the License.
16  
-*
17  
-* LICENSE@@@ */
18  
-
19  
-
20  
-
21  
-
22  
-#ifndef SOUNDPLAYERPOOL_H
23  
-#define SOUNDPLAYERPOOL_H
24  
-
25  
-#include "Common.h"
26  
-
27  
-#include <list>
28  
-#include <string>
29  
-#include <lunaservice.h>
30  
-
31  
-#include "sptr.h"
32  
-#include "Timer.h"
33  
-
34  
-#if defined(TARGET_DESKTOP) || defined(TARGET_EMULATOR)
35  
-#include "SoundPlayerDummy.h"
36  
-#else
37  
-#include "SoundPlayer.h"
38  
-#endif
39  
-
40  
-class SoundPlayerPool
41  
-{
42  
-public:
43  
-
44  
-	static SoundPlayerPool* instance();
45  
-
46  
-	sptr<SoundPlayer> play(const std::string& filePath,
47  
-						   const std::string& streamClass,
48  
-						   bool repeat, int duration);
49  
-	void stop(sptr<SoundPlayer> player);
50  
-
51  
-	void playFeedback(const std::string& name, const std::string& sinkName=std::string());
52  
-
53  
-private:
54  
-
55  
-	SoundPlayerPool();
56  
-	~SoundPlayerPool();
57  
-
58  
-	void queueFinishedPlayer(sptr<SoundPlayer> player);
59  
-	bool purgeTimerFired();