h6ah4i / android-openslmediaplayer

Re-implementation of Android's MediaPlayer and audio effect classes based on OpenSL ES APIs.
https://openslmediaplayer.h6ah4i.com
Apache License 2.0
419 stars 97 forks source link

Lossless FLAC file format issue #24

Open fgnm opened 7 years ago

fgnm commented 7 years ago

Hello, I've noticed that FLAC file format cannot be played both with OpenSL and Hybrid Player. The issue can be easily reproduced with demo app too. The logcat rise the following exception (running OnePlus 3 stock ROM - Android 6.0):

12-01 22:20:11.765: A/OMXCodec(29344): frameworks/av/media/libstagefright/OMXCodec.cpp:4118 CHECK_EQ( params.nBitPerSample,16u) failed: 0 vs. 16
12-01 22:20:11.766: A/libc(29344): Fatal signal 6 (SIGABRT), code -6 in tid 29529 (ALooper)

Or this (running OnePlus One - CyanogenMod 13):

12-01 22:23:30.848: I/FFmpegExtractor(2182): android-source:0x95e9dcc0
12-01 22:23:30.850: D/FFmpegExtractor(2182): unsuppoted codec(flac) by official Stagefright
12-01 22:23:30.850: D/FFmpegExtractor(2182): ffmpeg detected media content as 'audio/flac' with confidence 0.88
12-01 22:23:30.850: I/MediaExtractor(2182): Use extended extractor for the special mime(audio/flac) or codec
12-01 22:23:30.853: I/FFmpegExtractor(2182): the duration is 00:02:10.61
12-01 22:23:30.853: I/FFmpegExtractor(2182): stream_index: 0
12-01 22:23:30.853: I/FFmpegExtractor(2182): support the codec(flac) disposition(0)
12-01 22:23:30.853: I/hexdump(2182): 00000000:  10 00 10 00 00 00 0f 00  31 0a 0a c4 42 f0 00 57  ........1...B..W
12-01 22:23:30.853: I/hexdump(2182): 00000010:  e4 30 93 c0 95 86 14 10  a8 39 7b 3b a9 d8 5a e1  .0.......9{;..Z.
12-01 22:23:30.853: I/hexdump(2182): 00000020:  97 85                                             ..
12-01 22:23:30.853: D/FFmpegExtractor(2182): bit_rate: 0, sample_rate: 44100, channels: 2, bits_per_coded_sample: 0, block_align: 0 bits_per_raw_sample: 16, sample_format: 1
12-01 22:23:30.853: I/FFmpegExtractor(2182): the time is 00:02:10.61
12-01 22:23:30.853: D/FFmpegExtractor(2182): Reader thread starting
12-01 22:23:30.853: D/FFmpegExtractor(2182): supported mime: audio/flac
12-01 22:23:30.856: I/OMXClient(2182): Using client-side OMX mux.
12-01 22:23:30.926: V/FFmpegOMXPlugin(2182): makeComponentInstance 'OMX.ffmpeg.flac.decoder'
12-01 22:23:30.926: D/SoftFFmpegAudio(2182): SoftFFmpegAudio component: OMX.ffmpeg.flac.decoder mCodingType: 28
12-01 22:23:30.927: A/OMXCodec(2182): frameworks/av/media/libstagefright/OMXCodec.cpp:4129 CHECK_EQ( params.nBitPerSample,16u) failed: 0 vs. 16
12-01 22:23:30.928: A/libc(2182): Fatal signal 6 (SIGABRT), code -6 in tid 2346 (ALooper)

Standard Media Player works without problem. Is this a bug or FLAC are not supported? Thanks

fgnm commented 7 years ago

Hey maybe I'm near the solution but since I'm not so much familiar with your code there is still something I don't understand. I've changed this parameter useLowLatencyIfAvailable = true; (default is false). Now the OnePlus 3 works with .flac file format without issue (at least for now), but on OnePlus One still return the same error on OMXCodec.cpp So now I suppose that there is a problem while passing audio info between the player and flac decoder, in particular bitPerSample parameter.

I'll try to test this on more devices and see what's happens. Hope you can clarify my ideas :smiley:

h6ah4i commented 7 years ago

Hi. Thanks for the issue report.

However, I cannot reproduce this on my setup. I guess this might be a specific FLAC files or specific devices issue, so could you upload your FLAC files which can reproduce it?

(NOTE: email me if files should not be available on public)


My test setup:

fgnm commented 7 years ago

Okay so maybe you have right about device specific issue. Tested FLAC in 16, 24 bit PCM on a Galaxy Nexus running stock Android 4.3 and it works. Upgrade OnePlus 3 to Android 7.0 solve the issue once and for all, Galaxy S6 running Android 6.0.1 also no problem. So there must be something in the OnePlus One and in the older firmware of the 3 that makes crash with FLAC files. Anyway standard media player works always without issue, also PowerAmp and AIMP works always without issue (They have a 10 band equalizer so I suppose they use OpenSL too). So I'm wondering if there could be a workaround for this, maybe skip bitPerSample checks, because as I understand from CM source (https://github.com/CyanogenMod/android_frameworks_av/blob/cm-13.0/media/libstagefright/OMXCodec.cpp @ 4129) the problem is that 'nBitPerSample' param is always 0 whatever file I play. Or, if possible, include a FLAC decoder inside the library itself (I suspect that PowerAmp/AIMP works because this). Let me know what do you think.

h6ah4i commented 7 years ago

Thanks for the investigation! It seems a device specific issue around FLAC format extractor.

So I'm wondering if there could be a workaround for this, maybe skip bitPerSample checks

I am not sure that we can workaround this by skipping nBitPerSample checks, because PowerAmp and AIMP do not use Android framework audio decoder for FLAC format (*).

Or, if possible, include a FLAC decoder inside the library itself

Yeah, this is the most reliable solution. However it requires lots of work to integrate with current implementation of this library...

(*) PowerAmp and AIMP specs