On 2012 Feb 17, Fri 11:48:47 Stefan Sayer wrote:
> >>> Is there any drawbacks to this approach?
> >> 
> >> I don't see any, if you don't need the audio, or in-band DTMF. The
> >> DTMF event queue of the session is protected by its mutex, so it's
> >> safe to post events there from the RTP receiver threads the same way
> >> as the media processing thread. You have your sessions in the
> >> MediaProcessor, I guess, so DTMF should be processed and passed to the
> >> applicaiton.
> > 
> > So, shall I submit a proposed patch then?
> 
> yes, please.

attached

br

Szo
diff --git a/apps/ivr/IvrDialogBase.cpp b/apps/ivr/IvrDialogBase.cpp
index 8ba91af..36c3e53 100644
--- a/apps/ivr/IvrDialogBase.cpp
+++ b/apps/ivr/IvrDialogBase.cpp
@@ -214,6 +214,46 @@ static PyObject* IvrDialogBase_unmute(IvrDialogBase* self, PyObject* args)
   return Py_None;
 }
 
+static PyObject* IvrDialogBase_enableReceiving(IvrDialogBase* self, PyObject* args)
+{
+  assert(self->p_dlg);
+
+  self->p_dlg->setReceiving(true);
+    
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
+static PyObject* IvrDialogBase_disableReceiving(IvrDialogBase* self, PyObject* args)
+{
+  assert(self->p_dlg);
+
+  self->p_dlg->setReceiving(false);
+    
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
+static PyObject* IvrDialogBase_enableDTMFReceiving(IvrDialogBase* self, PyObject* args)
+{
+  assert(self->p_dlg);
+
+  self->p_dlg->setForceDtmfReceiving(true);
+    
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
+static PyObject* IvrDialogBase_disableDTMFReceiving(IvrDialogBase* self, PyObject* args)
+{
+  assert(self->p_dlg);
+
+  self->p_dlg->setForceDtmfReceiving(false);
+    
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
 static PyObject* IvrDialogBase_remove_mediaprocessor(IvrDialogBase* self, 
 						     PyObject* args)
 {
@@ -502,6 +542,18 @@ static PyMethodDef IvrDialogBase_methods[] = {
   {"unmute", (PyCFunction)IvrDialogBase_unmute, METH_NOARGS,
    "unmute the RTP stream (send packets)"
   },
+  {"enableReceiving", (PyCFunction)IvrDialogBase_enableReceiving, METH_NOARGS,
+   "enable receiving of RTP packets"
+  },
+  {"disableReceiving", (PyCFunction)IvrDialogBase_disableReceiving, METH_NOARGS,
+   "disable receiving of RTP packets"
+  },
+  {"enableDTMFReceiving", (PyCFunction)IvrDialogBase_enableDTMFReceiving, METH_NOARGS,
+   "enable receiving of RFC-2833 DTMF packets even if RTP receiving is disabled"
+  },
+  {"disableDTMFReceiving", (PyCFunction)IvrDialogBase_disableDTMFReceiving, METH_NOARGS,
+   "disable receiving of RFC-2833 DTMF packets when RTP receiving is disabled"
+  },
   {"connectMedia", (PyCFunction)IvrDialogBase_add_mediaprocessor, METH_NOARGS,
    "enable the processing of audio and RTP"
   },
diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp
index e2edf80..1973465 100644
--- a/core/AmRtpStream.cpp
+++ b/core/AmRtpStream.cpp
@@ -657,6 +657,15 @@ void AmRtpStream::bufferPacket(AmRtpPacket* p)
   memcpy(&last_recv_time, &p->recv_time, sizeof(struct timeval));
 
   if (!receiving && !passive) {
+    if (force_receive_dtmf && local_telephone_event_pt.get() &&
+        p->payload == local_telephone_event_pt->payload_type)
+    {
+      dtmf_payload_t* dpl = (dtmf_payload_t*)p->getData();
+
+      DBG("DTMF: event=%i; e=%i; r=%i; volume=%i; duration=%i; ts=%u\n",
+          dpl->event,dpl->e,dpl->r,dpl->volume,ntohs(dpl->duration),p->timestamp);
+      session->postDtmfEvent(new AmRtpDtmfEvent(dpl, getLocalTelephoneEventRate(), p->timestamp));
+    }
     mem.freePacket(p);
     return;
   }
diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h
index 7bcfb56..dd16dbe 100644
--- a/core/AmRtpStream.h
+++ b/core/AmRtpStream.h
@@ -250,6 +250,9 @@ public:
   /** should we receive packets? if not -> drop */
   bool receiving;
 
+  /** should we receive RFC-2833-style DTMF even when receiving is disabled? */
+  bool force_receive_dtmf;
+
   /** Allocates resources for future use of RTP. */
   AmRtpStream(AmSession* _s, int _if);
 
diff --git a/core/AmSession.h b/core/AmSession.h
index acbf6ad..481fcdf 100644
--- a/core/AmSession.h
+++ b/core/AmSession.h
@@ -340,6 +340,9 @@ public:
   /** setter for rtp_str->receiving */
   void setReceiving(bool receive) { RTPStream()->receiving = receive; }
 
+  /** setter for rtp_str->force_receive_dtmf*/
+  void setForceDtmfReceiving(bool receive) { RTPStream()->force_receive_dtmf = receive; }
+
   /* ----         SIP dialog attributes                  ---- */
 
   /** Gets the Session's call ID */
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to