6

I have developed a simple audio player in Android that, among others, plays .mp3-files. To decode the files I am using the Android MediaExtractor and the Android MediaCodec. The sample code looks as follows:

        int inIndex = mDecoder.dequeueInputBuffer(TIMEOUT_US);
        if (inIndex >= 0) {
            ByteBuffer buffer = inputBuffers[inIndex];
            int sampleSize = mExtractor.readSampleData(buffer, 0);
            if (sampleSize < 0) {
                // We shouldn't stop the playback at this point, just pass the EOS
                // flag to mDecoder, we will get it again from the
                // dequeueOutputBuffer
                Log.d(TAG, "InputBuffer BUFFER_FLAG_END_OF_STREAM");
                mDecoder.queueInputBuffer(inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);

            }
            else {
                mDecoder.queueInputBuffer(inIndex, 0, sampleSize, mExtractor.getSampleTime(), 0);
                mExtractor.advance();
            }

On all my test devices the code runs without any problems. Yet, after publishing the app on Google Play, I figured out that some users experience native crashes during the call

int sampleSize = mExtractor.readSampleData(buffer, 0);

From the Google play console I do not really get a lot of information, but it seems that it is a SIGSEGV error (SEGV_MAPERR) that occurs during a (native) memcpy operation, where the data is stored in the ByteBuffer. I strongly assume that these users simply do not have enough memory on their devices. Yet, it seems that the crash does not depend on the total memory available. The app might crash on a device with 4GB RAM but run smoothly on a device with only 2GB RAM.

It seems that this mainly happens when playing web radio streams.

Does any of you have an idea how to fix this? Is it sufficient to check the ByteBuffer's capacity prior to running readSampleData()? Or is there a way to catch this error? The most important thing for me is to make sure the app does not crash any more. Any help is greatly appreciated!

Martin
  • 361
  • 2
  • 8

0 Answers0