This commit is contained in:
Denny
2017-01-08 04:38:10 -05:00
parent 2226306de3
commit 49a1ea04f8
2 changed files with 776 additions and 590 deletions

View File

@@ -207,6 +207,16 @@ 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());
@@ -238,16 +248,6 @@ public class ChannelProcessingManager implements ChannelEventListener
} }
} }
/* 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)

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
@@ -218,7 +219,6 @@ 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.
@@ -294,6 +294,18 @@ public class ProcessingChain implements IChannelEventListener
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.
@@ -367,6 +379,77 @@ public class ProcessingChain implements IChannelEventListener
} }
} }
/**
* 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());
}
}
/** /**
* 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.
@@ -432,6 +515,63 @@ public class ProcessingChain implements IChannelEventListener
} }
} }
/**
* 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);
}
}
/** /**
* Starts processing if the chain has a valid source. Invocations on an * Starts processing if the chain has a valid source. Invocations on an
* already started chain have no effect. * already started chain have no effect.
@@ -547,6 +687,52 @@ public class ProcessingChain implements IChannelEventListener
{ {
module.stop(); module.stop();
} }
removeEventLoggingModules();
removeRecordingModules();
}
}
/**
* Removes any logging modules that are currently registered with this processing chain
*/
private 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
*/
private 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);
} }
} }