summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/jni/android_media_AudioRecord.cpp103
-rw-r--r--core/jni/android_media_AudioTrack.cpp7
-rw-r--r--media/java/android/media/AudioRecord.java27
-rw-r--r--media/java/android/media/AudioTrack.java9
4 files changed, 98 insertions, 48 deletions
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 8d193bfa1dd2..0e0f98ec1fc4 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -861,6 +861,23 @@ static int android_media_AudioRecord_set_preferred_microphone_field_dimension(
return jStatus;
}
+static void android_media_AudioRecord_setLogSessionId(JNIEnv *env, jobject thiz,
+ jstring jlogSessionId) {
+ sp<AudioRecord> record = getAudioRecord(env, thiz);
+ if (record == nullptr) {
+ jniThrowException(env, "java/lang/IllegalStateException",
+ "Unable to retrieve AudioRecord pointer for setLogSessionId()");
+ }
+ if (jlogSessionId == nullptr) {
+ ALOGV("%s: logSessionId nullptr", __func__);
+ record->setLogSessionId(nullptr);
+ return;
+ }
+ ScopedUtfChars logSessionId(env, jlogSessionId);
+ ALOGV("%s: logSessionId '%s'", __func__, logSessionId.c_str());
+ record->setLogSessionId(logSessionId.c_str());
+}
+
// ----------------------------------------------------------------------------
static jint android_media_AudioRecord_get_port_id(JNIEnv *env, jobject thiz) {
sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
@@ -876,50 +893,48 @@ static jint android_media_AudioRecord_get_port_id(JNIEnv *env, jobject thiz) {
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
static const JNINativeMethod gMethods[] = {
- // name, signature, funcPtr
- {"native_start", "(II)I", (void *)android_media_AudioRecord_start},
- {"native_stop", "()V", (void *)android_media_AudioRecord_stop},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;[IIIII[ILjava/lang/String;J)I",
- (void *)android_media_AudioRecord_setup},
- {"native_finalize", "()V", (void *)android_media_AudioRecord_finalize},
- {"native_release", "()V", (void *)android_media_AudioRecord_release},
- {"native_read_in_byte_array",
- "([BIIZ)I",
- (void *)android_media_AudioRecord_readInArray<jbyteArray>},
- {"native_read_in_short_array",
- "([SIIZ)I",
- (void *)android_media_AudioRecord_readInArray<jshortArray>},
- {"native_read_in_float_array",
- "([FIIZ)I",
- (void *)android_media_AudioRecord_readInArray<jfloatArray>},
- {"native_read_in_direct_buffer","(Ljava/lang/Object;IZ)I",
- (void *)android_media_AudioRecord_readInDirectBuffer},
- {"native_get_buffer_size_in_frames",
- "()I", (void *)android_media_AudioRecord_get_buffer_size_in_frames},
- {"native_set_marker_pos","(I)I", (void *)android_media_AudioRecord_set_marker_pos},
- {"native_get_marker_pos","()I", (void *)android_media_AudioRecord_get_marker_pos},
- {"native_set_pos_update_period",
- "(I)I", (void *)android_media_AudioRecord_set_pos_update_period},
- {"native_get_pos_update_period",
- "()I", (void *)android_media_AudioRecord_get_pos_update_period},
- {"native_get_min_buff_size",
- "(III)I", (void *)android_media_AudioRecord_get_min_buff_size},
- {"native_getMetrics", "()Landroid/os/PersistableBundle;",
- (void *)android_media_AudioRecord_native_getMetrics},
- {"native_setInputDevice", "(I)Z", (void *)android_media_AudioRecord_setInputDevice},
- {"native_getRoutedDeviceId", "()I", (void *)android_media_AudioRecord_getRoutedDeviceId},
- {"native_enableDeviceCallback", "()V", (void *)android_media_AudioRecord_enableDeviceCallback},
- {"native_disableDeviceCallback", "()V",
- (void *)android_media_AudioRecord_disableDeviceCallback},
- {"native_get_timestamp", "(Landroid/media/AudioTimestamp;I)I",
- (void *)android_media_AudioRecord_get_timestamp},
- {"native_get_active_microphones", "(Ljava/util/ArrayList;)I",
- (void *)android_media_AudioRecord_get_active_microphones},
- {"native_getPortId", "()I", (void *)android_media_AudioRecord_get_port_id},
- {"native_set_preferred_microphone_direction", "(I)I",
- (void *)android_media_AudioRecord_set_preferred_microphone_direction},
- {"native_set_preferred_microphone_field_dimension", "(F)I",
- (void *)android_media_AudioRecord_set_preferred_microphone_field_dimension},
+ {"native_start", "(II)I", (void *)android_media_AudioRecord_start},
+ {"native_stop", "()V", (void *)android_media_AudioRecord_stop},
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;[IIIII[ILjava/lang/String;J)I",
+ (void *)android_media_AudioRecord_setup},
+ {"native_finalize", "()V", (void *)android_media_AudioRecord_finalize},
+ {"native_release", "()V", (void *)android_media_AudioRecord_release},
+ {"native_read_in_byte_array", "([BIIZ)I",
+ (void *)android_media_AudioRecord_readInArray<jbyteArray>},
+ {"native_read_in_short_array", "([SIIZ)I",
+ (void *)android_media_AudioRecord_readInArray<jshortArray>},
+ {"native_read_in_float_array", "([FIIZ)I",
+ (void *)android_media_AudioRecord_readInArray<jfloatArray>},
+ {"native_read_in_direct_buffer", "(Ljava/lang/Object;IZ)I",
+ (void *)android_media_AudioRecord_readInDirectBuffer},
+ {"native_get_buffer_size_in_frames", "()I",
+ (void *)android_media_AudioRecord_get_buffer_size_in_frames},
+ {"native_set_marker_pos", "(I)I", (void *)android_media_AudioRecord_set_marker_pos},
+ {"native_get_marker_pos", "()I", (void *)android_media_AudioRecord_get_marker_pos},
+ {"native_set_pos_update_period", "(I)I",
+ (void *)android_media_AudioRecord_set_pos_update_period},
+ {"native_get_pos_update_period", "()I",
+ (void *)android_media_AudioRecord_get_pos_update_period},
+ {"native_get_min_buff_size", "(III)I", (void *)android_media_AudioRecord_get_min_buff_size},
+ {"native_getMetrics", "()Landroid/os/PersistableBundle;",
+ (void *)android_media_AudioRecord_native_getMetrics},
+ {"native_setInputDevice", "(I)Z", (void *)android_media_AudioRecord_setInputDevice},
+ {"native_getRoutedDeviceId", "()I", (void *)android_media_AudioRecord_getRoutedDeviceId},
+ {"native_enableDeviceCallback", "()V",
+ (void *)android_media_AudioRecord_enableDeviceCallback},
+ {"native_disableDeviceCallback", "()V",
+ (void *)android_media_AudioRecord_disableDeviceCallback},
+ {"native_get_timestamp", "(Landroid/media/AudioTimestamp;I)I",
+ (void *)android_media_AudioRecord_get_timestamp},
+ {"native_get_active_microphones", "(Ljava/util/ArrayList;)I",
+ (void *)android_media_AudioRecord_get_active_microphones},
+ {"native_getPortId", "()I", (void *)android_media_AudioRecord_get_port_id},
+ {"native_set_preferred_microphone_direction", "(I)I",
+ (void *)android_media_AudioRecord_set_preferred_microphone_direction},
+ {"native_set_preferred_microphone_field_dimension", "(F)I",
+ (void *)android_media_AudioRecord_set_preferred_microphone_field_dimension},
+ {"native_setLogSessionId", "(Ljava/lang/String;)V",
+ (void *)android_media_AudioRecord_setLogSessionId},
};
// field names found in android/media/AudioRecord.java
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index da60a75ba900..cae6db57e99c 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -1426,8 +1426,13 @@ static void android_media_AudioTrack_setLogSessionId(JNIEnv *env, jobject thiz,
jniThrowException(env, "java/lang/IllegalStateException",
"Unable to retrieve AudioTrack pointer for setLogSessionId()");
}
+ if (jlogSessionId == nullptr) {
+ ALOGV("%s: logSessionId nullptr", __func__);
+ track->setLogSessionId(nullptr);
+ return;
+ }
ScopedUtfChars logSessionId(env, jlogSessionId);
- ALOGV("%s: logSessionId %s", __func__, logSessionId.c_str());
+ ALOGV("%s: logSessionId '%s'", __func__, logSessionId.c_str());
track->setLogSessionId(logSessionId.c_str());
}
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index b19643761fd7..bf04b660425b 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -275,6 +275,12 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
private AudioAttributes mAudioAttributes;
private boolean mIsSubmixFullVolume = false;
+ /**
+ * The log session id used for metrics.
+ * A null or empty string here means it is not set.
+ */
+ private String mLogSessionId;
+
//---------------------------------------------------------
// Constructor, Finalize
//--------------------
@@ -1913,6 +1919,25 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
return native_set_preferred_microphone_field_dimension(zoom) == AudioSystem.SUCCESS;
}
+ /**
+ * Sets a string handle to this AudioRecord for metrics collection.
+ *
+ * @param logSessionId a string which is used to identify this object
+ * to the metrics service. Proper generated Ids must be obtained
+ * from the Java metrics service and should be considered opaque.
+ * Use null to remove the logSessionId association.
+ * @throws IllegalStateException if AudioRecord not initialized.
+ *
+ * @hide
+ */
+ public void setLogSessionId(@Nullable String logSessionId) {
+ if (mState == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("AudioRecord not initialized");
+ }
+ native_setLogSessionId(logSessionId);
+ mLogSessionId = logSessionId;
+ }
+
//---------------------------------------------------------
// Interface definitions
//--------------------
@@ -2072,6 +2097,8 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
private native int native_set_preferred_microphone_direction(int direction);
private native int native_set_preferred_microphone_field_dimension(float zoom);
+ private native void native_setLogSessionId(@Nullable String logSessionId);
+
//---------------------------------------------------------
// Utility methods
//------------------
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 6fcb75616f0d..0af521b6951a 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -567,6 +567,7 @@ public class AudioTrack extends PlayerBase
/**
* The log session id used for metrics.
+ * A null or empty string here means it is not set.
*/
private String mLogSessionId;
@@ -3977,12 +3978,14 @@ public class AudioTrack extends PlayerBase
* Sets a string handle to this AudioTrack for metrics collection.
*
* @param logSessionId a string which is used to identify this object
- * to the metrics service.
+ * to the metrics service. Proper generated Ids must be obtained
+ * from the Java metrics service and should be considered opaque.
+ * Use null to remove the logSessionId association.
* @throws IllegalStateException if AudioTrack not initialized.
*
* @hide
*/
- public void setLogSessionId(@NonNull String logSessionId) {
+ public void setLogSessionId(@Nullable String logSessionId) {
if (mState == STATE_UNINITIALIZED) {
throw new IllegalStateException("track not initialized");
}
@@ -4225,7 +4228,7 @@ public class AudioTrack extends PlayerBase
private native int native_get_audio_description_mix_level_db(float[] level);
private native int native_set_dual_mono_mode(int dualMonoMode);
private native int native_get_dual_mono_mode(int[] dualMonoMode);
- private native void native_setLogSessionId(@NonNull String logSessionId);
+ private native void native_setLogSessionId(@Nullable String logSessionId);
/**
* Sets the audio service Player Interface Id.