mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-21 13:05:43 -05:00
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:
@@ -207,9 +207,18 @@ public class ChannelProcessingManager implements ChannelEventListener
|
||||
MessageActivityModel messageModel = new MessageActivityModel(messageFilter);
|
||||
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 */
|
||||
List<Module> loggers = mEventLogManager.getLoggers(
|
||||
channel.getEventLogConfiguration(), channel.getName());
|
||||
List<Module> loggers = mEventLogManager.getLoggers(channel.getEventLogConfiguration(), channel.getName());
|
||||
|
||||
if (!loggers.isEmpty())
|
||||
{
|
||||
@@ -222,32 +231,18 @@ public class ChannelProcessingManager implements ChannelEventListener
|
||||
if (!recorders.isEmpty())
|
||||
{
|
||||
/* Add baseband recorder */
|
||||
if ((recorders.contains(RecorderType.BASEBAND) &&
|
||||
channel.getChannelType() == ChannelType.STANDARD))
|
||||
if ((recorders.contains(RecorderType.BASEBAND) && channel.getChannelType() == ChannelType.STANDARD))
|
||||
{
|
||||
processingChain.addModule(mRecorderManager.getBasebandRecorder(
|
||||
channel.toString()));
|
||||
processingChain.addModule(mRecorderManager.getBasebandRecorder(channel.toString()));
|
||||
}
|
||||
|
||||
/* Add traffic channel baseband recorder */
|
||||
if (recorders.contains(RecorderType.TRAFFIC_BASEBAND) &&
|
||||
channel.getChannelType() == ChannelType.TRAFFIC)
|
||||
if (recorders.contains(RecorderType.TRAFFIC_BASEBAND) && channel.getChannelType() == ChannelType.TRAFFIC)
|
||||
{
|
||||
processingChain.addModule(mRecorderManager
|
||||
.getBasebandRecorder(channel.toString()));
|
||||
processingChain.addModule(mRecorderManager.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);
|
||||
|
||||
if (event instanceof TrafficChannelEvent)
|
||||
@@ -275,9 +270,14 @@ public class ChannelProcessingManager implements ChannelEventListener
|
||||
|
||||
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));
|
||||
|
||||
@@ -285,7 +285,7 @@ public class ChannelProcessingManager implements ChannelEventListener
|
||||
{
|
||||
mProcessingChains.remove(channel.getChannelID());
|
||||
|
||||
chain.dispose();
|
||||
processingChain.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,20 @@
|
||||
******************************************************************************/
|
||||
package module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import audio.AudioPacket;
|
||||
import audio.IAudioPacketListener;
|
||||
import audio.IAudioPacketProvider;
|
||||
import audio.metadata.IMetadataListener;
|
||||
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.IMessageProvider;
|
||||
import message.Message;
|
||||
@@ -38,10 +46,11 @@ import module.decode.state.DecoderStateEvent.Event;
|
||||
import module.decode.state.IDecoderStateEventListener;
|
||||
import module.decode.state.IDecoderStateEventProvider;
|
||||
import module.decode.state.State;
|
||||
|
||||
import module.log.EventLogger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import record.wave.ComplexBufferWaveRecorder;
|
||||
import record.wave.RealBufferWaveRecorder;
|
||||
import sample.Broadcaster;
|
||||
import sample.Listener;
|
||||
import sample.complex.ComplexBuffer;
|
||||
@@ -59,20 +68,12 @@ import source.tuner.TunerChannelSource;
|
||||
import source.tuner.frequency.FrequencyChangeEvent;
|
||||
import source.tuner.frequency.IFrequencyChangeListener;
|
||||
import source.tuner.frequency.IFrequencyChangeProvider;
|
||||
import audio.AudioPacket;
|
||||
import audio.IAudioPacketListener;
|
||||
import audio.IAudioPacketProvider;
|
||||
import audio.metadata.IMetadataListener;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param source - real or complex sample source
|
||||
*
|
||||
* @throws IllegalStateException if the processing chain is currently
|
||||
* processing with another source. Invoke stop() before applying a new
|
||||
* source.
|
||||
@@ -294,6 +294,18 @@ public class ProcessingChain implements IChannelEventListener
|
||||
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
|
||||
* 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -45,7 +45,8 @@ public class RecorderManager implements Listener<AudioPacket>
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user