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