Merge "add getMetrics() apis for AudioTrack and AudioRecord"

This commit is contained in:
TreeHugger Robot
2018-01-25 20:31:07 +00:00
committed by Android (Google) Code Review
9 changed files with 212 additions and 2 deletions

View File

@@ -22101,6 +22101,7 @@ package android.media {
method public int getChannelConfiguration();
method public int getChannelCount();
method public android.media.AudioFormat getFormat();
method public android.os.PersistableBundle getMetrics();
method public static int getMinBufferSize(int, int, int);
method public int getNotificationMarkerPosition();
method public int getPositionNotificationPeriod();
@@ -22149,6 +22150,14 @@ package android.media {
method public android.media.AudioRecord.Builder setBufferSizeInBytes(int) throws java.lang.IllegalArgumentException;
}
public static final class AudioRecord.MetricsConstants {
field public static final java.lang.String CHANNELS = "android.media.audiorecord.channels";
field public static final java.lang.String ENCODING = "android.media.audiorecord.encoding";
field public static final java.lang.String LATENCY = "android.media.audiorecord.latency";
field public static final java.lang.String SAMPLERATE = "android.media.audiorecord.samplerate";
field public static final java.lang.String SOURCE = "android.media.audiorecord.source";
}
public static abstract interface AudioRecord.OnRecordPositionUpdateListener {
method public abstract void onMarkerReached(android.media.AudioRecord);
method public abstract void onPeriodicNotification(android.media.AudioRecord);
@@ -22208,6 +22217,7 @@ package android.media {
method public int getChannelCount();
method public android.media.AudioFormat getFormat();
method public static float getMaxVolume();
method public android.os.PersistableBundle getMetrics();
method public static int getMinBufferSize(int, int, int);
method public static float getMinVolume();
method protected deprecated int getNativeFrameCount();
@@ -22288,6 +22298,14 @@ package android.media {
method public android.media.AudioTrack.Builder setTransferMode(int) throws java.lang.IllegalArgumentException;
}
public static final class AudioTrack.MetricsConstants {
field public static final java.lang.String CHANNELMASK = "android.media.audiorecord.channelmask";
field public static final java.lang.String CONTENTTYPE = "android.media.audiotrack.type";
field public static final java.lang.String SAMPLERATE = "android.media.audiorecord.samplerate";
field public static final java.lang.String STREAMTYPE = "android.media.audiotrack.streamtype";
field public static final java.lang.String USAGE = "android.media.audiotrack.usage";
}
public static abstract interface AudioTrack.OnPlaybackPositionUpdateListener {
method public abstract void onMarkerReached(android.media.AudioTrack);
method public abstract void onPeriodicNotification(android.media.AudioTrack);

View File

@@ -163,6 +163,7 @@ cc_library_shared {
"android_media_AudioTrack.cpp",
"android_media_DeviceCallback.cpp",
"android_media_JetPlayer.cpp",
"android_media_MediaMetricsJNI.cpp",
"android_media_RemoteDisplay.cpp",
"android_media_ToneGenerator.cpp",
"android_hardware_Camera.cpp",
@@ -261,6 +262,7 @@ cc_library_shared {
"libselinux",
"libicuuc",
"libmedia",
"libmediametrics",
"libaudioclient",
"libjpeg",
"libusbhost",

View File

@@ -31,6 +31,7 @@
#include "android_media_AudioFormat.h"
#include "android_media_AudioErrors.h"
#include "android_media_DeviceCallback.h"
#include "android_media_MediaMetricsJNI.h"
// ----------------------------------------------------------------------------
@@ -750,6 +751,39 @@ static jint android_media_AudioRecord_get_timestamp(JNIEnv *env, jobject thiz,
return status;
}
// ----------------------------------------------------------------------------
static jobject
android_media_AudioRecord_native_getMetrics(JNIEnv *env, jobject thiz)
{
ALOGV("android_media_AudioRecord_native_getMetrics");
sp<AudioRecord> lpRecord = getAudioRecord(env, thiz);
if (lpRecord == NULL) {
ALOGE("Unable to retrieve AudioRecord pointer for getMetrics()");
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return (jobject) NULL;
}
// get what we have for the metrics from the record session
MediaAnalyticsItem *item = NULL;
status_t err = lpRecord->getMetrics(item);
if (err != OK) {
ALOGE("getMetrics failed");
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return (jobject) NULL;
}
jobject mybundle = MediaMetricsJNI::writeMetricsToBundle(env, item, NULL /* mybundle */);
// housekeeping
delete item;
item = NULL;
return mybundle;
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
static const JNINativeMethod gMethods[] = {
@@ -781,6 +815,8 @@ static const JNINativeMethod gMethods[] = {
"()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},

View File

@@ -34,6 +34,7 @@
#include "android_media_AudioFormat.h"
#include "android_media_AudioErrors.h"
#include "android_media_MediaMetricsJNI.h"
#include "android_media_PlaybackParams.h"
#include "android_media_DeviceCallback.h"
#include "android_media_VolumeShaper.h"
@@ -1011,6 +1012,39 @@ static jint android_media_AudioTrack_get_timestamp(JNIEnv *env, jobject thiz, j
return (jint) nativeToJavaStatus(status);
}
// ----------------------------------------------------------------------------
static jobject
android_media_AudioTrack_native_getMetrics(JNIEnv *env, jobject thiz)
{
ALOGD("android_media_AudioTrack_native_getMetrics");
sp<AudioTrack> lpTrack = getAudioTrack(env, thiz);
if (lpTrack == NULL) {
ALOGE("Unable to retrieve AudioTrack pointer for getMetrics()");
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return (jobject) NULL;
}
// get what we have for the metrics from the track
MediaAnalyticsItem *item = NULL;
status_t err = lpTrack->getMetrics(item);
if (err != OK) {
ALOGE("getMetrics failed");
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return (jobject) NULL;
}
jobject mybundle = MediaMetricsJNI::writeMetricsToBundle(env, item, NULL /* mybundle */);
// housekeeping
delete item;
item = NULL;
return mybundle;
}
// ----------------------------------------------------------------------------
static jint android_media_AudioTrack_set_loop(JNIEnv *env, jobject thiz,
@@ -1275,6 +1309,8 @@ static const JNINativeMethod gMethods[] = {
{"native_get_underrun_count", "()I", (void *)android_media_AudioTrack_get_underrun_count},
{"native_get_flags", "()I", (void *)android_media_AudioTrack_get_flags},
{"native_get_timestamp", "([J)I", (void *)android_media_AudioTrack_get_timestamp},
{"native_getMetrics", "()Landroid/os/PersistableBundle;",
(void *)android_media_AudioTrack_native_getMetrics},
{"native_set_loop", "(III)I", (void *)android_media_AudioTrack_set_loop},
{"native_reload_static", "()I", (void *)android_media_AudioTrack_reload},
{"native_get_output_sample_rate",

View File

@@ -32,6 +32,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.ArrayMap;
@@ -1314,6 +1315,23 @@ public class AudioRecord implements AudioRouting
return native_read_in_direct_buffer(audioBuffer, sizeInBytes, readMode == READ_BLOCKING);
}
/**
* Return Metrics data about the current AudioTrack instance.
*
* @return a {@link PersistableBundle} containing the set of attributes and values
* available for the media being handled by this instance of AudioRecord
* The attributes are descibed in {@link MetricsConstants}.
*
* Additional vendor-specific fields may also be present in
* the return value.
*/
public PersistableBundle getMetrics() {
PersistableBundle bundle = native_getMetrics();
return bundle;
}
private native PersistableBundle native_getMetrics();
//--------------------------------------------------------------------------
// Initialization / configuration
//--------------------
@@ -1739,4 +1757,46 @@ public class AudioRecord implements AudioRouting
private static void loge(String msg) {
Log.e(TAG, msg);
}
public static final class MetricsConstants
{
private MetricsConstants() {}
/**
* Key to extract the output format being recorded
* from the {@link AudioRecord#getMetrics} return value.
* The value is a String.
*/
public static final String ENCODING = "android.media.audiorecord.encoding";
/**
* Key to extract the Source Type for this track
* from the {@link AudioRecord#getMetrics} return value.
* The value is a String.
*/
public static final String SOURCE = "android.media.audiorecord.source";
/**
* Key to extract the estimated latency through the recording pipeline
* from the {@link AudioRecord#getMetrics} return value.
* This is in units of milliseconds.
* The value is an integer.
*/
public static final String LATENCY = "android.media.audiorecord.latency";
/**
* Key to extract the sink sample rate for this record track in Hz
* from the {@link AudioRecord#getMetrics} return value.
* The value is an integer.
*/
public static final String SAMPLERATE = "android.media.audiorecord.samplerate";
/**
* Key to extract the number of channels being recorded in this record track
* from the {@link AudioRecord#getMetrics} return value.
* The value is an integer.
*/
public static final String CHANNELS = "android.media.audiorecord.channels";
}
}

View File

@@ -36,6 +36,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -1718,6 +1719,23 @@ public class AudioTrack extends PlayerBase
return ret;
}
/**
* Return Metrics data about the current AudioTrack instance.
*
* @return a {@link PersistableBundle} containing the set of attributes and values
* available for the media being handled by this instance of AudioTrack
* The attributes are descibed in {@link MetricsConstants}.
*
* Additional vendor-specific fields may also be present in
* the return value.
*/
public PersistableBundle getMetrics() {
PersistableBundle bundle = native_getMetrics();
return bundle;
}
private native PersistableBundle native_getMetrics();
//--------------------------------------------------------------------------
// Initialization / configuration
//--------------------
@@ -3239,4 +3257,46 @@ public class AudioTrack extends PlayerBase
private static void loge(String msg) {
Log.e(TAG, msg);
}
public final static class MetricsConstants
{
private MetricsConstants() {}
/**
* Key to extract the Stream Type for this track
* from the {@link AudioTrack#getMetrics} return value.
* The value is a String.
*/
public static final String STREAMTYPE = "android.media.audiotrack.streamtype";
/**
* Key to extract the Content Type for this track
* from the {@link AudioTrack#getMetrics} return value.
* The value is a String.
*/
public static final String CONTENTTYPE = "android.media.audiotrack.type";
/**
* Key to extract the Content Type for this track
* from the {@link AudioTrack#getMetrics} return value.
* The value is a String.
*/
public static final String USAGE = "android.media.audiotrack.usage";
/**
* Key to extract the sample rate for this track in Hz
* from the {@link AudioTrack#getMetrics} return value.
* The value is an integer.
*/
public static final String SAMPLERATE = "android.media.audiorecord.samplerate";
/**
* Key to extract the channel mask information for this track
* from the {@link AudioTrack#getMetrics} return value.
*
* The value is a Long integer.
*/
public static final String CHANNELMASK = "android.media.audiorecord.channelmask";
}
}

View File

@@ -12,7 +12,6 @@ cc_library_shared {
"android_media_MediaDrm.cpp",
"android_media_MediaExtractor.cpp",
"android_media_MediaHTTPConnection.cpp",
"android_media_MediaMetricsJNI.cpp",
"android_media_MediaMetadataRetriever.cpp",
"android_media_MediaMuxer.cpp",
"android_media_MediaPlayer.cpp",
@@ -93,7 +92,6 @@ cc_library_shared {
"android_media_MediaCrypto.cpp",
"android_media_Media2DataSource.cpp",
"android_media_MediaDrm.cpp",
"android_media_MediaMetricsJNI.cpp",
"android_media_MediaPlayer2.cpp",
"android_media_SyncParams.cpp",
],