mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||
public abstract class AbstractAudioModule extends Module implements IAudioSegmentProvider, IdentifierUpdateListener
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AbstractAudioModule.class);
|
||||
public static final long DEFAULT_SEGMENT_AUDIO_SAMPLE_LENGTH = 60 * 8000; // 1 minute @ 8kHz
|
||||
public static final long DEFAULT_MAX_SEGMENT_LENGTH_MILLIS = 60_000; // 1 minute
|
||||
public static final int DEFAULT_TIMESLOT = 0;
|
||||
private final int mMaxSegmentAudioSampleLength;
|
||||
private Listener<AudioSegment> mAudioSegmentListener;
|
||||
@@ -51,12 +51,12 @@ public abstract class AbstractAudioModule extends Module implements IAudioSegmen
|
||||
* Constructs an abstract audio module
|
||||
*
|
||||
* @param aliasList for aliasing identifiers
|
||||
* @param maxSegmentAudioSampleLength in milliseconds
|
||||
* @param maxSegmentLengthMillis maximum audio segment length in milliseconds
|
||||
*/
|
||||
public AbstractAudioModule(AliasList aliasList, int timeslot, long maxSegmentAudioSampleLength)
|
||||
public AbstractAudioModule(AliasList aliasList, int timeslot, long maxSegmentLengthMillis)
|
||||
{
|
||||
mAliasList = aliasList;
|
||||
mMaxSegmentAudioSampleLength = (int)(maxSegmentAudioSampleLength * 8); //Convert milliseconds to samples
|
||||
mMaxSegmentAudioSampleLength = (int)(maxSegmentLengthMillis * 8); //Convert milliseconds to samples
|
||||
mTimeslot = timeslot;
|
||||
mIdentifierCollection = new MutableIdentifierCollection(getTimeslot());
|
||||
mIdentifierUpdateNotificationBroadcaster.addListener(mIdentifierCollection);
|
||||
@@ -67,7 +67,7 @@ public abstract class AbstractAudioModule extends Module implements IAudioSegmen
|
||||
*/
|
||||
public AbstractAudioModule(AliasList aliasList)
|
||||
{
|
||||
this(aliasList, DEFAULT_TIMESLOT, DEFAULT_SEGMENT_AUDIO_SAMPLE_LENGTH);
|
||||
this(aliasList, DEFAULT_TIMESLOT, DEFAULT_MAX_SEGMENT_LENGTH_MILLIS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,7 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
|
||||
|
||||
public JmbeAudioModule(UserPreferences userPreferences, AliasList aliasList, int timeslot)
|
||||
{
|
||||
super(aliasList, timeslot, DEFAULT_SEGMENT_AUDIO_SAMPLE_LENGTH);
|
||||
super(aliasList, timeslot, DEFAULT_MAX_SEGMENT_LENGTH_MILLIS);
|
||||
mUserPreferences = userPreferences;
|
||||
MyEventBus.getGlobalEventBus().register(this);
|
||||
loadConverter();
|
||||
|
||||
@@ -46,6 +46,12 @@ public class AudioChannel implements Listener<IdentifierUpdateNotification>
|
||||
* sample rate.
|
||||
*/
|
||||
public static final int SAMPLES_PER_INTERVAL = 160;
|
||||
/**
|
||||
* Quantity of consecutive intervals without new audio (1 second) before an incomplete audio segment is treated as
|
||||
* stalled and abandoned. An audio segment is delivered once to a single channel, so abandoning a segment that is
|
||||
* still live loses the rest of the call. This has to tolerate decoder gaps, such as a missed P25 LDU (180 ms).
|
||||
*/
|
||||
static final int MAX_STALLED_INTERVALS = 50;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AudioChannel.class);
|
||||
private final AudioBuffer mAudioBuffer = new AudioBuffer();
|
||||
private final Broadcaster<AudioEvent> mAudioEventBroadcaster = new Broadcaster<>();
|
||||
@@ -225,7 +231,7 @@ public class AudioChannel implements Listener<IdentifierUpdateNotification>
|
||||
}
|
||||
|
||||
//Dispose completed/fully-played audio segments and segments that have stalled/failed to progress
|
||||
if(mCurrentAudioSegment != null && ((mNoAudioFromSegmentIntervalCount >= 6) ||
|
||||
if(mCurrentAudioSegment != null && ((mNoAudioFromSegmentIntervalCount >= MAX_STALLED_INTERVALS) ||
|
||||
(mCurrentAudioSegment.isComplete() && (mCurrentBufferIndex >= mCurrentAudioSegment.getAudioBufferCount()))))
|
||||
{
|
||||
disposeCurrentAudioSegment();
|
||||
@@ -401,6 +407,24 @@ public class AudioChannel implements Listener<IdentifierUpdateNotification>
|
||||
return mAudioSegmentQueue.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Next audio segment queued for playback, without removing it from the queue.
|
||||
* @return queued audio segment or null if the queue is empty.
|
||||
*/
|
||||
AudioSegment peekQueuedAudioSegment()
|
||||
{
|
||||
return mAudioSegmentQueue.peek();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the next audio segment from the queue, transferring it (and its consumer count) to the caller.
|
||||
* @return queued audio segment or null if the queue is empty.
|
||||
*/
|
||||
AudioSegment pollQueuedAudioSegment()
|
||||
{
|
||||
return mAudioSegmentQueue.poll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the audio segment for playback. The audio segment user count should already be incremented by the
|
||||
* calling entity.
|
||||
@@ -475,6 +499,7 @@ public class AudioChannel implements Listener<IdentifierUpdateNotification>
|
||||
}
|
||||
|
||||
mCurrentBufferIndex = -1;
|
||||
mNoAudioFromSegmentIntervalCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -173,6 +173,7 @@ public class AudioPlaybackManager implements Listener<AudioSegment>, IAudioContr
|
||||
{
|
||||
Iterator<AudioSegment> it = mAudioSegments.iterator();
|
||||
AudioSegment audioSegment;
|
||||
List<AudioSegment> displaced = new ArrayList<>();
|
||||
|
||||
//Remove any audio segments flagged as do not monitor. Don't remove completed segments yet, because
|
||||
//we want to give them a brief chance at playback. Automatically assign linked audio segments to the
|
||||
@@ -200,6 +201,16 @@ public class AudioPlaybackManager implements Listener<AudioSegment>, IAudioContr
|
||||
if(audioOutput.isLinkedTo(audioSegment))
|
||||
{
|
||||
it.remove();
|
||||
|
||||
//Linked audio continues the current call, so it goes ahead of anything queued
|
||||
AudioSegment queued = audioOutput.pollQueuedAudioSegment();
|
||||
|
||||
while(queued != null)
|
||||
{
|
||||
displaced.add(queued);
|
||||
queued = audioOutput.pollQueuedAudioSegment();
|
||||
}
|
||||
|
||||
audioOutput.play(audioSegment);
|
||||
}
|
||||
}
|
||||
@@ -212,6 +223,8 @@ public class AudioPlaybackManager implements Listener<AudioSegment>, IAudioContr
|
||||
}
|
||||
}
|
||||
|
||||
mAudioSegments.addAll(displaced);
|
||||
|
||||
//Sort audio segments by playback priority and assign to empty audio outputs
|
||||
if(!mAudioSegments.isEmpty() && mAudioOutput != null)
|
||||
{
|
||||
@@ -232,6 +245,8 @@ public class AudioPlaybackManager implements Listener<AudioSegment>, IAudioContr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replaceLowerPriorityQueuedSegments(mAudioSegments, mAudioOutput.getAudioProvider().getAudioChannels());
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -255,6 +270,40 @@ public class AudioPlaybackManager implements Listener<AudioSegment>, IAudioContr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps audio segments queued on the audio channels for waiting audio segments that have a higher playback priority,
|
||||
* so that a segment queued behind the current playback can't hold a higher priority segment out of the channel.
|
||||
* Audio that is currently playing is not interrupted. Displaced segments are returned to the waiting list.
|
||||
*
|
||||
* @param waiting audio segments, sorted by playback priority.
|
||||
* @param audioChannels to evaluate.
|
||||
*/
|
||||
static void replaceLowerPriorityQueuedSegments(List<AudioSegment> waiting, List<AudioChannel> audioChannels)
|
||||
{
|
||||
for(AudioChannel audioChannel: audioChannels)
|
||||
{
|
||||
if(waiting.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSegment queued = audioChannel.peekQueuedAudioSegment();
|
||||
|
||||
if(queued != null &&
|
||||
waiting.getFirst().monitorPriorityProperty().get() < queued.monitorPriorityProperty().get())
|
||||
{
|
||||
//The audio thread may have taken the queued segment since the peek, so only return what we removed.
|
||||
queued = audioChannel.pollQueuedAudioSegment();
|
||||
audioChannel.play(waiting.removeFirst());
|
||||
|
||||
if(queued != null)
|
||||
{
|
||||
waiting.add(queued);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
MyEventBus.getGlobalEventBus().unregister(this);
|
||||
|
||||
Reference in New Issue
Block a user