Android Audio code analysis 22-AudioEffect: getEnabled Function

Source: Internet
Author: User

 

Let's take a look at the enable-related interfaces in AudioEffect today.

 

 

**************************************** * Source Code ************************************** ***********

// Test case 1.3: test getEnabled () failure when called on released effect

@ LargeTest

Public void test1_3GetEnabledAfterRelease () throws Exception {

Boolean result = false;

String msg = "test1_3GetEnabledAfterRelease ()";

 

 

Try {

AudioEffect effect = new AudioEffect (AudioEffect. EFFECT_TYPE_EQUALIZER,

AudioEffect. EFFECT_TYPE_NULL,

0,

0 );

AssertNotNull (msg + ": cocould not create AudioEffect", effect );

Effect. release ();

Try {

Effect. getEnabled ();

} Catch (IllegalStateException e ){

Result = true;

}

} Catch (IllegalArgumentException e ){

Msg = msg. concat (": Equalizer not found ");

} Catch (UnsupportedOperationException e ){

Msg = msg. concat (": Effect library not loaded ");

}

AssertTrue (msg, result );

}

**************************************** **************************************** **************

Source code path:

Frameworks \ base \ media \ tests \ mediaframeworktest \ src \ com \ android \ mediaframeworktest \ functional \ MediaAudioEffectTest. java

 

 

################ ################

// Test case 1.3: test getEnabled () failure when called on released effect

@ LargeTest

Public void test1_3GetEnabledAfterRelease () throws Exception {

Boolean result = false;

String msg = "test1_3GetEnabledAfterRelease ()";

 

 

Try {

AudioEffect effect = new AudioEffect (AudioEffect. EFFECT_TYPE_EQUALIZER,

AudioEffect. EFFECT_TYPE_NULL,

0,

0 );

AssertNotNull (msg + ": cocould not create AudioEffect", effect );

Effect. release ();

++ Release ++ ++

/**

* Releases the native AudioEffect resources. It is a good practice

* Release the effect engine when not in use as control can be returned

* Other applications or the native resources released.

*/

Public void release (){

Synchronized (mStateLock ){

Native_release ();

+++ ++ Android_media_audio=t_native_release ++ ++

Static void android_media_AudioEffect_native_release (JNIEnv * env, jobject thiz ){

 

 

// Do everything a call to finalize wowould

// Delete the object created when the AudioEffect is created

Android_media_AudioEffect_native_finalize (env, thiz );

++ Android_media_audio=t_native_finalize ++ ++

Static void android_media_AudioEffect_native_finalize (JNIEnv * env, jobject thiz ){

LOGV ("android_media_audio1_t_native_finalize jobject: % x \ n", (int) thiz );

 

 

// Delete the AudioEffect object

AudioEffect * lpAudioEffect = (AudioEffect *) env-> GetIntField (

Thiz, fields. fidNativeAudioEffect );

// LpAudioEffect is deleted here

// The lpAudioEffect interface will be called when getEnabled is enabled. Therefore, an exception occurs when the call is made after release and getEnabled.

If (lpAudioEffect ){

LOGV ("deleting AudioEffect: % x \ n", (int) lpAudioEffect );

Delete lpAudioEffect;

}

 

 

// Delete the JNI data

Audio1_tjnistorage * lpJniStorage = (audio1_tjnistorage *) env-> GetIntField (

Thiz, fields. fidJniData );

If (lpJniStorage ){

LOGV ("deleting pJniStorage: % x \ n", (int) lpJniStorage );

Delete lpJniStorage;

}

}

---------------------------- Android_media_audio1_t_native_finalize ----------------------------------

// + Reset the native resources in the Java object so any attempt to access

// Them after a call to release fails.

Env-> SetIntField (thiz, fields. fidNativeAudioEffect, 0 );

Env-> SetIntField (thiz, fields. fidJniData, 0 );

}

---------------------------- Android_media_audio1_t_native_release ----------------------------------

MState = STATE_UNINITIALIZED;

}

}

------------------------------ Release ----------------------------------

Try {

Effect. getEnabled ();

++ GetEnabled ++ ++

/**

* Returns effect enabled state

*

* @ Return true if the effect is enabled, false otherwise.

* @ Throws IllegalStateException

*/

Public boolean getEnabled () throws IllegalStateException {

CheckState ("getEnabled ()");

Return native_getEnabled ();

++ Android_media_audio=t_native_getenabled ++ ++

Static jboolean

Android_media_audiopolict_native_getenabled (JNIEnv * env, jobject thiz)

{

// Retrieve the AudioEffect object

AudioEffect * lpAudioEffect = (AudioEffect *) env-> GetIntField (

Thiz, fields. fidNativeAudioEffect );

 

 

If (lpAudioEffect = NULL ){

JniThrowException (env, "java/lang/IllegalStateException ",

"Unable to retrieve AudioEffect pointer for getEnabled ()");

Return false;

}

 

 

Return (jboolean) lpAudioEffect-> getEnabled ();

++ AudioEffect :: getEnabled ++

Bool AudioEffect: getEnabled () const

{

// MEnabled is assigned a value in the function AudioEffect: set: mEnabled = (volatile int32_t) enabled;

 

 

// Enabled is generated when the AudioFlinger: createEffect function is called.

// IEffect = audioFlinger-> createEffect (getpid (), (effect_descriptor_t *) & mDescriptor,

// MIEffectClient, priority, output, mSessionId, & mStatus, & mId, & enabled );

 

 

// The address is passed to the AudioFlinger: PlaybackThread: createEffect_l function.

// Create effect on selected output trhead

// Handle = thread-> createEffect_l (client, role tclient, priority, sessionId,

// & Desc, enabled, & lStatus );

 

 

// Call the function AudioFlinger: EffectModule: isEnabled

// * Enabled = (int) effect-> isEnabled ();

++ AudioFlinger: EffectModule :: isEnabled ++

Bool AudioFlinger: EffectModule: isEnabled ()

{

// The inittmodule constructor sets the mState to IDLE.

// The updateState function and setEnabled Function Change the mState.

// The function AudioFlinger: EffectChain: process_l calls the updateState function to update the status.

Switch (mState ){

Case RESTART:

Case STARTING:

Case ACTIVE:

Return true;

Case IDLE:

Case STOPPING:

Case STOPPED:

Default:

Return false;

}

}

---------------------------- AudioFlinger: EffectModule: isEnabled ------------------------------------

Return (mEnabled! = 0 );

}

---------------------------- AudioEffect: getEnabled ------------------------------------

}

---------------------------- Android_media_audio1_t_native_getenabled ----------------------------------

}

-------------------------------- GetEnabled --------------------------------

} Catch (IllegalStateException e ){

Result = true;

}

} Catch (IllegalArgumentException e ){

Msg = msg. concat (": Equalizer not found ");

} Catch (UnsupportedOperationException e ){

Msg = msg. concat (": Effect library not loaded ");

}

AssertTrue (msg, result );

}

######################################## ###################

 

 

& Summary &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&

The audio1_tjnistorage object and AudioEffect object created in native will be deleted during release.

GetEnabled is returned based on the status of the specified tmodule.

Call the getEnabled function after release. An exception occurs because the AudioEffect object has been deleted.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&

From: Jiangfeng's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.