2

我在安卓上使用 OpenSL ES。它似乎工作得很好。

但是,过了一会儿,我的应用程序在三星 Galaxy SII (GT-I9100) 上崩溃了。其他手机(ZTE Blade、Galaxy Nexus、HTC evo 3D)似乎不会以这种方式崩溃。

这是来自 logcat 的日志,不管它有什么好处:

D/AudioPolicyManager( 2591): HPH volume levels....  => music_hph 7, radio_hph 7, tts_hph 7
D/AudioPolicyManager( 2591): SPK volume levels....  => music 0, radio 0, tts 0
D/AudioPolicyManager( 2591): mCurDevice is 2
D/AudioPolicyManager( 2591): return MUSIC_SPK index
D/AudioPolicyManager( 2591): mCurDevice is 2
I/AudioFlinger( 2591): start output streamType (1, 3) for 1
I/OMXCodec(18102): [OMX.SEC.mp3dec] allocating 5 buffers of size 27648 on output port
I/libOpenSLES(18102): MediaSource::read encountered INFO_FORMAT_CHANGED
D/AudioPolicyManager( 2591): HPH volume levels....  => music_hph 7, radio_hph 7, tts_hph 7
D/AudioPolicyManager( 2591): SPK volume levels....  => music 0, radio 0, tts 0
D/AudioPolicyManager( 2591): mCurDevice is 2
D/AudioPolicyManager( 2591): return MUSIC_SPK index
D/AudioPolicyManager( 2591): mCurDevice is 2
I/AudioFlinger( 2591): start output streamType (1, 3) for 1
I/DEBUG   ( 5862): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 5862): Build fingerprint: 'samsung/GT-I9100/GT-I9100:2.3.5/GINGERBREAD/XWKI8:user/release-keys'
I/DEBUG   ( 5862): pid: 18102, tid: 18109  >>> com.example.apptest <<<
I/DEBUG   ( 5862): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
I/DEBUG   ( 5862):  r0 00000000  r1 00000000  r2 7e7eff57  r3 00000000
I/DEBUG   ( 5862):  r4 00d4afb0  r5 00000000  r6 00001004  r7 471b7f48
I/DEBUG   ( 5862):  r8 472b7b68  r9 471b7f40  10 00000980  fp 4051b400
I/DEBUG   ( 5862):  ip 81810a3c  sp 472b7a80  lr 81804b5d  pc a902ea94  cpsr 60000030
I/DEBUG   ( 5862):  d0  0000000100000001  d1  beb1dd3800000000
I/DEBUG   ( 5862):  d2  bfd180bc00000000  d3  3feec709dc3a03fd
I/DEBUG   ( 5862):  d4  447a000000000000  d5  3f800000000003e8
I/DEBUG   ( 5862):  d6  458000003f800000  d7  0000001200000012
I/DEBUG   ( 5862):  d8  0000000000000000  d9  0000000000000000
I/DEBUG   ( 5862):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   ( 5862):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   ( 5862):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   ( 5862):  d16 3f7266db21ab92c9  d17 3ff0000000000000
I/DEBUG   ( 5862):  d18 3e73d0d6657b02a7  d19 bf84ff4e5f0d318e
I/DEBUG   ( 5862):  d20 4000000000000000  d21 3f11543f572eff56
I/DEBUG   ( 5862):  d22 bebbb9c7c906b092  d23 3fc1e6e388e51000
I/DEBUG   ( 5862):  d24 3e66376972bea4d0  d25 c020000000000000
I/DEBUG   ( 5862):  d26 3ff4000000000000  d27 bf84ff4e5f0d318b
I/DEBUG   ( 5862):  d28 bffdd07cce68a9a8  d29 3fc1e6e4276bc32c
I/DEBUG   ( 5862):  d30 bc56bffbcaefb208  d31 3e73d0d665800000
I/DEBUG   ( 5862):  scr 80000010
I/DEBUG   ( 5862):
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1
I/DEBUG   ( 5862):          #00  pc 0002ea94  /system/lib/libmedia.so
I/DEBUG   ( 5862):          #01  pc 00004b5a  /system/lib/libOpenSLES.so
I/DEBUG   ( 5862):          #02  pc 000083f2  /system/lib/libOpenSLES.so
I/DEBUG   ( 5862):          #03  pc 0000cb5e  /system/lib/libOpenSLES.so
I/DEBUG   ( 5862):
I/DEBUG   ( 5862): code around pc:
I/DEBUG   ( 5862): a902ea74 69d869c3 bf004770 47703044 f1d06b00
I/DEBUG   ( 5862): a902ea84 bf380001 47702000 4604b570 460d6800
I/DEBUG   ( 5862): a902ea94 69cb6801 47984629 5023f884 bf00bd70
I/DEBUG   ( 5862): a902eaa4 0023f890 bf183800 47702001 6a00eef7
I/DEBUG   ( 5862): a902eab4 1a90ee07 2a10ee07 7ae6eef4 fa10eef1
I/DEBUG   ( 5862):
I/DEBUG   ( 5862): code around lr:
I/DEBUG   ( 5862): 81804b3c fefcf7ff 3788f8d4 d8092b01 0798f8d4
I/DEBUG   ( 5862): 81804b4c f894b130 39001778 2101bf18 eaf6f7ff
I/DEBUG   ( 5862): 81804b5c bd102000 f8d0b510 b93b3788 079cf8d0
I/DEBUG   ( 5862): 81804b6c 3900b120 2101bf18 fd74f001 bf00bd10
I/DEBUG   ( 5862): 81804b7c f8d0b510 460a3788 f8d0b923 b108079c
I/DEBUG   ( 5862):
I/DEBUG   ( 5862): stack:
I/DEBUG   ( 5862):     472b7a40  00000000
I/DEBUG   ( 5862):     472b7a44  00000000
I/DEBUG   ( 5862):     472b7a48  00d54fc8
I/DEBUG   ( 5862):     472b7a4c  00000001
I/DEBUG   ( 5862):     472b7a50  00000001
I/DEBUG   ( 5862):     472b7a54  00000002
I/DEBUG   ( 5862):     472b7a58  472b7b68
I/DEBUG   ( 5862):     472b7a5c  471b7f40
I/DEBUG   ( 5862):     472b7a60  00000980
I/DEBUG   ( 5862):     472b7a64  818049bd  /system/lib/libOpenSLES.so
I/DEBUG   ( 5862):     472b7a68  00000000
I/DEBUG   ( 5862):     472b7a6c  00000000
I/DEBUG   ( 5862):     472b7a70  00000000
I/DEBUG   ( 5862):     472b7a74  00000000
I/DEBUG   ( 5862):     472b7a78  df002777
I/DEBUG   ( 5862):     472b7a7c  e3a070ad
I/DEBUG   ( 5862): #00 472b7a80  00d54fc8
I/DEBUG   ( 5862):     472b7a84  00d54fc8
I/DEBUG   ( 5862):     472b7a88  00001004
I/DEBUG   ( 5862):     472b7a8c  81804b5d  /system/lib/libOpenSLES.so
I/DEBUG   ( 5862): #01 472b7a90  00000000
I/DEBUG   ( 5862):     472b7a94  818083f7  /system/lib/libOpenSLES.so
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1
I/AudioFlinger( 2591): stop output streamType (1, 3) for 1

很难说什么时候会发生这种崩溃,但可能是在开始播放 mp3 文件之后。另一方面,我注意到 BufferQueue 中经常有回调函数。我还注意到“INFO_FORMAT_CHANGED”似乎经常出现在崩溃之前(但不确定它是否相关)。

但如前所述,崩溃是罕见的。我主要对调试方法感兴趣。例如,有没有办法知道堆栈上有什么?我尝试使用 addr2line-command,但我从手机中提取的这些 .so 文件不知何故被打乱且不可读。

4

2 回答 2

1

不太确定,但似乎是在停止循环播放的声音时出现问题。所以在停止之前,我必须确保它没有被循环。三星的 libopensles.so 版本似乎对停止声音的含义有不同的实现。

所以,我改变了这个

(*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_STOPPED);  // bqPlayerPlay is SLPlayItf

进入这个:

(*bqPlayerSeek)->SetLoop(bqPlayerSeek, false, 0, SL_TIME_UNKNOWN);  // bqPlayerSeek is SLSeekItf    
(*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_STOPPED);  
于 2012-03-28T08:22:48.697 回答
0

我还注意到这个错误可能是由于我的 AssetManager 被垃圾收集引起的。所以我对它进行了全球参考,这似乎奏效了。

AAssetManager* asset_manager = 0;
jobject ref_asset_manager = 0;

JNIEXPORT void JNICALL Java_com_example_test_setassetmanager(JNIEnv *env, jobject obj, jobject assetManager)
{
    ref_asset_manager =  (jobject)env->NewGlobalRef(assetManager);
    asset_manager = AAssetManager_fromJava(env, assetManager);
}

此外,还有一个错误是AAsset_close不会关闭用AAsset_openFileDescriptor.

/**
 * Close the asset, freeing all associated resources.
 */
void AAsset_close(AAsset* asset);

/**
 * Open a new file descriptor that can be used to read the asset data.
 *
 * Returns < 0 if direct fd access is not possible (for example, if the asset is
 * compressed).
 */
int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength);

因此,每次AAsset_openFileDescriptor使用时,您也需要使用close它。

于 2012-04-19T10:57:22.097 回答