mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import io.github.dsheirer.dsp.filter.channelizer.output.OneChannelOutputProcesso
|
||||
import io.github.dsheirer.dsp.filter.channelizer.output.TwoChannelOutputProcessor;
|
||||
import io.github.dsheirer.dsp.filter.design.FilterDesignException;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.SerializedListener;
|
||||
import io.github.dsheirer.sample.complex.ComplexSamples;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
@@ -45,7 +46,8 @@ public class PolyphaseChannelSource extends TunerChannelSource implements Listen
|
||||
{
|
||||
private Logger mLog = LoggerFactory.getLogger(PolyphaseChannelSource.class);
|
||||
private IPolyphaseChannelOutputProcessor mPolyphaseChannelOutputProcessor;
|
||||
private Listener<ComplexSamples> mSamplesListener;
|
||||
//Output processor replacement can overlap the outgoing and incoming dispatcher threads, and consumers aren't thread safe
|
||||
private final SerializedListener<ComplexSamples> mSamplesListener = new SerializedListener<>();
|
||||
private double mChannelSampleRate;
|
||||
private long mIndexCenterFrequency;
|
||||
private List<Integer> mOutputProcessorIndexes = new ArrayList<>();
|
||||
@@ -148,23 +150,20 @@ public class PolyphaseChannelSource extends TunerChannelSource implements Listen
|
||||
@Override
|
||||
public void setListener(final Listener<ComplexSamples> listener)
|
||||
{
|
||||
mSamplesListener = listener;
|
||||
mSamplesListener.setListener(listener);
|
||||
mPolyphaseChannelOutputProcessor.setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(ComplexSamples complexSamples)
|
||||
{
|
||||
if(mSamplesListener != null)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
mSamplesListener.receive(complexSamples);
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
mLog.error("Error dispatching complex samples to listener [" + mSamplesListener.getClass() + "]", t);
|
||||
}
|
||||
mSamplesListener.receive(complexSamples);
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
mLog.error("Error dispatching complex samples to listener", t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 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 <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.sample;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Delivers to a listener that isn't thread safe from producers that can overlap. Dispatcher.stop() doesn't wait for
|
||||
* an in-progress buffer, so when a producer is replaced, the outgoing dispatcher thread can still be inside the listener
|
||||
* when the incoming dispatcher thread delivers its first buffer. This class makes the incoming thread wait for the
|
||||
* outgoing thread to leave the listener, which means that the thread that replaces the producer doesn't have to wait.
|
||||
*
|
||||
* Producers should acquire no other locks before calling receive(), so that this is always the outermost lock.
|
||||
*
|
||||
* @param <T> type of element delivered to the listener
|
||||
*/
|
||||
public class SerializedListener<T> implements Listener<T>
|
||||
{
|
||||
private final ReentrantLock mLock = new ReentrantLock();
|
||||
private volatile Listener<T> mListener;
|
||||
|
||||
/**
|
||||
* Sets or changes the listener. This does not wait for a delivery that is in progress to the previous listener.
|
||||
* @param listener to receive elements, or null to ignore elements.
|
||||
*/
|
||||
public void setListener(Listener<T> listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers the element to the listener once no other thread is delivering to the listener.
|
||||
* @param t element to deliver
|
||||
*/
|
||||
@Override
|
||||
public void receive(T t)
|
||||
{
|
||||
mLock.lock();
|
||||
|
||||
try
|
||||
{
|
||||
Listener<T> listener = mListener;
|
||||
|
||||
if(listener != null)
|
||||
{
|
||||
listener.receive(t);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
mLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package io.github.dsheirer.source.tuner.channel;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.SerializedListener;
|
||||
import io.github.dsheirer.sample.complex.ComplexSamples;
|
||||
import io.github.dsheirer.source.Source;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
@@ -51,7 +52,8 @@ public class MultiFrequencyTunerChannelSource extends TunerChannelSource
|
||||
private List<Long> mLockedFrequencies = new ArrayList<>();
|
||||
private int mFrequencyListPointer = 0;
|
||||
private ChannelSpecification mChannelSpecification;
|
||||
private Listener<ComplexSamples> mComplexSamplesListener;
|
||||
//Rotating to the next source can overlap the outgoing and incoming dispatcher threads and consumers aren't thread safe
|
||||
private final SerializedListener<ComplexSamples> mComplexSamplesListener = new SerializedListener<>();
|
||||
private Listener<Heartbeat> mHeartbeatListener;
|
||||
private String mPreferredTuner;
|
||||
private AtomicBoolean mChangingChannels = new AtomicBoolean();
|
||||
@@ -285,11 +287,11 @@ public class MultiFrequencyTunerChannelSource extends TunerChannelSource
|
||||
@Override
|
||||
public void setListener(Listener<ComplexSamples> complexSamplesListener)
|
||||
{
|
||||
mComplexSamplesListener = complexSamplesListener;
|
||||
mComplexSamplesListener.setListener(complexSamplesListener);
|
||||
|
||||
if(mTunerChannelSource != null)
|
||||
{
|
||||
mTunerChannelSource.setListener(complexSamplesListener);
|
||||
mTunerChannelSource.setListener(mComplexSamplesListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user