From df25675d3f395c40d944acc0f83fc5b08b03d2ff Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sat, 28 Mar 2020 16:03:47 +0000 Subject: [PATCH] Resolves #707 separate DTMF tones of the same value get merged together (#712) Co-authored-by: Denny --- .../decode/p25/audio/P25P2AudioModule.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2AudioModule.java b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2AudioModule.java index de3cae04..e9d508b7 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2AudioModule.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2AudioModule.java @@ -190,8 +190,9 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat */ private void processMetadata(IAudioWithMetadata audioWithMetadata) { - if(audioWithMetadata.hasMetadata() && mIdentifierUpdateNotificationListener != null) + if(audioWithMetadata.hasMetadata()) { + //JMBE only places 1 entry in the map, but for consistency we'll process the map entry set for(Map.Entry entry: audioWithMetadata.getMetadata().entrySet()) { //Each metadata map entry contains a tone-type (key) and tone (value) @@ -203,6 +204,10 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat } } } + else + { + mToneMetadataProcessor.closeMetadata(); + } } /** @@ -243,6 +248,7 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat public class ToneMetadataProcessor { private List mToneMetadata = new ArrayList<>(); + private ToneMetadata mCurrentToneMetadata; /** * Resets or clears any accumulated call tone metadata to prepare for the next call. @@ -265,18 +271,27 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat return null; } - ToneMetadata toneMetadata = (mToneMetadata.size() > 0 ? mToneMetadata.get(mToneMetadata.size() - 1) : null); - - if(toneMetadata == null || !toneMetadata.matches(type, value)) + if(mCurrentToneMetadata != null && mCurrentToneMetadata.matches(type, value)) { - toneMetadata = new ToneMetadata(type, value); - mToneMetadata.add(toneMetadata); + mCurrentToneMetadata.incrementCount(); + } + else + { + mCurrentToneMetadata = new ToneMetadata(type, value); + mToneMetadata.add(mCurrentToneMetadata); + mCurrentToneMetadata.incrementCount(); } - toneMetadata.incrementCount(); - return P25ToneIdentifier.create(Joiner.on(",").join(mToneMetadata)); } + + /** + * Closes current tone metadata when there is no metadata for the current audio frame. + */ + public void closeMetadata() + { + mCurrentToneMetadata = null; + } } /**