Merge "Add package name when creating AudioTrack." into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
933f16e524
@@ -20,6 +20,7 @@
|
||||
#include "android_media_AudioTrack.h"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <utils/Log.h>
|
||||
@@ -251,7 +252,7 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
jint audioFormat, jint buffSizeInBytes, jint memoryMode,
|
||||
jintArray jSession, jlong nativeAudioTrack,
|
||||
jboolean offload, jint encapsulationMode,
|
||||
jobject tunerConfiguration) {
|
||||
jobject tunerConfiguration, jstring opPackageName) {
|
||||
ALOGV("sampleRates=%p, channel mask=%x, index mask=%x, audioFormat(Java)=%d, buffSize=%d,"
|
||||
" nativeAudioTrack=0x%" PRIX64 ", offload=%d encapsulationMode=%d tuner=%p",
|
||||
jSampleRate, channelPositionMask, channelIndexMask, audioFormat, buffSizeInBytes,
|
||||
@@ -337,7 +338,8 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
}
|
||||
|
||||
// create the native AudioTrack object
|
||||
lpTrack = new AudioTrack();
|
||||
ScopedUtfChars opPackageNameStr(env, opPackageName);
|
||||
lpTrack = new AudioTrack(opPackageNameStr.c_str());
|
||||
|
||||
// read the AudioAttributes values
|
||||
auto paa = JNIAudioAttributeHelper::makeUnique();
|
||||
@@ -371,23 +373,24 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
status_t status = NO_ERROR;
|
||||
switch (memoryMode) {
|
||||
case MODE_STREAM:
|
||||
status = lpTrack->set(
|
||||
AUDIO_STREAM_DEFAULT,// stream type, but more info conveyed in paa (last argument)
|
||||
sampleRateInHertz,
|
||||
format,// word length, PCM
|
||||
nativeChannelMask,
|
||||
offload ? 0 : frameCount,
|
||||
offload ? AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD : AUDIO_OUTPUT_FLAG_NONE,
|
||||
audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user)
|
||||
0,// notificationFrames == 0 since not using EVENT_MORE_DATA to feed the AudioTrack
|
||||
0,// shared mem
|
||||
true,// thread can call Java
|
||||
sessionId,// audio session ID
|
||||
offload ? AudioTrack::TRANSFER_SYNC_NOTIF_CALLBACK : AudioTrack::TRANSFER_SYNC,
|
||||
offload ? &offloadInfo : NULL,
|
||||
-1, -1, // default uid, pid values
|
||||
paa.get());
|
||||
|
||||
status = lpTrack->set(AUDIO_STREAM_DEFAULT, // stream type, but more info conveyed
|
||||
// in paa (last argument)
|
||||
sampleRateInHertz,
|
||||
format, // word length, PCM
|
||||
nativeChannelMask, offload ? 0 : frameCount,
|
||||
offload ? AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD
|
||||
: AUDIO_OUTPUT_FLAG_NONE,
|
||||
audioCallback,
|
||||
&(lpJniStorage->mCallbackData), // callback, callback data (user)
|
||||
0, // notificationFrames == 0 since not using EVENT_MORE_DATA
|
||||
// to feed the AudioTrack
|
||||
0, // shared mem
|
||||
true, // thread can call Java
|
||||
sessionId, // audio session ID
|
||||
offload ? AudioTrack::TRANSFER_SYNC_NOTIF_CALLBACK
|
||||
: AudioTrack::TRANSFER_SYNC,
|
||||
offload ? &offloadInfo : NULL, -1, -1, // default uid, pid values
|
||||
paa.get());
|
||||
break;
|
||||
|
||||
case MODE_STATIC:
|
||||
@@ -398,22 +401,22 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
|
||||
goto native_init_failure;
|
||||
}
|
||||
|
||||
status = lpTrack->set(
|
||||
AUDIO_STREAM_DEFAULT,// stream type, but more info conveyed in paa (last argument)
|
||||
sampleRateInHertz,
|
||||
format,// word length, PCM
|
||||
nativeChannelMask,
|
||||
frameCount,
|
||||
AUDIO_OUTPUT_FLAG_NONE,
|
||||
audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user));
|
||||
0,// notificationFrames == 0 since not using EVENT_MORE_DATA to feed the AudioTrack
|
||||
lpJniStorage->mMemBase,// shared mem
|
||||
true,// thread can call Java
|
||||
sessionId,// audio session ID
|
||||
AudioTrack::TRANSFER_SHARED,
|
||||
NULL, // default offloadInfo
|
||||
-1, -1, // default uid, pid values
|
||||
paa.get());
|
||||
status = lpTrack->set(AUDIO_STREAM_DEFAULT, // stream type, but more info conveyed
|
||||
// in paa (last argument)
|
||||
sampleRateInHertz,
|
||||
format, // word length, PCM
|
||||
nativeChannelMask, frameCount, AUDIO_OUTPUT_FLAG_NONE,
|
||||
audioCallback,
|
||||
&(lpJniStorage->mCallbackData), // callback, callback data (user)
|
||||
0, // notificationFrames == 0 since not using EVENT_MORE_DATA
|
||||
// to feed the AudioTrack
|
||||
lpJniStorage->mMemBase, // shared mem
|
||||
true, // thread can call Java
|
||||
sessionId, // audio session ID
|
||||
AudioTrack::TRANSFER_SHARED,
|
||||
NULL, // default offloadInfo
|
||||
-1, -1, // default uid, pid values
|
||||
paa.get());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1428,7 +1431,8 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"native_stop", "()V", (void *)android_media_AudioTrack_stop},
|
||||
{"native_pause", "()V", (void *)android_media_AudioTrack_pause},
|
||||
{"native_flush", "()V", (void *)android_media_AudioTrack_flush},
|
||||
{"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;[IIIIII[IJZILjava/lang/Object;)I",
|
||||
{"native_setup",
|
||||
"(Ljava/lang/Object;Ljava/lang/Object;[IIIIII[IJZILjava/lang/Object;Ljava/lang/String;)I",
|
||||
(void *)android_media_AudioTrack_setup},
|
||||
{"native_finalize", "()V", (void *)android_media_AudioTrack_finalize},
|
||||
{"native_release", "()V", (void *)android_media_AudioTrack_release},
|
||||
|
||||
@@ -807,7 +807,8 @@ public class AudioTrack extends PlayerBase
|
||||
int initResult = native_setup(new WeakReference<AudioTrack>(this), mAttributes,
|
||||
sampleRate, mChannelMask, mChannelIndexMask, mAudioFormat,
|
||||
mNativeBufferSizeInBytes, mDataLoadMode, session, 0 /*nativeTrackInJavaObj*/,
|
||||
offload, encapsulationMode, tunerConfiguration);
|
||||
offload, encapsulationMode, tunerConfiguration,
|
||||
getCurrentOpPackageName());
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
@@ -893,7 +894,8 @@ public class AudioTrack extends PlayerBase
|
||||
nativeTrackInJavaObj,
|
||||
false /*offload*/,
|
||||
ENCAPSULATION_MODE_NONE,
|
||||
null /* tunerConfiguration */);
|
||||
null /* tunerConfiguration */,
|
||||
"" /* opPackagename */);
|
||||
if (initResult != SUCCESS) {
|
||||
loge("Error code "+initResult+" when initializing AudioTrack.");
|
||||
return; // with mState == STATE_UNINITIALIZED
|
||||
@@ -4062,7 +4064,8 @@ public class AudioTrack extends PlayerBase
|
||||
Object /*AudioAttributes*/ attributes,
|
||||
int[] sampleRate, int channelMask, int channelIndexMask, int audioFormat,
|
||||
int buffSizeInBytes, int mode, int[] sessionId, long nativeAudioTrack,
|
||||
boolean offload, int encapsulationMode, Object tunerConfiguration);
|
||||
boolean offload, int encapsulationMode, Object tunerConfiguration,
|
||||
@NonNull String opPackageName);
|
||||
|
||||
private native final void native_finalize();
|
||||
|
||||
|
||||
@@ -672,7 +672,8 @@ public class MediaPlayer extends PlayerBase
|
||||
/* Native setup requires a weak reference to our object.
|
||||
* It's easier to create it here than in C++.
|
||||
*/
|
||||
native_setup(new WeakReference<MediaPlayer>(this));
|
||||
native_setup(new WeakReference<MediaPlayer>(this),
|
||||
getCurrentOpPackageName());
|
||||
|
||||
baseRegisterPlayer();
|
||||
}
|
||||
@@ -2378,7 +2379,7 @@ public class MediaPlayer extends PlayerBase
|
||||
private native final int native_setMetadataFilter(Parcel request);
|
||||
|
||||
private static native final void native_init();
|
||||
private native final void native_setup(Object mediaplayer_this);
|
||||
private native void native_setup(Object mediaplayerThis, @NonNull String opPackageName);
|
||||
private native final void native_finalize();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.os.Parcelable;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
@@ -622,4 +623,8 @@ public abstract class PlayerBase {
|
||||
Log.w(className, "See the documentation of " + opName + " for what to use instead with " +
|
||||
"android.media.AudioAttributes to qualify your playback use case");
|
||||
}
|
||||
|
||||
protected String getCurrentOpPackageName() {
|
||||
return TextUtils.emptyIfNull(ActivityThread.currentOpPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <utils/threads.h>
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include "android_runtime/AndroidRuntime.h"
|
||||
#include "android_runtime/android_view_Surface.h"
|
||||
#include "android_runtime/Log.h"
|
||||
@@ -944,10 +945,12 @@ android_media_MediaPlayer_native_init(JNIEnv *env)
|
||||
}
|
||||
|
||||
static void
|
||||
android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
|
||||
android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
|
||||
jstring opPackageName)
|
||||
{
|
||||
ALOGV("native_setup");
|
||||
sp<MediaPlayer> mp = new MediaPlayer();
|
||||
ScopedUtfChars opPackageNameStr(env, opPackageName);
|
||||
sp<MediaPlayer> mp = new MediaPlayer(opPackageNameStr.c_str());
|
||||
if (mp == NULL) {
|
||||
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
|
||||
return;
|
||||
@@ -1403,7 +1406,7 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"native_setMetadataFilter", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_setMetadataFilter},
|
||||
{"native_getMetadata", "(ZZLandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_getMetadata},
|
||||
{"native_init", "()V", (void *)android_media_MediaPlayer_native_init},
|
||||
{"native_setup", "(Ljava/lang/Object;)V", (void *)android_media_MediaPlayer_native_setup},
|
||||
{"native_setup", "(Ljava/lang/Object;Ljava/lang/String;)V",(void *)android_media_MediaPlayer_native_setup},
|
||||
{"native_finalize", "()V", (void *)android_media_MediaPlayer_native_finalize},
|
||||
{"getAudioSessionId", "()I", (void *)android_media_MediaPlayer_get_audio_session_id},
|
||||
{"setAudioSessionId", "(I)V", (void *)android_media_MediaPlayer_set_audio_session_id},
|
||||
|
||||
Reference in New Issue
Block a user