Module: sems Branch: master Commit: 45bf224a359317baaa8f9b44600cbf66a60bdd05 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=45bf224a359317baaa8f9b44600cbf66a60bdd05
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Wed May 16 14:23:50 2012 +0200 b/f: fixes inband DTMF timestamps for internal detector --- core/AmDtmfDetector.cpp | 33 ++++++++++++++++++++++----------- core/AmDtmfDetector.h | 10 +++++----- core/AmSession.cpp | 4 ++-- core/AmSession.h | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/core/AmDtmfDetector.cpp b/core/AmDtmfDetector.cpp index c6cfaf3..489a23f 100644 --- a/core/AmDtmfDetector.cpp +++ b/core/AmDtmfDetector.cpp @@ -55,9 +55,9 @@ void AmDtmfEventQueue::processEvents() AmEventQueue::processEvents(); } -void AmDtmfEventQueue::putDtmfAudio(const unsigned char *buf, int size, int user_ts) +void AmDtmfEventQueue::putDtmfAudio(const unsigned char *buf, int size, unsigned long long system_ts) { - m_detector->putDtmfAudio(buf, size, user_ts); + m_detector->putDtmfAudio(buf, size, system_ts); } // @@ -273,8 +273,14 @@ void AmDtmfDetector::registerKeyReleased(int event, Dtmf::EventSource source, m_current_eventid = event_id; } - memcpy(&m_startTime, &start, sizeof(struct timeval)); - memcpy(&m_lastReportTime, &stop, sizeof(struct timeval)); + if(timercmp(&start,&stop,<)){ + memcpy(&m_startTime, &start, sizeof(struct timeval)); + memcpy(&m_lastReportTime, &stop, sizeof(struct timeval)); + } + else { + memcpy(&m_startTime, &stop, sizeof(struct timeval)); + memcpy(&m_lastReportTime, &start, sizeof(struct timeval)); + } switch (source) { case Dtmf::SOURCE_SIP: @@ -376,9 +382,9 @@ void AmDtmfDetector::reportEvent() m_reportLock.unlock(); } -void AmDtmfDetector::putDtmfAudio(const unsigned char *buf, int size, int user_ts) +void AmDtmfDetector::putDtmfAudio(const unsigned char *buf, int size, unsigned long long system_ts) { - m_inbandDetector->streamPut(buf, size, user_ts); + m_inbandDetector->streamPut(buf, size, system_ts); } // AmRtpDtmfDetector methods @@ -653,7 +659,8 @@ void AmSemsInbandDtmfDetector::isdn_audio_eval_dtmf_relative() if (what != m_last) { m_startTime.tv_sec = m_last_ts / SAMPLERATE; - m_startTime.tv_usec = (m_last_ts * 1000 / SAMPLERATE) % 1000; + m_startTime.tv_usec = ((m_last_ts * 10000) / (SAMPLERATE/100)) + % 1000000; } } else what = '.'; @@ -674,7 +681,7 @@ void AmSemsInbandDtmfDetector::isdn_audio_eval_dtmf_relative() { struct timeval stop; stop.tv_sec = m_last_ts / SAMPLERATE; - stop.tv_usec = (m_last_ts * 1000 / SAMPLERATE) % 1000; + stop.tv_usec = ((m_last_ts * 10000) / (SAMPLERATE/100)) % 1000000; m_keysink->registerKeyReleased(m_lastCode, Dtmf::SOURCE_INBAND, m_startTime, stop); } m_count = 0; @@ -710,9 +717,13 @@ void AmSemsInbandDtmfDetector::isdn_audio_calc_dtmf(const signed short* buf, int } } -int AmSemsInbandDtmfDetector::streamPut(const unsigned char* samples, unsigned int size, unsigned int user_ts) +int AmSemsInbandDtmfDetector::streamPut(const unsigned char* samples, unsigned int size, unsigned long long system_ts) { - isdn_audio_calc_dtmf((const signed short *)samples, size / 2, user_ts); + unsigned long long user_ts = + system_ts * ((unsigned long long)SAMPLERATE / 100) + / (WALLCLOCK_RATE / 100); + + isdn_audio_calc_dtmf((const signed short *)samples, size / 2, (unsigned int)user_ts); return size; } @@ -747,7 +758,7 @@ AmSpanDSPInbandDtmfDetector::~AmSpanDSPInbandDtmfDetector() { #endif } -int AmSpanDSPInbandDtmfDetector::streamPut(const unsigned char* samples, unsigned int size, unsigned int user_ts) { +int AmSpanDSPInbandDtmfDetector::streamPut(const unsigned char* samples, unsigned int size, unsigned long long system_ts) { dtmf_rx(rx_state, (const int16_t*) samples, size/2); return size; } diff --git a/core/AmDtmfDetector.h b/core/AmDtmfDetector.h index 88567e9..d5e764c 100644 --- a/core/AmDtmfDetector.h +++ b/core/AmDtmfDetector.h @@ -74,7 +74,7 @@ class AmDtmfEventQueue : public AmEventQueue * Reimplemented abstract method from AmEventQueue */ void processEvents(); - void putDtmfAudio(const unsigned char *, int size, int user_ts); + void putDtmfAudio(const unsigned char *, int size, unsigned long long system_ts); }; /** @@ -226,7 +226,7 @@ class AmInbandDtmfDetector /** * Entry point for audio stream */ - virtual int streamPut(const unsigned char* samples, unsigned int size, unsigned int user_ts) = 0; + virtual int streamPut(const unsigned char* samples, unsigned int size, unsigned long long system_ts) = 0; }; /** @@ -277,7 +277,7 @@ class AmSemsInbandDtmfDetector /** * Entry point for audio stream */ - int streamPut(const unsigned char* samples, unsigned int size, unsigned int user_ts); + int streamPut(const unsigned char* samples, unsigned int size, unsigned long long system_ts); }; @@ -308,7 +308,7 @@ class AmSpanDSPInbandDtmfDetector /** * Entry point for audio stream */ - int streamPut(const unsigned char* samples, unsigned int size, unsigned int user_ts); + int streamPut(const unsigned char* samples, unsigned int size, unsigned long long system_ts); }; #endif // USE_SPANDSP @@ -466,7 +466,7 @@ class AmDtmfDetector virtual ~AmDtmfDetector() {} void checkTimeout(); - void putDtmfAudio(const unsigned char *, int size, int user_ts); + void putDtmfAudio(const unsigned char *, int size, unsigned long long system_ts); void setInbandDetector(Dtmf::InbandDetectorType t, int sample_rate); friend class AmSipDtmfDetector; diff --git a/core/AmSession.cpp b/core/AmSession.cpp index c744d92..de0d8e5 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -673,9 +673,9 @@ void AmSession::processDtmfEvents() } } -void AmSession::putDtmfAudio(const unsigned char *buf, int size, int user_ts) +void AmSession::putDtmfAudio(const unsigned char *buf, int size, unsigned long long system_ts) { - m_dtmfEventQueue.putDtmfAudio(buf, size, user_ts); + m_dtmfEventQueue.putDtmfAudio(buf, size, system_ts); } void AmSession::sendDtmf(int event, unsigned int duration_ms) { diff --git a/core/AmSession.h b/core/AmSession.h index 74d131e..bf96438 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -421,7 +421,7 @@ public: void setInbandDetector(Dtmf::InbandDetectorType t); bool isDtmfDetectionEnabled() { return m_dtmfDetectionEnabled; } void setDtmfDetectionEnabled(bool e) { m_dtmfDetectionEnabled = e; } - void putDtmfAudio(const unsigned char *buf, int size, int user_ts); + void putDtmfAudio(const unsigned char *buf, int size, unsigned long long system_ts); /** * send a DTMF as RTP payload (RFC4733) _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
