Work in progress.

-Started work on new channel editor channel viewer/controller
-Removed a number of unused buffer package classes
-Moved automatic frequency control to be a module and removed special
handling
-Added IUnfilteredRealBufferListener & Provider interfaces
-Completely removed the ResourceManager class
This commit is contained in:
denny
2016-01-10 18:02:04 -05:00
parent c405ddad96
commit 4be63d4b95
197 changed files with 4181 additions and 4439 deletions

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2015 Dennis Sheirer
* Copyright (C) 2015-2016 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
@@ -26,8 +26,11 @@ import message.IMessageListener;
import message.IMessageProvider;
import message.Message;
import module.decode.event.CallEvent;
import module.decode.event.CallEventModel;
import module.decode.event.ICallEventListener;
import module.decode.event.ICallEventProvider;
import module.decode.event.MessageActivityModel;
import module.decode.state.ChannelState;
import module.decode.state.DecoderState;
import module.decode.state.DecoderStateEvent;
import module.decode.state.DecoderStateEvent.Event;
@@ -42,16 +45,19 @@ import sample.Broadcaster;
import sample.Listener;
import sample.complex.ComplexBuffer;
import sample.complex.IComplexBufferListener;
import sample.real.IRealBufferListener;
import sample.real.IRealBufferProvider;
import sample.real.IFilteredRealBufferListener;
import sample.real.IFilteredRealBufferProvider;
import sample.real.IUnFilteredRealBufferListener;
import sample.real.IUnFilteredRealBufferProvider;
import sample.real.RealBuffer;
import source.ComplexSource;
import source.RealSource;
import source.Source;
import source.SourceException;
import source.tuner.TunerChannelSource;
import source.tuner.frequency.FrequencyCorrectionControl;
import source.tuner.frequency.IFrequencyCorrectionController;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.IFrequencyChangeListener;
import source.tuner.frequency.IFrequencyChangeProvider;
import audio.AudioPacket;
import audio.IAudioPacketListener;
import audio.IAudioPacketProvider;
@@ -62,6 +68,7 @@ import audio.squelch.ISquelchStateListener;
import audio.squelch.ISquelchStateProvider;
import audio.squelch.SquelchState;
import controller.ThreadPoolManager;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent;
import controller.channel.IChannelEventListener;
import controller.channel.IChannelEventProvider;
@@ -95,8 +102,10 @@ public class ProcessingChain implements IChannelEventListener
private Broadcaster<ChannelEvent> mChannelEventBroadcaster = new Broadcaster<>();
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
private Broadcaster<DecoderStateEvent> mDecoderStateEventBroadcaster = new Broadcaster<>();
private Broadcaster<FrequencyChangeEvent> mFrequencyChangeEventBroadcaster = new Broadcaster<>();
private Broadcaster<Message> mMessageBroadcaster = new Broadcaster<>();
private Broadcaster<RealBuffer> mRealBufferBroadcaster = new Broadcaster<>();
private Broadcaster<RealBuffer> mFilteredRealBufferBroadcaster = new Broadcaster<>();
private Broadcaster<RealBuffer> mUnFilteredRealBufferBroadcaster = new Broadcaster<>();
private Broadcaster<SquelchState> mSquelchStateBroadcaster = new Broadcaster<>();
// private ThreadPoolManager mThreadPoolManager;
@@ -104,12 +113,50 @@ public class ProcessingChain implements IChannelEventListener
protected Source mSource;
private List<Module> mModules = new ArrayList<>();
private IFrequencyCorrectionController mFrequencyCorrectionController;
private CallEventModel mCallEventModel;
private ChannelState mChannelState;
private MessageActivityModel mMessageActivityModel;
public ProcessingChain()
public ProcessingChain( ChannelType channelType )
{
this( new ThreadPoolManager(), channelType );
}
public ProcessingChain( ThreadPoolManager threadManager,
ChannelType channelType )
{
mThreadPoolManager = threadManager;
mChannelState = new ChannelState( mThreadPoolManager, channelType );
addModule( mChannelState );
mCallEventModel = new CallEventModel();
addCallEventListener( mCallEventModel );
}
public MessageActivityModel getMessageActivityModel()
{
return mMessageActivityModel;
}
public CallEventModel getCallEventModel()
{
return mCallEventModel;
}
public ChannelState getChannelState()
{
return mChannelState;
}
public void setMessageActivityModel( MessageActivityModel model )
{
mMessageActivityModel = model;
addMessageListener( mMessageActivityModel );
}
public void dispose()
{
stop();
@@ -121,14 +168,16 @@ public class ProcessingChain implements IChannelEventListener
mModules.clear();
mFrequencyCorrectionController = null;
mThreadPoolManager = null;
mBufferProcessingTask = null;
mAudioPacketBroadcaster.dispose();
mCallEventBroadcaster.dispose();
mChannelEventBroadcaster.dispose();
mComplexBufferBroadcaster.dispose();
mMessageBroadcaster.dispose();
mRealBufferBroadcaster.dispose();
mFilteredRealBufferBroadcaster.dispose();
mSquelchStateBroadcaster.dispose();
}
@@ -147,7 +196,7 @@ public class ProcessingChain implements IChannelEventListener
* Indicates if this processing chain is currently receiving samples from
* a source and sending those samples to the decoders.
*/
public boolean processing()
public boolean isProcessing()
{
return mRunning.get();
}
@@ -160,28 +209,6 @@ public class ProcessingChain implements IChannelEventListener
return mSource != null;
}
/**
* Indicates if one of the modules provides frequency error control.
*/
public boolean hasFrequencyCorrectionControl()
{
return mFrequencyCorrectionController != null &&
mFrequencyCorrectionController.hasFrequencyCorrectionControl();
}
/**
* Frequency correction controller. Can be null.
*/
public FrequencyCorrectionControl getFrequencyCorrectionControl()
{
if( mFrequencyCorrectionController != null )
{
return mFrequencyCorrectionController.getFrequencyCorrectionControl();
}
return null;
}
/**
* Applies a sample source to this processing chain. Processing won't
* start until the start() method is invoked.
@@ -194,7 +221,7 @@ public class ProcessingChain implements IChannelEventListener
*/
public void setSource( Source source ) throws IllegalStateException
{
if( processing() )
if( isProcessing() )
{
throw new IllegalStateException( "Processing chain is currently "
+ "processing. Invoke stop() on the processing chain before "
@@ -202,23 +229,6 @@ public class ProcessingChain implements IChannelEventListener
}
mSource = source;
/* Establish two-way communication between the tuner channel source and
* the decoder for fine tuning frequency error correction feedback from
* the decoder. The tuner channel source will also notify the frequency
* controller during frequency changes to allow the controller to reset
* frequency error tracking */
if( mSource != null &&
mSource instanceof TunerChannelSource &&
hasFrequencyCorrectionControl() )
{
TunerChannelSource channel = (TunerChannelSource)mSource;
FrequencyCorrectionControl control = getFrequencyCorrectionControl();
channel.setFrequencyChangeListener( control );
control.setFrequencyChangeListener( channel );
}
}
/**
@@ -247,24 +257,45 @@ public class ProcessingChain implements IChannelEventListener
return decoderStates;
}
/**
* Adds the list of modules to this processing chain
*/
public void addModules( List<Module> modules )
{
for( Module module: modules )
{
addModule( module );
}
}
/**
* Adds a module to the processing chain. Each module is tested for the
* interfaces that it supports and is registered or receives a listener
* to consume or produce the supported interface data type. All elements
* that are produced by any component are automatically routed to all other
* components that support the corresponding listener interface.
* and events that are produced by any module are automatically routed to
* all other components that support the corresponding listener interface.
*
* At least one module should consume complex samples and either produce
* decoded messages and/or audio, or produce decoded real sample buffers
* for all other modules to consume.
*
* @param module - processing module, demodulator or decoder
* @param module - processing module, demodulator, decoder, source, state
* machine, etc.
*/
public void addModule( Module module )
{
mModules.add( module );
registerListeners( module );
registerProviders( module );
}
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Listeners <<<<<<<<<<<<<<<<<<<<<<<<<<< */
/**
* Registers the module as a listener to each of the broadcasters that
* provide the data interface(s) supported by the module.
*/
private void registerListeners( Module module )
{
if( module instanceof IAudioPacketListener )
{
mAudioPacketBroadcaster.addListener(
@@ -295,6 +326,12 @@ public class ProcessingChain implements IChannelEventListener
((IDecoderStateEventListener)module).getDecoderStateListener() );
}
if( module instanceof IFrequencyChangeListener )
{
mFrequencyChangeEventBroadcaster.addListener(
((IFrequencyChangeListener)module).getFrequencyChangeListener());
}
if( module instanceof IMessageListener )
{
mMessageBroadcaster.addListener(
@@ -307,10 +344,10 @@ public class ProcessingChain implements IChannelEventListener
((IMetadataListener)module).getMetadataListener() );
}
if( module instanceof IRealBufferListener )
if( module instanceof IFilteredRealBufferListener )
{
mRealBufferBroadcaster.addListener(
((IRealBufferListener)module).getRealBufferListener() );
mFilteredRealBufferBroadcaster.addListener(
((IFilteredRealBufferListener)module).getFilteredRealBufferListener() );
}
if( module instanceof ISquelchStateListener )
@@ -318,8 +355,20 @@ public class ProcessingChain implements IChannelEventListener
mSquelchStateBroadcaster.addListener(
((ISquelchStateListener)module).getSquelchStateListener() );
}
/* >>>>>>>>>>>>>>>>>>> Providers <<<<<<<<<<<<<<<<<<<<<<<<< */
if( module instanceof IUnFilteredRealBufferListener )
{
mFilteredRealBufferBroadcaster.addListener(
((IUnFilteredRealBufferListener)module).getUnFilteredRealBufferListener() );
}
}
/**
* Registers the broadcaster(s) as listeners to the module for each
* provider interface that is supported by the module.
*/
private void registerProviders( Module module )
{
if( module instanceof IAudioPacketProvider )
{
((IAudioPacketProvider)module).setAudioPacketListener(
@@ -342,12 +391,13 @@ public class ProcessingChain implements IChannelEventListener
((IDecoderStateEventProvider)module).setDecoderStateListener(
mDecoderStateEventBroadcaster );
}
if( module instanceof IFrequencyCorrectionController )
{
mFrequencyCorrectionController = (IFrequencyCorrectionController)module;
}
if( module instanceof IFrequencyChangeProvider )
{
((IFrequencyChangeProvider)module).setFrequencyChangeListener(
mFrequencyChangeEventBroadcaster );
}
if( module instanceof IMessageProvider )
{
((IMessageProvider)module).addMessageListener( mMessageBroadcaster );
@@ -359,9 +409,10 @@ public class ProcessingChain implements IChannelEventListener
mMetadataBroadcaster );
}
if( module instanceof IRealBufferProvider )
if( module instanceof IFilteredRealBufferProvider )
{
((IRealBufferProvider)module).setRealBufferListener( mRealBufferBroadcaster );
((IFilteredRealBufferProvider)module)
.setFilteredRealBufferListener( mFilteredRealBufferBroadcaster );
}
if( module instanceof ISquelchStateProvider )
@@ -369,19 +420,13 @@ public class ProcessingChain implements IChannelEventListener
((ISquelchStateProvider)module).setSquelchStateListener(
mSquelchStateBroadcaster );
}
}
/**
* Adds the list of modules to this processing chain
*/
public void addModules( List<Module> modules )
{
for( Module module: modules )
if( module instanceof IUnFilteredRealBufferProvider )
{
addModule( module );
((IUnFilteredRealBufferProvider)module)
.setUnFilteredRealBufferListener( mUnFilteredRealBufferBroadcaster );
}
}
/**
* Starts processing if the chain has a valid source. Invocations on an
@@ -421,7 +466,7 @@ public class ProcessingChain implements IChannelEventListener
((ComplexSource)mSource).setListener( mComplexBufferBroadcaster );
break;
case REAL:
((RealSource)mSource).setListener( mRealBufferBroadcaster );
((RealSource)mSource).setListener( mFilteredRealBufferBroadcaster );
break;
default:
throw new IllegalArgumentException( "Unrecognized source "
@@ -448,7 +493,7 @@ public class ProcessingChain implements IChannelEventListener
}
else
{
mLog.debug( "Source is null on start()" );
mLog.error( "Source is null on start()" );
}
}
}
@@ -469,7 +514,7 @@ public class ProcessingChain implements IChannelEventListener
((ComplexSource)mSource).removeListener( mComplexBufferBroadcaster );
break;
case REAL:
((RealSource)mSource).removeListener( mRealBufferBroadcaster );
((RealSource)mSource).removeListener( mFilteredRealBufferBroadcaster );
break;
default:
throw new IllegalArgumentException( "Unrecognized source "
@@ -585,12 +630,12 @@ public class ProcessingChain implements IChannelEventListener
public void addRealBufferListener( Listener<RealBuffer> listener )
{
mRealBufferBroadcaster.addListener( listener );
mFilteredRealBufferBroadcaster.addListener( listener );
}
public void removeRealBufferListener( Listener<RealBuffer> listener )
{
mRealBufferBroadcaster.removeListener( listener );
mFilteredRealBufferBroadcaster.removeListener( listener );
}
@Override