Commit f5c48430 authored by Thomas Guillem's avatar Thomas Guillem Committed by Geoffrey Métais

LibVLC: MediaPlayer: fix plug events thread safety

Unregister it before selecting a new output/device.
Register it after selecting a new output/device.

(cherry picked from commit 47b50ec3)
parent 5d98ec27
...@@ -690,6 +690,10 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> { ...@@ -690,6 +690,10 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
nativeSetAspectRatio(aspect); nativeSetAspectRatio(aspect);
} }
private boolean isAudioTrack() {
return mAudioOutput != null && mAudioOutput.equals("android_audiotrack");
}
/** /**
* Update the video viewpoint information * Update the video viewpoint information
* *
...@@ -717,31 +721,46 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> { ...@@ -717,31 +721,46 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
* *
* @return true on success. * @return true on success.
*/ */
public boolean setAudioOutput(String aout) { public synchronized boolean setAudioOutput(String aout) {
mAudioOutput = aout;
/* If The user forced an output different than AudioTrack, don't listen to audio
* plug events and let the user decide */
mListenAudioPlug = isAudioTrack();
if (!mListenAudioPlug)
registerAudioPlug(false);
final boolean ret = nativeSetAudioOutput(aout); final boolean ret = nativeSetAudioOutput(aout);
if (ret) {
synchronized (this) { if (!ret) {
mAudioOutput = aout; mAudioOutput = null;
/* The user forced an output, don't listen to audio plug events and let the user decide */ mListenAudioPlug = false;
mListenAudioPlug = false;
registerAudioPlug(false);
}
} }
if (mListenAudioPlug)
registerAudioPlug(true);
return ret; return ret;
} }
private boolean setAudioOutputDeviceInternal(String id, boolean fromUser) { private synchronized boolean setAudioOutputDeviceInternal(String id, boolean fromUser) {
mAudioOutputDevice = id;
if (fromUser) {
/* The user forced a device, don't listen to audio plug events and let the user decide */
mListenAudioPlug = mAudioOutputDevice == null && isAudioTrack();
if (!mListenAudioPlug)
registerAudioPlug(false);
}
final boolean ret = nativeSetAudioOutputDevice(id); final boolean ret = nativeSetAudioOutputDevice(id);
if (ret) {
synchronized (this) { if (!ret) {
mAudioOutputDevice = id; mAudioOutputDevice = null;
if (fromUser) { mListenAudioPlug = false;
/* The user forced a device, don't listen to audio plug events and let the user decide */
mListenAudioPlug = false;
registerAudioPlug(false);
}
}
} }
if (mListenAudioPlug)
registerAudioPlug(true);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment