Merge "Support query encapsulation information." into rvc-dev
This commit is contained in:
@@ -1149,6 +1149,21 @@ static constexpr size_t array_size(const T (&)[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,
|
||||
jobject *jAudioPort, const struct audio_port *nAudioPort)
|
||||
{
|
||||
@@ -1156,6 +1171,8 @@ static jint convertAudioPortFromNative(JNIEnv *env,
|
||||
jintArray jSamplingRates = NULL;
|
||||
jintArray jChannelMasks = NULL;
|
||||
jintArray jChannelIndexMasks = NULL;
|
||||
jintArray jEncapsulationModes = NULL;
|
||||
jintArray jEncapsulationMetadataTypes = NULL;
|
||||
int* cFormats = NULL;
|
||||
jintArray jFormats = NULL;
|
||||
jobjectArray jGains = NULL;
|
||||
@@ -1316,11 +1333,16 @@ static jint convertAudioPortFromNative(JNIEnv *env,
|
||||
if (nAudioPort->type == AUDIO_PORT_TYPE_DEVICE) {
|
||||
ALOGV("convertAudioPortFromNative is a device %08x", nAudioPort->ext.device.type);
|
||||
jstring jAddress = env->NewStringUTF(nAudioPort->ext.device.address);
|
||||
*jAudioPort = env->NewObject(gAudioDevicePortClass, gAudioDevicePortCstor,
|
||||
jHandle, jDeviceName,
|
||||
jSamplingRates, jChannelMasks, jChannelIndexMasks,
|
||||
jFormats, jGains,
|
||||
nAudioPort->ext.device.type, jAddress);
|
||||
jEncapsulationModes =
|
||||
convertEncapsulationInfoFromNative(env, nAudioPort->ext.device.encapsulation_modes);
|
||||
jEncapsulationMetadataTypes =
|
||||
convertEncapsulationInfoFromNative(env,
|
||||
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);
|
||||
} else if (nAudioPort->type == AUDIO_PORT_TYPE_MIX) {
|
||||
ALOGV("convertAudioPortFromNative is a mix");
|
||||
@@ -1362,6 +1384,12 @@ exit:
|
||||
if (jChannelIndexMasks != NULL) {
|
||||
env->DeleteLocalRef(jChannelIndexMasks);
|
||||
}
|
||||
if (jEncapsulationModes != NULL) {
|
||||
env->DeleteLocalRef(jEncapsulationModes);
|
||||
}
|
||||
if (jEncapsulationMetadataTypes != NULL) {
|
||||
env->DeleteLocalRef(jEncapsulationMetadataTypes);
|
||||
}
|
||||
if (cFormats != NULL) {
|
||||
delete[] cFormats;
|
||||
}
|
||||
@@ -2615,8 +2643,10 @@ int register_android_media_AudioSystem(JNIEnv *env)
|
||||
|
||||
jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort");
|
||||
gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass);
|
||||
gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>",
|
||||
"(Landroid/media/AudioHandle;Ljava/lang/String;[I[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V");
|
||||
gAudioDevicePortCstor =
|
||||
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
|
||||
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.
|
||||
*/
|
||||
public @NonNull @AudioTrack.EncapsulationMode int[] getEncapsulationModes() {
|
||||
// Implement a getter in r-dev or r-tv-dev as needed.
|
||||
return new int[0]; // be careful of returning a copy of any internal data.
|
||||
return mPort.encapsulationModes();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -474,8 +473,7 @@ public final class AudioDeviceInfo {
|
||||
* may be an empty array if no metadata types are supported.
|
||||
*/
|
||||
public @NonNull @AudioTrack.EncapsulationMetadataType int[] getEncapsulationMetadataTypes() {
|
||||
// Implement a getter in r-dev or r-tv-dev as needed.
|
||||
return new int[0]; // be careful of returning a copy of any internal data.
|
||||
return mPort.encapsulationMetadataTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package android.media;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The AudioDevicePort is a specialized type of AudioPort
|
||||
* 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 String mAddress;
|
||||
private final int[] mEncapsulationModes;
|
||||
private final int[] mEncapsulationMetadataTypes;
|
||||
|
||||
@UnsupportedAppUsage
|
||||
AudioDevicePort(AudioHandle handle, String deviceName,
|
||||
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,
|
||||
(AudioManager.isInputDevice(type) == true) ?
|
||||
AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK,
|
||||
deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains);
|
||||
mType = type;
|
||||
mAddress = address;
|
||||
mEncapsulationModes = encapsulationModes;
|
||||
mEncapsulationMetadataTypes = encapsulationMetadataTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +79,31 @@ public class AudioDevicePort extends AudioPort {
|
||||
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
|
||||
* like AudioManager.connectAudioPatch().
|
||||
|
||||
Reference in New Issue
Block a user