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
@@ -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.
@@ -550,6 +690,48 @@ public class ProcessingChain implements IChannelEventListener
} }
} }
/**
* 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.
*/ */

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)
{ {