I'm using OpenSL ES on android. It seems to work pretty well.
However, after a while my app crashes on Samsung Galaxy SII (GT-I9100). Other phones (ZTE Blade, Galaxy Nexus, HTC evo 3D) don't seem to crash this way.
Here's the log from logcat, whatever good it does:
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
It's hard to say when this crash can happen, but it might be just after starting to play an mp3-file. On the otherhand, I've noticed that there's often callback functions going on from BufferQueue. I also noticed that "INFO_FORMAT_CHANGED" seems to appear often before the crash (but no sure if it's related at all).
But as said, the crash is a rare occurrence. I'm mainly interested in ways of debugging this. For example, is there a way to know what's on the stack? I tried to use addr2line-command, but these .so files I pulled from the phone are somehow scrambled and unreadable.
I also noted that this fault could have been caused by my AssetManager being Garbage Collected. So I made a global reference of it and that seemed to work.
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);
}
Also, another bug there was is that AAsset_close
does not close the file descriptor opened with 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);
So each time AAsset_openFileDescriptor
is used, you'll need to close
it too.