--- a/mpd2src/mpd2sc.cpp
+++ b/mpd2src/mpd2sc.cpp
@@ -270,6 +270,9 @@
void PcmSender::Play()
{
+ if (m_audio)
+ m_audio->open();
+
iMutex.Wait();
iPaused = false;
iLastTimeUs = 0;
@@ -280,6 +283,9 @@
void PcmSender::Stop()
{
+ if (m_audio)
+ m_audio->close();
+
iMutex.Wait();
iPaused = true;
iMutex.Signal();
@@ -353,43 +359,27 @@
ssize_t nread = 0;
const unsigned char *cp = m_audio->data((size_t)iPacketBytes, nread);
- // If streaming was stopped still read the pipe. Assume, that receiving
- // less or no data from the pipe means no further audio data will follow.
- // This way, we can set the halt flag in the audio message to indicate
- // that the stream of audio has completed.
- bool eos = iPaused && ((nread == -1) || (nread < iPacketBytes));
-
- if ((nread > 0) && ((size_t)nread < iPacketBytes))
- LOGDEB("PcmSender::TimerExpired: requested " << iPacketBytes
- << " bytes, read " << nread << " bytes" << endl);
- if (eos) {
- LOGDEB("PcmSender::TimerExpired: EOS, nread=" << nread << endl);
- }
-
- if (cp == 0) {
- static bool sigsent = false;
- if (!sigsent) {
- LOGDEB("PcmSender::TimerExpired: killing myself\n");
- kill(getpid(), SIGUSR1);
- sigsent = true;
- }
- } else if (nread > 0) {
+ if (nread > 0) {
+ if ((size_t)nread < iPacketBytes) {
+ LOGDEB("PcmSender::TimerExpired: requested " << iPacketBytes
+ << " bytes, read " << nread << " bytes" << endl);
+ }
#ifdef HAVE_SENDAUDIO_PAUSE_FLAG
- iDriver->SendAudio(cp, iPacketBytes, eos || g_quitrequest);
+ iDriver->SendAudio(cp, iPacketBytes, iPaused || g_quitrequest);
#else
iDriver->SendAudio(cp, iPacketBytes);
#endif
- } else if (nread == -1 && eos) {
+ } else if (iPaused) {
// The audio stream was paused and no data could be read from the
// audio source anymore. To notify the receivers, send an empty audio
// message with the halt flag set.
#ifdef HAVE_SENDAUDIO_PAUSE_FLAG
LOGDEB("PcmSender::Send empty audio message\n");
- iDriver->SendAudio(cp, 0, eos);
+ iDriver->SendAudio(cp, 0, iPaused || g_quitrequest);
#endif
}
- if (!eos && !g_quitrequest) {
+ if (!iPaused && !g_quitrequest) {
TUint64 now = OsTimeInUs(iEnv.OsCtx());
if (!iPaced) {
@@ -450,7 +440,7 @@
iLastTimeUs = now;
}
} else {
- LOGDEB("PcmSender::TimerExpired: Stop firing\n");
+ LOGDEB("PcmSender::TimerExpired: Sender is paused. Stop firing\n");
}
iMutex.Signal();