Merge changes Iaa920c07,I4eb8046a into sc-dev

* changes:
  HwAudioSource: wrong native handle check
  AudioSystem: startAudioSource: ensure port handle initialized
This commit is contained in:
Eric Laurent
2021-04-22 14:14:49 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 6 deletions

View File

@@ -1930,7 +1930,11 @@ android_media_AudioSystem_startAudioSource(JNIEnv *env, jobject clazz,
audio_port_handle_t handle;
status_t status = AudioSystem::startAudioSource(&nAudioPortConfig, paa.get(), &handle);
ALOGV("AudioSystem::startAudioSource() returned %d handle %d", status, handle);
return handle > 0 ? handle : nativeToJavaStatus(status);
if (status != NO_ERROR) {
return nativeToJavaStatus(status);
}
ALOG_ASSERT(handle > 0, "%s: invalid handle reported on successful call", __func__);
return handle;
}
static jint

View File

@@ -37,7 +37,13 @@ public class HwAudioSource extends PlayerBase {
private final AudioDeviceInfo mAudioDeviceInfo;
private final AudioAttributes mAudioAttributes;
private int mNativeHandle;
/**
* The value of the native handle encodes the HwAudioSource state.
* The native handle returned by {@link AudioSystem#startAudioSource} is either valid
* (aka > 0, so successfully started) or hosting an error code (negative).
* 0 corresponds to an untialized or stopped HwAudioSource.
*/
private int mNativeHandle = 0;
/**
* Class constructor for a hardware audio source based player.
@@ -129,14 +135,18 @@ public class HwAudioSource extends PlayerBase {
/**
* Starts the playback from {@link AudioDeviceInfo}.
* Starts does not return any error code, caller must check {@link HwAudioSource#isPlaying} to
* ensure the state of the HwAudioSource encoded in {@link mNativeHandle}.
*/
public void start() {
Preconditions.checkState(!isPlaying(), "HwAudioSource is currently playing");
mNativeHandle = AudioSystem.startAudioSource(
mAudioDeviceInfo.getPort().activeConfig(),
mAudioAttributes);
// FIXME: b/174876389 clean up device id reporting
baseStart(getDeviceId());
if (isPlaying()) {
// FIXME: b/174876389 clean up device id reporting
baseStart(getDeviceId());
}
}
private int getDeviceId() {
@@ -162,18 +172,23 @@ public class HwAudioSource extends PlayerBase {
/**
* Checks whether the HwAudioSource player is playing.
* It checks the state of the HwAudioSource encoded in {@link HwAudioSource#isPlaying}.
* 0 corresponds to a stopped or uninitialized HwAudioSource.
* Negative value corresponds to a status reported by {@link AudioSystem#startAudioSource} to
* indicate a failure when trying to start the HwAudioSource.
*
* @return true if currently playing, false otherwise
*/
public boolean isPlaying() {
return mNativeHandle != 0;
return mNativeHandle > 0;
}
/**
* Stops the playback from {@link AudioDeviceInfo}.
*/
public void stop() {
baseStop();
if (mNativeHandle > 0) {
baseStop();
AudioSystem.stopAudioSource(mNativeHandle);
mNativeHandle = 0;
}