diff options
Diffstat (limited to 'src/jni/rtp/AudioGroup.cpp')
-rw-r--r-- | src/jni/rtp/AudioGroup.cpp | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/src/jni/rtp/AudioGroup.cpp b/src/jni/rtp/AudioGroup.cpp index 644b414..e92e799 100644 --- a/src/jni/rtp/AudioGroup.cpp +++ b/src/jni/rtp/AudioGroup.cpp @@ -44,6 +44,8 @@ #include <system/audio.h> #include <nativehelper/ScopedUtfChars.h> +#include <android/content/AttributionSourceState.h> +#include <android_os_Parcel.h> #include "jni.h" #include <nativehelper/JNIHelp.h> @@ -57,17 +59,10 @@ namespace { using namespace android; -using media::permission::Identity; +using android::content::AttributionSourceState; int gRandom = -1; -static struct { - jfieldID fieldUid; // Identity.uid - jfieldID fieldPid; // Identity.pid - jfieldID fieldPackageName; // Identity.packageName - jfieldID fieldAttributionTag; // Identity.attributionTag -} javaIdentityFields; - // We use a circular array to implement jitter buffer. The simplest way is doing // a modulo operation on the index while accessing the array. However modulo can // be expensive on some platforms, such as ARM. Thus we round up the size of the @@ -489,7 +484,7 @@ void AudioStream::decode(int tick) class AudioGroup { public: - explicit AudioGroup(const Identity &identity); + explicit AudioGroup(const AttributionSourceState &attributionSource); ~AudioGroup(); bool set(int sampleRate, int sampleCount); @@ -514,7 +509,7 @@ private: int mEventQueue; volatile int mDtmfEvent; - Identity mIdentity; + const AttributionSourceState mAttributionSource; int mMode; int mSampleRate; @@ -563,9 +558,9 @@ private: sp<DeviceThread> mDeviceThread; }; -AudioGroup::AudioGroup(const Identity &identity) +AudioGroup::AudioGroup(const AttributionSourceState &attributionSource) + : mAttributionSource(attributionSource) { - mIdentity = identity; mMode = ON_HOLD; mChain = NULL; mEventQueue = -1; @@ -827,7 +822,7 @@ bool AudioGroup::DeviceThread::threadLoop() // Initialize AudioTrack and AudioRecord. sp<AudioTrack> track = new AudioTrack(); - sp<AudioRecord> record = new AudioRecord(mGroup->mIdentity); + sp<AudioRecord> record = new AudioRecord(mGroup->mAttributionSource); // Set caller name so it can be logged in destructor. // MediaMetricsConstants.h: AMEDIAMETRICS_PROP_CALLERNAME_VALUE_RTP track->setCallerName("rtp"); @@ -860,7 +855,7 @@ bool AudioGroup::DeviceThread::threadLoop() sp<AudioEffect> aec; if (mode == ECHO_SUPPRESSION) { if (mGroup->platformHasAec()) { - aec = new AudioEffect(mGroup->mIdentity); + aec = new AudioEffect(mGroup->mAttributionSource); aec->set(FX_IID_AEC, NULL, 0, @@ -962,7 +957,7 @@ static jfieldID gMode; jlong add(JNIEnv *env, jobject thiz, jint mode, jint socket, jstring jRemoteAddress, jint remotePort, - jstring jCodecSpec, jint dtmfType, jobject jIdentity) + jstring jCodecSpec, jint dtmfType, jobject jAttributionSource) { AudioCodec *codec = NULL; AudioStream *stream = NULL; @@ -990,25 +985,9 @@ jlong add(JNIEnv *env, jobject thiz, jint mode, return 0; } - Identity identity; - identity.uid = env->GetIntField(jIdentity, javaIdentityFields.fieldUid); - identity.pid = env->GetIntField(jIdentity, javaIdentityFields.fieldPid); - jstring packageNameStr = static_cast<jstring>( - env->GetObjectField(jIdentity, javaIdentityFields.fieldPackageName)); - if (packageNameStr == NULL) { - identity.packageName = std::nullopt; - } else { - identity.packageName = std::optional<std::string>( - std::string(ScopedUtfChars(env, packageNameStr).c_str())); - } - jstring attributionTagStr = static_cast<jstring>( - env->GetObjectField(jIdentity, javaIdentityFields.fieldAttributionTag)); - if (attributionTagStr == NULL) { - identity.attributionTag = std::nullopt; - } else { - identity.attributionTag = std::optional<std::string>( - std::string(ScopedUtfChars(env, attributionTagStr).c_str())); - } + Parcel* parcel = parcelForJavaObject(env, jAttributionSource); + AttributionSourceState attributionSource; + attributionSource.readFromParcel(parcel); // Create audio codec. int codecType = -1; @@ -1039,7 +1018,7 @@ jlong add(JNIEnv *env, jobject thiz, jint mode, group = (AudioGroup *)env->GetLongField(thiz, gNative); if (!group) { int mode = env->GetIntField(thiz, gMode); - group = new AudioGroup(identity); + group = new AudioGroup(attributionSource); if (!group->set(8000, 256) || !group->setMode(mode)) { jniThrowException(env, "java/lang/IllegalStateException", "cannot initialize audio group"); @@ -1095,7 +1074,7 @@ void sendDtmf(JNIEnv *env, jobject thiz, jint event) } JNINativeMethod gMethods[] = { - {"nativeAdd", "(IILjava/lang/String;ILjava/lang/String;ILandroid/media/permission/Identity;)J", (void *)add}, + {"nativeAdd", "(IILjava/lang/String;ILjava/lang/String;ILandroid/os/Parcel;)J", (void *)add}, {"nativeRemove", "(J)V", (void *)remove}, {"nativeSetMode", "(I)V", (void *)setMode}, {"nativeSendDtmf", "(I)V", (void *)sendDtmf}, @@ -1120,16 +1099,5 @@ int registerAudioGroup(JNIEnv *env) return -1; } - // Get the Identity class and fields - jclass identityClass = env->FindClass("android/media/permission/Identity"); - javaIdentityFields.fieldUid = - env->GetFieldID(identityClass, "uid", "I"); - javaIdentityFields.fieldPid = - env->GetFieldID(identityClass, "pid", "I"); - javaIdentityFields.fieldPackageName = - env->GetFieldID(identityClass, "packageName", "Ljava/lang/String;"); - javaIdentityFields.fieldAttributionTag = - env->GetFieldID(identityClass, "attributionTag", "Ljava/lang/String;"); - return 0; } |