diff --git a/apps/ivr/IvrDialogBase.cpp b/apps/ivr/IvrDialogBase.cpp index 37e33254..8f5fff95 100644 --- a/apps/ivr/IvrDialogBase.cpp +++ b/apps/ivr/IvrDialogBase.cpp @@ -227,6 +227,13 @@ static PyObject* IvrDialogBase_flush(IvrDialogBase* self, PyObject* args) return Py_None; } +static PyObject* IvrDialogBase_queueIsEmpty(IvrDialogBase* self, PyObject* args) +{ + assert(self->p_dlg); + + return PyBool_FromLong(self->p_dlg->playlist.isEmpty()); +} + static PyObject* IvrDialogBase_mute(IvrDialogBase* self, PyObject* args) { assert(self->p_dlg); @@ -492,6 +499,9 @@ static PyMethodDef IvrDialogBase_methods[] = { {"enqueue", (PyCFunction)IvrDialogBase_enqueue, METH_VARARGS, "Add some audio to the queue (mostly IvrAudioFile)" }, + {"queueIsEmpty", (PyCFunction)IvrDialogBase_queueIsEmpty, METH_NOARGS, + "Is the audio queue empty?" + }, {"flush", (PyCFunction)IvrDialogBase_flush, METH_NOARGS, "Flush the queue" }, diff --git a/apps/mailbox/mailbox_query.py b/apps/mailbox/mailbox_query.py index 9bb52836..c5edae6d 100644 --- a/apps/mailbox/mailbox_query.py +++ b/apps/mailbox/mailbox_query.py @@ -152,8 +152,9 @@ class IvrDialog(IvrDialogBase): def onEmptyQueue(self): if self.exit: - self.bye() - self.stopSession() + if self.queueIsEmpty(): + self.bye() + self.stopSession() def onDtmf(self,key,duration): diff --git a/core/AmPlaylist.cpp b/core/AmPlaylist.cpp index 57d8cbde..e5de7c4f 100644 --- a/core/AmPlaylist.cpp +++ b/core/AmPlaylist.cpp @@ -31,8 +31,10 @@ void AmPlaylist::gotoNextItem() } updateCurrentItem(); - if(had_item && !cur_item) + if(had_item && !cur_item){ + DBG("posting AmAudioEvent::noAudio event!\n"); ev_q->postEvent(new AmAudioEvent(AmAudioEvent::noAudio)); + } } int AmPlaylist::get(unsigned int user_ts, unsigned char* buffer, unsigned int nb_samples) @@ -120,3 +122,18 @@ void AmPlaylist::close() gotoNextItem(); cur_mut.unlock(); } + +bool AmPlaylist::isEmpty() +{ + bool res(true); + + cur_mut.lock(); + items_mut.lock(); + + res = (!cur_item) && items.empty(); + + items_mut.unlock(); + cur_mut.unlock(); + + return res; +} diff --git a/core/AmPlaylist.h b/core/AmPlaylist.h index e613f67b..3054fd17 100644 --- a/core/AmPlaylist.h +++ b/core/AmPlaylist.h @@ -54,6 +54,8 @@ class AmPlaylist: public AmAudio AmPlaylist(AmEventQueue* q); ~AmPlaylist(); + bool isEmpty(); + void addToPlaylist(AmPlaylistItem* item); void addToPlayListFront(AmPlaylistItem* item); void close();