Merge pull request #94 from DSheirer/#66_remove_loggers_and_recorders_between_channel_restarts

#66 remove loggers and recorders between channel restarts
This commit is contained in:
Denny Sheirer
2017-01-08 05:28:16 -05:00
committed by GitHub
3 changed files with 777 additions and 594 deletions

View File

@@ -207,9 +207,18 @@ public class ChannelProcessingManager implements ChannelEventListener
MessageActivityModel messageModel = new MessageActivityModel(messageFilter); MessageActivityModel messageModel = new MessageActivityModel(messageFilter);
processingChain.setMessageActivityModel(messageModel); processingChain.setMessageActivityModel(messageModel);
/* Inject channel metadata that will be inserted into audio packets
* for the recorder manager and streaming */
processingChain.broadcast(
new Metadata(MetadataType.SYSTEM, channel.getSystem()));
processingChain.broadcast(
new Metadata(MetadataType.SITE_ID, channel.getSite()));
processingChain.broadcast(
new Metadata(MetadataType.CHANNEL_NAME, channel.getName()));
}
/* Setup event logging */ /* Setup event logging */
List<Module> loggers = mEventLogManager.getLoggers( List<Module> loggers = mEventLogManager.getLoggers(channel.getEventLogConfiguration(), channel.getName());
channel.getEventLogConfiguration(), channel.getName());
if (!loggers.isEmpty()) if (!loggers.isEmpty())
{ {
@@ -222,32 +231,18 @@ public class ChannelProcessingManager implements ChannelEventListener
if (!recorders.isEmpty()) if (!recorders.isEmpty())
{ {
/* Add baseband recorder */ /* Add baseband recorder */
if ((recorders.contains(RecorderType.BASEBAND) && if ((recorders.contains(RecorderType.BASEBAND) && channel.getChannelType() == ChannelType.STANDARD))
channel.getChannelType() == ChannelType.STANDARD))
{ {
processingChain.addModule(mRecorderManager.getBasebandRecorder( processingChain.addModule(mRecorderManager.getBasebandRecorder(channel.toString()));
channel.toString()));
} }
/* Add traffic channel baseband recorder */ /* Add traffic channel baseband recorder */
if (recorders.contains(RecorderType.TRAFFIC_BASEBAND) && if (recorders.contains(RecorderType.TRAFFIC_BASEBAND) && channel.getChannelType() == ChannelType.TRAFFIC)
channel.getChannelType() == ChannelType.TRAFFIC)
{ {
processingChain.addModule(mRecorderManager processingChain.addModule(mRecorderManager.getBasebandRecorder(channel.toString()));
.getBasebandRecorder(channel.toString()));
} }
} }
/* Inject channel metadata that will be inserted into audio packets
* for the recorder manager and streaming */
processingChain.broadcast(
new Metadata(MetadataType.SYSTEM, channel.getSystem()));
processingChain.broadcast(
new Metadata(MetadataType.SITE_ID, channel.getSite()));
processingChain.broadcast(
new Metadata(MetadataType.CHANNEL_NAME, channel.getName()));
}
processingChain.setSource(source); processingChain.setSource(source);
if (event instanceof TrafficChannelEvent) if (event instanceof TrafficChannelEvent)
@@ -275,9 +270,14 @@ public class ChannelProcessingManager implements ChannelEventListener
if (mProcessingChains.containsKey(channel.getChannelID())) if (mProcessingChains.containsKey(channel.getChannelID()))
{ {
ProcessingChain chain = mProcessingChains.get(channel.getChannelID()); ProcessingChain processingChain = mProcessingChains.get(channel.getChannelID());
processingChain.stop();
processingChain.removeEventLoggingModules();
processingChain.removeRecordingModules();
chain.stop();
mChannelModel.broadcast(new ChannelEvent(channel, Event.NOTIFICATION_PROCESSING_STOP)); mChannelModel.broadcast(new ChannelEvent(channel, Event.NOTIFICATION_PROCESSING_STOP));
@@ -285,7 +285,7 @@ public class ChannelProcessingManager implements ChannelEventListener
{ {
mProcessingChains.remove(channel.getChannelID()); mProcessingChains.remove(channel.getChannelID());
chain.dispose(); processingChain.dispose();
} }
} }
} }

View File

