Resolves issue with scheduled thread pool overtasking. Removes tuner

channel source decimation processing over to its own thread pool.
This commit is contained in:
denny
2016-02-15 08:42:29 -05:00
parent e7d3713791
commit e2a0451bfb
16 changed files with 62 additions and 58 deletions

View File

@@ -37,7 +37,7 @@ public class SourceManager
ThreadPoolManager threadPoolManager )
{
mMixerManager = new MixerManager();
mRecordingSourceManager = new RecordingSourceManager( settingsManager, threadPoolManager );
mRecordingSourceManager = new RecordingSourceManager( settingsManager );
mTunerManager = new TunerManager( mMixerManager, settingsManager, threadPoolManager );
}

View File

@@ -64,9 +64,8 @@ public class Recording implements Comparable<Recording>,
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException,
SourceException
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException
{
// TODO Auto-generated method stub
return null;

View File

@@ -41,13 +41,10 @@ public class RecordingSourceManager
private ArrayList<Recording> mRecordings = new ArrayList<Recording>();
private SettingsManager mSettingsManager;
private ThreadPoolManager mThreadPoolManager;
public RecordingSourceManager( SettingsManager settingsManager,
ThreadPoolManager threadPoolManager )
public RecordingSourceManager( SettingsManager settingsManager )
{
mSettingsManager = settingsManager;
mThreadPoolManager = threadPoolManager;
loadRecordings();
}
@@ -73,7 +70,7 @@ public class RecordingSourceManager
if( recording != null )
{
retVal = recording.getChannel( mThreadPoolManager, tunerChannel );
retVal = recording.getChannel( tunerChannel );
}
else
{

View File

@@ -20,7 +20,6 @@ package source.tuner;
import java.util.concurrent.RejectedExecutionException;
import source.SourceException;
import controller.ThreadPoolManager;
public interface ITunerChannelProvider
{
@@ -31,8 +30,8 @@ public interface ITunerChannelProvider
*
* @return - source for 48k sample rate
*/
public abstract TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException, SourceException;
public abstract TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException;
/**
* Releases the tuned channel resources

View File

@@ -145,8 +145,8 @@ public abstract class Tuner implements IFrequencyChangeProcessor,
*
* @return - source for 48k sample rate
*/
public abstract TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException, SourceException;
public abstract TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException;
/**
* Releases the tuned channel resources

View File

@@ -19,8 +19,10 @@ package source.tuner;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
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;
@@ -37,7 +39,7 @@ import source.SourceException;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.FrequencyChangeEvent.Event;
import source.tuner.frequency.IFrequencyChangeProcessor;
import controller.ThreadPoolManager;
import controller.NamingThreadFactory;
import controller.ThreadPoolManager.ThreadType;
import dsp.filter.FilterFactory;
import dsp.filter.Window.WindowType;
@@ -61,7 +63,7 @@ public class TunerChannelSource extends ComplexSource
private ComplexPrimeCICDecimate mDecimationFilter;
private Listener<ComplexBuffer> mListener;
private IFrequencyChangeProcessor mFrequencyChangeProcessor;
private ThreadPoolManager mThreadPoolManager;
private ScheduledExecutorService mScheduledExecutorService;
private ScheduledFuture<?> mTaskHandle;
private long mTunerFrequency = 0;
@@ -91,12 +93,9 @@ public class TunerChannelSource extends ComplexSource
* accept the decimation processing task
* @throws SourceException if the tuner has an issue providing IQ samples
*/
public TunerChannelSource( ThreadPoolManager threadPoolManager, Tuner tuner,
TunerChannel tunerChannel )
public TunerChannelSource( Tuner tuner, TunerChannel tunerChannel )
throws RejectedExecutionException, SourceException
{
mThreadPoolManager = threadPoolManager;
mTuner = tuner;
mTuner.addListener( this );
@@ -133,9 +132,12 @@ public class TunerChannelSource extends ComplexSource
if( mRunning.compareAndSet( false, true ))
{
/* Schedule the decimation task to run every 20 ms (50 iterations/second) */
mTaskHandle = mThreadPoolManager.scheduleFixedRate( ThreadType.DECIMATION,
mDecimationProcessor, 20, TimeUnit.MILLISECONDS );
mScheduledExecutorService = Executors.newScheduledThreadPool( 1,
new NamingThreadFactory( "tuner channel source" ) );
/* Schedule the decimation task to run every 10 ms (100 iterations/second) */
mTaskHandle = mScheduledExecutorService.scheduleAtFixedRate(
mDecimationProcessor, 0, 10, TimeUnit.MILLISECONDS );
/* Finally, register to receive samples from the tuner */
mTuner.addListener( (Listener<ComplexBuffer>)this );
@@ -156,10 +158,15 @@ public class TunerChannelSource extends ComplexSource
mTuner.releaseChannel( this );
mDecimationProcessor.shutdown();
if( mThreadPoolManager != null && mTaskHandle != null )
if( mScheduledExecutorService != null && mTaskHandle != null )
{
mThreadPoolManager.cancel( mTaskHandle );
mTaskHandle = null;
if( mTaskHandle != null )
{
mTaskHandle.cancel( true );
mTaskHandle = null;
}
mScheduledExecutorService.shutdownNow();
}
mBuffer.clear();
@@ -340,7 +347,9 @@ public class TunerChannelSource extends ComplexSource
{
if( mBuffer != null )
{
mBuffer.drainTo( mSampleBuffers, 4 );
long start = System.currentTimeMillis();
mBuffer.drainTo( mSampleBuffers );
for( Buffer buffer: mSampleBuffers )
{
@@ -378,6 +387,8 @@ public class TunerChannelSource extends ComplexSource
}
}
mLog.debug( "Processed [" + mSampleBuffers.size() + "] in " + ( System.currentTimeMillis() - start ) );
mSampleBuffers.clear();
}
}

View File

@@ -194,8 +194,8 @@ public abstract class TunerController implements Tunable
*
* @throws RejectedExecutionException if the decimation processor has an error
*/
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
Tuner tuner, TunerChannel channel ) throws RejectedExecutionException
public TunerChannelSource getChannel( Tuner tuner, TunerChannel channel )
throws RejectedExecutionException
{
TunerChannelSource source = null;
@@ -210,8 +210,7 @@ public abstract class TunerController implements Tunable
updateLOFrequency();
}
source = new TunerChannelSource( threadPoolManager,
tuner, channel );
source = new TunerChannelSource( tuner, channel );
}
catch( SourceException se )
{

View File

@@ -104,7 +104,7 @@ public class TunerManager
try
{
retVal = tuner.getChannel( mThreadPoolManager, tunerChannel );
retVal = tuner.getChannel( tunerChannel );
}
catch ( RejectedExecutionException ree )
{

View File

@@ -35,7 +35,6 @@ import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.airspy.AirspyTunerController.BoardID;
import controller.ThreadPoolManager;
public class AirspyTuner extends Tuner
{
@@ -128,8 +127,8 @@ public class AirspyTuner extends Tuner
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException, SourceException
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException
{
//TODO: this channel has a decimated sample rate of:
// 10.0 MSps = 10,000,000 / 208 = 48076.923
@@ -138,7 +137,7 @@ public class AirspyTuner extends Tuner
//Consider implementing a fractional resampler to get a correct 48 kHz
//output sample rate
return mController.getChannel( threadPoolManager, this, channel );
return mController.getChannel( this, channel );
}
@Override

View File

@@ -99,8 +99,8 @@ public class B100Tuner extends Tuner
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException, SourceException
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException
{
//TODO: pass this call to the tuner controller
return null;

View File

@@ -33,7 +33,6 @@ import source.tuner.TunerChannelSource;
import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import controller.ThreadPoolManager;
public class FCDTuner extends MixerTuner
{
@@ -111,11 +110,10 @@ public class FCDTuner extends MixerTuner
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel tunerChannel ) throws RejectedExecutionException,
SourceException
public TunerChannelSource getChannel( TunerChannel tunerChannel )
throws RejectedExecutionException, SourceException
{
return mController.getChannel( threadPoolManager, this, tunerChannel );
return mController.getChannel( this, tunerChannel );
}
/**

View File

@@ -35,7 +35,6 @@ import source.tuner.TunerClass;
import source.tuner.TunerConfiguration;
import source.tuner.TunerType;
import source.tuner.hackrf.HackRFTunerController.BoardID;
import controller.ThreadPoolManager;
public class HackRFTuner extends Tuner
{
@@ -106,10 +105,10 @@ public class HackRFTuner extends Tuner
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel ) throws RejectedExecutionException, SourceException
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException, SourceException
{
return mController.getChannel( threadPoolManager, this, channel );
return mController.getChannel( this, channel );
}
@Override

View File

@@ -148,8 +148,7 @@ public class RTL2832Tuner extends Tuner
}
@Override
public TunerChannelSource getChannel( ThreadPoolManager threadPoolManager,
TunerChannel channel )
public TunerChannelSource getChannel( TunerChannel channel )
throws RejectedExecutionException,
SourceException
{
@@ -157,7 +156,7 @@ public class RTL2832Tuner extends Tuner
try
{
source = mController.getChannel( threadPoolManager, this, channel );
source = mController.getChannel( this, channel );
}
catch( Exception e )
{