当前位置:操作系统 > 安卓/Android >>

Android Audio代码分析22 - AudioEffect::getEnabled函数

 

今天来看看AudioEffect中enable相关的接口。

 

 

*****************************************源码*************************************************

    //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 + ": could 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);

    }

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

源码路径:

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 + ": could not create AudioEffect", effect);

            effect.release();

++++++++++++++++++++++++++++++release++++++++++++++++++++++++++++++++++

    /**

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

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

     * other applications or the native resources released.

     */

    public void release() {

        synchronized (mStateLock) {

            native_release();

++++++++++++++++++++++++++++++android_media_AudioEffect_native_release++++++++++++++++++++++++++++++++++

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

 

 

    // do everything a call to finalize would

// 删除创建AudioEffect时,创建的对象

    android_media_AudioEffect_native_finalize(env, thiz);

++++++++++++++++++++++++++++++android_media_AudioEffect_native_finalize++++++++++++++++++++++++++++++++++

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

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

 

 

    // delete the AudioEffect object

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

        thiz, fields.fidNativeAudioEffect);

// 此处删除了lpAudioEffect

// getEnabled的时候会调用lpAudioEffect的接口,所以release后再getEnabled会产生异常

    if (lpAudioEffect) {

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

        delete lpAudioEffect;

    }

 

 

    // delete the JNI data

    AudioEffectJniStorage* lpJniStorage = (AudioEffectJniStorage *)env->GetIntField(

        thiz, fields.fidJniData);

    if (lpJniStorage) {

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

        delete lpJniStorage;

    }

}

------------------------------android_media_AudioEffect_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_AudioEffect_native_release----------------------------------

            mState = STATE_UNINITIALIZED;

        }

    }

------------------------------release----------------------------------

            try {

                effect.getEn

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,