mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-16 10:37:26 -05:00
Resolves issue where higher priority audio was not preempting lower priority audio.
This commit is contained in:
@@ -86,6 +86,9 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the saved mixer configuration or a default configuration for audio playback.
|
||||||
|
*/
|
||||||
private void loadSettings()
|
private void loadSettings()
|
||||||
{
|
{
|
||||||
MixerChannelConfiguration configuration = null;
|
MixerChannelConfiguration configuration = null;
|
||||||
@@ -132,6 +135,9 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a default audio playback configuration with a mono audio playback channel.
|
||||||
|
*/
|
||||||
private MixerChannelConfiguration getDefaultConfiguration()
|
private MixerChannelConfiguration getDefaultConfiguration()
|
||||||
{
|
{
|
||||||
/* Use the system default mixer and mono channel as default startup */
|
/* Use the system default mixer and mono channel as default startup */
|
||||||
@@ -161,6 +167,9 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
mAudioOutputConnections.clear();
|
mAudioOutputConnections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary ingest point for audio produced by all decoding channels, for distribution to audio playback devices.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void receive(AudioPacket packet)
|
public synchronized void receive(AudioPacket packet)
|
||||||
{
|
{
|
||||||
@@ -176,11 +185,11 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
|
|
||||||
for(AudioOutputConnection connection : mAudioOutputConnections)
|
for(AudioOutputConnection connection : mAudioOutputConnections)
|
||||||
{
|
{
|
||||||
if(connection.isInactive() &&
|
if(connection.isInactive() && mChannelConnectionMap.containsKey(connection.getChannelMetadataID()))
|
||||||
mChannelConnectionMap.containsKey(connection.getChannelMetadataID()))
|
|
||||||
{
|
{
|
||||||
mChannelConnectionMap.remove(connection.getChannelMetadataID());
|
mChannelConnectionMap.remove(connection.getChannelMetadataID());
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
mAvailableConnectionCount++;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +201,7 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies the lowest priority channel connection
|
* Identifies the lowest priority channel connection where the a higher value indicates a lower priority.
|
||||||
*/
|
*/
|
||||||
private void updateLowestPriorityAssignment()
|
private void updateLowestPriorityAssignment()
|
||||||
{
|
{
|
||||||
@@ -201,19 +210,32 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
for(AudioOutputConnection connection : mAudioOutputConnections)
|
for(AudioOutputConnection connection : mAudioOutputConnections)
|
||||||
{
|
{
|
||||||
if(connection.isConnected() &&
|
if(connection.isConnected() &&
|
||||||
(mLowestPriorityConnection == null || mLowestPriorityConnection.getPriority() > connection.getPriority()))
|
(mLowestPriorityConnection == null || mLowestPriorityConnection.getPriority() < connection.getPriority()))
|
||||||
{
|
{
|
||||||
mLowestPriorityConnection = connection;
|
mLowestPriorityConnection = connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio playback to use the configuration specified in the entry argument.
|
||||||
|
*
|
||||||
|
* @param entry to use in configuring the audio playback setup.
|
||||||
|
* @throws AudioException if there is an error
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setMixerChannelConfiguration(MixerChannelConfiguration entry) throws AudioException
|
public void setMixerChannelConfiguration(MixerChannelConfiguration entry) throws AudioException
|
||||||
{
|
{
|
||||||
setMixerChannelConfiguration(entry, true);
|
setMixerChannelConfiguration(entry, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures audio playback to use the configuration specified in the entry argument.
|
||||||
|
*
|
||||||
|
* @param entry to use in configuring the audio playback setup.
|
||||||
|
* @param saveSettings to save the audio playback configuration settings in the properties file.
|
||||||
|
* @throws AudioException if there is an error
|
||||||
|
*/
|
||||||
public void setMixerChannelConfiguration(MixerChannelConfiguration entry, boolean saveSettings) throws AudioException
|
public void setMixerChannelConfiguration(MixerChannelConfiguration entry, boolean saveSettings) throws AudioException
|
||||||
{
|
{
|
||||||
if(entry != null && (entry.getMixerChannel() == MixerChannel.MONO || entry.getMixerChannel() == MixerChannel.STEREO))
|
if(entry != null && (entry.getMixerChannel() == MixerChannel.MONO || entry.getMixerChannel() == MixerChannel.STEREO))
|
||||||
@@ -266,9 +288,8 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all channel assignments and terminates all audio outputs in
|
* Clears all channel assignments and terminates all audio outputs in preparation for complete shutdown or change
|
||||||
* preparation for complete shutdown or change to another mixer/channel
|
* to another mixer/channel configuration
|
||||||
* configuration
|
|
||||||
*/
|
*/
|
||||||
private void disposeCurrentConfiguration()
|
private void disposeCurrentConfiguration()
|
||||||
{
|
{
|
||||||
@@ -288,12 +309,18 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
mLowestPriorityConnection = null;
|
mLowestPriorityConnection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current audio playback mixer channel configuration setting.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MixerChannelConfiguration getMixerChannelConfiguration() throws AudioException
|
public MixerChannelConfiguration getMixerChannelConfiguration() throws AudioException
|
||||||
{
|
{
|
||||||
return mMixerChannelConfiguration;
|
return mMixerChannelConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of audio outputs available for the current mixer channel configuration
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AudioOutput> getAudioOutputs()
|
public List<AudioOutput> getAudioOutputs()
|
||||||
{
|
{
|
||||||
@@ -311,12 +338,18 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an audio event listener to receive audio event notifications.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addControllerListener(Listener<AudioEvent> listener)
|
public void addControllerListener(Listener<AudioEvent> listener)
|
||||||
{
|
{
|
||||||
mControllerBroadcaster.addListener(listener);
|
mControllerBroadcaster.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an audio event listener from receiving audio event notifications.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void removeControllerListener(Listener<AudioEvent> listener)
|
public void removeControllerListener(Listener<AudioEvent> listener)
|
||||||
{
|
{
|
||||||
@@ -324,16 +357,15 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an audio output connection for the packet if one is
|
* Returns an audio output connection for the packet if one is available, or overrides an existing lower priority
|
||||||
* available, or overrides an existing lower priority connection.
|
* connection. Returns null if no connection is available for the audio packet.
|
||||||
* Returns null if no connection is available for the audio packet.
|
|
||||||
*
|
*
|
||||||
* @param packet from a source
|
* @param audioPacket from a decoding channel source
|
||||||
* @return an audio output connection or null
|
* @return an audio output connection or null
|
||||||
*/
|
*/
|
||||||
private AudioOutputConnection getConnection(AudioPacket packet)
|
private AudioOutputConnection getConnection(AudioPacket audioPacket)
|
||||||
{
|
{
|
||||||
int channelMetadataID = packet.getMetadata().getMetadataID();
|
int channelMetadataID = audioPacket.getMetadata().getMetadataID();
|
||||||
|
|
||||||
//Use an existing connection
|
//Use an existing connection
|
||||||
if(mChannelConnectionMap.containsKey(channelMetadataID))
|
if(mChannelConnectionMap.containsKey(channelMetadataID))
|
||||||
@@ -341,37 +373,35 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
return mChannelConnectionMap.get(channelMetadataID);
|
return mChannelConnectionMap.get(channelMetadataID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Connect to and use an available connection
|
//Connect to an unused, available connection
|
||||||
if(mAvailableConnectionCount > 0)
|
if(mAvailableConnectionCount > 0)
|
||||||
{
|
{
|
||||||
for(AudioOutputConnection connection : mAudioOutputConnections)
|
for(AudioOutputConnection connection : mAudioOutputConnections)
|
||||||
{
|
{
|
||||||
if(connection.isDisconnected())
|
if(connection.isDisconnected())
|
||||||
{
|
{
|
||||||
connection.connect(channelMetadataID);
|
connection.connect(channelMetadataID, audioPacket.getMetadata().getAudioPriority());
|
||||||
mChannelConnectionMap.put(channelMetadataID, connection);
|
mChannelConnectionMap.put(channelMetadataID, connection);
|
||||||
|
mAvailableConnectionCount--;
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Preempt an existing connection and connect it to this higher priority source
|
//Preempt an existing lower priority connection and connect when this is a higher priority packet
|
||||||
else //Check for a channel priority override
|
else
|
||||||
{
|
{
|
||||||
int priority = packet.getMetadata().getAudioPriority();
|
int priority = audioPacket.getMetadata().getAudioPriority();
|
||||||
|
|
||||||
if(mLowestPriorityConnection != null &&
|
AudioOutputConnection connection = mLowestPriorityConnection;
|
||||||
priority < mLowestPriorityConnection.getPriority())
|
|
||||||
|
if(connection != null && priority < connection.getPriority())
|
||||||
{
|
{
|
||||||
AudioOutputConnection connection = mLowestPriorityConnection;
|
|
||||||
|
|
||||||
mChannelConnectionMap.remove(connection.getChannelMetadataID());
|
mChannelConnectionMap.remove(connection.getChannelMetadataID());
|
||||||
|
|
||||||
connection.connect(channelMetadataID);
|
connection.connect(channelMetadataID, priority);
|
||||||
|
|
||||||
mChannelConnectionMap.put(channelMetadataID, connection);
|
mChannelConnectionMap.put(channelMetadataID, connection);
|
||||||
|
|
||||||
updateLowestPriorityAssignment();
|
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +426,7 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
|
|
||||||
for(AudioPacket packet : packets)
|
for(AudioPacket packet : packets)
|
||||||
{
|
{
|
||||||
/* Don't process any packet's marked as do not monitor */
|
/* Don't process any packet's marked as do not monitor */
|
||||||
if(!packet.getMetadata().isDoNotMonitor() && packet.getType() == AudioPacket.Type.AUDIO)
|
if(!packet.getMetadata().isDoNotMonitor() && packet.getType() == AudioPacket.Type.AUDIO)
|
||||||
{
|
{
|
||||||
AudioOutputConnection connection = getConnection(packet);
|
AudioOutputConnection connection = getConnection(packet);
|
||||||
@@ -494,9 +524,11 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
|
|||||||
* Connects this assignment to the indicated source so that audio
|
* Connects this assignment to the indicated source so that audio
|
||||||
* packets from this source can be sent to the audio output
|
* packets from this source can be sent to the audio output
|
||||||
*/
|
*/
|
||||||
public void connect(int source)
|
public void connect(int source, int priority)
|
||||||
{
|
{
|
||||||
mChannelMetadataID = source;
|
mChannelMetadataID = source;
|
||||||
|
mPriority = priority;
|
||||||
|
updateLowestPriorityAssignment();
|
||||||
|
|
||||||
mAudioOutput.updateTimestamp();
|
mAudioOutput.updateTimestamp();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user