From 6edab7d31c59cbb48adf26cb85a4a9d98bebb1e2 Mon Sep 17 00:00:00 2001 From: Dennis Sheirer Date: Fri, 1 Nov 2024 04:42:56 -0400 Subject: [PATCH] #2055 MultiFrequencyTunerChannelSource Null Pointer Error On Channel Source Shutdown - different solution to resolve possible memory leak with previous solution. Also fixes P25 issue where a traffic channel that doesn't get started is returned to the traffic channel pool. --- .../channelizer/PolyphaseChannelManager.java | 9 +++++++-- .../decode/p25/P25TrafficChannelManager.java | 12 ++++++++++++ .../MultiFrequencyTunerChannelSource.java | 18 ++++++------------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/PolyphaseChannelManager.java b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/PolyphaseChannelManager.java index 9e5636da8..751422a2e 100644 --- a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/PolyphaseChannelManager.java +++ b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/PolyphaseChannelManager.java @@ -252,11 +252,16 @@ private void stopChannelSource(PolyphaseChannelSource channelSource) synchronized(mBufferDispatcher) { mChannelSources.remove(channelSource); - mPolyphaseChannelizer.removeChannel(channelSource); + + if(mPolyphaseChannelizer != null) + { + mPolyphaseChannelizer.removeChannel(channelSource); + } + mSourceEventBroadcaster.broadcast(SourceEvent.channelCountChange(getTunerChannelCount())); //If this is the last/only channel, deregister to stop the sample buffers - if(mPolyphaseChannelizer.getRegisteredChannelCount() == 0) + if(mPolyphaseChannelizer != null && mPolyphaseChannelizer.getRegisteredChannelCount() == 0) { mNativeBufferProvider.removeBufferListener(mBufferDispatcher); mBufferDispatcher.stop(); diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/P25TrafficChannelManager.java b/src/main/java/io/github/dsheirer/module/decode/p25/P25TrafficChannelManager.java index ccc480785..1c5ae213a 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/P25TrafficChannelManager.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/P25TrafficChannelManager.java @@ -1086,6 +1086,18 @@ private void requestTrafficChannelStart(Channel trafficChannel, APCO25Channel ap startChannelRequest.addPreloadDataContent(new P25FrequencyBandPreloadDataContent(mFrequencyBandMap.values())); getInterModuleEventBus().post(startChannelRequest); } + else + { + //Return the channel to the traffic channel pool since we didn't start it. + if(mManagedPhase1TrafficChannels.contains(trafficChannel)) + { + mAvailablePhase1TrafficChannelQueue.add(trafficChannel); + } + else if(mManagedPhase2TrafficChannels.contains(trafficChannel)) + { + mAvailablePhase2TrafficChannelQueue.add(trafficChannel); + } + } } /** 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 1bcedae9e..95e1515e1 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,19 +153,13 @@ public void start() @Override public void stop() { - //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) - { - mStarted = false; + mStarted = false; - if(mTunerChannelSource != null) - { - mTunerChannelSource.stop(); - mTunerChannelSource.removeSourceEventListener(); - mTunerChannelSource = null; - } + if(mTunerChannelSource != null) + { + mTunerChannelSource.stop(); + mTunerChannelSource.removeSourceEventListener(); + mTunerChannelSource = null; } }