Merge "MediaMetrics: Send playerIId to native AudioTrack" into sc-dev

This commit is contained in:
Andy Hung
2021-02-22 19:36:43 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 1 deletions

View File

@@ -1419,6 +1419,16 @@ static jint android_media_AudioTrack_getDualMonoMode(JNIEnv *env, jobject thiz,
return nativeToJavaStatus(status); return nativeToJavaStatus(status);
} }
static void android_media_AudioTrack_setPlayerIId(JNIEnv *env, jobject thiz, jint playerIId) {
sp<AudioTrack> track = getAudioTrack(env, thiz);
if (track == nullptr) {
jniThrowException(env, "java/lang/IllegalStateException",
"Unable to retrieve AudioTrack pointer for setPlayerIId()");
}
ALOGV("%s: playerIId %d", __func__, playerIId);
track->setPlayerIId(playerIId);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static const JNINativeMethod gMethods[] = { static const JNINativeMethod gMethods[] = {
@@ -1496,6 +1506,7 @@ static const JNINativeMethod gMethods[] = {
(void *)android_media_AudioTrack_getAudioDescriptionMixLeveldB}, (void *)android_media_AudioTrack_getAudioDescriptionMixLeveldB},
{"native_set_dual_mono_mode", "(I)I", (void *)android_media_AudioTrack_setDualMonoMode}, {"native_set_dual_mono_mode", "(I)I", (void *)android_media_AudioTrack_setDualMonoMode},
{"native_get_dual_mono_mode", "([I)I", (void *)android_media_AudioTrack_getDualMonoMode}, {"native_get_dual_mono_mode", "([I)I", (void *)android_media_AudioTrack_getDualMonoMode},
{"native_setPlayerIId", "(I)V", (void *)android_media_AudioTrack_setPlayerIId},
}; };
// field names found in android/media/AudioTrack.java // field names found in android/media/AudioTrack.java

View File

@@ -837,6 +837,7 @@ public class AudioTrack extends PlayerBase
} }
baseRegisterPlayer(mSessionId); baseRegisterPlayer(mSessionId);
native_setPlayerIId(mPlayerIId); // mPlayerIId now ready to send to native AudioTrack.
} }
/** /**
@@ -4203,6 +4204,20 @@ public class AudioTrack extends PlayerBase
private native int native_set_dual_mono_mode(int dualMonoMode); private native int native_set_dual_mono_mode(int dualMonoMode);
private native int native_get_dual_mono_mode(int[] dualMonoMode); private native int native_get_dual_mono_mode(int[] dualMonoMode);
/**
* Sets the audio service Player Interface Id.
*
* The playerIId does not change over the lifetime of the client
* Java AudioTrack and is set automatically on creation.
*
* This call informs the native AudioTrack for metrics logging purposes.
*
* @param id the value reported by AudioManager when registering the track.
* A value of -1 indicates invalid - the playerIId was never set.
* @throws IllegalStateException if AudioTrack not initialized.
*/
private native void native_setPlayerIId(int playerIId);
//--------------------------------------------------------- //---------------------------------------------------------
// Utility methods // Utility methods
//------------------ //------------------

View File

@@ -78,7 +78,7 @@ public abstract class PlayerBase {
private final int mImplType; private final int mImplType;
// uniquely identifies the Player Interface throughout the system (P I Id) // uniquely identifies the Player Interface throughout the system (P I Id)
private int mPlayerIId = AudioPlaybackConfiguration.PLAYER_PIID_INVALID; protected int mPlayerIId = AudioPlaybackConfiguration.PLAYER_PIID_INVALID;
@GuardedBy("mLock") @GuardedBy("mLock")
private int mState; private int mState;