diff --git a/src/main/java/io/github/dsheirer/source/tuner/channel/MultiFrequencyTunerChannelSource.java b/src/main/java/io/github/dsheirer/source/tuner/channel/MultiFrequencyTunerChannelSource.java index 95e1515e1..1bcedae9e 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/channel/MultiFrequencyTunerChannelSource.java +++ b/src/main/java/io/github/dsheirer/source/tuner/channel/MultiFrequencyTunerChannelSource.java @@ -153,13 +153,19 @@ public void start() @Override public void stop() { - mStarted = false; - - if(mTunerChannelSource != null) + //Don't perform stop sequence if we haven't been started. There can be a small window on startup where the + //channel rotation monitor can get ahead of the channel source and cause it to try to stop and rotate before + //it has even started, causing an error in the polyphase channel source. + if(mStarted) { - mTunerChannelSource.stop(); - mTunerChannelSource.removeSourceEventListener(); - mTunerChannelSource = null; + mStarted = false; + + if(mTunerChannelSource != null) + { + mTunerChannelSource.stop(); + mTunerChannelSource.removeSourceEventListener(); + mTunerChannelSource = null; + } } } diff --git a/src/main/java/io/github/dsheirer/source/tuner/channel/rotation/ChannelRotationMonitor.java b/src/main/java/io/github/dsheirer/source/tuner/channel/rotation/ChannelRotationMonitor.java index 1d43629c6..f9509a060 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/channel/rotation/ChannelRotationMonitor.java +++ b/src/main/java/io/github/dsheirer/source/tuner/channel/rotation/ChannelRotationMonitor.java @@ -68,9 +68,13 @@ public ChannelRotationMonitor(Collection activeStates, long rotationDelay mRotationDelay = rotationDelay; mUserPreferences = userPreferences; - if(mRotationDelay == 0) + if(mRotationDelay < CHANNEL_ROTATION_DELAY_MINIMUM) { - mRotationDelay = 200; + mRotationDelay = CHANNEL_ROTATION_DELAY_MINIMUM; + } + else if(mRotationDelay > CHANNEL_ROTATION_DELAY_MAXIMUM) + { + mRotationDelay = CHANNEL_ROTATION_DELAY_MAXIMUM; } } @@ -184,7 +188,7 @@ public void start() } }; - mScheduledFuture = ThreadPool.SCHEDULED.scheduleAtFixedRate(runnable, mRotationDelay, + mScheduledFuture = ThreadPool.SCHEDULED.scheduleAtFixedRate(runnable, mRotationDelay * 2, mRotationDelay / 2, TimeUnit.MILLISECONDS); } }