diff --git a/src/main/java/io/github/dsheirer/audio/AbstractAudioModule.java b/src/main/java/io/github/dsheirer/audio/AbstractAudioModule.java index 5165a591..99e1f1c3 100644 --- a/src/main/java/io/github/dsheirer/audio/AbstractAudioModule.java +++ b/src/main/java/io/github/dsheirer/audio/AbstractAudioModule.java @@ -36,8 +36,9 @@ import org.slf4j.LoggerFactory; public abstract class AbstractAudioModule extends Module implements IAudioSegmentProvider, IdentifierUpdateListener { private final static Logger mLog = LoggerFactory.getLogger(AbstractAudioModule.class); - private static final int MAX_SEGMENT_AUDIO_SAMPLE_LENGTH = 8000 * 60 * 1; //8 kHz - 1 minute + private static final int DEFAULT_SEGMENT_AUDIO_SAMPLE_LENGTH = 60 * 8000; // 1 minute @ 8kHz + private final int mMaxSegmentAudioSampleLength; private Listener mAudioSegmentListener; protected MutableIdentifierCollection mIdentifierCollection = new MutableIdentifierCollection(); private Broadcaster mIdentifierUpdateNotificationBroadcaster = new Broadcaster<>(); @@ -49,12 +50,21 @@ public abstract class AbstractAudioModule extends Module implements IAudioSegmen /** * Constructs an abstract audio module */ - public AbstractAudioModule(AliasList aliasList) + public AbstractAudioModule(AliasList aliasList, int maxSegmentAudioSampleLength) { mAliasList = aliasList; + mMaxSegmentAudioSampleLength = maxSegmentAudioSampleLength; mIdentifierUpdateNotificationBroadcaster.addListener(mIdentifierCollection); } + /** + * Constructs an abstract audio module + */ + public AbstractAudioModule(AliasList aliasList) + { + this(aliasList, DEFAULT_SEGMENT_AUDIO_SAMPLE_LENGTH); + } + protected abstract int getTimeslot(); /** @@ -117,7 +127,7 @@ public abstract class AbstractAudioModule extends Module implements IAudioSegmen //If the current segment exceeds the max samples length, close it so that a new segment gets generated //and then link the segments together - if(mAudioSampleCount >= MAX_SEGMENT_AUDIO_SAMPLE_LENGTH) + if(mAudioSampleCount >= mMaxSegmentAudioSampleLength) { AudioSegment previous = getAudioSegment(); closeAudioSegment(); diff --git a/src/main/java/io/github/dsheirer/audio/AudioModule.java b/src/main/java/io/github/dsheirer/audio/AudioModule.java index 5d336213..f71ded9a 100644 --- a/src/main/java/io/github/dsheirer/audio/AudioModule.java +++ b/src/main/java/io/github/dsheirer/audio/AudioModule.java @@ -77,6 +77,14 @@ public class AudioModule extends AbstractAudioModule implements ISquelchStateLis private SquelchStateListener mSquelchStateListener = new SquelchStateListener(); private SquelchState mSquelchState = SquelchState.SQUELCH; + /** + * Creates an Audio Module. + */ + public AudioModule(AliasList aliasList, int maxSegmentAudioSampleLength) + { + super(aliasList, maxSegmentAudioSampleLength); + } + /** * Creates an Audio Module. */ diff --git a/src/main/java/io/github/dsheirer/channel/state/SingleChannelState.java b/src/main/java/io/github/dsheirer/channel/state/SingleChannelState.java index 9574be6e..20675e28 100644 --- a/src/main/java/io/github/dsheirer/channel/state/SingleChannelState.java +++ b/src/main/java/io/github/dsheirer/channel/state/SingleChannelState.java @@ -40,6 +40,7 @@ import io.github.dsheirer.identifier.configuration.SiteConfigurationIdentifier; import io.github.dsheirer.identifier.configuration.SystemConfigurationIdentifier; import io.github.dsheirer.identifier.decoder.ChannelStateIdentifier; import io.github.dsheirer.module.decode.config.DecodeConfiguration; +import io.github.dsheirer.module.decode.config.WithCallTimeout; import io.github.dsheirer.module.decode.event.IDecodeEvent; import io.github.dsheirer.sample.Listener; import io.github.dsheirer.source.ISourceEventListener; @@ -115,7 +116,12 @@ public class SingleChannelState extends AbstractChannelState implements IDecoder } else { - mStateMachine.setFadeTimeoutBuffer(DecodeConfiguration.DEFAULT_CALL_TIMEOUT_DELAY_SECONDS * 1000); + final DecodeConfiguration decodeConfig = channel.getDecodeConfiguration(); + final int fadeTimeoutSeconds = decodeConfig instanceof WithCallTimeout + ? ((WithCallTimeout) decodeConfig).getCallTimeout() + : DecodeConfiguration.DEFAULT_CALL_TIMEOUT_DELAY_SECONDS; + + mStateMachine.setFadeTimeoutBuffer(fadeTimeoutSeconds * 1000); } } diff --git a/src/main/java/io/github/dsheirer/gui/playlist/channel/MPT1327ConfigurationEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/channel/MPT1327ConfigurationEditor.java index 242f0694..f078a384 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/channel/MPT1327ConfigurationEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/channel/MPT1327ConfigurationEditor.java @@ -60,6 +60,9 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import static io.github.dsheirer.module.decode.config.DecodeConfiguration.CALL_TIMEOUT_MAXIMUM; +import static io.github.dsheirer.module.decode.config.DecodeConfiguration.CALL_TIMEOUT_MINIMUM; + /** * MPT-1327 channel configuration editor */ @@ -301,11 +304,11 @@ public class MPT1327ConfigurationEditor extends ChannelConfigurationEditor { if(mCallTimeoutSpinner == null) { - mCallTimeoutSpinner = new Spinner(); + mCallTimeoutSpinner = new Spinner<>(); mCallTimeoutSpinner.setDisable(true); mCallTimeoutSpinner.setTooltip(new Tooltip("Maximum call limit in seconds")); mCallTimeoutSpinner.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL); - SpinnerValueFactory svf = new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 120); + var svf = new SpinnerValueFactory.IntegerSpinnerValueFactory(CALL_TIMEOUT_MINIMUM, CALL_TIMEOUT_MAXIMUM); mCallTimeoutSpinner.setValueFactory(svf); mCallTimeoutSpinner.getValueFactory().valueProperty() .addListener((observable, oldValue, newValue) -> modifiedProperty().set(true)); diff --git a/src/main/java/io/github/dsheirer/module/decode/DecoderFactory.java b/src/main/java/io/github/dsheirer/module/decode/DecoderFactory.java index e93c5f42..7239565f 100644 --- a/src/main/java/io/github/dsheirer/module/decode/DecoderFactory.java +++ b/src/main/java/io/github/dsheirer/module/decode/DecoderFactory.java @@ -226,15 +226,19 @@ public class DecoderFactory ChannelMap channelMap = channelMapModel.getChannelMap(mptConfig.getChannelMapName()); Sync sync = mptConfig.getSync(); modules.add(new MPT1327Decoder(sync)); - modules.add(new AudioModule(aliasList)); + + final int timeout = mptConfig.getCallTimeout() * 1000; + // Set max segment audio sample length slightly above call timeout to + // not create a new segment if the processing chain finishes a bit after + // actual call timeout. + modules.add(new AudioModule(aliasList, timeout + 5000)); + SourceType sourceType = channel.getSourceConfiguration().getSourceType(); if(sourceType == SourceType.TUNER || sourceType == SourceType.TUNER_MULTIPLE_FREQUENCIES) { modules.add(new FMDemodulatorModule(FM_CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE)); } - long timeout = mptConfig.getCallTimeout() * 1000; - if(channelType == ChannelType.STANDARD) { MPT1327TrafficChannelManager trafficChannelManager = new MPT1327TrafficChannelManager(channel, channelMap); diff --git a/src/main/java/io/github/dsheirer/module/decode/config/DecodeConfiguration.java b/src/main/java/io/github/dsheirer/module/decode/config/DecodeConfiguration.java index c24e6f52..77432370 100644 --- a/src/main/java/io/github/dsheirer/module/decode/config/DecodeConfiguration.java +++ b/src/main/java/io/github/dsheirer/module/decode/config/DecodeConfiguration.java @@ -55,7 +55,7 @@ public abstract class DecodeConfiguration extends Configuration { public static final int DEFAULT_CALL_TIMEOUT_DELAY_SECONDS = 45; public static final int CALL_TIMEOUT_MINIMUM = 1; - public static final int CALL_TIMEOUT_MAXIMUM = 300; //5 minutes + public static final int CALL_TIMEOUT_MAXIMUM = 180; public static final int TRAFFIC_CHANNEL_LIMIT_DEFAULT = 3; public static final int TRAFFIC_CHANNEL_LIMIT_MINIMUM = 0; diff --git a/src/main/java/io/github/dsheirer/module/decode/config/WithCallTimeout.java b/src/main/java/io/github/dsheirer/module/decode/config/WithCallTimeout.java new file mode 100644 index 00000000..a9c36249 --- /dev/null +++ b/src/main/java/io/github/dsheirer/module/decode/config/WithCallTimeout.java @@ -0,0 +1,34 @@ +/* + * + * * ****************************************************************************** + * * Copyright (C) 2014-2020 Dennis Sheirer + * * + * * This program is free software: you can redistribute it and/or modify + * * it under the terms of the GNU General Public License as published by + * * the Free Software Foundation, either version 3 of the License, or + * * (at your option) any later version. + * * + * * This program is distributed in the hope that it will be useful, + * * but WITHOUT ANY WARRANTY; without even the implied warranty of + * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * * GNU General Public License for more details. + * * + * * You should have received a copy of the GNU General Public License + * * along with this program. If not, see + * * ***************************************************************************** + * + * + */ + +package io.github.dsheirer.module.decode.config; + +/** + * Trait of decoder configurations that support providing information about call timeout. + */ +public interface WithCallTimeout +{ + /** + * @return call timeout in seconds + */ + int getCallTimeout(); +} diff --git a/src/main/java/io/github/dsheirer/module/decode/mpt1327/DecodeConfigMPT1327.java b/src/main/java/io/github/dsheirer/module/decode/mpt1327/DecodeConfigMPT1327.java index d6cf458f..b06ccddd 100644 --- a/src/main/java/io/github/dsheirer/module/decode/mpt1327/DecodeConfigMPT1327.java +++ b/src/main/java/io/github/dsheirer/module/decode/mpt1327/DecodeConfigMPT1327.java @@ -25,9 +25,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.module.decode.DecoderType; import io.github.dsheirer.module.decode.config.DecodeConfiguration; +import io.github.dsheirer.module.decode.config.WithCallTimeout; import io.github.dsheirer.source.tuner.channel.ChannelSpecification; -public class DecodeConfigMPT1327 extends DecodeConfiguration +public class DecodeConfigMPT1327 extends DecodeConfiguration implements WithCallTimeout { private String mChannelMapName; private Sync mSync = Sync.NORMAL; @@ -74,7 +75,7 @@ public class DecodeConfigMPT1327 extends DecodeConfiguration } /** - * Sets the call timeout value in seconds ( 10 - 600 ); + * Sets the call timeout value in seconds ( 1 - 180 ); * * @param timeout */ diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/DecodeConfigP25Phase1.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/DecodeConfigP25Phase1.java index d64acb99..f7afe9ed 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/DecodeConfigP25Phase1.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/DecodeConfigP25Phase1.java @@ -32,7 +32,6 @@ public class DecodeConfigP25Phase1 extends DecodeConfiguration { private P25P1Decoder.Modulation mModulation = P25P1Decoder.Modulation.C4FM; - private int mCallTimeout = 1; private int mTrafficChannelPoolSize = TRAFFIC_CHANNEL_LIMIT_DEFAULT; private boolean mIgnoreDataCalls = false; @@ -68,28 +67,6 @@ public class DecodeConfigP25Phase1 extends DecodeConfiguration mIgnoreDataCalls = ignore; } - /** - * Note: this field is now deprecated. - * - * @return - */ - @JsonIgnore - @Deprecated - public int getCallTimeout() - { - return mCallTimeout; - } - - /** - * Sets the call timeout value in seconds ( 10 - 600 ); - * - * @param timeout - */ - @Deprecated - public void setCallTimeout(int timeout) - { - } - @JacksonXmlProperty(isAttribute = true, localName = "traffic_channel_pool_size") public int getTrafficChannelPoolSize()