@@ -17,12 +17,20 @@
******************************************************************************/ ******************************************************************************/
package module; package module;
import java.util.ArrayList; import audio.AudioPacket;
import java.util.List; import audio.IAudioPacketListener;
import java.util.concurrent.Executors; import audio.IAudioPacketProvider;
import java.util.concurrent.ScheduledExecutorService; import audio.metadata.IMetadataListener;
import java.util.concurrent.atomic.AtomicBoolean; import audio.metadata.IMetadataProvider;
import audio.metadata.Metadata;
import audio.squelch.ISquelchStateListener;
import audio.squelch.ISquelchStateProvider;
import audio.squelch.SquelchState;
import controller.NamingThreadFactory;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent;
import controller.channel.IChannelEventListener;
import controller.channel.IChannelEventProvider;
import message.IMessageListener; import message.IMessageListener;
import message.IMessageProvider; import message.IMessageProvider;
import message.Message; import message.Message;
@@ -38,10 +46,11 @@ import module.decode.state.DecoderStateEvent.Event;
import module.decode.state.IDecoderStateEventListener; import module.decode.state.IDecoderStateEventListener;
import module.decode.state.IDecoderStateEventProvider; import module.decode.state.IDecoderStateEventProvider;
import module.decode.state.State; import module.decode.state.State;
import module.log.EventLogger;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import record.wave.ComplexBufferWaveRecorder;
import record.wave.RealBufferWaveRecorder;
import sample.Broadcaster; import sample.Broadcaster;
import sample.Listener; import sample.Listener;
import sample.complex.ComplexBuffer; import sample.complex.ComplexBuffer;
@@ -59,20 +68,12 @@ import source.tuner.TunerChannelSource;
import source.tuner.frequency.FrequencyChangeEvent; import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.IFrequencyChangeListener; import source.tuner.frequency.IFrequencyChangeListener;
import source.tuner.frequency.IFrequencyChangeProvider; import source.tuner.frequency.IFrequencyChangeProvider;
import audio.AudioPacket;
import audio.IAudioPacketListener; import java.util.ArrayList;
import audio.IAudioPacketProvider; import java.util.List;
import audio.metadata.IMetadataListener; import java.util.concurrent.Executors;
import audio.metadata.IMetadataProvider; import java.util.concurrent.ScheduledExecutorService;
import audio.metadata.Metadata; import java.util.concurrent.atomic.AtomicBoolean;
import audio.squelch.ISquelchStateListener;
import audio.squelch.ISquelchStateProvider;
import audio.squelch.SquelchState;
import controller.NamingThreadFactory;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent;
import controller.channel.IChannelEventListener;
import controller.channel.IChannelEventProvider;
/** /**
* Processing chain provides a framework for connecting a complex or real sample * Processing chain provides a framework for connecting a complex or real sample
@@ -94,7 +95,7 @@ import controller.channel.IChannelEventProvider;
*/ */
public class ProcessingChain implements IChannelEventListener public class ProcessingChain implements IChannelEventListener
{ {
private final static Logger mLog = LoggerFactory.getLogger( ProcessingChain.class ); private final static Logger mLog = LoggerFactory.getLogger(ProcessingChain.class);
private Broadcaster<AudioPacket> mAudioPacketBroadcaster = new Broadcaster<>(); private Broadcaster<AudioPacket> mAudioPacketBroadcaster = new Broadcaster<>();
private Broadcaster<Metadata> mMetadataBroadcaster = new Broadcaster<>(); private Broadcaster<Metadata> mMetadataBroadcaster = new Broadcaster<>();
@@ -124,15 +125,15 @@ public class ProcessingChain implements IChannelEventListener
* @param name for thread pool naming each thread * @param name for thread pool naming each thread
* @param channelType * @param channelType
*/ */
public ProcessingChain( String name, ChannelType channelType ) public ProcessingChain(String name, ChannelType channelType)
{ {
mName = name; mName = name;
mChannelState = new ChannelState( channelType ); mChannelState = new ChannelState(channelType);
addModule( mChannelState ); addModule(mChannelState);
mCallEventModel = new CallEventModel(); mCallEventModel = new CallEventModel();
addCallEventListener( mCallEventModel ); addCallEventListener(mCallEventModel);
} }
public CallEventModel getCallEventModel() public CallEventModel getCallEventModel()
@@ -150,18 +151,18 @@ public class ProcessingChain implements IChannelEventListener
return mMessageActivityModel; return mMessageActivityModel;
} }
public void setMessageActivityModel( MessageActivityModel model ) public void setMessageActivityModel(MessageActivityModel model)
{ {
mMessageActivityModel = model; mMessageActivityModel = model;
addMessageListener( mMessageActivityModel ); addMessageListener(mMessageActivityModel);
} }
public void dispose() public void dispose()
{ {
stop(); stop();
for( Module module: mModules ) for(Module module : mModules)
{ {
module.dispose(); module.dispose();
} }
@@ -179,7 +180,7 @@ public class ProcessingChain implements IChannelEventListener
mFilteredRealBufferBroadcaster.dispose(); mFilteredRealBufferBroadcaster.dispose();
mSquelchStateBroadcaster.dispose(); mSquelchStateBroadcaster.dispose();
if( mScheduledExecutorService != null ) if(mScheduledExecutorService != null)
{ {
mScheduledExecutorService.shutdownNow(); mScheduledExecutorService.shutdownNow();
} }
@@ -188,11 +189,11 @@ public class ProcessingChain implements IChannelEventListener
/** /**
* Broadcasts the metadata to any registered listeners * Broadcasts the metadata to any registered listeners
*/ */
public void broadcast( Metadata metadata ) public void broadcast(Metadata metadata)
{ {
if( mMetadataBroadcaster != null ) if(mMetadataBroadcaster != null)
{ {
mMetadataBroadcaster.broadcast( metadata ); mMetadataBroadcaster.broadcast(metadata);
} }
} }
@@ -218,18 +219,17 @@ public class ProcessingChain implements IChannelEventListener
* start until the start() method is invoked. * start until the start() method is invoked.
* *
* @param source - real or complex sample source * @param source - real or complex sample source
*
* @throws IllegalStateException if the processing chain is currently * @throws IllegalStateException if the processing chain is currently
* processing with another source. Invoke stop() before applying a new * processing with another source. Invoke stop() before applying a new
* source. * source.
*/ */
public void setSource( Source source ) throws IllegalStateException public void setSource(Source source) throws IllegalStateException
{ {
if( isProcessing() ) if(isProcessing())
{ {
throw new IllegalStateException( "Processing chain is currently " throw new IllegalStateException("Processing chain is currently "
+ "processing. Invoke stop() on the processing chain before " + "processing. Invoke stop() on the processing chain before "
+ "applying a new sample source" ); + "applying a new sample source");
} }
mSource = source; mSource = source;
@@ -250,11 +250,11 @@ public class ProcessingChain implements IChannelEventListener
{ {
List<DecoderState> decoderStates = new ArrayList<>(); List<DecoderState> decoderStates = new ArrayList<>();
for( Module module: mModules ) for(Module module : mModules)
{ {
if( module instanceof DecoderState ) if(module instanceof DecoderState)
{ {
decoderStates.add( (DecoderState)module ); decoderStates.add((DecoderState) module);
} }
} }
@@ -264,11 +264,11 @@ public class ProcessingChain implements IChannelEventListener
/** /**
* Adds the list of modules to this processing chain * Adds the list of modules to this processing chain
*/ */
public void addModules( List<Module> modules ) public void addModules(List<Module> modules)
{ {
for( Module module: modules ) for(Module module : modules)
{ {
addModule( module ); addModule(module);
} }
} }
@@ -286,84 +286,167 @@ public class ProcessingChain implements IChannelEventListener
* @param module - processing module, demodulator, decoder, source, state * @param module - processing module, demodulator, decoder, source, state
* machine, etc. * machine, etc.
*/ */
public void addModule( Module module ) public void addModule(Module module)
{ {
mModules.add( module ); mModules.add(module);
registerListeners( module ); registerListeners(module);
registerProviders( module ); registerProviders(module);
}
/**
* Removes the module from the processing chain and deregisters the module as a listener and
* as a provider
*/
public void removeModule(Module module)
{
unregisterListeners(module);
unregisterProviders(module);
mModules.remove(module);
} }
/** /**
* Registers the module as a listener to each of the broadcasters that * Registers the module as a listener to each of the broadcasters that
* provide the data interface(s) supported by the module. * provide the data interface(s) supported by the module.
*/ */
private void registerListeners( Module module ) private void registerListeners(Module module)
{ {
if( module instanceof IAudioPacketListener ) if(module instanceof IAudioPacketListener)
{ {
mAudioPacketBroadcaster.addListener( mAudioPacketBroadcaster.addListener(
((IAudioPacketListener)module).getAudioPacketListener() ); ((IAudioPacketListener) module).getAudioPacketListener());
} }
if( module instanceof ICallEventListener ) if(module instanceof ICallEventListener)
{ {
mCallEventBroadcaster.addListener( mCallEventBroadcaster.addListener(
((ICallEventListener)module).getCallEventListener() ); ((ICallEventListener) module).getCallEventListener());
} }
if( module instanceof IChannelEventListener ) if(module instanceof IChannelEventListener)
{ {
mChannelEventBroadcaster.addListener( mChannelEventBroadcaster.addListener(
((IChannelEventListener)module).getChannelEventListener() ); ((IChannelEventListener) module).getChannelEventListener());
} }
if( module instanceof IComplexBufferListener ) if(module instanceof IComplexBufferListener)
{ {
mComplexBufferBroadcaster.addListener( mComplexBufferBroadcaster.addListener(
((IComplexBufferListener)module).getComplexBufferListener() ); ((IComplexBufferListener) module).getComplexBufferListener());
} }
if( module instanceof IDecoderStateEventListener ) if(module instanceof IDecoderStateEventListener)
{ {
mDecoderStateEventBroadcaster.addListener( mDecoderStateEventBroadcaster.addListener(
((IDecoderStateEventListener)module).getDecoderStateListener() ); ((IDecoderStateEventListener) module).getDecoderStateListener());
} }
if( module instanceof IFrequencyChangeListener ) if(module instanceof IFrequencyChangeListener)
{ {
mFrequencyChangeEventBroadcaster.addListener( mFrequencyChangeEventBroadcaster.addListener(
((IFrequencyChangeListener)module).getFrequencyChangeListener()); ((IFrequencyChangeListener) module).getFrequencyChangeListener());
} }
if( module instanceof IMessageListener ) if(module instanceof IMessageListener)
{ {
mMessageBroadcaster.addListener( mMessageBroadcaster.addListener(
((IMessageListener)module).getMessageListener() ); ((IMessageListener) module).getMessageListener());
} }
if( module instanceof IMetadataListener ) if(module instanceof IMetadataListener)
{ {
mMetadataBroadcaster.addListener( mMetadataBroadcaster.addListener(
((IMetadataListener)module).getMetadataListener() ); ((IMetadataListener) module).getMetadataListener());
} }
if( module instanceof IFilteredRealBufferListener ) if(module instanceof IFilteredRealBufferListener)
{ {
mFilteredRealBufferBroadcaster.addListener( mFilteredRealBufferBroadcaster.addListener(
((IFilteredRealBufferListener)module).getFilteredRealBufferListener() ); ((IFilteredRealBufferListener) module).getFilteredRealBufferListener());
} }
if( module instanceof ISquelchStateListener ) if(module instanceof ISquelchStateListener)
{ {
mSquelchStateBroadcaster.addListener( mSquelchStateBroadcaster.addListener(
((ISquelchStateListener)module).getSquelchStateListener() ); ((ISquelchStateListener) module).getSquelchStateListener());
} }
if( module instanceof IUnFilteredRealBufferListener ) if(module instanceof IUnFilteredRealBufferListener)
{ {
mUnFilteredRealBufferBroadcaster.addListener( mUnFilteredRealBufferBroadcaster.addListener(
((IUnFilteredRealBufferListener)module).getUnFilteredRealBufferListener() ); ((IUnFilteredRealBufferListener) module).getUnFilteredRealBufferListener());
}
}
/**
* Registers the module as a listener to each of the broadcasters that
* provide the data interface(s) supported by the module.
*/
private void unregisterListeners(Module module)
{
if(module instanceof IAudioPacketListener)
{
mAudioPacketBroadcaster.removeListener(
((IAudioPacketListener) module).getAudioPacketListener());
}
if(module instanceof ICallEventListener)
{
mCallEventBroadcaster.removeListener(
((ICallEventListener) module).getCallEventListener());
}
if(module instanceof IChannelEventListener)
{
mChannelEventBroadcaster.removeListener(
((IChannelEventListener) module).getChannelEventListener());
}
if(module instanceof IComplexBufferListener)
{
mComplexBufferBroadcaster.removeListener(
((IComplexBufferListener) module).getComplexBufferListener());
}
if(module instanceof IDecoderStateEventListener)
{
mDecoderStateEventBroadcaster.removeListener(
((IDecoderStateEventListener) module).getDecoderStateListener());
}
if(module instanceof IFrequencyChangeListener)
{
mFrequencyChangeEventBroadcaster.removeListener(
((IFrequencyChangeListener) module).getFrequencyChangeListener());
}
if(module instanceof IMessageListener)
{
mMessageBroadcaster.removeListener(((IMessageListener) module).getMessageListener());
}
if(module instanceof IMetadataListener)
{
mMetadataBroadcaster.removeListener(((IMetadataListener) module).getMetadataListener());
}
if(module instanceof IFilteredRealBufferListener)
{
mFilteredRealBufferBroadcaster.removeListener(
((IFilteredRealBufferListener) module).getFilteredRealBufferListener());
}
if(module instanceof ISquelchStateListener)
{
mSquelchStateBroadcaster.removeListener(
((ISquelchStateListener) module).getSquelchStateListener());
}
if(module instanceof IUnFilteredRealBufferListener)
{
mUnFilteredRealBufferBroadcaster.removeListener(
((IUnFilteredRealBufferListener) module).getUnFilteredRealBufferListener());
} }
} }
@@ -371,64 +454,121 @@ public class ProcessingChain implements IChannelEventListener
* Registers the broadcaster(s) as listeners to the module for each * Registers the broadcaster(s) as listeners to the module for each
* provider interface that is supported by the module. * provider interface that is supported by the module.
*/ */
private void registerProviders( Module module ) private void registerProviders(Module module)
{ {
if( module instanceof IAudioPacketProvider ) if(module instanceof IAudioPacketProvider)
{ {
((IAudioPacketProvider)module).setAudioPacketListener( ((IAudioPacketProvider) module).setAudioPacketListener(
mAudioPacketBroadcaster ); mAudioPacketBroadcaster);
} }
if( module instanceof ICallEventProvider ) if(module instanceof ICallEventProvider)
{ {
((ICallEventProvider)module).addCallEventListener( mCallEventBroadcaster ); ((ICallEventProvider) module).addCallEventListener(mCallEventBroadcaster);
} }
if( module instanceof IChannelEventProvider ) if(module instanceof IChannelEventProvider)
{ {
((IChannelEventProvider)module).setChannelEventListener( ((IChannelEventProvider) module).setChannelEventListener(
mChannelEventBroadcaster ); mChannelEventBroadcaster);
} }
if( module instanceof IDecoderStateEventProvider ) if(module instanceof IDecoderStateEventProvider)
{ {
((IDecoderStateEventProvider)module).setDecoderStateListener( ((IDecoderStateEventProvider) module).setDecoderStateListener(
mDecoderStateEventBroadcaster ); mDecoderStateEventBroadcaster);
} }
if( module instanceof IFrequencyChangeProvider ) if(module instanceof IFrequencyChangeProvider)
{ {
((IFrequencyChangeProvider)module).setFrequencyChangeListener( ((IFrequencyChangeProvider) module).setFrequencyChangeListener(
mFrequencyChangeEventBroadcaster ); mFrequencyChangeEventBroadcaster);
} }
if( module instanceof IMessageProvider ) if(module instanceof IMessageProvider)
{ {
((IMessageProvider)module).setMessageListener( mMessageBroadcaster ); ((IMessageProvider) module).setMessageListener(mMessageBroadcaster);
} }
if( module instanceof IMetadataProvider ) if(module instanceof IMetadataProvider)
{ {
((IMetadataProvider)module).setMetadataListener( ((IMetadataProvider) module).setMetadataListener(
mMetadataBroadcaster ); mMetadataBroadcaster);
} }
if( module instanceof IFilteredRealBufferProvider ) if(module instanceof IFilteredRealBufferProvider)
{ {
((IFilteredRealBufferProvider)module) ((IFilteredRealBufferProvider) module)
.setFilteredRealBufferListener( mFilteredRealBufferBroadcaster ); .setFilteredRealBufferListener(mFilteredRealBufferBroadcaster);
} }
if( module instanceof ISquelchStateProvider ) if(module instanceof ISquelchStateProvider)
{ {
((ISquelchStateProvider)module).setSquelchStateListener( ((ISquelchStateProvider) module).setSquelchStateListener(
mSquelchStateBroadcaster ); mSquelchStateBroadcaster);
} }
if( module instanceof IUnFilteredRealBufferProvider ) if(module instanceof IUnFilteredRealBufferProvider)
{ {
((IUnFilteredRealBufferProvider)module) ((IUnFilteredRealBufferProvider) module)
.setUnFilteredRealBufferListener( mUnFilteredRealBufferBroadcaster ); .setUnFilteredRealBufferListener(mUnFilteredRealBufferBroadcaster);
}
}
/**
* Unregisters the broadcaster(s) as listeners to the module for each
* provider interface that is supported by the module.
*/
private void unregisterProviders(Module module)
{
if(module instanceof IAudioPacketProvider)
{
((IAudioPacketProvider) module).setAudioPacketListener(null);
}
if(module instanceof ICallEventProvider)
{
((ICallEventProvider) module).removeCallEventListener(mCallEventBroadcaster);
}
if(module instanceof IChannelEventProvider)
{
((IChannelEventProvider) module).setChannelEventListener(null);
}
if(module instanceof IDecoderStateEventProvider)
{
((IDecoderStateEventProvider) module).setDecoderStateListener(null);
}
if(module instanceof IFrequencyChangeProvider)
{
((IFrequencyChangeProvider) module).setFrequencyChangeListener(null);
}
if(module instanceof IMessageProvider)
{
((IMessageProvider) module).setMessageListener(null);
}
if(module instanceof IMetadataProvider)
{
((IMetadataProvider) module).setMetadataListener(null);
}
if(module instanceof IFilteredRealBufferProvider)
{
((IFilteredRealBufferProvider) module).setFilteredRealBufferListener(null);
}
if(module instanceof ISquelchStateProvider)
{
((ISquelchStateProvider) module).setSquelchStateListener(null);
}
if(module instanceof IUnFilteredRealBufferProvider)
{
((IUnFilteredRealBufferProvider) module).setUnFilteredRealBufferListener(null);
} }
} }
@@ -438,12 +578,12 @@ public class ProcessingChain implements IChannelEventListener
*/ */
public void start() public void start()
{ {
if( mRunning.compareAndSet( false, true ) ) if(mRunning.compareAndSet(false, true))
{ {
if( mSource != null ) if(mSource != null)
{ {
/* Reset each of the modules */ /* Reset each of the modules */
for( Module module: mModules ) for(Module module : mModules)
{ {
module.reset(); module.reset();
} }
@@ -451,63 +591,63 @@ public class ProcessingChain implements IChannelEventListener
/* Register with the source to receive sample data. Setup a /* Register with the source to receive sample data. Setup a
* timer task to process the buffer queues 50 times a second * timer task to process the buffer queues 50 times a second
* (every 20 ms) */ * (every 20 ms) */
switch( mSource.getSampleType() ) switch(mSource.getSampleType())
{ {
case COMPLEX: case COMPLEX:
((ComplexSource)mSource).setListener( mComplexBufferBroadcaster ); ((ComplexSource) mSource).setListener(mComplexBufferBroadcaster);
break; break;
case REAL: case REAL:
((RealSource)mSource).setListener( mFilteredRealBufferBroadcaster ); ((RealSource) mSource).setListener(mFilteredRealBufferBroadcaster);
break; break;
default: default:
throw new IllegalArgumentException( "Unrecognized source " throw new IllegalArgumentException("Unrecognized source "
+ "sample type - cannot start processing chain" ); + "sample type - cannot start processing chain");
} }
/* If this is a tuner source, broadcast the frequency to all /* If this is a tuner source, broadcast the frequency to all
* of the decoder state's and start the samples flowing */ * of the decoder state's and start the samples flowing */
if( mSource instanceof TunerChannelSource ) if(mSource instanceof TunerChannelSource)
{ {
TunerChannelSource tcs = (TunerChannelSource)mSource; TunerChannelSource tcs = (TunerChannelSource) mSource;
try try
{ {
long frequency = tcs.getFrequency(); long frequency = tcs.getFrequency();
mDecoderStateEventBroadcaster.broadcast( mDecoderStateEventBroadcaster.broadcast(
new DecoderStateEvent( this, Event.SOURCE_FREQUENCY, new DecoderStateEvent(this, Event.SOURCE_FREQUENCY,
State.IDLE, frequency ) ); State.IDLE, frequency));
} }
catch( SourceException e ) catch(SourceException e)
{ {
mLog.error( "Error getting frequency from tuner channel source", e ); mLog.error("Error getting frequency from tuner channel source", e);
} }
} }
if( mScheduledExecutorService == null ) if(mScheduledExecutorService == null)
{ {
mScheduledExecutorService = Executors.newScheduledThreadPool( mScheduledExecutorService = Executors.newScheduledThreadPool(
1, new NamingThreadFactory( "channel " + mName ) ); 1, new NamingThreadFactory("channel " + mName));
} }
/* Start each of the modules */ /* Start each of the modules */
for( Module module: mModules ) for(Module module : mModules)
{ {
try try
{ {
module.start( mScheduledExecutorService ); module.start(mScheduledExecutorService);
} }
catch( Exception e ) catch(Exception e)
{ {
mLog.error( "Error starting module", e ); mLog.error("Error starting module", e);
} }
} }
mSource.start( mScheduledExecutorService ); mSource.start(mScheduledExecutorService);
} }
else else
{ {
mLog.error( "Source is null on start()" ); mLog.error("Source is null on start()");
} }
} }
} }
@@ -518,23 +658,23 @@ public class ProcessingChain implements IChannelEventListener
*/ */
public void stop() public void stop()
{ {
if( mRunning.compareAndSet( true, false ) ) if(mRunning.compareAndSet(true, false))
{ {
if( mSource != null ) if(mSource != null)
{ {
mSource.stop(); mSource.stop();
switch( mSource.getSampleType() ) switch(mSource.getSampleType())
{ {
case COMPLEX: case COMPLEX:
((ComplexSource)mSource).removeListener( mComplexBufferBroadcaster ); ((ComplexSource) mSource).removeListener(mComplexBufferBroadcaster);
break; break;
case REAL: case REAL:
((RealSource)mSource).removeListener( mFilteredRealBufferBroadcaster ); ((RealSource) mSource).removeListener(mFilteredRealBufferBroadcaster);
break; break;
default: default:
throw new IllegalArgumentException( "Unrecognized source " throw new IllegalArgumentException("Unrecognized source "
+ "sample type - cannot start processing chain" ); + "sample type - cannot start processing chain");
} }
/* Release the source */ /* Release the source */
@@ -543,63 +683,105 @@ public class ProcessingChain implements IChannelEventListener
} }
/* Stop each of the modules */ /* Stop each of the modules */
for( Module module: mModules ) for(Module module : mModules)
{ {
module.stop(); module.stop();
} }
} }
} }
/**
* Removes any logging modules that are currently registered with this processing chain
*/
public void removeEventLoggingModules()
{
List<Module> eventLoggingModules = new ArrayList<>();
for(Module module: mModules)
{
if(module instanceof EventLogger)
{
eventLoggingModules.add(module);
}
}
for(Module eventLoggingModule: eventLoggingModules)
{
removeModule(eventLoggingModule);
}
}
/**
* Removes any recording modules that are currently registered with this processing chain
*/
public void removeRecordingModules()
{
List<Module> recordingModules = new ArrayList<>();
for(Module module: mModules)
{
if(module instanceof RealBufferWaveRecorder || module instanceof ComplexBufferWaveRecorder)
{
recordingModules.add(module);
}
}
for(Module recordingModule: recordingModules)
{
removeModule(recordingModule);
}
}
/** /**
* Adds the listener to receive audio packets from all modules. * Adds the listener to receive audio packets from all modules.
*/ */
public void addAudioPacketListener( Listener<AudioPacket> listener ) public void addAudioPacketListener(Listener<AudioPacket> listener)
{ {
mAudioPacketBroadcaster.addListener( listener ); mAudioPacketBroadcaster.addListener(listener);
} }
public void removeAudioPacketListener( Listener<AudioPacket> listener ) public void removeAudioPacketListener(Listener<AudioPacket> listener)
{ {
mAudioPacketBroadcaster.removeListener( listener ); mAudioPacketBroadcaster.removeListener(listener);
} }
/** /**
* Adds the listener to receive call events from all modules. * Adds the listener to receive call events from all modules.
*/ */
public void addCallEventListener( Listener<CallEvent> listener ) public void addCallEventListener(Listener<CallEvent> listener)
{ {
mCallEventBroadcaster.addListener( listener ); mCallEventBroadcaster.addListener(listener);
} }
public void removeCallEventListener( Listener<CallEvent> listener ) public void removeCallEventListener(Listener<CallEvent> listener)
{ {
mCallEventBroadcaster.removeListener( listener ); mCallEventBroadcaster.removeListener(listener);
} }
/** /**
* Adds the listener to receive call events from all modules. * Adds the listener to receive call events from all modules.
*/ */
public void addChannelEventListener( Listener<ChannelEvent> listener ) public void addChannelEventListener(Listener<ChannelEvent> listener)
{ {
mChannelEventBroadcaster.addListener( listener ); mChannelEventBroadcaster.addListener(listener);
} }
public void removeChannelEventListener( Listener<ChannelEvent> listener ) public void removeChannelEventListener(Listener<ChannelEvent> listener)
{ {
mChannelEventBroadcaster.removeListener( listener ); mChannelEventBroadcaster.removeListener(listener);
} }
/** /**
* Adds the listener to receive decoder state events from decoder modules * Adds the listener to receive decoder state events from decoder modules
*/ */
public void addDecoderStateEventListener( Listener<DecoderStateEvent> listener ) public void addDecoderStateEventListener(Listener<DecoderStateEvent> listener)
{ {
mDecoderStateEventBroadcaster.addListener( listener ); mDecoderStateEventBroadcaster.addListener(listener);
} }
public void removeDecoderStateEventListener( Listener<DecoderStateEvent> listener) public void removeDecoderStateEventListener(Listener<DecoderStateEvent> listener)
{ {
mDecoderStateEventBroadcaster.removeListener( listener ); mDecoderStateEventBroadcaster.removeListener(listener);
} }
public Listener<DecoderStateEvent> getDecoderStateEventListener() public Listener<DecoderStateEvent> getDecoderStateEventListener()
@@ -610,48 +792,48 @@ public class ProcessingChain implements IChannelEventListener
/** /**
* Adds the listener to receive decoded messages from all decoders. * Adds the listener to receive decoded messages from all decoders.
*/ */
public void addMessageListener( Listener<Message> listener ) public void addMessageListener(Listener<Message> listener)
{ {
mMessageBroadcaster.addListener( listener ); mMessageBroadcaster.addListener(listener);
} }
/** /**
* Adds the list of listeners to receive decoded messages from all decoders. * Adds the list of listeners to receive decoded messages from all decoders.
*/ */
public void addMessageListeners( List<Listener<Message>> listeners ) public void addMessageListeners(List<Listener<Message>> listeners)
{ {
for( Listener<Message> listener: listeners ) for(Listener<Message> listener : listeners)
{ {
mMessageBroadcaster.addListener( listener ); mMessageBroadcaster.addListener(listener);
} }
} }
public void removeMessageListener( Listener<Message> listener ) public void removeMessageListener(Listener<Message> listener)
{ {
mMessageBroadcaster.removeListener( listener ); mMessageBroadcaster.removeListener(listener);
} }
/** /**
* Adds the listener to receive call events from all modules. * Adds the listener to receive call events from all modules.
*/ */
public void addSquelchStateListener( Listener<SquelchState> listener ) public void addSquelchStateListener(Listener<SquelchState> listener)
{ {
mSquelchStateBroadcaster.addListener( listener ); mSquelchStateBroadcaster.addListener(listener);
} }
public void removeSquelchStateListener( Listener<SquelchState> listener ) public void removeSquelchStateListener(Listener<SquelchState> listener)
{ {
mSquelchStateBroadcaster.removeListener( listener ); mSquelchStateBroadcaster.removeListener(listener);
} }
public void addRealBufferListener( Listener<RealBuffer> listener ) public void addRealBufferListener(Listener<RealBuffer> listener)
{ {
mFilteredRealBufferBroadcaster.addListener( listener ); mFilteredRealBufferBroadcaster.addListener(listener);
} }
public void removeRealBufferListener( Listener<RealBuffer> listener ) public void removeRealBufferListener(Listener<RealBuffer> listener)
{ {
mFilteredRealBufferBroadcaster.removeListener( listener ); mFilteredRealBufferBroadcaster.removeListener(listener);
} }
@Override @Override

View File

@@ -45,7 +45,8 @@ public class RecorderManager implements Listener<AudioPacket>
private boolean mCanStartNewRecorders = true; private boolean mCanStartNewRecorders = true;
/** /**
* Manages starting and stopping all system recorders and distributes channel audio to each of the recorders. * Manages all audio recording for all processing channels. Reconstructs audio streams and distributes channel
* audio to each of the recorders, starting and stopping the recorders as needed.
*/ */
public RecorderManager(ThreadPoolManager threadPoolManager) public RecorderManager(ThreadPoolManager threadPoolManager)
{ {