Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2006 AudioOutput Recreated Once It Fails To Accept Audio Samples For Playback #2011

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/main/java/io/github/dsheirer/audio/playback/AudioOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.identifier.IdentifierCollection;
import io.github.dsheirer.identifier.IdentifierUpdateNotification;
import io.github.dsheirer.log.LoggingSuppressor;
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.sample.Broadcaster;
Expand Down Expand Up @@ -58,6 +59,7 @@
public abstract class AudioOutput implements LineListener, Listener<IdentifierUpdateNotification>
{
private final static Logger mLog = LoggerFactory.getLogger(AudioOutput.class);
private static final LoggingSuppressor LOGGING_SUPPRESSOR = new LoggingSuppressor(mLog);
private int mBufferStartThreshold;
private int mBufferStopThreshold;
private Listener<IdentifierCollection> mIdentifierCollectionListener;
Expand All @@ -83,6 +85,7 @@ public abstract class AudioOutput implements LineListener, Listener<IdentifierUp
private long mOutputLastTimestamp = 0;
private static final long STALE_PLAYBACK_THRESHOLD_MS = 500;
private AudioFormat mAudioFormat;
private Line.Info mLineInfo;
private int mRequestedBufferSize;

/**
Expand All @@ -109,11 +112,12 @@ public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioForm
mUserPreferences = userPreferences;
mDropDuplicates = mUserPreferences.getDuplicateCallDetectionPreference().isDuplicatePlaybackSuppressionEnabled();
mAudioFormat = audioFormat;
mLineInfo = lineInfo;
mRequestedBufferSize = requestedBufferSize;

try
{
mOutput = (SourceDataLine) mMixer.getLine(lineInfo);
mOutput = (SourceDataLine) mMixer.getLine(mLineInfo);

if(mOutput != null)
{
Expand Down Expand Up @@ -270,6 +274,12 @@ private void updateToneInsertionAudioClips()
*/
private void playAudio(ByteBuffer buffer)
{
if(mOutput == null)
{
LOGGING_SUPPRESSOR.error("null output", 5, "Audio Output is null - ignoring audio playback request");
return;
}

if(buffer != null)
{
int wrote = 0;
Expand Down Expand Up @@ -298,6 +308,29 @@ private void playAudio(ByteBuffer buffer)
{
mOutput.close();

try
{
mOutput = (SourceDataLine)mMixer.getLine(mLineInfo);

if(mOutput != null)
{
LOGGING_SUPPRESSOR.info("reopen audio output success", 5,
"Closed and reopened audio output - success - mOutput is not null");
}
else
{
LOGGING_SUPPRESSOR.info("reopen audio output fail", 5,
"Closed and reopened audio output - fail - mOutput is null");
return;
}
}
catch(LineUnavailableException lue)
{
LOGGING_SUPPRESSOR.error("reopen fail for lua", 3, "Attempt to reopen " +
"audio source data line failed", lue);
return;
}

try
{
mOutput.open(mAudioFormat, mRequestedBufferSize);
Expand All @@ -315,7 +348,8 @@ private void playAudio(ByteBuffer buffer)
}
catch(IllegalArgumentException iae)
{
mLog.warn("Couldn't obtain MASTER GAIN control for stereo line [" + getChannelName() + "]");
mLog.warn("Couldn't obtain MASTER GAIN control for stereo line [" + getChannelName() +
"] after reopening the source data line");
}

try
Expand All @@ -325,7 +359,8 @@ private void playAudio(ByteBuffer buffer)
}
catch(IllegalArgumentException iae)
{
mLog.warn("Couldn't obtain MUTE control for stereo line [" + getChannelName() + "]");
mLog.warn("Couldn't obtain MUTE control for stereo line [" + getChannelName() +
"] after reopening the source data line");
}

mAudioStartEvent = new AudioEvent(AudioEvent.Type.AUDIO_STARTED, getChannelName());
Expand All @@ -334,8 +369,10 @@ private void playAudio(ByteBuffer buffer)
}
catch(LineUnavailableException e)
{
mLog.error("Couldn't obtain audio source data line for audio output - mixer [" +
LOGGING_SUPPRESSOR.error("failed reopen source data line lua", 3,
"Failed to (re)open the source data line for audio output - mixer [" +
mMixer.getMixerInfo().getName() + "]");
return;
}
}
}
Expand Down
Loading