0

在某些设备上,用于高性能音频的 android oboe 库运行良好。但是在其他设备上加载声音文件后它会崩溃。

这个 jni 方法执行得很好:

void SoundFunctions::loadSounds() {

    LOGD("SoundFunctions loadSounds called");

    // Load the RAW PCM data files for both the clap sound and backing track into memory.
    stdB = SoundRecording::loadFromAssets(mAssetManager, "std_kit_b.wav");
    stdSN= SoundRecording::loadFromAssets(mAssetManager, "std_kit_sn.wav");

    // Add all to mixer
    mMixer.addTrack(stdB);
    mMixer.addTrack(stdSN);


    // Create a builder
    AudioStreamBuilder builder;
    builder.setFormat(AudioFormat::I16);
    builder.setChannelCount(1);
    builder.setSampleRate(kSampleRateHz);
    builder.setCallback(this);
    builder.setPerformanceMode(PerformanceMode::LowLatency);
    builder.setSharingMode(SharingMode::Exclusive);
    LOGD("After creating a builder");

    // Open stream
    Result result = builder.openStream(&mAudioStream);
    if (result != Result::OK){
        LOGE("Failed to open stream. Error: %s", convertToText(result));
    }
    LOGD("After openstream");

    // Reduce stream latency by setting the buffer size to a multiple of the burst size
    mAudioStream->setBufferSizeInFrames(mAudioStream->getFramesPerBurst() * 2);

    // Start the stream
    result = mAudioStream->requestStart();
    if (result != Result::OK){
        LOGE("Failed to start stream. Error: %s", convertToText(result));
    }
    LOGD("After starting stream");


}

然而,不久之后,有一个原生崩溃 E/AudioALSAPlaybackHandlerBase: openPcmDriver(), pcm_start(0xeff82fc0) fail due to cannot start channel: Broken pipe

这是什么意思,我该如何解决?

这是错误日志:

12-12 14:55:14.995 11622-11622/com.learntomaster.dlmp D/RhythmGame: 开始流后 12-12 14:55:15.006 1462-1987/? E/AudioALSAPlaybackHandlerBase: openPcmDriver(), pcm_start(0xeff82fc0) 由于无法启动通道而失败:管道损坏

--------- beginning of crash 12-12 14:55:15.047 11622-11622/com.learntomaster.dlmp A/libc: Fatal signal 11 (SIGSEGV),

代码 1,故障地址 0x90 在 tid 11622 (rntomaster.dlmp) 12-12 14:55:15.137 10957-11660/? E/Icing:中止对语料库播放列表的索引 12-12 14:55:15.151 11895-11895/?I/AEE/AED:* * 12-12 14:55:15.152 11895-11895/? I/AEE/AED:构建指纹:'Lenovo/LenovoTB3-850F/TB3-850F:6.0/MRA58K/TB3-850F_S100031_171010_ROW:user/release-keys' 12-12 14:55:15.152 11895-11895/? I/AEE/AED:修订:'0' 12-12 14:55:15.152 11895-11895/? I/AEE/AED: ABI: 'arm64' 12-12 14:55:15.152 11895-11895/? I/AEE/AED:pid:11622,tid:11622,名称:rntomaster.dlmp

