Skip to content

Commit

Permalink
reduce redundancy for dtmf duration fix
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Jeske committed Nov 15, 2024
1 parent 8cb0f86 commit 65f91a8
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions pjmedia/src/pjmedia/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,19 @@ static void handle_incoming_dtmf( pjmedia_stream *stream,
event_duration = pj_ntohs(event->duration);
is_event_end = (event->e_vol & PJMEDIA_RTP_DTMF_EVENT_END_MASK) != 0;

/* Correct duration and timestamp for codecs where clock_rate
* differs from sample rate
*/
float ts_modifier = 1.0;
#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
if (stream->has_g722_mpeg_bug == PJ_TRUE) {
ts_modifier = 2;
}
#endif
if (!pj_stricmp2(&stream->si.fmt.encoding_name, "opus")) {
ts_modifier = (float)stream->codec_param.info.clock_rate / 48000;
}

/* Check if this is the same/current digit of the last packet. */
if (stream->last_dtmf != -1 &&
event->event == stream->last_dtmf &&
Expand All @@ -1813,20 +1826,6 @@ static void handle_incoming_dtmf( pjmedia_stream *stream,
* already, call it.
*/
if (stream->dtmf_event_cb && emit_event) {

/* Correct duration and timestamp for codecs where clock_rate
* differs from sample rate
*/
float ts_modifier = 1.0;
#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
if (stream->has_g722_mpeg_bug == PJ_TRUE) {
ts_modifier = 2;
}
#endif
if (!pj_stricmp2(&stream->si.fmt.encoding_name, "opus")) {
ts_modifier = (float)stream->codec_param.info.clock_rate / 48000;
}

dtmf_event.digit = digitmap[event->event];
dtmf_event.timestamp = (pj_uint32_t)(ts_modifier * timestamp->u64 /
(stream->codec_param.info.clock_rate / 1000));
Expand Down Expand Up @@ -1855,19 +1854,6 @@ static void handle_incoming_dtmf( pjmedia_stream *stream,
* the DTMF digits in the buffer.
*/
if (stream->dtmf_event_cb) {
/* Correct duration and timestamp for codecs where clock_rate
* differs from sample rate
*/
float ts_modifier = 1.0;
#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
if (stream->has_g722_mpeg_bug == PJ_TRUE) {
ts_modifier = 2;
}
#endif
if (!pj_stricmp2(&stream->si.fmt.encoding_name, "opus")) {
ts_modifier = (float)stream->codec_param.info.clock_rate / 48000;
}

dtmf_event.digit = digitmap[event->event];
dtmf_event.timestamp = (pj_uint32_t)(ts_modifier * timestamp->u64 /
(stream->codec_param.info.clock_rate / 1000));
Expand Down

0 comments on commit 65f91a8

Please sign in to comment.