Merge "Support query encapsulation information." into rvc-dev am: acc2acafe7 am: b6f9d6aa03 am: 9318d709d6
Change-Id: I3b2a8209551d73734696816e93878d0cc4b1a9a0
This commit is contained in:
@@ -1149,6 +1149,21 @@ static constexpr size_t array_size(const T (&)[N]) {
|
|||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jintArray convertEncapsulationInfoFromNative(JNIEnv *env, uint32_t encapsulationInfo) {
|
||||||
|
std::vector<int> encapsulation;
|
||||||
|
// Ignore the first bit, which is ENCAPSULATION_.*_NONE, as an empty array
|
||||||
|
// should be returned if no encapsulation is supported.
|
||||||
|
encapsulationInfo >>= 1;
|
||||||
|
for (int bitPosition = 1; encapsulationInfo; encapsulationInfo >>= 1, bitPosition++) {
|
||||||
|
if (encapsulationInfo & 1) {
|
||||||
|
encapsulation.push_back(bitPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jintArray result = env->NewIntArray(encapsulation.size());
|
||||||
|
env->SetIntArrayRegion(result, 0, encapsulation.size(), (jint *)encapsulation.data());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static jint convertAudioPortFromNative(JNIEnv *env,
|
static jint convertAudioPortFromNative(JNIEnv *env,
|
||||||
jobject *jAudioPort, const struct audio_port *nAudioPort)
|
jobject *jAudioPort, const struct audio_port *nAudioPort)
|
||||||
{
|
{
|
||||||
@@ -1156,6 +1171,8 @@ static jint convertAudioPortFromNative(JNIEnv *env,
|
|||||||
jintArray jSamplingRates = NULL;
|
jintArray jSamplingRates = NULL;
|
||||||
jintArray jChannelMasks = NULL;
|
jintArray jChannelMasks = NULL;
|
||||||
jintArray jChannelIndexMasks = NULL;
|
jintArray jChannelIndexMasks = NULL;
|
||||||
|
jintArray jEncapsulationModes = NULL;
|
||||||
|
jintArray jEncapsulationMetadataTypes = NULL;
|
||||||
int* cFormats = NULL;
|
int* cFormats = NULL;
|
||||||
jintArray jFormats = NULL;
|
jintArray jFormats = NULL;
|
||||||
jobjectArray jGains = NULL;
|
jobjectArray jGains = NULL;
|
||||||
@@ -1316,11 +1333,16 @@ static jint convertAudioPortFromNative(JNIEnv *env,
|
|||||||
if (nAudioPort->type == AUDIO_PORT_TYPE_DEVICE) {
|
if (nAudioPort->type == AUDIO_PORT_TYPE_DEVICE) {
|
||||||
ALOGV("convertAudioPortFromNative is a device %08x", nAudioPort->ext.device.type);
|
ALOGV("convertAudioPortFromNative is a device %08x", nAudioPort->ext.device.type);
|
||||||
jstring jAddress = env->NewStringUTF(nAudioPort->ext.device.address);
|
jstring jAddress = env->NewStringUTF(nAudioPort->ext.device.address);
|
||||||
*jAudioPort = env->NewObject(gAudioDevicePortClass, gAudioDevicePortCstor,
|
jEncapsulationModes =
|
||||||
jHandle, jDeviceName,
|
convertEncapsulationInfoFromNative(env, nAudioPort->ext.device.encapsulation_modes);
|
||||||
jSamplingRates, jChannelMasks, jChannelIndexMasks,
|
jEncapsulationMetadataTypes =
|
||||||
jFormats, jGains,
|
convertEncapsulationInfoFromNative(env,
|
||||||
nAudioPort->ext.device.type, jAddress);
|
nAudioPort->ext.device
|
||||||
|
.encapsulation_metadata_types);
|
||||||
|
*jAudioPort = env->NewObject(gAudioDevicePortClass, gAudioDevicePortCstor, jHandle,
|
||||||
|
jDeviceName, jSamplingRates, jChannelMasks, jChannelIndexMasks,
|
||||||
|
jFormats, jGains, nAudioPort->ext.device.type, jAddress,
|
||||||
|
jEncapsulationModes, jEncapsulationMetadataTypes);
|
||||||
env->DeleteLocalRef(jAddress);
|
env->DeleteLocalRef(jAddress);
|
||||||
} else if (nAudioPort->type == AUDIO_PORT_TYPE_MIX) {
|
} else if (nAudioPort->type == AUDIO_PORT_TYPE_MIX) {
|
||||||
ALOGV("convertAudioPortFromNative is a mix");
|
ALOGV("convertAudioPortFromNative is a mix");
|
||||||
@@ -1362,6 +1384,12 @@ exit:
|
|||||||
if (jChannelIndexMasks != NULL) {
|
if (jChannelIndexMasks != NULL) {
|
||||||
env->DeleteLocalRef(jChannelIndexMasks);
|
env->DeleteLocalRef(jChannelIndexMasks);
|
||||||
}
|
}
|
||||||
|
if (jEncapsulationModes != NULL) {
|
||||||
|
env->DeleteLocalRef(jEncapsulationModes);
|
||||||
|
}
|
||||||
|
if (jEncapsulationMetadataTypes != NULL) {
|
||||||
|
env->DeleteLocalRef(jEncapsulationMetadataTypes);
|
||||||
|
}
|
||||||
if (cFormats != NULL) {
|
if (cFormats != NULL) {
|
||||||
delete[] cFormats;
|
delete[] cFormats;
|
||||||
}
|
}
|
||||||
@@ -2615,8 +2643,10 @@ int register_android_media_AudioSystem(JNIEnv *env)
|
|||||||
|
|
||||||
jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort");
|
jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort");
|
||||||
gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass);
|
gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass);
|
||||||
gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>",
|
gAudioDevicePortCstor =
|
||||||
"(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V");
|
GetMethodIDOrDie(env, audioDevicePortClass, "<init>",
|
||||||
|
"(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[I"
|
||||||
|
"[Landroid/media/AudioGain;ILjava/lang/String;[I[I)V");
|
||||||
|
|
||||||
// When access AudioPort as AudioDevicePort
|
// When access AudioPort as AudioDevicePort
|
||||||
gAudioPortFields.mType = GetFieldIDOrDie(env, audioDevicePortClass, "mType", "I");
|
gAudioPortFields.mType = GetFieldIDOrDie(env, audioDevicePortClass, "mType", "I");
|
||||||
|
|||||||
@@ -455,8 +455,7 @@ public final class AudioDeviceInfo {
|
|||||||
* may be an empty array if no encapsulation modes are supported.
|
* may be an empty array if no encapsulation modes are supported.
|
||||||
*/
|
*/
|
||||||
public @NonNull @AudioTrack.EncapsulationMode int[] getEncapsulationModes() {
|
public @NonNull @AudioTrack.EncapsulationMode int[] getEncapsulationModes() {
|
||||||
// Implement a getter in r-dev or r-tv-dev as needed.
|
return mPort.encapsulationModes();
|
||||||
return new int[0]; // be careful of returning a copy of any internal data.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -474,8 +473,7 @@ public final class AudioDeviceInfo {
|
|||||||
* may be an empty array if no metadata types are supported.
|
* may be an empty array if no metadata types are supported.
|
||||||
*/
|
*/
|
||||||
public @NonNull @AudioTrack.EncapsulationMetadataType int[] getEncapsulationMetadataTypes() {
|
public @NonNull @AudioTrack.EncapsulationMetadataType int[] getEncapsulationMetadataTypes() {
|
||||||
// Implement a getter in r-dev or r-tv-dev as needed.
|
return mPort.encapsulationMetadataTypes();
|
||||||
return new int[0]; // be careful of returning a copy of any internal data.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package android.media;
|
package android.media;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AudioDevicePort is a specialized type of AudioPort
|
* The AudioDevicePort is a specialized type of AudioPort
|
||||||
* describing an input (e.g microphone) or output device (e.g speaker)
|
* describing an input (e.g microphone) or output device (e.g speaker)
|
||||||
@@ -35,17 +38,22 @@ public class AudioDevicePort extends AudioPort {
|
|||||||
|
|
||||||
private final int mType;
|
private final int mType;
|
||||||
private final String mAddress;
|
private final String mAddress;
|
||||||
|
private final int[] mEncapsulationModes;
|
||||||
|
private final int[] mEncapsulationMetadataTypes;
|
||||||
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
AudioDevicePort(AudioHandle handle, String deviceName,
|
AudioDevicePort(AudioHandle handle, String deviceName,
|
||||||
int[] samplingRates, int[] channelMasks, int[] channelIndexMasks,
|
int[] samplingRates, int[] channelMasks, int[] channelIndexMasks,
|
||||||
int[] formats, AudioGain[] gains, int type, String address) {
|
int[] formats, AudioGain[] gains, int type, String address, int[] encapsulationModes,
|
||||||
|
@AudioTrack.EncapsulationMetadataType int[] encapsulationMetadataTypes) {
|
||||||
super(handle,
|
super(handle,
|
||||||
(AudioManager.isInputDevice(type) == true) ?
|
(AudioManager.isInputDevice(type) == true) ?
|
||||||
AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK,
|
AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK,
|
||||||
deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains);
|
deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains);
|
||||||
mType = type;
|
mType = type;
|
||||||
mAddress = address;
|
mAddress = address;
|
||||||
|
mEncapsulationModes = encapsulationModes;
|
||||||
|
mEncapsulationMetadataTypes = encapsulationMetadataTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,6 +79,31 @@ public class AudioDevicePort extends AudioPort {
|
|||||||
return mAddress;
|
return mAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get supported encapsulation modes.
|
||||||
|
*/
|
||||||
|
public @NonNull @AudioTrack.EncapsulationMode int[] encapsulationModes() {
|
||||||
|
if (mEncapsulationModes == null) {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
return Arrays.stream(mEncapsulationModes).boxed()
|
||||||
|
.filter(mode -> mode != AudioTrack.ENCAPSULATION_MODE_HANDLE)
|
||||||
|
.mapToInt(Integer::intValue).toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get supported encapsulation metadata types.
|
||||||
|
*/
|
||||||
|
public @NonNull @AudioTrack.EncapsulationMetadataType int[] encapsulationMetadataTypes() {
|
||||||
|
if (mEncapsulationMetadataTypes == null) {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
int[] encapsulationMetadataTypes = new int[mEncapsulationMetadataTypes.length];
|
||||||
|
System.arraycopy(mEncapsulationMetadataTypes, 0,
|
||||||
|
encapsulationMetadataTypes, 0, mEncapsulationMetadataTypes.length);
|
||||||
|
return encapsulationMetadataTypes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a specific configuration of this audio device port for use by methods
|
* Build a specific configuration of this audio device port for use by methods
|
||||||
* like AudioManager.connectAudioPatch().
|
* like AudioManager.connectAudioPatch().
|
||||||
|
|||||||
Reference in New Issue
Block a user