Merge "Native routing phase 4" into nyc-dev

This commit is contained in:
Paul Mclean
2016-03-14 19:56:49 +00:00
committed by Android (Google) Code Review
2 changed files with 78 additions and 40 deletions

View File

@@ -394,30 +394,48 @@ public class AudioRecord implements AudioRouting
* value here as no error checking is or can be done.
*/
/*package*/ AudioRecord(long nativeRecordInJavaObj) {
int[] session = { 0 };
int[] rates = { 0 };
//TODO: update native initialization when information about hardware init failure
// due to capture device already open is available.
// Note that for this native_setup, we are providing an already created/initialized
// *Native* AudioRecord, so the attributes parameters to native_setup() are ignored.
int initResult = native_setup(new WeakReference<AudioRecord>(this),
null /*mAudioAttributes*/,
rates /*mSampleRates*/,
0 /*mChannelMask*/,
0 /*mChannelIndexMask*/,
0 /*mAudioFormat*/,
0 /*mNativeBufferSizeInBytes*/,
session,
ActivityThread.currentOpPackageName(),
nativeRecordInJavaObj);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing native AudioRecord object.");
return; // with mState == STATE_UNINITIALIZED
mNativeRecorderInJavaObj = 0;
mNativeCallbackCookie = 0;
mNativeDeviceCallback = 0;
// other initialization...
if (nativeRecordInJavaObj != 0) {
deferred_connect(nativeRecordInJavaObj);
} else {
mState = STATE_UNINITIALIZED;
}
}
mSessionId = session[0];
/**
* @hide
*/
/* package */ void deferred_connect(long nativeRecordInJavaObj) {
if (mState != STATE_INITIALIZED) {
int[] session = { 0 };
int[] rates = { 0 };
//TODO: update native initialization when information about hardware init failure
// due to capture device already open is available.
// Note that for this native_setup, we are providing an already created/initialized
// *Native* AudioRecord, so the attributes parameters to native_setup() are ignored.
int initResult = native_setup(new WeakReference<AudioRecord>(this),
null /*mAudioAttributes*/,
rates /*mSampleRates*/,
0 /*mChannelMask*/,
0 /*mChannelIndexMask*/,
0 /*mAudioFormat*/,
0 /*mNativeBufferSizeInBytes*/,
session,
ActivityThread.currentOpPackageName(),
nativeRecordInJavaObj);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing native AudioRecord object.");
return; // with mState == STATE_UNINITIALIZED
}
mState = STATE_INITIALIZED;
mSessionId = session[0];
mState = STATE_INITIALIZED;
}
}
/**

View File

@@ -526,11 +526,18 @@ public class AudioTrack implements AudioRouting
* the AudioTrackRoutingProxy subclass.
* @param nativeTrackInJavaObj a C/C++ pointer to a native AudioTrack
* (associated with an OpenSL ES player).
* IMPORTANT: For "N", this method is ONLY called to setup a Java routing proxy,
* i.e. IAndroidConfiguration::AcquireJavaProxy(). If we call with a 0 in nativeTrackInJavaObj
* it means that the OpenSL player interface hasn't been realized, so there is no native
* Audiotrack to connect to. In this case wait to call deferred_connect() until the
* OpenSLES interface is realized.
*/
/*package*/ AudioTrack(long nativeTrackInJavaObj) {
// "final"s
mAttributes = null;
mAppOps = null;
mNativeTrackInJavaObj = 0;
mJniData = 0;
// remember which looper is associated with the AudioTrack instantiation
Looper looper;
@@ -540,28 +547,41 @@ public class AudioTrack implements AudioRouting
mInitializationLooper = looper;
// other initialization...
// Note that for this native_setup, we are providing an already created/initialized
// *Native* AudioTrack, so the attributes parameters to native_setup() are ignored.
int[] session = { 0 };
int[] rates = { 0 };
int initResult = native_setup(new WeakReference<AudioTrack>(this),
null /*mAttributes - NA*/,
rates /*sampleRate - NA*/,
0 /*mChannelMask - NA*/,
0 /*mChannelIndexMask - NA*/,
0 /*mAudioFormat - NA*/,
0 /*mNativeBufferSizeInBytes - NA*/,
0 /*mDataLoadMode - NA*/,
session,
nativeTrackInJavaObj);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing AudioTrack.");
return; // with mState == STATE_UNINITIALIZED
if (nativeTrackInJavaObj != 0) {
deferred_connect(nativeTrackInJavaObj);
} else {
mState = STATE_UNINITIALIZED;
}
}
mSessionId = session[0];
/**
* @hide
*/
/* package */ void deferred_connect(long nativeTrackInJavaObj) {
if (mState != STATE_INITIALIZED) {
// Note that for this native_setup, we are providing an already created/initialized
// *Native* AudioTrack, so the attributes parameters to native_setup() are ignored.
int[] session = { 0 };
int[] rates = { 0 };
int initResult = native_setup(new WeakReference<AudioTrack>(this),
null /*mAttributes - NA*/,
rates /*sampleRate - NA*/,
0 /*mChannelMask - NA*/,
0 /*mChannelIndexMask - NA*/,
0 /*mAudioFormat - NA*/,
0 /*mNativeBufferSizeInBytes - NA*/,
0 /*mDataLoadMode - NA*/,
session,
nativeTrackInJavaObj);
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing AudioTrack.");
return; // with mState == STATE_UNINITIALIZED
}
mState = STATE_INITIALIZED;
mSessionId = session[0];
mState = STATE_INITIALIZED;
}
}
/**