mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-16 10:37:26 -05:00
Merge pull request #127 from DSheirer/#108-thread-pool-cleanup
#108 thread pool cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,19 +14,20 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package alias.action;
|
package alias.action;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
|
||||||
|
|
||||||
import message.Message;
|
|
||||||
import alias.Alias;
|
import alias.Alias;
|
||||||
import alias.action.beep.BeepAction;
|
import alias.action.beep.BeepAction;
|
||||||
import alias.action.clip.ClipAction;
|
import alias.action.clip.ClipAction;
|
||||||
import alias.action.script.ScriptAction;
|
import alias.action.script.ScriptAction;
|
||||||
import controller.ThreadPoolManager;
|
import message.Message;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||||
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias action defines an action to execute when an alias is detected active.
|
* Alias action defines an action to execute when an alias is detected active.
|
||||||
@@ -48,9 +49,7 @@ public abstract class AliasAction
|
|||||||
* action attached. The alias argument is the parent alias containing the
|
* action attached. The alias argument is the parent alias containing the
|
||||||
* alias action.
|
* alias action.
|
||||||
*/
|
*/
|
||||||
public abstract void execute( ThreadPoolManager threadPoolManager,
|
public abstract void execute( ScheduledExecutorService scheduledExecutorService, Alias alias, Message message );
|
||||||
Alias alias,
|
|
||||||
Message message );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismiss a persistent alias action
|
* Dismiss a persistent alias action
|
||||||
|
|||||||
@@ -1,11 +1,29 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* sdrtrunk
|
||||||
|
* Copyright (C) 2014-2017 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
package alias.action;
|
package alias.action;
|
||||||
|
|
||||||
import java.util.List;
|
import alias.Alias;
|
||||||
|
|
||||||
import message.Message;
|
import message.Message;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import alias.Alias;
|
import util.ThreadPool;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all alias action events. Each received message is interrogated for
|
* Manages all alias action events. Each received message is interrogated for
|
||||||
@@ -16,11 +34,8 @@ import controller.ThreadPoolManager;
|
|||||||
*/
|
*/
|
||||||
public class AliasActionManager implements Listener<Message>
|
public class AliasActionManager implements Listener<Message>
|
||||||
{
|
{
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
public AliasActionManager()
|
||||||
|
|
||||||
public AliasActionManager( ThreadPoolManager threadPoolManager )
|
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,7 +59,7 @@ public class AliasActionManager implements Listener<Message>
|
|||||||
* action needs to setup a timer, and provide the original
|
* action needs to setup a timer, and provide the original
|
||||||
* message to be used as part of the action (e.g. sending
|
* message to be used as part of the action (e.g. sending
|
||||||
* the message as a text message to a cell phone */
|
* the message as a text message to a cell phone */
|
||||||
action.execute( mThreadPoolManager, alias, message );
|
action.execute(ThreadPool.SCHEDULED, alias, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,35 @@
|
|||||||
package alias.action;
|
package alias.action;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
import alias.Alias;
|
||||||
|
import message.Message;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
|
||||||
|
|
||||||
import message.Message;
|
|
||||||
import alias.Alias;
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
|
|
||||||
public abstract class RecurringAction extends AliasAction
|
public abstract class RecurringAction extends AliasAction
|
||||||
{
|
{
|
||||||
@XmlTransient
|
@XmlTransient
|
||||||
protected AtomicBoolean mRunning = new AtomicBoolean(false);
|
protected AtomicBoolean mRunning = new AtomicBoolean(false);
|
||||||
@XmlTransient
|
@XmlTransient
|
||||||
private ScheduledFuture<?> mPerpetualAction;
|
private ScheduledFuture<?> mPerpetualAction;
|
||||||
|
@XmlTransient
|
||||||
|
protected ScheduledExecutorService mScheduledExecutorService;
|
||||||
|
|
||||||
protected Interval mInterval = Interval.ONCE;
|
protected Interval mInterval = Interval.ONCE;
|
||||||
protected int mPeriod = 5;
|
protected int mPeriod = 5;
|
||||||
|
|
||||||
protected ThreadPoolManager mThreadPoolManager;
|
|
||||||
|
|
||||||
public abstract void performAction(Alias alias, Message message);
|
public abstract void performAction(Alias alias, Message message);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute( ThreadPoolManager threadPoolManager,
|
public void execute(ScheduledExecutorService scheduledExecutorService, Alias alias, Message message)
|
||||||
Alias alias,
|
|
||||||
Message message )
|
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
mScheduledExecutorService = scheduledExecutorService;
|
||||||
|
|
||||||
if(mRunning.compareAndSet(false, true))
|
if(mRunning.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
@@ -45,14 +41,11 @@ public abstract class RecurringAction extends AliasAction
|
|||||||
break;
|
break;
|
||||||
case DELAYED_RESET:
|
case DELAYED_RESET:
|
||||||
performThreadedAction(alias, message);
|
performThreadedAction(alias, message);
|
||||||
mThreadPoolManager.scheduleOnce( new ResetTask(),
|
mScheduledExecutorService.schedule(new ResetTask(), mPeriod, TimeUnit.SECONDS);
|
||||||
mPeriod, TimeUnit.SECONDS );
|
|
||||||
break;
|
break;
|
||||||
case UNTIL_DISMISSED:
|
case UNTIL_DISMISSED:
|
||||||
mPerpetualAction = mThreadPoolManager
|
mPerpetualAction = mScheduledExecutorService.scheduleAtFixedRate(
|
||||||
.scheduleFixedRate( ThreadType.DECODER,
|
new PerformActionTask(alias, message), mPeriod, mPeriod, TimeUnit.SECONDS);
|
||||||
new PerformActionTask( alias, message ),
|
|
||||||
mPeriod, TimeUnit.SECONDS );
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("<html><div width='250'>Alias [");
|
sb.append("<html><div width='250'>Alias [");
|
||||||
@@ -73,8 +66,7 @@ public abstract class RecurringAction extends AliasAction
|
|||||||
|
|
||||||
dismiss(false);
|
dismiss(false);
|
||||||
|
|
||||||
mThreadPoolManager.scheduleOnce( new ResetTask(),
|
mScheduledExecutorService.schedule(new ResetTask(), 15, TimeUnit.SECONDS);
|
||||||
15, TimeUnit.SECONDS );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -89,13 +81,14 @@ public abstract class RecurringAction extends AliasAction
|
|||||||
*/
|
*/
|
||||||
private void performThreadedAction(final Alias alias, final Message message)
|
private void performThreadedAction(final Alias alias, final Message message)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce( new Runnable() {
|
mScheduledExecutorService.schedule(new Runnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
performAction(alias, message);
|
performAction(alias, message);
|
||||||
}}, 0, TimeUnit.SECONDS );
|
}
|
||||||
|
}, 0, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import audio.AudioEvent.Type;
|
|||||||
import audio.output.AudioOutput;
|
import audio.output.AudioOutput;
|
||||||
import audio.output.MonoAudioOutput;
|
import audio.output.MonoAudioOutput;
|
||||||
import audio.output.StereoAudioOutput;
|
import audio.output.StereoAudioOutput;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
@@ -32,6 +30,7 @@ import sample.Listener;
|
|||||||
import source.mixer.MixerChannel;
|
import source.mixer.MixerChannel;
|
||||||
import source.mixer.MixerChannelConfiguration;
|
import source.mixer.MixerChannelConfiguration;
|
||||||
import source.mixer.MixerManager;
|
import source.mixer.MixerManager;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioSystem;
|
import javax.sound.sampled.AudioSystem;
|
||||||
import javax.sound.sampled.Mixer;
|
import javax.sound.sampled.Mixer;
|
||||||
@@ -70,7 +69,6 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
|
|
||||||
private Broadcaster<AudioEvent> mControllerBroadcaster = new Broadcaster<>();
|
private Broadcaster<AudioEvent> mControllerBroadcaster = new Broadcaster<>();
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private ScheduledFuture<?> mProcessingTask;
|
private ScheduledFuture<?> mProcessingTask;
|
||||||
private MixerManager mMixerManager;
|
private MixerManager mMixerManager;
|
||||||
private MixerChannelConfiguration mMixerChannelConfiguration;
|
private MixerChannelConfiguration mMixerChannelConfiguration;
|
||||||
@@ -81,9 +79,8 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
* packets to any combination of outputs based on any alias audio routing
|
* packets to any combination of outputs based on any alias audio routing
|
||||||
* options specified by the user.
|
* options specified by the user.
|
||||||
*/
|
*/
|
||||||
public AudioManager(ThreadPoolManager manager, MixerManager mixerManager)
|
public AudioManager(MixerManager mixerManager)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = manager;
|
|
||||||
mMixerManager = mixerManager;
|
mMixerManager = mixerManager;
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
@@ -145,14 +142,13 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
|
|
||||||
public void dispose()
|
public void dispose()
|
||||||
{
|
{
|
||||||
if(mThreadPoolManager != null && mProcessingTask != null)
|
if(mProcessingTask != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.cancel(mProcessingTask);
|
mProcessingTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mAudioPacketQueue.clear();
|
mAudioPacketQueue.clear();
|
||||||
|
|
||||||
mThreadPoolManager = null;
|
|
||||||
mProcessingTask = null;
|
mProcessingTask = null;
|
||||||
|
|
||||||
mChannelConnectionMap.clear();
|
mChannelConnectionMap.clear();
|
||||||
@@ -224,9 +220,9 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
{
|
{
|
||||||
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_STARTED);
|
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_STARTED);
|
||||||
|
|
||||||
if(mThreadPoolManager != null && mProcessingTask != null)
|
if(mProcessingTask != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.cancel(mProcessingTask);
|
mProcessingTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
disposeCurrentConfiguration();
|
disposeCurrentConfiguration();
|
||||||
@@ -234,19 +230,18 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
switch(entry.getMixerChannel())
|
switch(entry.getMixerChannel())
|
||||||
{
|
{
|
||||||
case MONO:
|
case MONO:
|
||||||
AudioOutput mono = new MonoAudioOutput(mThreadPoolManager,
|
AudioOutput mono = new MonoAudioOutput(entry.getMixer());
|
||||||
entry.getMixer());
|
|
||||||
mAudioOutputConnections.add(new AudioOutputConnection(mono));
|
mAudioOutputConnections.add(new AudioOutputConnection(mono));
|
||||||
mAvailableConnectionCount++;
|
mAvailableConnectionCount++;
|
||||||
mAudioOutputMap.put(mono.getChannelName(), mono);
|
mAudioOutputMap.put(mono.getChannelName(), mono);
|
||||||
break;
|
break;
|
||||||
case STEREO:
|
case STEREO:
|
||||||
AudioOutput left = new StereoAudioOutput(mThreadPoolManager, entry.getMixer(), MixerChannel.LEFT);
|
AudioOutput left = new StereoAudioOutput(entry.getMixer(), MixerChannel.LEFT);
|
||||||
mAudioOutputConnections.add(new AudioOutputConnection(left));
|
mAudioOutputConnections.add(new AudioOutputConnection(left));
|
||||||
mAvailableConnectionCount++;
|
mAvailableConnectionCount++;
|
||||||
mAudioOutputMap.put(left.getChannelName(), left);
|
mAudioOutputMap.put(left.getChannelName(), left);
|
||||||
|
|
||||||
AudioOutput right = new StereoAudioOutput(mThreadPoolManager, entry.getMixer(), MixerChannel.RIGHT);
|
AudioOutput right = new StereoAudioOutput(entry.getMixer(), MixerChannel.RIGHT);
|
||||||
mAudioOutputConnections.add(new AudioOutputConnection(right));
|
mAudioOutputConnections.add(new AudioOutputConnection(right));
|
||||||
mAvailableConnectionCount++;
|
mAvailableConnectionCount++;
|
||||||
mAudioOutputMap.put(right.getChannelName(), right);
|
mAudioOutputMap.put(right.getChannelName(), right);
|
||||||
@@ -256,9 +251,8 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
+ "configuration: " + entry.getMixerChannel());
|
+ "configuration: " + entry.getMixerChannel());
|
||||||
}
|
}
|
||||||
|
|
||||||
mProcessingTask = mThreadPoolManager.scheduleFixedRate(
|
mProcessingTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new AudioPacketProcessor(),
|
||||||
ThreadType.AUDIO_PROCESSING, new AudioPacketProcessor(), 15,
|
0, 15, TimeUnit.MILLISECONDS);
|
||||||
TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_COMPLETE);
|
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_COMPLETE);
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ package audio.broadcast;
|
|||||||
|
|
||||||
import audio.convert.ISilenceGenerator;
|
import audio.convert.ISilenceGenerator;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -40,7 +40,6 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
|
|||||||
|
|
||||||
public static final int PROCESSOR_RUN_INTERVAL_MS = 1000;
|
public static final int PROCESSOR_RUN_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private ScheduledFuture mScheduledTask;
|
private ScheduledFuture mScheduledTask;
|
||||||
|
|
||||||
private RecordingQueueProcessor mRecordingQueueProcessor = new RecordingQueueProcessor();
|
private RecordingQueueProcessor mRecordingQueueProcessor = new RecordingQueueProcessor();
|
||||||
@@ -77,19 +76,13 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
|
|||||||
* The last audio packet's metadata is automatically attached to the closed audio recording when it is enqueued for
|
* The last audio packet's metadata is automatically attached to the closed audio recording when it is enqueued for
|
||||||
* broadcast. That metadata will be updated on the remote server once the audio recording is opened for streaming.
|
* broadcast. That metadata will be updated on the remote server once the audio recording is opened for streaming.
|
||||||
*/
|
*/
|
||||||
public AudioBroadcaster(ThreadPoolManager threadPoolManager, BroadcastConfiguration broadcastConfiguration)
|
public AudioBroadcaster(BroadcastConfiguration broadcastConfiguration)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mBroadcastConfiguration = broadcastConfiguration;
|
mBroadcastConfiguration = broadcastConfiguration;
|
||||||
mDelay = mBroadcastConfiguration.getDelay();
|
mDelay = mBroadcastConfiguration.getDelay();
|
||||||
mSilenceGenerator = BroadcastFactory.getSilenceGenerator(broadcastConfiguration.getBroadcastFormat());
|
mSilenceGenerator = BroadcastFactory.getSilenceGenerator(broadcastConfiguration.getBroadcastFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ThreadPoolManager getThreadPoolManager()
|
|
||||||
{
|
|
||||||
return mThreadPoolManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast binary audio data frames or sequences.
|
* Broadcast binary audio data frames or sequences.
|
||||||
*/
|
*/
|
||||||
@@ -129,11 +122,8 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
|
|||||||
{
|
{
|
||||||
if(mScheduledTask == null)
|
if(mScheduledTask == null)
|
||||||
{
|
{
|
||||||
if(mThreadPoolManager != null)
|
ThreadPool.SCHEDULED.scheduleAtFixedRate(mRecordingQueueProcessor, 0,
|
||||||
{
|
PROCESSOR_RUN_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
||||||
mScheduledTask = mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_PROCESSING,
|
|
||||||
mRecordingQueueProcessor, PROCESSOR_RUN_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,9 +135,9 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
|
|||||||
{
|
{
|
||||||
if(mStreaming.compareAndSet(true, false))
|
if(mStreaming.compareAndSet(true, false))
|
||||||
{
|
{
|
||||||
if(mThreadPoolManager != null && mScheduledTask != null)
|
if(mScheduledTask != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.cancel(mScheduledTask);
|
mScheduledTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import audio.convert.IAudioConverter;
|
|||||||
import audio.convert.ISilenceGenerator;
|
import audio.convert.ISilenceGenerator;
|
||||||
import audio.convert.MP3AudioConverter;
|
import audio.convert.MP3AudioConverter;
|
||||||
import audio.convert.MP3SilenceGenerator;
|
import audio.convert.MP3SilenceGenerator;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import gui.editor.Editor;
|
import gui.editor.Editor;
|
||||||
import gui.editor.EmptyEditor;
|
import gui.editor.EmptyEditor;
|
||||||
import icon.IconManager;
|
import icon.IconManager;
|
||||||
@@ -45,7 +44,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import record.AudioRecorder;
|
import record.AudioRecorder;
|
||||||
import record.mp3.MP3Recorder;
|
import record.mp3.MP3Recorder;
|
||||||
import settings.SettingsManager;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@@ -58,12 +56,11 @@ public class BroadcastFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an audio streaming broadcaster for the configuration
|
* Creates an audio streaming broadcaster for the configuration
|
||||||
* @param threadPoolManager for creating an audio broadcasting connection thread
|
*
|
||||||
* @param configuration describing the server and audio types
|
* @param configuration describing the server and audio types
|
||||||
* @return configured broadcaster or null
|
* @return configured broadcaster or null
|
||||||
*/
|
*/
|
||||||
public static AudioBroadcaster getBroadcaster(ThreadPoolManager threadPoolManager,
|
public static AudioBroadcaster getBroadcaster(BroadcastConfiguration configuration)
|
||||||
BroadcastConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
if(configuration != null)
|
if(configuration != null)
|
||||||
{
|
{
|
||||||
@@ -74,20 +71,15 @@ public class BroadcastFactory
|
|||||||
switch(configuration.getBroadcastServerType())
|
switch(configuration.getBroadcastServerType())
|
||||||
{
|
{
|
||||||
case BROADCASTIFY:
|
case BROADCASTIFY:
|
||||||
return new IcecastTCPAudioBroadcaster(threadPoolManager,
|
return new IcecastTCPAudioBroadcaster((BroadcastifyConfiguration) configuration);
|
||||||
(BroadcastifyConfiguration)configuration);
|
|
||||||
case ICECAST_TCP:
|
case ICECAST_TCP:
|
||||||
return new IcecastTCPAudioBroadcaster(threadPoolManager,
|
return new IcecastTCPAudioBroadcaster((IcecastTCPConfiguration) configuration);
|
||||||
(IcecastTCPConfiguration)configuration);
|
|
||||||
case ICECAST_HTTP:
|
case ICECAST_HTTP:
|
||||||
return new IcecastHTTPAudioBroadcaster(threadPoolManager,
|
return new IcecastHTTPAudioBroadcaster((IcecastHTTPConfiguration) configuration);
|
||||||
(IcecastHTTPConfiguration)configuration);
|
|
||||||
case SHOUTCAST_V1:
|
case SHOUTCAST_V1:
|
||||||
return new ShoutcastV1AudioBroadcaster(threadPoolManager,
|
return new ShoutcastV1AudioBroadcaster((ShoutcastV1Configuration) configuration);
|
||||||
(ShoutcastV1Configuration)configuration);
|
|
||||||
case SHOUTCAST_V2:
|
case SHOUTCAST_V2:
|
||||||
return new ShoutcastV2AudioBroadcaster(threadPoolManager,
|
return new ShoutcastV2AudioBroadcaster((ShoutcastV2Configuration) configuration);
|
||||||
(ShoutcastV2Configuration)configuration);
|
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
default:
|
default:
|
||||||
mLog.info("Unrecognized broadcastAudio configuration: " + configuration.getBroadcastFormat().name());
|
mLog.info("Unrecognized broadcastAudio configuration: " + configuration.getBroadcastFormat().name());
|
||||||
@@ -101,6 +93,7 @@ public class BroadcastFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an audio convert to convert from 8 kHz PCM audio to the specified format
|
* Creates an audio convert to convert from 8 kHz PCM audio to the specified format
|
||||||
|
*
|
||||||
* @param configuration containing the requested output audio format
|
* @param configuration containing the requested output audio format
|
||||||
* @return audio convert or null
|
* @return audio convert or null
|
||||||
*/
|
*/
|
||||||
@@ -149,6 +142,7 @@ public class BroadcastFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an editor for the specified broadcastAudio configuration
|
* Constructs an editor for the specified broadcastAudio configuration
|
||||||
|
*
|
||||||
* @param configuration to modify or view
|
* @param configuration to modify or view
|
||||||
* @param broadcastModel model for broadcastAudio configurations
|
* @param broadcastModel model for broadcastAudio configurations
|
||||||
* @return an editor for the specified broadcastAudio configuration
|
* @return an editor for the specified broadcastAudio configuration
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ package audio.broadcast;
|
|||||||
import alias.id.broadcast.BroadcastChannel;
|
import alias.id.broadcast.BroadcastChannel;
|
||||||
import audio.AudioPacket;
|
import audio.AudioPacket;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import icon.IconManager;
|
import icon.IconManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
import sample.Broadcaster;
|
import sample.Broadcaster;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
@@ -66,7 +66,6 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
|
|||||||
|
|
||||||
private Map<String,BroadcastConfiguration> mBroadcastConfigurationMap = new HashMap<>();
|
private Map<String,BroadcastConfiguration> mBroadcastConfigurationMap = new HashMap<>();
|
||||||
private Map<String,AudioBroadcaster> mBroadcasterMap = new HashMap<>();
|
private Map<String,AudioBroadcaster> mBroadcasterMap = new HashMap<>();
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private IconManager mIconManager;
|
private IconManager mIconManager;
|
||||||
private StreamManager mStreamManager;
|
private StreamManager mStreamManager;
|
||||||
private Broadcaster<BroadcastEvent> mBroadcastEventBroadcaster = new Broadcaster<>();
|
private Broadcaster<BroadcastEvent> mBroadcastEventBroadcaster = new Broadcaster<>();
|
||||||
@@ -74,17 +73,16 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
|
|||||||
/**
|
/**
|
||||||
* Model for managing Broadcast configurations and any associated broadcaster instances.
|
* Model for managing Broadcast configurations and any associated broadcaster instances.
|
||||||
*/
|
*/
|
||||||
public BroadcastModel(ThreadPoolManager threadPoolManager, IconManager iconManager)
|
public BroadcastModel(IconManager iconManager)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mIconManager = iconManager;
|
mIconManager = iconManager;
|
||||||
mStreamManager = new StreamManager(threadPoolManager, new CompletedRecordingListener(), BroadcastFormat.MP3,
|
mStreamManager = new StreamManager(new CompletedRecordingListener(), BroadcastFormat.MP3,
|
||||||
SystemProperties.getInstance().getApplicationFolder(TEMPORARY_STREAM_DIRECTORY));
|
SystemProperties.getInstance().getApplicationFolder(TEMPORARY_STREAM_DIRECTORY));
|
||||||
mStreamManager.start();
|
mStreamManager.start();
|
||||||
|
|
||||||
//Monitor to remove temporary recording files that have been streamed by all audio broadcasters
|
//Monitor to remove temporary recording files that have been streamed by all audio broadcasters
|
||||||
mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_RECORDING,
|
ThreadPool.SCHEDULED.scheduleAtFixedRate(new RecordingDeletionMonitor(),
|
||||||
new RecordingDeletionMonitor(), 15l, TimeUnit.SECONDS);
|
15l, 15l, TimeUnit.SECONDS);
|
||||||
|
|
||||||
removeOrphanedTemporaryRecordings();
|
removeOrphanedTemporaryRecordings();
|
||||||
}
|
}
|
||||||
@@ -293,8 +291,7 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
|
|||||||
broadcastConfiguration.isValid() &&
|
broadcastConfiguration.isValid() &&
|
||||||
!mBroadcasterMap.containsKey(broadcastConfiguration.getName()))
|
!mBroadcasterMap.containsKey(broadcastConfiguration.getName()))
|
||||||
{
|
{
|
||||||
AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(mThreadPoolManager,
|
AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(broadcastConfiguration);
|
||||||
broadcastConfiguration);
|
|
||||||
|
|
||||||
if(audioBroadcaster != null)
|
if(audioBroadcaster != null)
|
||||||
{
|
{
|
||||||
@@ -403,7 +400,8 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
|
|||||||
deleteBroadcaster(previousChannelName);
|
deleteBroadcaster(previousChannelName);
|
||||||
|
|
||||||
//Delay restarting the broadcaster to allow remote server time to cleanup
|
//Delay restarting the broadcaster to allow remote server time to cleanup
|
||||||
mThreadPoolManager.scheduleOnce(new DelayedBroadcasterStartup(broadcastConfiguration), 1, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(new DelayedBroadcasterStartup(broadcastConfiguration),
|
||||||
|
1, TimeUnit.SECONDS);
|
||||||
break;
|
break;
|
||||||
case CONFIGURATION_DELETE:
|
case CONFIGURATION_DELETE:
|
||||||
deleteBroadcaster(broadcastEvent.getBroadcastConfiguration().getName());
|
deleteBroadcaster(broadcastEvent.getBroadcastConfiguration().getName());
|
||||||
|
|||||||
@@ -19,11 +19,11 @@
|
|||||||
package audio.broadcast;
|
package audio.broadcast;
|
||||||
|
|
||||||
import audio.AudioPacket;
|
import audio.AudioPacket;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import record.AudioRecorder;
|
import record.AudioRecorder;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
import util.ThreadPool;
|
||||||
import util.TimeStamp;
|
import util.TimeStamp;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -44,7 +44,6 @@ public class StreamManager implements Listener<AudioPacket>
|
|||||||
|
|
||||||
private static AtomicInteger sNextRecordingNumber = new AtomicInteger();
|
private static AtomicInteger sNextRecordingNumber = new AtomicInteger();
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private Listener<AudioRecording> mAudioRecordingListener;
|
private Listener<AudioRecording> mAudioRecordingListener;
|
||||||
private BroadcastFormat mBroadcastFormat;
|
private BroadcastFormat mBroadcastFormat;
|
||||||
private Path mTempDirectory;
|
private Path mTempDirectory;
|
||||||
@@ -61,17 +60,13 @@ public class StreamManager implements Listener<AudioPacket>
|
|||||||
*
|
*
|
||||||
* Completed streamable audio recordings are nominated to the output listener (for broadcast) upon completion
|
* Completed streamable audio recordings are nominated to the output listener (for broadcast) upon completion
|
||||||
*
|
*
|
||||||
* @param threadPoolManager for scheduling runnables
|
|
||||||
* @param listener to receive completed audio recordings
|
* @param listener to receive completed audio recordings
|
||||||
* @param tempDirectory where to store temporary audio recordings
|
* @param tempDirectory where to store temporary audio recordings
|
||||||
*/
|
*/
|
||||||
public StreamManager(ThreadPoolManager threadPoolManager, Listener<AudioRecording> listener,
|
public StreamManager(Listener<AudioRecording> listener, BroadcastFormat broadcastFormat, Path tempDirectory)
|
||||||
BroadcastFormat broadcastFormat, Path tempDirectory)
|
|
||||||
{
|
{
|
||||||
assert (tempDirectory != null && Files.isDirectory(tempDirectory));
|
assert (tempDirectory != null && Files.isDirectory(tempDirectory));
|
||||||
assert (mThreadPoolManager != null);
|
|
||||||
|
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mAudioRecordingListener = listener;
|
mAudioRecordingListener = listener;
|
||||||
mBroadcastFormat = broadcastFormat;
|
mBroadcastFormat = broadcastFormat;
|
||||||
mTempDirectory = tempDirectory;
|
mTempDirectory = tempDirectory;
|
||||||
@@ -90,8 +85,8 @@ public class StreamManager implements Listener<AudioPacket>
|
|||||||
mRecorderMonitor = new RecorderMonitor();
|
mRecorderMonitor = new RecorderMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
mRecorderMonitorFuture = mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_PROCESSING,
|
mRecorderMonitorFuture = ThreadPool.SCHEDULED.scheduleAtFixedRate(mRecorderMonitor,
|
||||||
mRecorderMonitor, 2, TimeUnit.SECONDS);
|
0,2, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +140,7 @@ public class StreamManager implements Listener<AudioPacket>
|
|||||||
{
|
{
|
||||||
AudioRecorder recorder = BroadcastFactory.getAudioRecorder(getTemporaryRecordingPath(),
|
AudioRecorder recorder = BroadcastFactory.getAudioRecorder(getTemporaryRecordingPath(),
|
||||||
mBroadcastFormat);
|
mBroadcastFormat);
|
||||||
recorder.start(mThreadPoolManager.getScheduledExecutorService());
|
recorder.start(ThreadPool.SCHEDULED);
|
||||||
recorder.receive(audioPacket);
|
recorder.receive(audioPacket);
|
||||||
mStreamRecorders.put(channelMetadataID, recorder);
|
mStreamRecorders.put(channelMetadataID, recorder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,14 @@ package audio.broadcast.icecast;
|
|||||||
import audio.broadcast.AudioBroadcaster;
|
import audio.broadcast.AudioBroadcaster;
|
||||||
import audio.broadcast.BroadcastConfiguration;
|
import audio.broadcast.BroadcastConfiguration;
|
||||||
import audio.broadcast.IBroadcastMetadataUpdater;
|
import audio.broadcast.IBroadcastMetadataUpdater;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
|
||||||
public abstract class IcecastAudioBroadcaster extends AudioBroadcaster
|
public abstract class IcecastAudioBroadcaster extends AudioBroadcaster
|
||||||
{
|
{
|
||||||
private IBroadcastMetadataUpdater mMetadataUpdater;
|
private IBroadcastMetadataUpdater mMetadataUpdater;
|
||||||
|
|
||||||
public IcecastAudioBroadcaster(ThreadPoolManager threadPoolManager, BroadcastConfiguration broadcastConfiguration)
|
public IcecastAudioBroadcaster(BroadcastConfiguration broadcastConfiguration)
|
||||||
{
|
{
|
||||||
super(threadPoolManager, broadcastConfiguration);
|
super(broadcastConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +44,7 @@ public abstract class IcecastAudioBroadcaster extends AudioBroadcaster
|
|||||||
{
|
{
|
||||||
if(mMetadataUpdater == null)
|
if(mMetadataUpdater == null)
|
||||||
{
|
{
|
||||||
mMetadataUpdater = new IcecastBroadcastMetadataUpdater(getThreadPoolManager(), getConfiguration());
|
mMetadataUpdater = new IcecastBroadcastMetadataUpdater(getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mMetadataUpdater;
|
return mMetadataUpdater;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package audio.broadcast.icecast;
|
|||||||
|
|
||||||
import audio.broadcast.IBroadcastMetadataUpdater;
|
import audio.broadcast.IBroadcastMetadataUpdater;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
import org.apache.mina.core.service.IoHandlerAdapter;
|
import org.apache.mina.core.service.IoHandlerAdapter;
|
||||||
import org.apache.mina.core.session.IoSession;
|
import org.apache.mina.core.session.IoSession;
|
||||||
@@ -33,6 +32,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -50,7 +50,6 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
|
|||||||
private final static Logger mLog = LoggerFactory.getLogger(IcecastBroadcastMetadataUpdater.class);
|
private final static Logger mLog = LoggerFactory.getLogger(IcecastBroadcastMetadataUpdater.class);
|
||||||
private final static String UTF8 = "UTF-8";
|
private final static String UTF8 = "UTF-8";
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private IcecastConfiguration mIcecastConfiguration;
|
private IcecastConfiguration mIcecastConfiguration;
|
||||||
|
|
||||||
private NioSocketConnector mSocketConnector;
|
private NioSocketConnector mSocketConnector;
|
||||||
@@ -65,9 +64,8 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
|
|||||||
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
|
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
|
||||||
* sequence, those updates will be queued and processed in the order received.
|
* sequence, those updates will be queued and processed in the order received.
|
||||||
*/
|
*/
|
||||||
public IcecastBroadcastMetadataUpdater(ThreadPoolManager threadPoolManager, IcecastConfiguration icecastConfiguration)
|
public IcecastBroadcastMetadataUpdater(IcecastConfiguration icecastConfiguration)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mIcecastConfiguration = icecastConfiguration;
|
mIcecastConfiguration = icecastConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +126,7 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
|
|||||||
|
|
||||||
if(updateRequest != null)
|
if(updateRequest != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce(new Runnable()
|
ThreadPool.SCHEDULED.schedule(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package audio.broadcast.icecast;
|
|||||||
|
|
||||||
import audio.broadcast.BroadcastState;
|
import audio.broadcast.BroadcastState;
|
||||||
import audio.convert.MP3AudioConverter;
|
import audio.convert.MP3AudioConverter;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.RuntimeIoException;
|
import org.apache.mina.core.RuntimeIoException;
|
||||||
import org.apache.mina.core.buffer.IoBuffer;
|
import org.apache.mina.core.buffer.IoBuffer;
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
@@ -38,6 +37,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@@ -69,9 +69,9 @@ public class IcecastHTTPAudioBroadcaster extends IcecastAudioBroadcaster
|
|||||||
*
|
*
|
||||||
* @param configuration for the Icecast stream
|
* @param configuration for the Icecast stream
|
||||||
*/
|
*/
|
||||||
public IcecastHTTPAudioBroadcaster(ThreadPoolManager threadPoolManager, IcecastHTTPConfiguration configuration)
|
public IcecastHTTPAudioBroadcaster(IcecastHTTPConfiguration configuration)
|
||||||
{
|
{
|
||||||
super(threadPoolManager, configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +159,7 @@ public class IcecastHTTPAudioBroadcaster extends IcecastAudioBroadcaster
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package audio.broadcast.icecast;
|
|||||||
import audio.broadcast.BroadcastState;
|
import audio.broadcast.BroadcastState;
|
||||||
import audio.broadcast.icecast.codec.IcecastCodecFactory;
|
import audio.broadcast.icecast.codec.IcecastCodecFactory;
|
||||||
import audio.convert.MP3AudioConverter;
|
import audio.convert.MP3AudioConverter;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.RuntimeIoException;
|
import org.apache.mina.core.RuntimeIoException;
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
import org.apache.mina.core.service.IoHandlerAdapter;
|
import org.apache.mina.core.service.IoHandlerAdapter;
|
||||||
@@ -31,6 +30,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -62,9 +62,9 @@ public class IcecastTCPAudioBroadcaster extends IcecastAudioBroadcaster
|
|||||||
*
|
*
|
||||||
* @param configuration for the Icecast stream
|
* @param configuration for the Icecast stream
|
||||||
*/
|
*/
|
||||||
public IcecastTCPAudioBroadcaster(ThreadPoolManager threadPoolManager, IcecastTCPConfiguration configuration)
|
public IcecastTCPAudioBroadcaster(IcecastTCPConfiguration configuration)
|
||||||
{
|
{
|
||||||
super(threadPoolManager, configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,8 +149,7 @@ public class IcecastTCPAudioBroadcaster extends IcecastAudioBroadcaster
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connected();
|
return connected();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package audio.broadcast.shoutcast.v1;
|
|||||||
import audio.broadcast.AudioBroadcaster;
|
import audio.broadcast.AudioBroadcaster;
|
||||||
import audio.broadcast.BroadcastState;
|
import audio.broadcast.BroadcastState;
|
||||||
import audio.broadcast.IBroadcastMetadataUpdater;
|
import audio.broadcast.IBroadcastMetadataUpdater;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.RuntimeIoException;
|
import org.apache.mina.core.RuntimeIoException;
|
||||||
import org.apache.mina.core.buffer.IoBuffer;
|
import org.apache.mina.core.buffer.IoBuffer;
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
@@ -32,6 +31,7 @@ import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
|
|||||||
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -61,9 +61,9 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
|
|||||||
*
|
*
|
||||||
* @param configuration for the Shoutcast stream
|
* @param configuration for the Shoutcast stream
|
||||||
*/
|
*/
|
||||||
public ShoutcastV1AudioBroadcaster(ThreadPoolManager threadPoolManager, ShoutcastV1Configuration configuration)
|
public ShoutcastV1AudioBroadcaster(ShoutcastV1Configuration configuration)
|
||||||
{
|
{
|
||||||
super(threadPoolManager, configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +79,7 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
|
|||||||
{
|
{
|
||||||
if(mMetadataUpdater == null)
|
if(mMetadataUpdater == null)
|
||||||
{
|
{
|
||||||
mMetadataUpdater = new ShoutcastV1BroadcastMetadataUpdater(getThreadPoolManager(), getConfiguration());
|
mMetadataUpdater = new ShoutcastV1BroadcastMetadataUpdater(getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mMetadataUpdater;
|
return mMetadataUpdater;
|
||||||
@@ -171,8 +171,7 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connected();
|
return connected();
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package audio.broadcast.shoutcast.v1;
|
|||||||
|
|
||||||
import audio.broadcast.IBroadcastMetadataUpdater;
|
import audio.broadcast.IBroadcastMetadataUpdater;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
import org.apache.mina.core.service.IoHandlerAdapter;
|
import org.apache.mina.core.service.IoHandlerAdapter;
|
||||||
import org.apache.mina.core.session.IoSession;
|
import org.apache.mina.core.session.IoSession;
|
||||||
@@ -32,6 +31,7 @@ import org.apache.mina.http.api.HttpVersion;
|
|||||||
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -49,7 +49,6 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
|
|||||||
private final static Logger mLog = LoggerFactory.getLogger(ShoutcastV1BroadcastMetadataUpdater.class);
|
private final static Logger mLog = LoggerFactory.getLogger(ShoutcastV1BroadcastMetadataUpdater.class);
|
||||||
private final static String UTF8 = "UTF-8";
|
private final static String UTF8 = "UTF-8";
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private ShoutcastV1Configuration mShoutcastV1Configuration;
|
private ShoutcastV1Configuration mShoutcastV1Configuration;
|
||||||
|
|
||||||
private NioSocketConnector mSocketConnector;
|
private NioSocketConnector mSocketConnector;
|
||||||
@@ -63,9 +62,8 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
|
|||||||
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
|
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
|
||||||
* sequence, those updates will be queued and processed in the order received.
|
* sequence, those updates will be queued and processed in the order received.
|
||||||
*/
|
*/
|
||||||
public ShoutcastV1BroadcastMetadataUpdater(ThreadPoolManager threadPoolManager, ShoutcastV1Configuration shoutcastV1Configuration)
|
public ShoutcastV1BroadcastMetadataUpdater(ShoutcastV1Configuration shoutcastV1Configuration)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mShoutcastV1Configuration = shoutcastV1Configuration;
|
mShoutcastV1Configuration = shoutcastV1Configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +125,7 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
|
|||||||
|
|
||||||
if(updateRequest != null)
|
if(updateRequest != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce(new Runnable()
|
ThreadPool.SCHEDULED.schedule(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import audio.broadcast.shoutcast.v2.ultravox.UltravoxMessageType;
|
|||||||
import audio.broadcast.shoutcast.v2.ultravox.UltravoxMetadata;
|
import audio.broadcast.shoutcast.v2.ultravox.UltravoxMetadata;
|
||||||
import audio.broadcast.shoutcast.v2.ultravox.UltravoxProtocolFactory;
|
import audio.broadcast.shoutcast.v2.ultravox.UltravoxProtocolFactory;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.apache.mina.core.RuntimeIoException;
|
import org.apache.mina.core.RuntimeIoException;
|
||||||
import org.apache.mina.core.future.ConnectFuture;
|
import org.apache.mina.core.future.ConnectFuture;
|
||||||
import org.apache.mina.core.service.IoHandlerAdapter;
|
import org.apache.mina.core.service.IoHandlerAdapter;
|
||||||
@@ -48,6 +47,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -81,12 +81,11 @@ public class ShoutcastV2AudioBroadcaster extends AudioBroadcaster implements IBr
|
|||||||
* This broadcaster uses the Apache Mina library for the streaming socket connection. The
|
* This broadcaster uses the Apache Mina library for the streaming socket connection. The
|
||||||
* ShoutcastV2IOHandler manages all interaction with the Shoutcast server and manages the overall broadcast state.
|
* ShoutcastV2IOHandler manages all interaction with the Shoutcast server and manages the overall broadcast state.
|
||||||
*
|
*
|
||||||
* @param threadPoolManager for thread pool access
|
|
||||||
* @param configuration for the Shoutcast V2 stream
|
* @param configuration for the Shoutcast V2 stream
|
||||||
*/
|
*/
|
||||||
public ShoutcastV2AudioBroadcaster(ThreadPoolManager threadPoolManager, ShoutcastV2Configuration configuration)
|
public ShoutcastV2AudioBroadcaster(ShoutcastV2Configuration configuration)
|
||||||
{
|
{
|
||||||
super(threadPoolManager, configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShoutcastV2Configuration getConfiguration()
|
public ShoutcastV2Configuration getConfiguration()
|
||||||
@@ -207,8 +206,7 @@ public class ShoutcastV2AudioBroadcaster extends AudioBroadcaster implements IBr
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connected();
|
return connected();
|
||||||
|
|||||||
@@ -22,13 +22,12 @@ import audio.AudioEvent;
|
|||||||
import audio.AudioPacket;
|
import audio.AudioPacket;
|
||||||
import audio.AudioPacket.Type;
|
import audio.AudioPacket.Type;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sample.Broadcaster;
|
import sample.Broadcaster;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import source.mixer.MixerChannel;
|
import source.mixer.MixerChannel;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
import javax.sound.sampled.BooleanControl;
|
import javax.sound.sampled.BooleanControl;
|
||||||
@@ -59,7 +58,6 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
|
|||||||
private Listener<Metadata> mMetadataListener;
|
private Listener<Metadata> mMetadataListener;
|
||||||
private Broadcaster<AudioEvent> mAudioEventBroadcaster = new Broadcaster<>();
|
private Broadcaster<AudioEvent> mAudioEventBroadcaster = new Broadcaster<>();
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private ScheduledFuture<?> mProcessorTask;
|
private ScheduledFuture<?> mProcessorTask;
|
||||||
|
|
||||||
private SourceDataLine mOutput;
|
private SourceDataLine mOutput;
|
||||||
@@ -82,21 +80,18 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
|
|||||||
* Maintains an internal non-blocking audio packet queue and processes this
|
* Maintains an internal non-blocking audio packet queue and processes this
|
||||||
* queue 25 times a second (every 40 ms).
|
* queue 25 times a second (every 40 ms).
|
||||||
*
|
*
|
||||||
* @param threadPoolManager for assigning buffer processing schedule task
|
|
||||||
* @param mixer to obtain source data line
|
* @param mixer to obtain source data line
|
||||||
* @param mixerChannel either mono or left/right stereo
|
* @param mixerChannel either mono or left/right stereo
|
||||||
* @param audioFormat to use during playback
|
* @param audioFormat to use during playback
|
||||||
* @param lineInfo to use when obtaining the source data line
|
* @param lineInfo to use when obtaining the source data line
|
||||||
* @param requestedBufferSize of approximately 1 second of audio
|
* @param requestedBufferSize of approximately 1 second of audio
|
||||||
*/
|
*/
|
||||||
public AudioOutput(ThreadPoolManager threadPoolManager,
|
public AudioOutput(Mixer mixer,
|
||||||
Mixer mixer,
|
|
||||||
MixerChannel mixerChannel,
|
MixerChannel mixerChannel,
|
||||||
AudioFormat audioFormat,
|
AudioFormat audioFormat,
|
||||||
Line.Info lineInfo,
|
Line.Info lineInfo,
|
||||||
int requestedBufferSize)
|
int requestedBufferSize)
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mMixer = mixer;
|
mMixer = mixer;
|
||||||
mMixerChannel = mixerChannel;
|
mMixerChannel = mixerChannel;
|
||||||
|
|
||||||
@@ -141,9 +136,8 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Run the queue processor task every 40 milliseconds or 25 times a second */
|
/* Run the queue processor task every 40 milliseconds or 25 times a second */
|
||||||
mProcessorTask = mThreadPoolManager.scheduleFixedRate(
|
mProcessorTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferProcessor(),
|
||||||
ThreadType.AUDIO_PROCESSING, new BufferProcessor(),
|
0, 40, TimeUnit.MILLISECONDS);
|
||||||
40, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mAudioStartEvent = new AudioEvent(AudioEvent.Type.AUDIO_STARTED,
|
mAudioStartEvent = new AudioEvent(AudioEvent.Type.AUDIO_STARTED,
|
||||||
@@ -170,12 +164,11 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
|
|||||||
{
|
{
|
||||||
mCanProcessAudio = false;
|
mCanProcessAudio = false;
|
||||||
|
|
||||||
if(mProcessorTask != null && mThreadPoolManager != null)
|
if(mProcessorTask != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.cancel(mProcessorTask);
|
mProcessorTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mThreadPoolManager = null;
|
|
||||||
mProcessorTask = null;
|
mProcessorTask = null;
|
||||||
|
|
||||||
mBuffer.clear();
|
mBuffer.clear();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,20 +14,19 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package audio.output;
|
package audio.output;
|
||||||
|
|
||||||
|
import audio.AudioFormats;
|
||||||
|
import audio.AudioPacket;
|
||||||
|
import source.mixer.MixerChannel;
|
||||||
|
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import javax.sound.sampled.Mixer;
|
|
||||||
|
|
||||||
import source.mixer.MixerChannel;
|
|
||||||
import audio.AudioFormats;
|
|
||||||
import audio.AudioPacket;
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mono Audio output implementation
|
* Mono Audio output implementation
|
||||||
*/
|
*/
|
||||||
@@ -35,14 +34,10 @@ public class MonoAudioOutput extends AudioOutput
|
|||||||
{
|
{
|
||||||
private final static int BUFFER_SIZE = 8000;
|
private final static int BUFFER_SIZE = 8000;
|
||||||
|
|
||||||
public MonoAudioOutput( ThreadPoolManager threadPoolManager, Mixer mixer )
|
public MonoAudioOutput(Mixer mixer)
|
||||||
{
|
{
|
||||||
super( threadPoolManager,
|
super(mixer, MixerChannel.MONO, AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
|
||||||
mixer,
|
AudioFormats.MONO_SOURCE_DATALINE_INFO, BUFFER_SIZE);
|
||||||
MixerChannel.MONO,
|
|
||||||
AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
|
|
||||||
AudioFormats.MONO_SOURCE_DATALINE_INFO,
|
|
||||||
BUFFER_SIZE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,9 +50,7 @@ public class MonoAudioOutput extends AudioOutput
|
|||||||
float[] samples = packet.getAudioBuffer().getSamples();
|
float[] samples = packet.getAudioBuffer().getSamples();
|
||||||
|
|
||||||
/* Little-endian byte buffer */
|
/* Little-endian byte buffer */
|
||||||
ByteBuffer buffer =
|
ByteBuffer buffer = ByteBuffer.allocate(samples.length * 2).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
ByteBuffer.allocate( samples.length * 2 )
|
|
||||||
.order( ByteOrder.LITTLE_ENDIAN );
|
|
||||||
|
|
||||||
ShortBuffer shortBuffer = buffer.asShortBuffer();
|
ShortBuffer shortBuffer = buffer.asShortBuffer();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,20 +14,19 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package audio.output;
|
package audio.output;
|
||||||
|
|
||||||
|
import audio.AudioFormats;
|
||||||
|
import audio.AudioPacket;
|
||||||
|
import source.mixer.MixerChannel;
|
||||||
|
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import javax.sound.sampled.Mixer;
|
|
||||||
|
|
||||||
import source.mixer.MixerChannel;
|
|
||||||
import audio.AudioFormats;
|
|
||||||
import audio.AudioPacket;
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stereo audio output implementation.
|
* Stereo audio output implementation.
|
||||||
*/
|
*/
|
||||||
@@ -35,14 +34,9 @@ public class StereoAudioOutput extends AudioOutput
|
|||||||
{
|
{
|
||||||
private final static int BUFFER_SIZE = 16000;
|
private final static int BUFFER_SIZE = 16000;
|
||||||
|
|
||||||
public StereoAudioOutput( ThreadPoolManager threadPoolManager,
|
public StereoAudioOutput(Mixer mixer, MixerChannel channel)
|
||||||
Mixer mixer, MixerChannel channel )
|
|
||||||
{
|
{
|
||||||
super( threadPoolManager,
|
super(mixer, channel, AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO, AudioFormats.STEREO_SOURCE_DATALINE_INFO,
|
||||||
mixer,
|
|
||||||
channel,
|
|
||||||
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO,
|
|
||||||
AudioFormats.STEREO_SOURCE_DATALINE_INFO,
|
|
||||||
BUFFER_SIZE);
|
BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package channel.metadata;
|
|||||||
|
|
||||||
import alias.Alias;
|
import alias.Alias;
|
||||||
import channel.state.State;
|
import channel.state.State;
|
||||||
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
|
|
||||||
import controller.channel.Channel;
|
import controller.channel.Channel;
|
||||||
import controller.channel.ChannelProcessingManager;
|
import controller.channel.ChannelProcessingManager;
|
||||||
import icon.IconManager;
|
import icon.IconManager;
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* SDR Trunk
|
|
||||||
* Copyright (C) 2014 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
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
******************************************************************************/
|
|
||||||
package controller;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class ThreadPoolManager
|
|
||||||
{
|
|
||||||
private final static Logger mLog = LoggerFactory.getLogger( ThreadPoolManager.class );
|
|
||||||
|
|
||||||
private int THREAD_POOL_SIZE = 2;
|
|
||||||
|
|
||||||
private HashMap<ScheduledFuture<?>,ThreadType> mTasks =
|
|
||||||
new HashMap<ScheduledFuture<?>,ThreadType>();
|
|
||||||
|
|
||||||
private ScheduledExecutorService mExecutor;
|
|
||||||
|
|
||||||
public ThreadPoolManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScheduledExecutorService getScheduledExecutorService()
|
|
||||||
{
|
|
||||||
if( mExecutor == null )
|
|
||||||
{
|
|
||||||
mExecutor = Executors.newScheduledThreadPool( THREAD_POOL_SIZE,
|
|
||||||
new NamingThreadFactory( "sdrtrunk" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return mExecutor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScheduledFuture<?> scheduleFixedRate( ThreadType type,
|
|
||||||
Runnable command,
|
|
||||||
long period,
|
|
||||||
TimeUnit unit )
|
|
||||||
throws RejectedExecutionException
|
|
||||||
{
|
|
||||||
ScheduledExecutorService executorService = getScheduledExecutorService();
|
|
||||||
|
|
||||||
ScheduledFuture<?> task =
|
|
||||||
executorService.scheduleAtFixedRate( command, 0, period, unit );
|
|
||||||
|
|
||||||
mTasks.put( task, type );
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void scheduleOnce( Runnable command, long delay, TimeUnit unit )
|
|
||||||
throws RejectedExecutionException
|
|
||||||
{
|
|
||||||
ScheduledExecutorService executorService = getScheduledExecutorService();
|
|
||||||
|
|
||||||
executorService.schedule( command, delay, unit );
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean cancel( ScheduledFuture<?> task )
|
|
||||||
{
|
|
||||||
boolean success = task.cancel( true );
|
|
||||||
|
|
||||||
mTasks.remove( task );
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTaskCount( ThreadType type )
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for( ThreadType current: mTasks.values() )
|
|
||||||
{
|
|
||||||
if( current == type )
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ThreadType
|
|
||||||
{
|
|
||||||
AUDIO_PROCESSING,
|
|
||||||
AUDIO_RECORDING,
|
|
||||||
BASEBAND_RECORDING,
|
|
||||||
SOURCE_SAMPLE_PROCESSING,
|
|
||||||
DECIMATION,
|
|
||||||
DECODER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
@@ -24,9 +25,6 @@ import audio.broadcast.BroadcastModel;
|
|||||||
import audio.broadcast.BroadcastStatusPanel;
|
import audio.broadcast.BroadcastStatusPanel;
|
||||||
import com.jidesoft.swing.JideSplitPane;
|
import com.jidesoft.swing.JideSplitPane;
|
||||||
import controller.ControllerPanel;
|
import controller.ControllerPanel;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
import controller.channel.ChannelEventListener;
|
|
||||||
import controller.channel.ChannelModel;
|
import controller.channel.ChannelModel;
|
||||||
import controller.channel.ChannelProcessingManager;
|
import controller.channel.ChannelProcessingManager;
|
||||||
import controller.channel.ChannelSelectionManager;
|
import controller.channel.ChannelSelectionManager;
|
||||||
@@ -48,6 +46,7 @@ import source.tuner.TunerModel;
|
|||||||
import source.tuner.TunerSpectralDisplayManager;
|
import source.tuner.TunerSpectralDisplayManager;
|
||||||
import source.tuner.configuration.TunerConfigurationModel;
|
import source.tuner.configuration.TunerConfigurationModel;
|
||||||
import spectrum.SpectralDisplayPanel;
|
import spectrum.SpectralDisplayPanel;
|
||||||
|
import util.ThreadPool;
|
||||||
import util.TimeStamp;
|
import util.TimeStamp;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
@@ -61,7 +60,6 @@ import java.io.IOException;
|
|||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class SDRTrunk implements Listener<TunerEvent>
|
public class SDRTrunk implements Listener<TunerEvent>
|
||||||
{
|
{
|
||||||
@@ -80,22 +78,24 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
|
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
|
|
||||||
private boolean mLogChannelAndMemoryUsage = false;
|
|
||||||
|
|
||||||
public SDRTrunk()
|
public SDRTrunk()
|
||||||
{
|
{
|
||||||
mLog.info("");
|
|
||||||
mLog.info("");
|
mLog.info("");
|
||||||
mLog.info("*******************************************************************");
|
mLog.info("*******************************************************************");
|
||||||
mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***");
|
mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***");
|
||||||
mLog.info("**** website: https://github.com/dsheirer/sdrtrunk ***");
|
mLog.info("**** website: https://github.com/dsheirer/sdrtrunk ***");
|
||||||
mLog.info("*******************************************************************");
|
mLog.info("*******************************************************************");
|
||||||
mLog.info("");
|
mLog.info("");
|
||||||
mLog.info("");
|
mLog.info("Host CPU Cores: " + Runtime.getRuntime().availableProcessors());
|
||||||
|
mLog.info("Host Memory Total: " + Runtime.getRuntime().totalMemory());
|
||||||
|
mLog.info("Host Memory Max: " + Runtime.getRuntime().maxMemory());
|
||||||
|
mLog.info("Host Memory Free: " + Runtime.getRuntime().freeMemory());
|
||||||
|
|
||||||
//Setup the application home directory
|
//Setup the application home directory
|
||||||
Path home = getHomePath();
|
Path home = getHomePath();
|
||||||
|
|
||||||
|
ThreadPool.logSettings();
|
||||||
|
|
||||||
mLog.info("Home path: " + home.toString());
|
mLog.info("Home path: " + home.toString());
|
||||||
|
|
||||||
//Load properties file
|
//Load properties file
|
||||||
@@ -110,11 +110,9 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
|
TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
|
||||||
TunerModel tunerModel = new TunerModel(tunerConfigurationModel);
|
TunerModel tunerModel = new TunerModel(tunerConfigurationModel);
|
||||||
|
|
||||||
ThreadPoolManager threadPoolManager = new ThreadPoolManager();
|
mIconManager = new IconManager();
|
||||||
|
|
||||||
mIconManager = new IconManager(threadPoolManager);
|
mSettingsManager = new SettingsManager(tunerConfigurationModel);
|
||||||
|
|
||||||
mSettingsManager = new SettingsManager(threadPoolManager, tunerConfigurationModel);
|
|
||||||
|
|
||||||
AliasModel aliasModel = new AliasModel();
|
AliasModel aliasModel = new AliasModel();
|
||||||
|
|
||||||
@@ -124,10 +122,9 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
|
|
||||||
EventLogManager eventLogManager = new EventLogManager();
|
EventLogManager eventLogManager = new EventLogManager();
|
||||||
|
|
||||||
RecorderManager recorderManager = new RecorderManager(threadPoolManager);
|
RecorderManager recorderManager = new RecorderManager();
|
||||||
|
|
||||||
SourceManager sourceManager = new SourceManager(tunerModel,
|
SourceManager sourceManager = new SourceManager(tunerModel, mSettingsManager);
|
||||||
mSettingsManager, threadPoolManager);
|
|
||||||
|
|
||||||
ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(
|
ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(
|
||||||
channelModel, channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager);
|
channelModel, channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager);
|
||||||
@@ -139,13 +136,13 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
new ChannelSelectionManager(channelModel);
|
new ChannelSelectionManager(channelModel);
|
||||||
channelModel.addListener(channelSelectionManager);
|
channelModel.addListener(channelSelectionManager);
|
||||||
|
|
||||||
AliasActionManager aliasActionManager = new AliasActionManager(threadPoolManager);
|
AliasActionManager aliasActionManager = new AliasActionManager();
|
||||||
channelProcessingManager.addMessageListener(aliasActionManager);
|
channelProcessingManager.addMessageListener(aliasActionManager);
|
||||||
|
|
||||||
AudioManager audioManager = new AudioManager(threadPoolManager, sourceManager.getMixerManager());
|
AudioManager audioManager = new AudioManager(sourceManager.getMixerManager());
|
||||||
channelProcessingManager.addAudioPacketListener(audioManager);
|
channelProcessingManager.addAudioPacketListener(audioManager);
|
||||||
|
|
||||||
mBroadcastModel = new BroadcastModel(threadPoolManager, mIconManager);
|
mBroadcastModel = new BroadcastModel(mIconManager);
|
||||||
|
|
||||||
channelProcessingManager.addAudioPacketListener(mBroadcastModel);
|
channelProcessingManager.addAudioPacketListener(mBroadcastModel);
|
||||||
|
|
||||||
@@ -165,19 +162,11 @@ public class SDRTrunk implements Listener<TunerEvent>
|
|||||||
tunerModel.addListener(tunerSpectralDisplayManager);
|
tunerModel.addListener(tunerSpectralDisplayManager);
|
||||||
tunerModel.addListener(this);
|
tunerModel.addListener(this);
|
||||||
|
|
||||||
PlaylistManager playlistManager = new PlaylistManager(threadPoolManager,
|
PlaylistManager playlistManager = new PlaylistManager(aliasModel, mBroadcastModel, channelModel,
|
||||||
aliasModel, mBroadcastModel, channelModel, channelMapModel);
|
channelMapModel);
|
||||||
|
|
||||||
playlistManager.init();
|
playlistManager.init();
|
||||||
|
|
||||||
if (mLogChannelAndMemoryUsage)
|
|
||||||
{
|
|
||||||
Runnable cml = new ChannelMemoryLogger();
|
|
||||||
channelModel.addListener((ChannelEventListener) cml);
|
|
||||||
threadPoolManager.scheduleFixedRate(
|
|
||||||
ThreadType.DECODER, cml, 5, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
mLog.info("starting main application gui");
|
mLog.info("starting main application gui");
|
||||||
|
|
||||||
//Initialize the GUI
|
//Initialize the GUI
|
||||||
|
|||||||
@@ -18,14 +18,12 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package icon;
|
package icon;
|
||||||
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.ListDataEvent;
|
|
||||||
import javax.swing.event.ListDataListener;
|
|
||||||
import javax.swing.event.TableModelEvent;
|
import javax.swing.event.TableModelEvent;
|
||||||
import javax.swing.event.TableModelListener;
|
import javax.swing.event.TableModelListener;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
@@ -54,16 +52,14 @@ public class IconManager
|
|||||||
private Path mIconBackupFilePath;
|
private Path mIconBackupFilePath;
|
||||||
private Path mIconLockFilePath;
|
private Path mIconLockFilePath;
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private IconEditor mIconEditor;
|
private IconEditor mIconEditor;
|
||||||
private IconTableModel mIconTableModel;
|
private IconTableModel mIconTableModel;
|
||||||
private AtomicBoolean mSavingIcons = new AtomicBoolean();
|
private AtomicBoolean mSavingIcons = new AtomicBoolean();
|
||||||
|
|
||||||
private Map<String,ImageIcon> mResizedIcons = new HashMap<>();
|
private Map<String,ImageIcon> mResizedIcons = new HashMap<>();
|
||||||
|
|
||||||
public IconManager(ThreadPoolManager threadPoolManager)
|
public IconManager()
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -412,7 +408,7 @@ public class IconManager
|
|||||||
{
|
{
|
||||||
if(mSavingIcons.compareAndSet(false, true))
|
if(mSavingIcons.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce(new IconSaveTask(), 2, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(new IconSaveTask(), 2, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
package instrument.gui;
|
package instrument.gui;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import alias.AliasModel;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JDesktopPane;
|
|
||||||
import javax.swing.JInternalFrame;
|
|
||||||
|
|
||||||
import audio.broadcast.BroadcastModel;
|
import audio.broadcast.BroadcastModel;
|
||||||
|
import controller.channel.ChannelModel;
|
||||||
|
import controller.channel.map.ChannelMapModel;
|
||||||
import module.decode.DecodeConfigurationEditor;
|
import module.decode.DecodeConfigurationEditor;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import playlist.PlaylistManager;
|
import playlist.PlaylistManager;
|
||||||
import source.IControllableFileSource;
|
import source.IControllableFileSource;
|
||||||
import alias.AliasModel;
|
|
||||||
import controller.ThreadPoolManager;
|
import javax.swing.*;
|
||||||
import controller.channel.ChannelModel;
|
import java.awt.*;
|
||||||
import controller.channel.map.ChannelMapModel;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class DecoderSelectionFrame extends JInternalFrame
|
public class DecoderSelectionFrame extends JInternalFrame
|
||||||
{
|
{
|
||||||
@@ -31,14 +27,12 @@ public class DecoderSelectionFrame extends JInternalFrame
|
|||||||
public DecoderSelectionFrame(JDesktopPane desktop,
|
public DecoderSelectionFrame(JDesktopPane desktop,
|
||||||
IControllableFileSource source)
|
IControllableFileSource source)
|
||||||
{
|
{
|
||||||
ThreadPoolManager tpm = new ThreadPoolManager();
|
|
||||||
|
|
||||||
AliasModel aliasModel = new AliasModel();
|
AliasModel aliasModel = new AliasModel();
|
||||||
BroadcastModel broadcastModel = new BroadcastModel(tpm, null);
|
BroadcastModel broadcastModel = new BroadcastModel(null);
|
||||||
ChannelModel channelModel = new ChannelModel();
|
ChannelModel channelModel = new ChannelModel();
|
||||||
ChannelMapModel channelMapModel = new ChannelMapModel();
|
ChannelMapModel channelMapModel = new ChannelMapModel();
|
||||||
|
|
||||||
mPlaylistManager = new PlaylistManager( tpm, aliasModel, broadcastModel, channelModel, channelMapModel );
|
mPlaylistManager = new PlaylistManager(aliasModel, broadcastModel, channelModel, channelMapModel);
|
||||||
|
|
||||||
mDesktop = desktop;
|
mDesktop = desktop;
|
||||||
mSource = source;
|
mSource = source;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
package map;
|
package map;
|
||||||
|
|
||||||
import alias.Alias;
|
import alias.Alias;
|
||||||
import controller.NamingThreadFactory;
|
|
||||||
import icon.IconManager;
|
import icon.IconManager;
|
||||||
import message.Message;
|
import message.Message;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
@@ -28,9 +27,8 @@ import java.awt.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
public class MapService implements Listener<Message>
|
public class MapService implements Listener<Message>
|
||||||
{
|
{
|
||||||
@@ -39,12 +37,7 @@ public class MapService implements Listener<Message>
|
|||||||
|
|
||||||
private static final Color sDEFAULT_COLOR = Color.BLACK;
|
private static final Color sDEFAULT_COLOR = Color.BLACK;
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler =
|
private List<PlottableUpdateListener> mListeners = new ArrayList<PlottableUpdateListener>();
|
||||||
Executors.newScheduledThreadPool(1,
|
|
||||||
new NamingThreadFactory("map tile fetcher"));
|
|
||||||
|
|
||||||
private ArrayList<PlottableUpdateListener> mListeners =
|
|
||||||
new ArrayList<PlottableUpdateListener>();
|
|
||||||
|
|
||||||
private HashMap<String, PlottableEntity> mEntities =
|
private HashMap<String, PlottableEntity> mEntities =
|
||||||
new HashMap<String, PlottableEntity>();
|
new HashMap<String, PlottableEntity>();
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import channel.state.DecoderStateEvent.Event;
|
|||||||
import channel.state.IDecoderStateEventListener;
|
import channel.state.IDecoderStateEventListener;
|
||||||
import channel.state.IDecoderStateEventProvider;
|
import channel.state.IDecoderStateEventProvider;
|
||||||
import channel.state.State;
|
import channel.state.State;
|
||||||
import controller.NamingThreadFactory;
|
|
||||||
import controller.channel.Channel.ChannelType;
|
import controller.channel.Channel.ChannelType;
|
||||||
import controller.channel.ChannelEvent;
|
import controller.channel.ChannelEvent;
|
||||||
import controller.channel.IChannelEventListener;
|
import controller.channel.IChannelEventListener;
|
||||||
@@ -69,11 +68,10 @@ 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 util.ThreadPool;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +108,6 @@ public class ProcessingChain implements IChannelEventListener
|
|||||||
private Broadcaster<RealBuffer> mUnFilteredRealBufferBroadcaster = new Broadcaster<>();
|
private Broadcaster<RealBuffer> mUnFilteredRealBufferBroadcaster = new Broadcaster<>();
|
||||||
private Broadcaster<SquelchState> mSquelchStateBroadcaster = new Broadcaster<>();
|
private Broadcaster<SquelchState> mSquelchStateBroadcaster = new Broadcaster<>();
|
||||||
|
|
||||||
private ScheduledExecutorService mScheduledExecutorService;
|
|
||||||
private String mName;
|
private String mName;
|
||||||
private AtomicBoolean mRunning = new AtomicBoolean();
|
private AtomicBoolean mRunning = new AtomicBoolean();
|
||||||
|
|
||||||
@@ -170,9 +167,6 @@ public class ProcessingChain implements IChannelEventListener
|
|||||||
|
|
||||||
mModules.clear();
|
mModules.clear();
|
||||||
|
|
||||||
mScheduledExecutorService.shutdownNow();
|
|
||||||
mScheduledExecutorService = null;
|
|
||||||
|
|
||||||
mAudioPacketBroadcaster.dispose();
|
mAudioPacketBroadcaster.dispose();
|
||||||
mCallEventBroadcaster.dispose();
|
mCallEventBroadcaster.dispose();
|
||||||
mChannelEventBroadcaster.dispose();
|
mChannelEventBroadcaster.dispose();
|
||||||
@@ -180,11 +174,6 @@ public class ProcessingChain implements IChannelEventListener
|
|||||||
mMessageBroadcaster.dispose();
|
mMessageBroadcaster.dispose();
|
||||||
mFilteredRealBufferBroadcaster.dispose();
|
mFilteredRealBufferBroadcaster.dispose();
|
||||||
mSquelchStateBroadcaster.dispose();
|
mSquelchStateBroadcaster.dispose();
|
||||||
|
|
||||||
if(mScheduledExecutorService != null)
|
|
||||||
{
|
|
||||||
mScheduledExecutorService.shutdownNow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -584,18 +573,12 @@ public class ProcessingChain implements IChannelEventListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mScheduledExecutorService == null)
|
|
||||||
{
|
|
||||||
mScheduledExecutorService = Executors.newScheduledThreadPool(
|
|
||||||
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(ThreadPool.SCHEDULED);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -603,7 +586,7 @@ public class ProcessingChain implements IChannelEventListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSource.start(mScheduledExecutorService);
|
mSource.start(ThreadPool.SCHEDULED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import alias.AliasEvent;
|
|||||||
import alias.AliasModel;
|
import alias.AliasModel;
|
||||||
import audio.broadcast.BroadcastEvent;
|
import audio.broadcast.BroadcastEvent;
|
||||||
import audio.broadcast.BroadcastModel;
|
import audio.broadcast.BroadcastModel;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.channel.Channel.ChannelType;
|
import controller.channel.Channel.ChannelType;
|
||||||
import controller.channel.ChannelEvent;
|
import controller.channel.ChannelEvent;
|
||||||
import controller.channel.ChannelEventListener;
|
import controller.channel.ChannelEventListener;
|
||||||
@@ -33,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import playlist.version1.PlaylistConverterV1ToV2;
|
import playlist.version1.PlaylistConverterV1ToV2;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
@@ -51,7 +51,6 @@ public class PlaylistManager implements ChannelEventListener
|
|||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger(PlaylistManager.class);
|
private final static Logger mLog = LoggerFactory.getLogger(PlaylistManager.class);
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private AliasModel mAliasModel;
|
private AliasModel mAliasModel;
|
||||||
private BroadcastModel mBroadcastModel;
|
private BroadcastModel mBroadcastModel;
|
||||||
private ChannelModel mChannelModel;
|
private ChannelModel mChannelModel;
|
||||||
@@ -72,16 +71,10 @@ public class PlaylistManager implements ChannelEventListener
|
|||||||
* Monitors playlist changes to automatically save configuration changes
|
* Monitors playlist changes to automatically save configuration changes
|
||||||
* after they occur.
|
* after they occur.
|
||||||
*
|
*
|
||||||
* @param threadPoolManager
|
|
||||||
* @param channelModel
|
* @param channelModel
|
||||||
*/
|
*/
|
||||||
public PlaylistManager(ThreadPoolManager threadPoolManager,
|
public PlaylistManager(AliasModel aliasModel, BroadcastModel broadcastModel, ChannelModel channelModel, ChannelMapModel channelMapModel)
|
||||||
AliasModel aliasModel,
|
|
||||||
BroadcastModel broadcastModel,
|
|
||||||
ChannelModel channelModel,
|
|
||||||
ChannelMapModel channelMapModel)
|
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mAliasModel = aliasModel;
|
mAliasModel = aliasModel;
|
||||||
mBroadcastModel = broadcastModel;
|
mBroadcastModel = broadcastModel;
|
||||||
mChannelModel = channelModel;
|
mChannelModel = channelModel;
|
||||||
@@ -421,7 +414,7 @@ public class PlaylistManager implements ChannelEventListener
|
|||||||
{
|
{
|
||||||
if(mPlaylistSavePending.compareAndSet(false, true))
|
if(mPlaylistSavePending.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce(new PlaylistSaveTask(), 2, TimeUnit.SECONDS);
|
ThreadPool.SCHEDULED.schedule(new PlaylistSaveTask(), 2, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ package properties;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -34,8 +34,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -54,7 +52,6 @@ public class SystemProperties
|
|||||||
private Path mPropertiesPath;
|
private Path mPropertiesPath;
|
||||||
private String mApplicationName;
|
private String mApplicationName;
|
||||||
private AtomicBoolean mSavePending = new AtomicBoolean();
|
private AtomicBoolean mSavePending = new AtomicBoolean();
|
||||||
private ScheduledExecutorService mScheduledExecutorService;
|
|
||||||
|
|
||||||
private SystemProperties()
|
private SystemProperties()
|
||||||
{
|
{
|
||||||
@@ -83,12 +80,7 @@ public class SystemProperties
|
|||||||
{
|
{
|
||||||
if(mSavePending.compareAndSet(false, true))
|
if(mSavePending.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
if(mScheduledExecutorService == null)
|
ThreadPool.SCHEDULED.schedule(new SavePropertiesTask(), 2, TimeUnit.SECONDS);
|
||||||
{
|
|
||||||
mScheduledExecutorService = Executors.newScheduledThreadPool(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
mScheduledExecutorService.schedule(new SavePropertiesTask(), 2, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ package record;
|
|||||||
|
|
||||||
import audio.AudioPacket;
|
import audio.AudioPacket;
|
||||||
import channel.metadata.Metadata;
|
import channel.metadata.Metadata;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
import properties.SystemProperties;
|
||||||
import record.wave.ComplexBufferWaveRecorder;
|
import record.wave.ComplexBufferWaveRecorder;
|
||||||
import record.wave.RealBufferWaveRecorder;
|
import record.wave.RealBufferWaveRecorder;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -39,22 +39,18 @@ public class RecorderManager implements Listener<AudioPacket>
|
|||||||
|
|
||||||
private Map<String,RealBufferWaveRecorder> mRecorders = new HashMap<>();
|
private Map<String,RealBufferWaveRecorder> mRecorders = new HashMap<>();
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
|
|
||||||
private boolean mCanStartNewRecorders = true;
|
private boolean mCanStartNewRecorders = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all audio recording for all processing channels. Reconstructs audio streams and distributes channel
|
* 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.
|
* audio to each of the recorders, starting and stopping the recorders as needed.
|
||||||
*/
|
*/
|
||||||
public RecorderManager(ThreadPoolManager threadPoolManager)
|
public RecorderManager()
|
||||||
{
|
{
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose()
|
public void dispose()
|
||||||
{
|
{
|
||||||
mThreadPoolManager = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,7 +87,7 @@ public class RecorderManager implements Listener<AudioPacket>
|
|||||||
{
|
{
|
||||||
recorder = new RealBufferWaveRecorder(AUDIO_SAMPLE_RATE, filePrefix);
|
recorder = new RealBufferWaveRecorder(AUDIO_SAMPLE_RATE, filePrefix);
|
||||||
|
|
||||||
recorder.start(mThreadPoolManager.getScheduledExecutorService());
|
recorder.start(ThreadPool.SCHEDULED);
|
||||||
|
|
||||||
recorder.receive(audioPacket.getAudioBuffer());
|
recorder.receive(audioPacket.getAudioBuffer());
|
||||||
mRecorders.put(identifier, recorder);
|
mRecorders.put(identifier, recorder);
|
||||||
|
|||||||
@@ -19,37 +19,15 @@
|
|||||||
package record.mp3;
|
package record.mp3;
|
||||||
|
|
||||||
import audio.AudioPacket;
|
import audio.AudioPacket;
|
||||||
import audio.IAudioPacketListener;
|
|
||||||
import audio.broadcast.BroadcastModel;
|
|
||||||
import audio.convert.MP3AudioConverter;
|
import audio.convert.MP3AudioConverter;
|
||||||
import module.Module;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import properties.SystemProperties;
|
|
||||||
import record.AudioRecorder;
|
import record.AudioRecorder;
|
||||||
import record.wave.AudioPacketMonoWaveReader;
|
|
||||||
import sample.Listener;
|
|
||||||
import util.TimeStamp;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MP3 recorder for converting 8 kHz PCM audio packets to MP3 and writing to .mp3 file.
|
* MP3 recorder for converting 8 kHz PCM audio packets to MP3 and writing to .mp3 file.
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package settings;
|
package settings;
|
||||||
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -27,6 +26,7 @@ import settings.ColorSetting.ColorSettingName;
|
|||||||
import source.recording.RecordingConfiguration;
|
import source.recording.RecordingConfiguration;
|
||||||
import source.tuner.configuration.TunerConfigurationEvent;
|
import source.tuner.configuration.TunerConfigurationEvent;
|
||||||
import source.tuner.configuration.TunerConfigurationModel;
|
import source.tuner.configuration.TunerConfigurationModel;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
@@ -54,18 +54,15 @@ public class SettingsManager implements Listener<TunerConfigurationEvent>
|
|||||||
private Settings mSettings = new Settings();
|
private Settings mSettings = new Settings();
|
||||||
private List<SettingChangeListener> mListeners = new ArrayList<>();
|
private List<SettingChangeListener> mListeners = new ArrayList<>();
|
||||||
private TunerConfigurationModel mTunerConfigurationModel;
|
private TunerConfigurationModel mTunerConfigurationModel;
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private boolean mLoadingSettings = false;
|
private boolean mLoadingSettings = false;
|
||||||
private AtomicBoolean mSettingsSavePending = new AtomicBoolean();
|
private AtomicBoolean mSettingsSavePending = new AtomicBoolean();
|
||||||
|
|
||||||
public SettingsManager(ThreadPoolManager threadPoolManager,
|
public SettingsManager(TunerConfigurationModel tunerConfigurationModel)
|
||||||
TunerConfigurationModel tunerConfigurationModel)
|
|
||||||
{
|
{
|
||||||
//TODO: move settings into a SettingsModel
|
//TODO: move settings into a SettingsModel
|
||||||
//and update this class to only provide loading, saving, and model
|
//and update this class to only provide loading, saving, and model
|
||||||
//change detection producing a save.
|
//change detection producing a save.
|
||||||
|
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
mTunerConfigurationModel = tunerConfigurationModel;
|
mTunerConfigurationModel = tunerConfigurationModel;
|
||||||
|
|
||||||
//Register for tuner config events so that we can save the settings
|
//Register for tuner config events so that we can save the settings
|
||||||
@@ -481,8 +478,7 @@ public class SettingsManager implements Listener<TunerConfigurationEvent>
|
|||||||
{
|
{
|
||||||
if(mSettingsSavePending.compareAndSet(false, true))
|
if(mSettingsSavePending.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
mThreadPoolManager.scheduleOnce(new SettingsSaveTask(),
|
ThreadPool.SCHEDULED.schedule(new SettingsSaveTask(), 2, TimeUnit.SECONDS);
|
||||||
2, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source;
|
package source;
|
||||||
|
|
||||||
@@ -24,7 +25,6 @@ import source.mixer.MixerManager;
|
|||||||
import source.recording.RecordingSourceManager;
|
import source.recording.RecordingSourceManager;
|
||||||
import source.tuner.TunerManager;
|
import source.tuner.TunerManager;
|
||||||
import source.tuner.TunerModel;
|
import source.tuner.TunerModel;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
|
||||||
public class SourceManager
|
public class SourceManager
|
||||||
{
|
{
|
||||||
@@ -33,14 +33,12 @@ public class SourceManager
|
|||||||
private TunerManager mTunerManager;
|
private TunerManager mTunerManager;
|
||||||
private TunerModel mTunerModel;
|
private TunerModel mTunerModel;
|
||||||
|
|
||||||
public SourceManager( TunerModel tunerModel,
|
public SourceManager(TunerModel tunerModel, SettingsManager settingsManager)
|
||||||
SettingsManager settingsManager,
|
|
||||||
ThreadPoolManager threadPoolManager )
|
|
||||||
{
|
{
|
||||||
mTunerModel = tunerModel;
|
mTunerModel = tunerModel;
|
||||||
mMixerManager = new MixerManager();
|
mMixerManager = new MixerManager();
|
||||||
mRecordingSourceManager = new RecordingSourceManager(settingsManager);
|
mRecordingSourceManager = new RecordingSourceManager(settingsManager);
|
||||||
mTunerManager = new TunerManager( mMixerManager, tunerModel, threadPoolManager );
|
mTunerManager = new TunerManager(mMixerManager, tunerModel);
|
||||||
|
|
||||||
//TODO: change mixer & recording managers to be models and hand them
|
//TODO: change mixer & recording managers to be models and hand them
|
||||||
//in via the constructor. Perform loading outside of this class.
|
//in via the constructor. Perform loading outside of this class.
|
||||||
|
|||||||
@@ -17,18 +17,12 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner;
|
package source.tuner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import dsp.filter.FilterFactory;
|
||||||
import java.util.List;
|
import dsp.filter.Window.WindowType;
|
||||||
import java.util.concurrent.LinkedTransferQueue;
|
import dsp.filter.cic.ComplexPrimeCICDecimate;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import dsp.mixer.Oscillator;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sample.Buffer;
|
import sample.Buffer;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import sample.complex.Complex;
|
import sample.complex.Complex;
|
||||||
@@ -38,10 +32,15 @@ import source.SourceException;
|
|||||||
import source.tuner.frequency.FrequencyChangeEvent;
|
import source.tuner.frequency.FrequencyChangeEvent;
|
||||||
import source.tuner.frequency.FrequencyChangeEvent.Event;
|
import source.tuner.frequency.FrequencyChangeEvent.Event;
|
||||||
import source.tuner.frequency.IFrequencyChangeProcessor;
|
import source.tuner.frequency.IFrequencyChangeProcessor;
|
||||||
import dsp.filter.FilterFactory;
|
|
||||||
import dsp.filter.Window.WindowType;
|
import java.util.ArrayList;
|
||||||
import dsp.filter.cic.ComplexPrimeCICDecimate;
|
import java.util.List;
|
||||||
import dsp.mixer.Oscillator;
|
import java.util.concurrent.LinkedTransferQueue;
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class TunerChannelSource extends ComplexSource
|
public class TunerChannelSource extends ComplexSource
|
||||||
implements IFrequencyChangeProcessor, Listener<ComplexBuffer>
|
implements IFrequencyChangeProcessor, Listener<ComplexBuffer>
|
||||||
@@ -172,14 +171,14 @@ public class TunerChannelSource extends ComplexSource
|
|||||||
{
|
{
|
||||||
/* Tell the tuner to release/unregister our resources */
|
/* Tell the tuner to release/unregister our resources */
|
||||||
mTuner.getTunerController().removeListener(this);
|
mTuner.getTunerController().removeListener(this);
|
||||||
mTuner = null;
|
// mTuner = null;
|
||||||
mTunerChannel = null;
|
// mTunerChannel = null;
|
||||||
mBuffer = null;
|
// mBuffer = null;
|
||||||
mFrequencyChangeProcessor = null;
|
// mFrequencyChangeProcessor = null;
|
||||||
mListener = null;
|
// mListener = null;
|
||||||
mMixer = null;
|
// mMixer = null;
|
||||||
mDecimationFilter.dispose();
|
// mDecimationFilter.dispose();
|
||||||
mDecimationFilter = null;
|
// mDecimationFilter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,8 +329,6 @@ public class TunerChannelSource extends ComplexSource
|
|||||||
if(mProcessing)
|
if(mProcessing)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// long start = System.currentTimeMillis();
|
|
||||||
|
|
||||||
mBuffer.drainTo(mSampleBuffers, 8);
|
mBuffer.drainTo(mSampleBuffers, 8);
|
||||||
|
|
||||||
for(Buffer buffer : mSampleBuffers)
|
for(Buffer buffer : mSampleBuffers)
|
||||||
@@ -363,15 +360,14 @@ public class TunerChannelSource extends ComplexSource
|
|||||||
samples[x], samples[x + 1], mMixer.inphase(), mMixer.quadrature());
|
samples[x], samples[x + 1], mMixer.inphase(), mMixer.quadrature());
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mProcessing && mDecimationFilter != null )
|
if(mProcessing)
|
||||||
{
|
{
|
||||||
mDecimationFilter.receive( new ComplexBuffer( translated ) );
|
final ComplexPrimeCICDecimate filter = mDecimationFilter;
|
||||||
|
filter.receive(new ComplexBuffer(translated));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mLog.debug( "Processed [" + mSampleBuffers.size() + "] in " + ( System.currentTimeMillis() - start ) );
|
|
||||||
|
|
||||||
mSampleBuffers.clear();
|
mSampleBuffers.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* SDR Trunk
|
* sdrtrunk
|
||||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,18 +14,16 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner;
|
package source.tuner;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.usb4java.Device;
|
import org.usb4java.Device;
|
||||||
import org.usb4java.DeviceDescriptor;
|
import org.usb4java.DeviceDescriptor;
|
||||||
import org.usb4java.DeviceList;
|
import org.usb4java.DeviceList;
|
||||||
import org.usb4java.LibUsb;
|
import org.usb4java.LibUsb;
|
||||||
|
|
||||||
import source.SourceException;
|
import source.SourceException;
|
||||||
import source.mixer.MixerManager;
|
import source.mixer.MixerManager;
|
||||||
import source.tuner.airspy.AirspyTuner;
|
import source.tuner.airspy.AirspyTuner;
|
||||||
@@ -39,7 +37,8 @@ import source.tuner.rtl.RTL2832Tuner;
|
|||||||
import source.tuner.rtl.RTL2832TunerController;
|
import source.tuner.rtl.RTL2832TunerController;
|
||||||
import source.tuner.rtl.e4k.E4KTunerController;
|
import source.tuner.rtl.e4k.E4KTunerController;
|
||||||
import source.tuner.rtl.r820t.R820TTunerController;
|
import source.tuner.rtl.r820t.R820TTunerController;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class TunerManager
|
public class TunerManager
|
||||||
{
|
{
|
||||||
@@ -48,15 +47,11 @@ public class TunerManager
|
|||||||
|
|
||||||
private MixerManager mMixerManager;
|
private MixerManager mMixerManager;
|
||||||
private TunerModel mTunerModel;
|
private TunerModel mTunerModel;
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
|
|
||||||
public TunerManager( MixerManager mixerManager,
|
public TunerManager(MixerManager mixerManager, TunerModel tunerModel)
|
||||||
TunerModel tunerModel,
|
|
||||||
ThreadPoolManager threadPoolManager )
|
|
||||||
{
|
{
|
||||||
mMixerManager = mixerManager;
|
mMixerManager = mixerManager;
|
||||||
mTunerModel = tunerModel;
|
mTunerModel = tunerModel;
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
|
|
||||||
initTuners();
|
initTuners();
|
||||||
}
|
}
|
||||||
@@ -214,8 +209,7 @@ public class TunerManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AirspyTunerController airspyController =
|
AirspyTunerController airspyController = new AirspyTunerController(device);
|
||||||
new AirspyTunerController( device, mThreadPoolManager );
|
|
||||||
|
|
||||||
airspyController.init();
|
airspyController.init();
|
||||||
|
|
||||||
@@ -233,7 +227,6 @@ public class TunerManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private TunerInitStatus initEttusB100Tuner(Device device,
|
private TunerInitStatus initEttusB100Tuner(Device device,
|
||||||
DeviceDescriptor descriptor)
|
DeviceDescriptor descriptor)
|
||||||
{
|
{
|
||||||
@@ -323,9 +316,7 @@ public class TunerManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HackRFTunerController hackRFController =
|
HackRFTunerController hackRFController = new HackRFTunerController(device, descriptor);
|
||||||
new HackRFTunerController( device, descriptor,
|
|
||||||
mThreadPoolManager );
|
|
||||||
|
|
||||||
hackRFController.init();
|
hackRFController.init();
|
||||||
|
|
||||||
@@ -368,33 +359,27 @@ public class TunerManager
|
|||||||
case ELONICS_E4000:
|
case ELONICS_E4000:
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
E4KTunerController controller =
|
E4KTunerController controller = new E4KTunerController(device, deviceDescriptor);
|
||||||
new E4KTunerController( device, deviceDescriptor,
|
|
||||||
mThreadPoolManager );
|
|
||||||
|
|
||||||
controller.init();
|
controller.init();
|
||||||
|
|
||||||
RTL2832Tuner rtlTuner =
|
RTL2832Tuner rtlTuner = new RTL2832Tuner(tunerClass, controller);
|
||||||
new RTL2832Tuner( tunerClass, controller );
|
|
||||||
|
|
||||||
return new TunerInitStatus(rtlTuner, "LOADED");
|
return new TunerInitStatus(rtlTuner, "LOADED");
|
||||||
}
|
}
|
||||||
catch(SourceException se)
|
catch(SourceException se)
|
||||||
{
|
{
|
||||||
return new TunerInitStatus( null, "Error constructing E4K tuner "
|
return new TunerInitStatus(null, "Error constructing E4K tuner controller - " +
|
||||||
+ "controller - " + se.getLocalizedMessage() );
|
se.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
case RAFAELMICRO_R820T:
|
case RAFAELMICRO_R820T:
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
R820TTunerController controller =
|
R820TTunerController controller = new R820TTunerController(device, deviceDescriptor);
|
||||||
new R820TTunerController( device, deviceDescriptor,
|
|
||||||
mThreadPoolManager );
|
|
||||||
|
|
||||||
controller.init();
|
controller.init();
|
||||||
|
|
||||||
RTL2832Tuner rtlTuner =
|
RTL2832Tuner rtlTuner = new RTL2832Tuner(tunerClass, controller);
|
||||||
new RTL2832Tuner( tunerClass, controller );
|
|
||||||
|
|
||||||
return new TunerInitStatus(rtlTuner, "LOADED");
|
return new TunerInitStatus(rtlTuner, "LOADED");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
package source.tuner.airspy;
|
package source.tuner.airspy;
|
||||||
|
|
||||||
|
import dsp.filter.dc.DCRemovalFilter_RB;
|
||||||
|
import dsp.filter.hilbert.HilbertTransform;
|
||||||
|
import org.apache.commons.io.EndianUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.usb4java.Device;
|
||||||
|
import org.usb4java.DeviceHandle;
|
||||||
|
import org.usb4java.LibUsb;
|
||||||
|
import org.usb4java.LibUsbException;
|
||||||
|
import org.usb4java.Transfer;
|
||||||
|
import org.usb4java.TransferCallback;
|
||||||
|
import sample.Broadcaster;
|
||||||
|
import sample.Listener;
|
||||||
|
import sample.complex.ComplexBuffer;
|
||||||
|
import source.SourceException;
|
||||||
|
import source.tuner.TunerController;
|
||||||
|
import source.tuner.configuration.TunerConfiguration;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
|
import javax.usb.UsbException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@@ -11,32 +31,9 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.usb.UsbException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.EndianUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.usb4java.Device;
|
|
||||||
import org.usb4java.DeviceHandle;
|
|
||||||
import org.usb4java.LibUsb;
|
|
||||||
import org.usb4java.LibUsbException;
|
|
||||||
import org.usb4java.Transfer;
|
|
||||||
import org.usb4java.TransferCallback;
|
|
||||||
|
|
||||||
import sample.Broadcaster;
|
|
||||||
import sample.Listener;
|
|
||||||
import sample.complex.ComplexBuffer;
|
|
||||||
import source.SourceException;
|
|
||||||
import source.tuner.TunerController;
|
|
||||||
import source.tuner.configuration.TunerConfiguration;
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
import dsp.filter.dc.DCRemovalFilter_RB;
|
|
||||||
import dsp.filter.hilbert.HilbertTransform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SDR Trunk
|
* SDR Trunk
|
||||||
* Copyright (C) 2015-2016 Dennis Sheirer
|
* Copyright (C) 2015-2017 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* Ported from libairspy at:
|
* Ported from libairspy at:
|
||||||
* https://github.com/airspy/host/tree/master/libairspy
|
* https://github.com/airspy/host/tree/master/libairspy
|
||||||
@@ -113,15 +110,12 @@ public class AirspyTunerController extends TunerController
|
|||||||
|
|
||||||
public static final DecimalFormat MHZ_FORMATTER = new DecimalFormat("#.00 MHz");
|
public static final DecimalFormat MHZ_FORMATTER = new DecimalFormat("#.00 MHz");
|
||||||
|
|
||||||
private final static Logger mLog =
|
private final static Logger mLog = LoggerFactory.getLogger(AirspyTunerController.class);
|
||||||
LoggerFactory.getLogger( AirspyTunerController.class );
|
|
||||||
|
|
||||||
private Device mDevice;
|
private Device mDevice;
|
||||||
private DeviceHandle mDeviceHandle;
|
private DeviceHandle mDeviceHandle;
|
||||||
|
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
private LinkedTransferQueue<byte[]> mFilledBuffers = new LinkedTransferQueue<byte[]>();
|
||||||
private LinkedTransferQueue<byte[]> mFilledBuffers =
|
|
||||||
new LinkedTransferQueue<byte[]>();
|
|
||||||
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
|
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
|
||||||
private int mBufferSize = 262144;
|
private int mBufferSize = 262144;
|
||||||
private BufferProcessor mBufferProcessor = new BufferProcessor();
|
private BufferProcessor mBufferProcessor = new BufferProcessor();
|
||||||
@@ -133,13 +127,11 @@ public class AirspyTunerController extends TunerController
|
|||||||
private List<AirspySampleRate> mSampleRates = new ArrayList<>();
|
private List<AirspySampleRate> mSampleRates = new ArrayList<>();
|
||||||
private int mSampleRate = 0;
|
private int mSampleRate = 0;
|
||||||
|
|
||||||
public AirspyTunerController( Device device, ThreadPoolManager threadPoolManager )
|
public AirspyTunerController(Device device) throws SourceException
|
||||||
throws SourceException
|
|
||||||
{
|
{
|
||||||
super(FREQUENCY_MIN, FREQUENCY_MAX, 0, USABLE_BANDWIDTH_PERCENT);
|
super(FREQUENCY_MIN, FREQUENCY_MAX, 0, USABLE_BANDWIDTH_PERCENT);
|
||||||
|
|
||||||
mDevice = device;
|
mDevice = device;
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() throws SourceException
|
public void init() throws SourceException
|
||||||
@@ -406,11 +398,9 @@ public class AirspyTunerController extends TunerController
|
|||||||
* available sample rates map
|
* available sample rates map
|
||||||
*
|
*
|
||||||
* @param rate to a sample rate in the available samples rates map.
|
* @param rate to a sample rate in the available samples rates map.
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException if index is not a valid rate index
|
* @throws IllegalArgumentException if index is not a valid rate index
|
||||||
* @throws LibUsbException if there was a read error or if this operation
|
* @throws LibUsbException if there was a read error or if this operation
|
||||||
* is not supported by the current firmware
|
* is not supported by the current firmware
|
||||||
*
|
|
||||||
* @throws UsbException if there was a USB error
|
* @throws UsbException if there was a USB error
|
||||||
*/
|
*/
|
||||||
public void setSampleRate(AirspySampleRate rate) throws
|
public void setSampleRate(AirspySampleRate rate) throws
|
||||||
@@ -473,7 +463,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* into 3 bytes (enabled) or 4 bytes (disabled).
|
* into 3 bytes (enabled) or 4 bytes (disabled).
|
||||||
*
|
*
|
||||||
* @param enabled
|
* @param enabled
|
||||||
*
|
|
||||||
* @throws UsbException if sample packing is not supported by the current
|
* @throws UsbException if sample packing is not supported by the current
|
||||||
* device firmware or if there were usb communication issues
|
* device firmware or if there were usb communication issues
|
||||||
*/
|
*/
|
||||||
@@ -496,7 +485,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Enables/disables the mixer automatic gain setting
|
* Enables/disables the mixer automatic gain setting
|
||||||
*
|
*
|
||||||
* @param enabled
|
* @param enabled
|
||||||
*
|
|
||||||
* @throws LibUsbException on unsuccessful read operation
|
* @throws LibUsbException on unsuccessful read operation
|
||||||
* @throws UsbException on USB error
|
* @throws UsbException on USB error
|
||||||
*/
|
*/
|
||||||
@@ -515,7 +503,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Enables/disables the low noise amplifier automatic gain setting
|
* Enables/disables the low noise amplifier automatic gain setting
|
||||||
*
|
*
|
||||||
* @param enabled
|
* @param enabled
|
||||||
*
|
|
||||||
* @throws LibUsbException on unsuccessful read operation
|
* @throws LibUsbException on unsuccessful read operation
|
||||||
* @throws UsbException on USB error
|
* @throws UsbException on USB error
|
||||||
*/
|
*/
|
||||||
@@ -545,7 +532,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Sets LNA gain
|
* Sets LNA gain
|
||||||
*
|
*
|
||||||
* @param gain - value within range of LNA_GAIN_MIN to LNA_GAIN_MAX
|
* @param gain - value within range of LNA_GAIN_MIN to LNA_GAIN_MAX
|
||||||
*
|
|
||||||
* @throws LibUsbException on error in java USB wrapper
|
* @throws LibUsbException on error in java USB wrapper
|
||||||
* @throws UsbException on error in USB transfer
|
* @throws UsbException on error in USB transfer
|
||||||
* @throws IllegalArgumentException if gain value is invalid
|
* @throws IllegalArgumentException if gain value is invalid
|
||||||
@@ -573,7 +559,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Sets Mixer gain
|
* Sets Mixer gain
|
||||||
*
|
*
|
||||||
* @param gain - value within range of MIXER_GAIN_MIN to MIXER_GAIN_MAX
|
* @param gain - value within range of MIXER_GAIN_MIN to MIXER_GAIN_MAX
|
||||||
*
|
|
||||||
* @throws LibUsbException on error in java USB wrapper
|
* @throws LibUsbException on error in java USB wrapper
|
||||||
* @throws UsbException on error in USB transfer
|
* @throws UsbException on error in USB transfer
|
||||||
* @throws IllegalArgumentException if gain value is invalid
|
* @throws IllegalArgumentException if gain value is invalid
|
||||||
@@ -601,7 +586,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Sets IF (VGA) gain
|
* Sets IF (VGA) gain
|
||||||
*
|
*
|
||||||
* @param gain - value within range of VGA_GAIN_MIN to VGA_GAIN_MAX
|
* @param gain - value within range of VGA_GAIN_MIN to VGA_GAIN_MAX
|
||||||
*
|
|
||||||
* @throws LibUsbException on error in java USB wrapper
|
* @throws LibUsbException on error in java USB wrapper
|
||||||
* @throws UsbException on error in USB transfer
|
* @throws UsbException on error in USB transfer
|
||||||
* @throws IllegalArgumentException if gain value is invalid
|
* @throws IllegalArgumentException if gain value is invalid
|
||||||
@@ -752,12 +736,9 @@ public class AirspyTunerController extends TunerController
|
|||||||
* Reads a single byte value from the device.
|
* Reads a single byte value from the device.
|
||||||
*
|
*
|
||||||
* @param command - airspy command
|
* @param command - airspy command
|
||||||
*
|
|
||||||
* @param value - value field for usb setup packet
|
* @param value - value field for usb setup packet
|
||||||
* @param index - index field for usb setup packet
|
* @param index - index field for usb setup packet
|
||||||
*
|
|
||||||
* @return - byte value as an integer
|
* @return - byte value as an integer
|
||||||
*
|
|
||||||
* @throws LibUsbException if the operation is unsuccesful
|
* @throws LibUsbException if the operation is unsuccesful
|
||||||
* @throws UsbException on any usb errors
|
* @throws UsbException on any usb errors
|
||||||
*/
|
*/
|
||||||
@@ -807,7 +788,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
* @param index - usb packet index
|
* @param index - usb packet index
|
||||||
* @param length - number of bytes to read
|
* @param length - number of bytes to read
|
||||||
* @return - bytes read from the device
|
* @return - bytes read from the device
|
||||||
*
|
|
||||||
* @throws LibUsbException if quantity of bytes read doesn't equal the
|
* @throws LibUsbException if quantity of bytes read doesn't equal the
|
||||||
* requested number of bytes
|
* requested number of bytes
|
||||||
* @throws UsbException on error communicating with the device
|
* @throws UsbException on error communicating with the device
|
||||||
@@ -1034,7 +1014,6 @@ public class AirspyTunerController extends TunerController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Airspy Board Identifier
|
* Airspy Board Identifier
|
||||||
*/
|
*/
|
||||||
@@ -1285,9 +1264,8 @@ public class AirspyTunerController extends TunerController
|
|||||||
{
|
{
|
||||||
prepareTransfers();
|
prepareTransfers();
|
||||||
|
|
||||||
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
|
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
|
||||||
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
|
20, 20, TimeUnit.MILLISECONDS);
|
||||||
20, TimeUnit.MILLISECONDS );
|
|
||||||
|
|
||||||
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
||||||
|
|
||||||
@@ -1309,8 +1287,7 @@ public class AirspyTunerController extends TunerController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mLog.error( "error submitting transfer [" +
|
mLog.error("error submitting transfer [" + LibUsb.errorName(result) + "]");
|
||||||
LibUsb.errorName( result ) + "]" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,18 +53,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner.hackrf;
|
package source.tuner.hackrf;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.LinkedTransferQueue;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import javax.usb.UsbException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.EndianUtils;
|
import org.apache.commons.io.EndianUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -75,7 +63,6 @@ import org.usb4java.LibUsb;
|
|||||||
import org.usb4java.LibUsbException;
|
import org.usb4java.LibUsbException;
|
||||||
import org.usb4java.Transfer;
|
import org.usb4java.Transfer;
|
||||||
import org.usb4java.TransferCallback;
|
import org.usb4java.TransferCallback;
|
||||||
|
|
||||||
import sample.Broadcaster;
|
import sample.Broadcaster;
|
||||||
import sample.Listener;
|
import sample.Listener;
|
||||||
import sample.adapter.ByteSampleAdapter;
|
import sample.adapter.ByteSampleAdapter;
|
||||||
@@ -83,8 +70,18 @@ import sample.complex.ComplexBuffer;
|
|||||||
import source.SourceException;
|
import source.SourceException;
|
||||||
import source.tuner.TunerController;
|
import source.tuner.TunerController;
|
||||||
import source.tuner.configuration.TunerConfiguration;
|
import source.tuner.configuration.TunerConfiguration;
|
||||||
import controller.ThreadPoolManager;
|
import util.ThreadPool;
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
|
import javax.usb.UsbException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.LinkedTransferQueue;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
|
||||||
public class HackRFTunerController extends TunerController
|
public class HackRFTunerController extends TunerController
|
||||||
@@ -129,16 +126,13 @@ public class HackRFTunerController extends TunerController
|
|||||||
private Device mDevice;
|
private Device mDevice;
|
||||||
private DeviceDescriptor mDeviceDescriptor;
|
private DeviceDescriptor mDeviceDescriptor;
|
||||||
private DeviceHandle mDeviceHandle;
|
private DeviceHandle mDeviceHandle;
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
|
|
||||||
public HackRFTunerController( Device device, DeviceDescriptor descriptor,
|
public HackRFTunerController(Device device, DeviceDescriptor descriptor) throws SourceException
|
||||||
ThreadPoolManager threadPoolManager ) throws SourceException
|
|
||||||
{
|
{
|
||||||
super(MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT);
|
super(MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT);
|
||||||
|
|
||||||
mDevice = device;
|
mDevice = device;
|
||||||
mDeviceDescriptor = descriptor;
|
mDeviceDescriptor = descriptor;
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() throws SourceException
|
public void init() throws SourceException
|
||||||
@@ -950,9 +944,8 @@ public class HackRFTunerController extends TunerController
|
|||||||
{
|
{
|
||||||
prepareTransfers();
|
prepareTransfers();
|
||||||
|
|
||||||
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
|
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
|
||||||
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
|
20, 20, TimeUnit.MILLISECONDS);
|
||||||
20, TimeUnit.MILLISECONDS );
|
|
||||||
|
|
||||||
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,27 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner.rtl;
|
package source.tuner.rtl;
|
||||||
|
|
||||||
|
import buffer.FloatAveragingBuffer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.usb4java.Device;
|
||||||
|
import org.usb4java.DeviceDescriptor;
|
||||||
|
import org.usb4java.DeviceHandle;
|
||||||
|
import org.usb4java.LibUsb;
|
||||||
|
import org.usb4java.LibUsbException;
|
||||||
|
import org.usb4java.Transfer;
|
||||||
|
import org.usb4java.TransferCallback;
|
||||||
|
import sample.Broadcaster;
|
||||||
|
import sample.Listener;
|
||||||
|
import sample.adapter.ByteSampleAdapter;
|
||||||
|
import sample.complex.ComplexBuffer;
|
||||||
|
import source.SourceException;
|
||||||
|
import source.tuner.TunerController;
|
||||||
|
import source.tuner.TunerType;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
|
import javax.usb.UsbDisconnectedException;
|
||||||
|
import javax.usb.UsbException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@@ -34,34 +55,9 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.usb.UsbDisconnectedException;
|
|
||||||
import javax.usb.UsbException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.usb4java.Device;
|
|
||||||
import org.usb4java.DeviceDescriptor;
|
|
||||||
import org.usb4java.DeviceHandle;
|
|
||||||
import org.usb4java.LibUsb;
|
|
||||||
import org.usb4java.LibUsbException;
|
|
||||||
import org.usb4java.Transfer;
|
|
||||||
import org.usb4java.TransferCallback;
|
|
||||||
|
|
||||||
import sample.Broadcaster;
|
|
||||||
import sample.Listener;
|
|
||||||
import sample.adapter.ByteSampleAdapter;
|
|
||||||
import sample.complex.ComplexBuffer;
|
|
||||||
import source.SourceException;
|
|
||||||
import source.tuner.TunerController;
|
|
||||||
import source.tuner.TunerType;
|
|
||||||
import buffer.FloatAveragingBuffer;
|
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
import controller.ThreadPoolManager.ThreadType;
|
|
||||||
|
|
||||||
public abstract class RTL2832TunerController extends TunerController
|
public abstract class RTL2832TunerController extends TunerController
|
||||||
{
|
{
|
||||||
private final static Logger mLog =
|
private final static Logger mLog = LoggerFactory.getLogger(RTL2832TunerController.class);
|
||||||
LoggerFactory.getLogger( RTL2832TunerController.class );
|
|
||||||
|
|
||||||
public final static int INT_NULL_VALUE = -1;
|
public final static int INT_NULL_VALUE = -1;
|
||||||
public final static long LONG_NULL_VALUE = -1l;
|
public final static long LONG_NULL_VALUE = -1l;
|
||||||
@@ -120,19 +116,14 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
public int mBufferSize = 131072;
|
public int mBufferSize = 131072;
|
||||||
|
|
||||||
protected Descriptor mDescriptor;
|
protected Descriptor mDescriptor;
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract tuner controller device. Use the static getTunerClass() method
|
* Abstract tuner controller device. Use the static getTunerClass() method
|
||||||
* to determine the tuner type, and construct the corresponding child
|
* to determine the tuner type, and construct the corresponding child
|
||||||
* tuner controller class for that tuner type.
|
* tuner controller class for that tuner type.
|
||||||
*/
|
*/
|
||||||
public RTL2832TunerController( Device device,
|
public RTL2832TunerController(Device device, DeviceDescriptor deviceDescriptor, long minTunableFrequency,
|
||||||
DeviceDescriptor deviceDescriptor,
|
long maxTunableFrequency, int centerUnusableBandwidth,
|
||||||
ThreadPoolManager threadPoolManager,
|
|
||||||
long minTunableFrequency,
|
|
||||||
long maxTunableFrequency,
|
|
||||||
int centerUnusableBandwidth,
|
|
||||||
double usableBandwidthPercentage) throws SourceException
|
double usableBandwidthPercentage) throws SourceException
|
||||||
{
|
{
|
||||||
super(minTunableFrequency,
|
super(minTunableFrequency,
|
||||||
@@ -140,8 +131,6 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
centerUnusableBandwidth,
|
centerUnusableBandwidth,
|
||||||
usableBandwidthPercentage);
|
usableBandwidthPercentage);
|
||||||
|
|
||||||
mThreadPoolManager = threadPoolManager;
|
|
||||||
|
|
||||||
mDevice = device;
|
mDevice = device;
|
||||||
mDeviceDescriptor = deviceDescriptor;
|
mDeviceDescriptor = deviceDescriptor;
|
||||||
}
|
}
|
||||||
@@ -613,6 +602,7 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables GPIO Output
|
* Enables GPIO Output
|
||||||
|
*
|
||||||
* @param handle - usb tuner device
|
* @param handle - usb tuner device
|
||||||
* @param bitMask - mask containing one bit value in targeted bit field(s)
|
* @param bitMask - mask containing one bit value in targeted bit field(s)
|
||||||
* @throws UsbDisconnectedException
|
* @throws UsbDisconnectedException
|
||||||
@@ -910,7 +900,6 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
* Reads byte array from index at the address.
|
* Reads byte array from index at the address.
|
||||||
*
|
*
|
||||||
* @return big-endian byte array (needs to be swapped to be usable)
|
* @return big-endian byte array (needs to be swapped to be usable)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected static void read(DeviceHandle handle,
|
protected static void read(DeviceHandle handle,
|
||||||
short address,
|
short address,
|
||||||
@@ -927,7 +916,6 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
* @param handle - handle to the usb tuner device
|
* @param handle - handle to the usb tuner device
|
||||||
* @param controlI2CRepeater - indicates if the method should control the
|
* @param controlI2CRepeater - indicates if the method should control the
|
||||||
* I2C repeater independently
|
* I2C repeater independently
|
||||||
*
|
|
||||||
* @return - true if the device is the specified tuner type
|
* @return - true if the device is the specified tuner type
|
||||||
*/
|
*/
|
||||||
protected static boolean isTuner(TunerTypeCheck type,
|
protected static boolean isTuner(TunerTypeCheck type,
|
||||||
@@ -1312,6 +1300,7 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
/**
|
/**
|
||||||
* Returns the sample rate that is equal to the argument or the next
|
* Returns the sample rate that is equal to the argument or the next
|
||||||
* higher sample rate
|
* higher sample rate
|
||||||
|
*
|
||||||
* @param sampleRate
|
* @param sampleRate
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -1341,7 +1330,7 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
|
|
||||||
if(mBufferProcessor == null)
|
if(mBufferProcessor == null)
|
||||||
{
|
{
|
||||||
mBufferProcessor = new BufferProcessor( mThreadPoolManager );
|
mBufferProcessor = new BufferProcessor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mBufferProcessor.isRunning())
|
if(!mBufferProcessor.isRunning())
|
||||||
@@ -1382,13 +1371,11 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
private LinkedTransferQueue<Transfer> mAvailableTransfers;
|
private LinkedTransferQueue<Transfer> mAvailableTransfers;
|
||||||
private LinkedTransferQueue<Transfer> mTransfersInProgress = new LinkedTransferQueue<>();
|
private LinkedTransferQueue<Transfer> mTransfersInProgress = new LinkedTransferQueue<>();
|
||||||
private AtomicBoolean mRunning = new AtomicBoolean();
|
private AtomicBoolean mRunning = new AtomicBoolean();
|
||||||
private ThreadPoolManager mThreadPoolManager;
|
|
||||||
private ByteBuffer mLibUsbHandlerStatus;
|
private ByteBuffer mLibUsbHandlerStatus;
|
||||||
private boolean mCancel = false;
|
private boolean mCancel = false;
|
||||||
|
|
||||||
public BufferProcessor( ThreadPoolManager manager )
|
public BufferProcessor()
|
||||||
{
|
{
|
||||||
mThreadPoolManager = manager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1411,16 +1398,8 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
|
|
||||||
prepareTransfers();
|
prepareTransfers();
|
||||||
|
|
||||||
try
|
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
|
||||||
{
|
20, 20, TimeUnit.MILLISECONDS);
|
||||||
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
|
|
||||||
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
|
|
||||||
20, TimeUnit.MILLISECONDS );
|
|
||||||
}
|
|
||||||
catch( NullPointerException npe )
|
|
||||||
{
|
|
||||||
mLog.error( "NPE! = tpm null: " + ( mThreadPoolManager == null ), npe );
|
|
||||||
}
|
|
||||||
|
|
||||||
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
|
||||||
|
|
||||||
@@ -1491,7 +1470,7 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
{
|
{
|
||||||
if(mSampleDispatcherTask != null)
|
if(mSampleDispatcherTask != null)
|
||||||
{
|
{
|
||||||
mThreadPoolManager.cancel( mSampleDispatcherTask );
|
mSampleDispatcherTask.cancel(true);
|
||||||
mSampleDispatcherTask = null;
|
mSampleDispatcherTask = null;
|
||||||
mFilledBuffers.clear();
|
mFilledBuffers.clear();
|
||||||
}
|
}
|
||||||
@@ -1628,10 +1607,11 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class USBEventHandlingThread implements Runnable
|
public class USBEventHandlingThread implements Runnable
|
||||||
{
|
{
|
||||||
/** If thread should abort. */
|
/**
|
||||||
|
* If thread should abort.
|
||||||
|
*/
|
||||||
private volatile boolean mAbort;
|
private volatile boolean mAbort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1794,6 +1774,7 @@ public abstract class RTL2832TunerController extends TunerController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RTL2832 EEPROM byte array descriptor parsing class
|
* RTL2832 EEPROM byte array descriptor parsing class
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,10 +17,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner.rtl.e4k;
|
package source.tuner.rtl.e4k;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.usb.UsbException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.usb4java.Device;
|
import org.usb4java.Device;
|
||||||
@@ -28,12 +24,13 @@ import org.usb4java.DeviceDescriptor;
|
|||||||
import org.usb4java.DeviceHandle;
|
import org.usb4java.DeviceHandle;
|
||||||
import org.usb4java.LibUsb;
|
import org.usb4java.LibUsb;
|
||||||
import org.usb4java.LibUsbException;
|
import org.usb4java.LibUsbException;
|
||||||
|
|
||||||
import source.SourceException;
|
import source.SourceException;
|
||||||
import source.tuner.TunerType;
|
import source.tuner.TunerType;
|
||||||
import source.tuner.configuration.TunerConfiguration;
|
import source.tuner.configuration.TunerConfiguration;
|
||||||
import source.tuner.rtl.RTL2832TunerController;
|
import source.tuner.rtl.RTL2832TunerController;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
import javax.usb.UsbException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class E4KTunerController extends RTL2832TunerController
|
public class E4KTunerController extends RTL2832TunerController
|
||||||
{
|
{
|
||||||
@@ -108,13 +105,9 @@ public class E4KTunerController extends RTL2832TunerController
|
|||||||
|
|
||||||
public static final byte CHFCALIB_CMD = (byte) 0x01;
|
public static final byte CHFCALIB_CMD = (byte) 0x01;
|
||||||
|
|
||||||
public E4KTunerController( Device device,
|
public E4KTunerController(Device device, DeviceDescriptor deviceDescriptor) throws SourceException
|
||||||
DeviceDescriptor deviceDescriptor,
|
|
||||||
ThreadPoolManager threadPoolManager )
|
|
||||||
throws SourceException
|
|
||||||
{
|
{
|
||||||
super( device, deviceDescriptor, threadPoolManager, MIN_FREQUENCY,
|
super(device, deviceDescriptor, MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT);
|
||||||
MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -702,6 +695,7 @@ public class E4KTunerController extends RTL2832TunerController
|
|||||||
* Gets the enhanced gain setting in the E4K tuner.
|
* Gets the enhanced gain setting in the E4K tuner.
|
||||||
*
|
*
|
||||||
* Note: requires I2C repeater
|
* Note: requires I2C repeater
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws UsbException
|
* @throws UsbException
|
||||||
*/
|
*/
|
||||||
@@ -1432,6 +1426,7 @@ public class E4KTunerController extends RTL2832TunerController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the correct filter to use for the bandwidth/sample rate
|
* Returns the correct filter to use for the bandwidth/sample rate
|
||||||
|
*
|
||||||
* @param bandwidth - current sample rate
|
* @param bandwidth - current sample rate
|
||||||
* @return - correct filter to use for the bandwidth/sample rate
|
* @return - correct filter to use for the bandwidth/sample rate
|
||||||
*/
|
*/
|
||||||
@@ -1542,6 +1537,7 @@ public class E4KTunerController extends RTL2832TunerController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the correct filter to use for the bandwidth/sample rate
|
* Returns the correct filter to use for the bandwidth/sample rate
|
||||||
|
*
|
||||||
* @param bandwidth - current sample rate
|
* @param bandwidth - current sample rate
|
||||||
* @return - correct filter to use for the bandwidth/sample rate
|
* @return - correct filter to use for the bandwidth/sample rate
|
||||||
*/
|
*/
|
||||||
@@ -1668,6 +1664,7 @@ public class E4KTunerController extends RTL2832TunerController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the correct filter to use for the bandwidth/sample rate
|
* Returns the correct filter to use for the bandwidth/sample rate
|
||||||
|
*
|
||||||
* @param bandwidth - current sample rate
|
* @param bandwidth - current sample rate
|
||||||
* @return - correct filter to use for the bandwidth/sample rate
|
* @return - correct filter to use for the bandwidth/sample rate
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,22 +22,19 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package source.tuner.rtl.r820t;
|
package source.tuner.rtl.r820t;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.usb.UsbException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.usb4java.Device;
|
import org.usb4java.Device;
|
||||||
import org.usb4java.DeviceDescriptor;
|
import org.usb4java.DeviceDescriptor;
|
||||||
import org.usb4java.LibUsbException;
|
import org.usb4java.LibUsbException;
|
||||||
|
|
||||||
import source.SourceException;
|
import source.SourceException;
|
||||||
import source.tuner.TunerType;
|
import source.tuner.TunerType;
|
||||||
import source.tuner.configuration.TunerConfiguration;
|
import source.tuner.configuration.TunerConfiguration;
|
||||||
import source.tuner.rtl.RTL2832TunerController;
|
import source.tuner.rtl.RTL2832TunerController;
|
||||||
import controller.ThreadPoolManager;
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.usb.UsbException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class R820TTunerController extends RTL2832TunerController
|
public class R820TTunerController extends RTL2832TunerController
|
||||||
{
|
{
|
||||||
@@ -75,13 +72,10 @@ public class R820TTunerController extends RTL2832TunerController
|
|||||||
|
|
||||||
private JPanel mEditor;
|
private JPanel mEditor;
|
||||||
|
|
||||||
public R820TTunerController( Device device,
|
public R820TTunerController(Device device, DeviceDescriptor deviceDescriptor) throws SourceException
|
||||||
DeviceDescriptor deviceDescriptor,
|
|
||||||
ThreadPoolManager threadPoolManager )
|
|
||||||
throws SourceException
|
|
||||||
{
|
{
|
||||||
super( device, deviceDescriptor, threadPoolManager, MIN_FREQUENCY,
|
super(device, deviceDescriptor, MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER,
|
||||||
MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT );
|
USABLE_BANDWIDTH_PERCENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -561,6 +555,7 @@ public class R820TTunerController extends RTL2832TunerController
|
|||||||
* Writes initial starting value of registers 0x05 through 0x1F using the
|
* Writes initial starting value of registers 0x05 through 0x1F using the
|
||||||
* default value initialized in the shadow register array. This method only
|
* default value initialized in the shadow register array. This method only
|
||||||
* needs to be called once, upon initialization.
|
* needs to be called once, upon initialization.
|
||||||
|
*
|
||||||
* @throws UsbException
|
* @throws UsbException
|
||||||
*/
|
*/
|
||||||
private void initializeRegisters(boolean controlI2C) throws UsbException
|
private void initializeRegisters(boolean controlI2C) throws UsbException
|
||||||
@@ -1161,6 +1156,7 @@ public class R820TTunerController extends RTL2832TunerController
|
|||||||
* Returns the correct frequency divider for the specified frequency,
|
* Returns the correct frequency divider for the specified frequency,
|
||||||
* or returns divider #5, if the frequency is outside of the specified
|
* or returns divider #5, if the frequency is outside of the specified
|
||||||
* frequency ranges.
|
* frequency ranges.
|
||||||
|
*
|
||||||
* @param frequency - desired frequency
|
* @param frequency - desired frequency
|
||||||
* @return - FrequencyDivider to use for the specified frequency
|
* @return - FrequencyDivider to use for the specified frequency
|
||||||
*/
|
*/
|
||||||
@@ -1231,7 +1227,6 @@ public class R820TTunerController extends RTL2832TunerController
|
|||||||
* 8 I * 7.2 MHz
|
* 8 I * 7.2 MHz
|
||||||
* 4 I * 14.4 MHz
|
* 4 I * 14.4 MHz
|
||||||
* 2 I * 28.8 MHz
|
* 2 I * 28.8 MHz
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public enum Integral
|
public enum Integral
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package spectrum;
|
package spectrum;
|
||||||
|
|
||||||
import controller.NamingThreadFactory;
|
|
||||||
import dsp.filter.Window;
|
import dsp.filter.Window;
|
||||||
import dsp.filter.Window.WindowType;
|
import dsp.filter.Window.WindowType;
|
||||||
import org.jtransforms.fft.FloatFFT_1D;
|
import org.jtransforms.fft.FloatFFT_1D;
|
||||||
@@ -32,14 +31,14 @@ import sample.complex.ComplexBuffer;
|
|||||||
import source.tuner.frequency.FrequencyChangeEvent;
|
import source.tuner.frequency.FrequencyChangeEvent;
|
||||||
import source.tuner.frequency.IFrequencyChangeProcessor;
|
import source.tuner.frequency.IFrequencyChangeProcessor;
|
||||||
import spectrum.converter.DFTResultsConverter;
|
import spectrum.converter.DFTResultsConverter;
|
||||||
|
import util.ThreadPool;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -60,8 +59,7 @@ public class DFTProcessor implements Listener<ComplexBuffer>, IFrequencyChangePr
|
|||||||
//so we set it at 12.
|
//so we set it at 12.
|
||||||
private BlockingQueue<ComplexBuffer> mQueue = new ArrayBlockingQueue<>(12);
|
private BlockingQueue<ComplexBuffer> mQueue = new ArrayBlockingQueue<>(12);
|
||||||
|
|
||||||
private ScheduledExecutorService mScheduler = Executors
|
private ScheduledFuture<?> mProcessorTaskHandle;
|
||||||
.newScheduledThreadPool(1, new NamingThreadFactory("spectrum dft processor"));
|
|
||||||
|
|
||||||
public static final String FRAME_RATE_PROPERTY = "spectral.display.frame.rate";
|
public static final String FRAME_RATE_PROPERTY = "spectral.display.frame.rate";
|
||||||
|
|
||||||
@@ -184,38 +182,20 @@ public class DFTProcessor implements Listener<ComplexBuffer>, IFrequencyChangePr
|
|||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
/**
|
//Schedule the DFT to run calculations at a fixed rate
|
||||||
* Reset the scheduler
|
|
||||||
*/
|
|
||||||
mScheduler = Executors.newScheduledThreadPool(1, new NamingThreadFactory("spectrum dft"));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schedule the DFT to run calculations at a fixed rate
|
|
||||||
*/
|
|
||||||
int initialDelay = 0;
|
int initialDelay = 0;
|
||||||
int period = (int) (1000 / mFrameRate);
|
int period = (int) (1000 / mFrameRate);
|
||||||
TimeUnit unit = TimeUnit.MILLISECONDS;
|
|
||||||
|
|
||||||
mScheduler.scheduleAtFixedRate(new DFTCalculationTask(),
|
mProcessorTaskHandle = ThreadPool.SCHEDULED.scheduleAtFixedRate(new DFTCalculationTask(), initialDelay, period,
|
||||||
initialDelay, period, unit);
|
TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
/**
|
//Cancel running DFT calculation task
|
||||||
* Shutdown the scheduler and clear out any remaining tasks
|
if(mProcessorTaskHandle != null)
|
||||||
*/
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
mScheduler.shutdown();
|
mProcessorTaskHandle.cancel(true);
|
||||||
|
|
||||||
mScheduler.awaitTermination(100, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
catch(InterruptedException e)
|
|
||||||
{
|
|
||||||
/* Do nothing ... we're shutting down */
|
|
||||||
// mLog.error( "DFTProcessor - exception while awaiting shutdown of "
|
|
||||||
// + "calculation scheduler for reset", e );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
src/util/ThreadPool.java
Normal file
54
src/util/ThreadPool.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* sdrtrunk
|
||||||
|
* Copyright (C) 2014-2017 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
package util;
|
||||||
|
|
||||||
|
import controller.NamingThreadFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
public class ThreadPool
|
||||||
|
{
|
||||||
|
private final static Logger mLog = LoggerFactory.getLogger(ThreadPool.class);
|
||||||
|
|
||||||
|
private static int CORES = Runtime.getRuntime().availableProcessors();
|
||||||
|
public static ScheduledExecutorService SCHEDULED;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
//Create a scheduled thread pool sized according to the available processors/cores, minimum 2
|
||||||
|
CORES = (CORES < 2 ? 2 : CORES);
|
||||||
|
|
||||||
|
SCHEDULED = Executors.newScheduledThreadPool(CORES, new NamingThreadFactory("sdrtrunk"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application-wide shared thread pools and scheduled executor service.
|
||||||
|
*/
|
||||||
|
public ThreadPool()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logSettings()
|
||||||
|
{
|
||||||
|
mLog.info("Application thread pool created with [" + CORES + "] threads");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user