Module: sems Branch: 1.2 Commit: b11ad220730983be2a91928c57967c8ee2587df6 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=b11ad220730983be2a91928c57967c8ee2587df6
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Thu Jul 1 16:12:53 2010 +0200 de03bc1 --- core/AmDtmfDetector.cpp | 32 +++++++++++++++++++++----------- core/AmDtmfDetector.h | 25 ++++++++++++++++--------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/core/AmDtmfDetector.cpp b/core/AmDtmfDetector.cpp index 678ccdd..d9d1381 100644 --- a/core/AmDtmfDetector.cpp +++ b/core/AmDtmfDetector.cpp @@ -238,19 +238,24 @@ void AmDtmfDetector::process(AmEvent *evt) evt->processed = true; } +void AmDtmfDetector::flushKey(unsigned int event_id) { + // flush the current key if it corresponds to the one with event_id + if (m_eventPending && m_current_eventid_i && event_id == m_current_eventid) { + reportEvent(); + } +} + void AmDtmfDetector::registerKeyReleased(int event, Dtmf::EventSource source, const struct timeval& start, const struct timeval& stop, - bool flush, bool has_eventid, unsigned int event_id) { // Old event has not been sent yet // push out it now - if (flush || (m_eventPending && m_currentEvent != event) || - (m_eventPending && has_eventid && m_current_eventid_i && (event_id != m_current_eventid))) - { - reportEvent(); - } + if ((m_eventPending && m_currentEvent != event) || + (m_eventPending && has_eventid && m_current_eventid_i && (event_id != m_current_eventid))) { + reportEvent(); + } m_eventPending = true; m_currentEvent = event; @@ -277,7 +282,7 @@ void AmDtmfDetector::registerKeyReleased(int event, Dtmf::EventSource source, } } -void AmDtmfDetector::registerKeyPressed(int event, Dtmf::EventSource type) +void AmDtmfDetector::registerKeyPressed(int event, Dtmf::EventSource type, bool has_eventid, unsigned int event_id) { struct timeval tm; gettimeofday(&tm, NULL); @@ -298,6 +303,11 @@ void AmDtmfDetector::registerKeyPressed(int event, Dtmf::EventSource type) if (delta_msec > 0) memcpy(&m_lastReportTime, &tm, sizeof(struct timeval)); } + + if (has_eventid) { + m_current_eventid_i = true; + m_current_eventid = event_id; + } } void AmDtmfDetector::checkTimeout() @@ -379,7 +389,7 @@ void AmRtpDtmfDetector::process(AmRtpDtmfEvent *evt) (m_currentTS_i && (evt->ts() != m_currentTS))) { // Previous event does not end correctly so send out it now... - sendPending(true); + m_keysink->flushKey(m_currentTS); // ... and reinitialize to process current event gettimeofday(&m_startTime, NULL); m_eventPending = true; @@ -388,17 +398,17 @@ void AmRtpDtmfDetector::process(AmRtpDtmfEvent *evt) m_currentTS_i = true; } } - m_keysink->registerKeyPressed(m_currentEvent, Dtmf::SOURCE_RTP); + m_keysink->registerKeyPressed(m_currentEvent, Dtmf::SOURCE_RTP, true, m_currentTS); } } -void AmRtpDtmfDetector::sendPending(bool flush) +void AmRtpDtmfDetector::sendPending() { if (m_eventPending) { struct timeval end_time; gettimeofday(&end_time, NULL); - m_keysink->registerKeyReleased(m_currentEvent, Dtmf::SOURCE_RTP, m_startTime, end_time, flush, true, m_currentTS); + m_keysink->registerKeyReleased(m_currentEvent, Dtmf::SOURCE_RTP, m_startTime, end_time, true, m_currentTS); m_eventPending = false; m_currentTS_i = false; m_lastTS = m_currentTS; diff --git a/core/AmDtmfDetector.h b/core/AmDtmfDetector.h index e9dba50..1afcdad 100644 --- a/core/AmDtmfDetector.h +++ b/core/AmDtmfDetector.h @@ -129,18 +129,26 @@ class AmKeyPressSink { * @param source which detector posted this event * @param start time when key was pressed * @param stop time when key was released - * @param flush whether key should be registered as own keypress immediately + * @param has_eventid whether event has an id + * @param event_id id of the event */ virtual void registerKeyReleased(int event, Dtmf::EventSource source, - const struct timeval& start, const struct timeval& stop, bool flush=false, + const struct timeval& start, const struct timeval& stop, bool has_eventid = false, unsigned int event_id = 0) = 0; /** * Through this method the AmDtmfDetector receives events that was * detected by specific detectors. * @param event code of key released * @param source which detector posted this event + * @param has_eventid whether event has an id + * @param event_id id of the event */ - virtual void registerKeyPressed(int event, Dtmf::EventSource source) = 0; + virtual void registerKeyPressed(int event, Dtmf::EventSource source, bool has_eventid=false, unsigned int event_id=0) = 0; + /** + * Flush (report to session) any pending key if ti matches the event id + * @param event_id ID of the event (e.g. RTP TS) + */ + virtual void flushKey(unsigned int event_id) = 0; }; /** @@ -355,7 +363,7 @@ class AmRtpDtmfDetector /** * Send out pending event */ - void sendPending(bool flush=false); + void sendPending(); public: /** @@ -423,20 +431,19 @@ class AmDtmfDetector * @param source which detector posted this event * @param start time when key was pressed * @param stop time when key was released - * @param flush whether key should be registered as own keypress immediately - * @param has_eventid whether event has an id - * @param event_id id of the event */ void registerKeyReleased(int event, Dtmf::EventSource source, const struct timeval& start, const struct timeval& stop, - bool flush=false, bool has_eventid = false, unsigned int event_id = 0); + bool has_eventid = false, unsigned int event_id = 0); /** * Through this method the AmDtmfDetector receives events that was * detected by specific detectors. * @param event code of key released * @param source which detector posted this event */ - void registerKeyPressed(int event, Dtmf::EventSource source); + void registerKeyPressed(int event, Dtmf::EventSource source, bool has_eventid=false, unsigned int event_id=0); + + void flushKey(unsigned int event_id); public: /** _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