com.learntomaster.dlmp <<< 12-12 14:55:15.152 11895-11895/? I/AEE/AED:信号 11 (SIGSEGV),代码 1 (SEGV_MAPERR),故障地址 0x90 12-12 14:55:15.174 11895-11895/? I/AEE/AED: x0 0000000000000090 x1 0000007fdedc7540 x2 0000000000000000 x3 0000000000000000 12-12 14:55:15.174 11895-11895/? I/AEE/AED: x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 0000000000000000 12-12 14:55:15.174 11895-11895/? I/AEE/AED:x8 0000000000000001 x9 0000007f956290a0 x10 0000000000000001 x11 0000007f937c20e0 12-12 14:55:15.174 11895-11895/?I/AEE/AED:x12 0000007f96ecea40 x13 0000000000000004 x14 0000000000000005 x15 00000000000000c0 12-12 14:55:15.174 11895-11895/?I/AEE/AED:x16 0000007f9562e760 x17 0000007f96e9048c x18 0000007f937c20e0 x19 0000000000000000 12-12 14:55:15.174 11895-11895/?I/AEE/AED:x20 0000000000000090 x21 0000007f7ea3b488 x22 0000007f7ea3b380 x23 0000007f7ea3b4b0 12-12 14:55:15.174 11895-11895/?I/AEE/AED: x24 0000007fdedc7540 x25 0000000000000000 x26 0000007fdedc7a78 x27 0000279200002d66 12-12 14:55:15.174 11895-11895/? I/AEE/AED: x28 0000279200002d66 x29 0000007fdedc7490 x30 0000007f955948a4 12-12 14:55:15.174 11895-11895/? I/AEE/AED: sp 0000007fdedc7490 pc 174 11895-11895/? I/AEE/AED: x24 0000007fdedc7540 x25 0000000000000000 x26 0000007fdedc7a78 x27 0000279200002d66 12-12 14:55:15.174 11895-11895/? I/AEE/AED: x28 0000279200002d66 x29 0000007fdedc7490 x30 0000007f955948a4 12-12 14:55:15.174 11895-11895/? I/AEE/AED: sp 0000007fdedc7490 pc 174 11895-11895/? I/AEE/AED: x24 0000007fdedc7540 x25 0000000000000000 x26 0000007fdedc7a78 x27 0000279200002d66 12-12 14:55:15.174 11895-11895/? I/AEE/AED: x28 0000279200002d66 x29 0000007fdedc7490 x30 0000007f955948a4 12-12 14:55:15.174 11895-11895/? I/AEE/AED: sp 0000007fdedc7490 pc
0000007f96e90494 pstate 0000000060000000 12-12 14:55:15.195 1462-1988/? E/AudioFlinger:getNextBuffer,获取空缓冲区 12-12 14:55:15.203 11895-11895/? I/AEE/AED:回溯:12-12 14:55:15.203 11895-11895/? I/AEE/AED:#00 pc 0000000000068494 /system/lib64/libc.so (pthread_mutex_lock+8) 12-12 14:55:15.203 11895-11895/? I/AEE/AED: #01 pc 000000000002f8a0 /system/lib64/libhwui.so (_ZN7android10uirenderer12renderthread12RenderThread5queueEPNS1_10RenderTaskE+28) 12-12 14:55:15.203 11895-11895/? I/AEE/AED: #02 pc 000000000002e324 /system/lib64/libhwui.so (_ZN7android10uirenderer12renderthread11RenderProxy11postAndWaitEPNS1_22MethodInvokeRenderTaskE+132) 12-12 14:55:15.203 11895-11895/? I/AEE/AED:#03 pc 000000000002e600 /system/lib64/libhwui.so (_ZN7android10uirenderer12renderthread11RenderProxy20loadSystemPropertiesEv+92) 12-12 14:55:15.203 11895-11895/? I/AEE/AED:#04 pc 0000000002a1b990 /system/framework/arm64/boot.oat(偏移量 0x2439000)12-12 14:55:15.795 1858-1858/?E/WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9 12-12 14:55:15.796 1858-1858/? E/WifiTrafficPoller:数据包计数 Tx=11477 Rx=15018 12-12 14:55:15.823 11895-11895/? I/AEE/AED:墓碑写入:/data/tombstones/tombstone_04 12-12 14:55:15.824 11895-11895/? E/AEE/AED:AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 所以(_ZN7android10uirenderer12renderthread11RenderProxy20loadSystemPropertiesEv+92)12-12 14:55:15.203 11895-11895/?I/AEE/AED:#04 pc 0000000002a1b990 /system/framework/arm64/boot.oat(偏移量 0x2439000)12-12 14:55:15.795 1858-1858/?E/WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9 12-12 14:55:15.796 1858-1858/? E/WifiTrafficPoller:数据包计数 Tx=11477 Rx=15018 12-12 14:55:15.823 11895-11895/? I/AEE/AED:墓碑写入:/data/tombstones/tombstone_04 12-12 14:55:15.824 11895-11895/? E/AEE/AED:AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 所以(_ZN7android10uirenderer12renderthread11RenderProxy20loadSystemPropertiesEv+92)12-12 14:55:15.203 11895-11895/?I/AEE/AED:#04 pc 0000000002a1b990 /system/framework/arm64/boot.oat(偏移量 0x2439000)12-12 14:55:15.795 1858-1858/?E/WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9 12-12 14:55:15.796 1858-1858/? E/WifiTrafficPoller:数据包计数 Tx=11477 Rx=15018 12-12 14:55:15.823 11895-11895/? I/AEE/AED:墓碑写入:/data/tombstones/tombstone_04 12-12 14:55:15.824 11895-11895/? E/AEE/AED:AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 燕麦(偏移量 0x2439000)12-12 14:55:15.795 1858-1858/?E/WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9 12-12 14:55:15.796 1858-1858/? E/WifiTrafficPoller:数据包计数 Tx=11477 Rx=15018 12-12 14:55:15.823 11895-11895/? I/AEE/AED:墓碑写入:/data/tombstones/tombstone_04 12-12 14:55:15.824 11895-11895/? E/AEE/AED:AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 燕麦(偏移量 0x2439000)12-12 14:55:15.795 1858-1858/?E/WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 14 num clients 9 12-12 14:55:15.796 1858-1858/? E/WifiTrafficPoller:数据包计数 Tx=11477 Rx=15018 12-12 14:55:15.823 11895-11895/? I/AEE/AED:墓碑写入:/data/tombstones/tombstone_04 12-12 14:55:15.824 11895-11895/? E/AEE/AED:AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0 AM 写入失败:管道损坏 12-12 14:55:15.824 11895-11895/? E/AEE/AED:request.action:0

4

1 回答 1

1

我的猜测是您的应用程序正在尝试使用比可用内存更多的内存。每次调用时,SoundRecording::loadFromAssets您都会将声音文件的全部内容加载到内存中,并且您有 40 个声音文件。

如果这些声音文件之一无法加载,则生成的SoundRecording *对象将是空指针。这被添加到Mixer. 在调用mAudioStream->requestStart()第一个回调之后发生Mixer::renderAudio调用,然后调用取消引用导致 SEGV_MAPERR 的SoundRecording::renderAudio空指针。

我不是 100% 确定,但我认为至少需要发生一个回调来启动流(使用 OpenSL ES 时肯定会发生),这可以解释该pcm_start方法失败的原因。

验证这一点的一种简单方法是nullptr在调用后检查loadFromAssets

if (stdB == nullptr){ LOGE("Failed to load sound file"); }

您还应该查看更新的示例代码,它修复了 RhythmGame 示例中的内存泄漏,并使用了智能指针。

于 2018-12-27T17:17:03.807 回答