-
-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android][AAudio] Crash occurs when creating and running a stream the second time. #466
Comments
Thanks for the report. Are you able to post the exact Simple Playback example code? Is it basically just the code below? Also, are you able to force the OpenSL backend just so I can see if it's a more general miniaudio problem or if it's specific to the AAudio backend ( #define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
#include <stdio.h>
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
if (pDecoder == NULL) {
return;
}
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);
(void)pInput;
}
int run(int argc, char** argv)
{
ma_result result;
ma_decoder decoder;
ma_device_config deviceConfig;
ma_device device;
if (argc < 2) {
printf("No input file.\n");
return -1;
}
result = ma_decoder_init_file(argv[1], NULL, &decoder);
if (result != MA_SUCCESS) {
printf("Could not load file: %s\n", argv[1]);
return -2;
}
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = decoder.outputFormat;
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &decoder;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
ma_decoder_uninit(&decoder);
return -3;
}
if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n");
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
return -4;
}
printf("Press Enter to quit...");
getchar();
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
return 0;
}
int main(int argc, char** argv)
{
int i;
for (i = 0; i < 2; i += 1) {
int result = run(argc, argv);
if (result != 0) {
return result;
}
}
return 0;
} It's surprising to me that it runs for a while before crashing. Just looking at the code, the teardown for AAudio looks fairly simple to me. I'll have a look at how Oboe does it's teardown when I get a chance. |
Hi! Sorry for the delay.
//...
// Some includes and other uninteresting stuff above.
//...
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
if (pDecoder == NULL) {
return;
}
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);
(void)pInput;
}
TEST_F(AudioOutTest, MA_SAMPLE_1) {
ma_result result;
ma_decoder decoder;
ma_device_config deviceConfig;
ma_device device;
result = ma_decoder_init_file((APP_FILES_PATH + TEST_AUDIO_WAV_FILEANAME).c_str(), NULL, &decoder);
if (result != MA_SUCCESS) {
printf("Could not load file: %s\n", (APP_FILES_PATH + TEST_AUDIO_WAV_FILEANAME).c_str());
ASSERT_EQ(false, false);
}
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = decoder.outputFormat;
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &decoder;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
ma_decoder_uninit(&decoder);
ASSERT_EQ(false, false);
}
if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n");
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
ASSERT_EQ(false, false);
}
using namespace std::chrono_literals;
std::this_thread::sleep_for(5s);
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
}
TEST_F(AudioOutTest, MA_SAMPLE_2) {
ma_result result;
ma_decoder decoder;
ma_device_config deviceConfig;
ma_device device;
result = ma_decoder_init_file((APP_FILES_PATH + TEST_AUDIO_WAV_FILEANAME).c_str(), NULL, &decoder);
if (result != MA_SUCCESS) {
printf("Could not load file: %s\n", (APP_FILES_PATH + TEST_AUDIO_WAV_FILEANAME).c_str());
ASSERT_EQ(false, false);
}
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = decoder.outputFormat;
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &decoder;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
ma_decoder_uninit(&decoder);
ASSERT_EQ(false, false);
}
if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n");
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
ASSERT_EQ(false, false);
}
using namespace std::chrono_literals;
std::this_thread::sleep_for(5s);
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
}
// End of file.
I checked with OpenSL only, both tests passed and no crash was observed. It seems like it's the issue only with AAudio.
|
Unfortunately I've been unable to replicate this one. I'm using the "Pixel XL API 26" emulator and it works just fine. I reduced the test down a bit to remove the void crash_test_instance_gh466()
{
ma_device_config deviceConfig;
ma_device device;
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = ma_format_f32;
deviceConfig.playback.channels = 2;
deviceConfig.sampleRate = 44100;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = NULL;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
return;
}
if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n");
ma_device_uninit(&device);
return;
}
ma_sleep(5000);
ma_device_uninit(&device);
}
void crash_test_gh466()
{
crash_test_instance_gh466();
crash_test_instance_gh466();
} I just call the I've added the "help wanted" tag to this ticket. If the community doesn't respond after a period of time I'll close this one. |
I'm wondering if issue #590 could be related. Are you able to replicate this bug with |
This has been open for close to a year now and considering I haven't been able to replicate it and the community hasn't presented a concrete solution I'm going to go ahead and close this one. Happy to reopen this if someone else reports the same issue. |
I've caught a crash while was testing my application with google test framework. The same happened when I just substituted my code with the Simple Playback sample. The resulted code consists of 2 tests each of which contains the duplicate of the Simple Playback sample code. As soon as the first test passed, the crash occurs as a result of running the second one after calling ma_device_start function. The callback works for awhile and then crashes.
As an attempt to find out what happened I tried to remove ma_device_uninit function from the first test and the second test with the application code didn't crash again. However the same doesn't work with samples.
It looks like there is a problem with ma_device_uninit function which doesn't perform full cleanup.
It's not an issue with AAudio itself because I use Oboe Library with the same application and it works well.
Steps to reproduce:
Precondition: not empty WAV file.
OS: Android 11 (AAudio)
HW: both Emulator (x86_64) and Device (aarmv8)
Occurence: 100%
Full log:
The text was updated successfully, but these errors were encountered: