llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
241 stars 202 forks source link

[Android] Recording of WAV, OPUS and other files fails silently on certain device(s) #393

Closed felixmede closed 1 week ago

felixmede commented 2 months ago

Package version

Environment

Describe the bug

Recording of WAV, OPUS, aacLc and other files fails silently

To Reproduce

Steps to reproduce the behavior:

  1. Create a new Recorder
  2. create a new RecordingConfig
  3. Start recording with config
  4. try to listen to recorder.onAmplitudeChanged
  5. stop recording
  6. try to listen to recorded file

Expected behavior

creating a useful recording file

Additional context

the amplitude is current:-infinity max: -160 It is working on 1.2.4 without any issues Other devices we tested work without any issues No error in console

llfbandit commented 2 months ago

Thanks for the report. Using wav, opus or aac encoders fails the same way on those devices? Are they on the same Android version?

llfbandit commented 2 months ago

I made an attempt to fix your issue in compat_effect_issue_393 branch, are you able to test it? To make it work, you should not use any effect like echo cancel, ...

felixmede commented 2 months ago

I did test it and it is still the same behaviour as before with no audio recorded and current volume being -infinity when recording with aacLc I used the example project and here is the logs of it

Launching lib/main.dart on ONEPLUS A6013 in debug mode... Running Gradle task 'assembleDebug'... ✓ Built build/app/outputs/flutter-apk/app-debug.apk Installing build/app/outputs/flutter-apk/app-debug.apk... Debug service listening on ws://127.0.0.1:61327/Q_eNHH-MhL0=/ws Syncing files to device ONEPLUS A6013... I/Gralloc4(14743): mapper 4.x is not supported W/Gralloc3(14743): mapper 3.x is not supported D/DecorView(14743): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@30c4d7e[MainActivity] D/ViewRootImplMainActivity: windowFocusChanged hasFocus=true inTouchMode=true D/ProfileInstaller(14743): Installing profile for com.llfbandit.record_example W/VideoCapabilities(14743): Unsupported mime image/vnd.android.heic W/VideoCapabilities(14743): Unrecognized profile/level 0/3 for video/mpeg2 W/VideoCapabilities(14743): Unrecognized profile/level 0/3 for video/mpeg2 W/VideoCapabilities(14743): Unsupported mime video/x-ms-wmv I/flutter (14743): [ id: 17 I/flutter (14743): label: ONEPLUS A6013 (built-in microphone, bottom) I/flutter (14743): , id: 18 I/flutter (14743): label: ONEPLUS A6013 (built-in microphone, back) I/flutter (14743): , id: 19 I/flutter (14743): label: ONEPLUS A6013 (FM tuner, ) I/flutter (14743): ] I/AudioRecord(14743): set(): inputSource 7, sampleRate 44100, format 0x1, channelMask 0xc, frameCount 3552, notificationFrames 0, sessionId 0, transferType 0, flags 0, opPackageName com.llfbandit.record_example uid -1, pid -1 D/AudioRecord(14743): start(37): sync event 0 trigger session 0 D/CCodec (14743): allocate(c2.android.aac.encoder) I/Codec2Client(14743): Available Codec2 services: "software" I/CCodec (14743): Created component [c2.android.aac.encoder] D/CCodecConfig(14743): read media type: audio/mp4a-latm D/ReflectedParamUpdater(14743): extent() != 1 for single value type: algo.buffers.max-count.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: output.subscribed-indices.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: input.buffers.allocator-ids.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: output.buffers.allocator-ids.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: algo.buffers.allocator-ids.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: output.buffers.pool-ids.values D/ReflectedParamUpdater(14743): extent() != 1 for single value type: algo.buffers.pool-ids.values I/CCodecConfig(14743): query failed after returning 9 values (BAD_INDEX) D/CCodecConfig(14743): c2 config diff is Dict { D/CCodecConfig(14743): c2::u32 coded.bitrate.value = 64000 D/CCodecConfig(14743): c2::u32 coded.pl.level = 0 D/CCodecConfig(14743): c2::u32 coded.pl.profile = 8192 D/CCodecConfig(14743): c2::u32 coding.aac-sbr-mode.value = 3 D/CCodecConfig(14743): c2::u32 input.buffers.max-size.value = 2048 D/CCodecConfig(14743): c2::u32 input.delay.value = 0 D/CCodecConfig(14743): string input.media-type.value = "audio/raw" D/CCodecConfig(14743): string output.media-type.value = "audio/mp4a-latm" D/CCodecConfig(14743): c2::u32 raw.channel-count.value = 1 D/CCodecConfig(14743): c2::u32 raw.sample-rate.value = 44100 D/CCodecConfig(14743): } I/MediaCodec(14743): MediaCodec will operate in async mode D/CCodec (14743): [c2.android.aac.encoder] buffers are bound to CCodec for this session D/CCodecConfig(14743): no c2 equivalents for aac-profile D/CCodecConfig(14743): no c2 equivalents for flags D/CCodecConfig(14743): no c2 equivalents for encoder D/CCodecConfig(14743): c2 config diff is c2::u32 coded.bitrate.value = 128000 D/CCodecConfig(14743): c2::u32 raw.channel-count.value = 2 W/Codec2Client(14743): query -- param skipped: index = 1107298332. D/CCodec (14743): setup formats input: AMessage(what = 0x00000000) = { D/CCodec (14743): int32_t aac-sbr-mode = 3 D/CCodec (14743): int32_t channel-count = 2 D/CCodec (14743): int32_t max-input-size = 4096 D/CCodec (14743): string mime = "audio/raw" D/CCodec (14743): int32_t sample-rate = 44100 D/CCodec (14743): } and output: AMessage(what = 0x00000000) = { D/CCodec (14743): int32_t aac-sbr-mode = 3 D/CCodec (14743): int32_t bitrate = 128000 D/CCodec (14743): int32_t channel-count = 2 D/CCodec (14743): int32_t level = 0 D/CCodec (14743): int32_t max-bitrate = 128000 D/CCodec (14743): string mime = "audio/mp4a-latm" D/CCodec (14743): int32_t profile = 2 D/CCodec (14743): int32_t sample-rate = 44100 D/CCodec (14743): } W/Codec2Client(14743): query -- param skipped: index = 1342179345. W/Codec2Client(14743): query -- param skipped: index = 2415921170. E/FMQ (14743): grantorIdx must be less than 3 E/FMQ (14743): grantorIdx must be less than 3 D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] Created input block pool with allocatorID 16 => poolID 17 - OK (0) I/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] Created output block pool with allocatorID 16 => poolID 38 - OK D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] Configured output block pool ids 38 => OK D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] start: updating output delay 0 E/ion (14743): ioctl c0044901 failed with code -1: Invalid argument D/MPEG4Writer(14743): PreAllocation enabled E/Utils (14743): csd0 too small E/ExtendedUtils(14743): csd0 too small D/MPEG4Writer(14743): fpathconf _PC_FILESIZEBITS:64 D/MPEG4Writer(14743): File size limit set to 4503599627370495 bytes implicitly D/MPEG4Writer(14743): MP4WtrCtrlHlpLooper Started I/MPEG4Writer(14743): limits: 4503599627370495/0 bytes/us, bit rate: -1 bps and the estimated moov size 3192 bytes D/MPEG4Writer(14743): kWhatNoIOErrorSoFar D/MediaCodecEncoder(14743): Output format set: {max-bitrate=128000, aac-sbr-mode=3, sample-rate=44100, level=0, mime=audio/mp4a-latm, profile=2, channel-count=2, bitrate=128000, csd-0=java.nio.HeapByteBuffer[pos=0 lim=2 cap=2]} I/MPEG4Writer(14743): setStartTimestampUs: 0 I/MPEG4Writer(14743): Earliest track starting time: 0 E/FMQ (14743): grantorIdx must be less than 3 E/FMQ (14743): grantorIdx must be less than 3 D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] DEBUG: elapsed: n=4 [in=0 pipeline=0 out=0 smoothness=4] D/PipelineWatcher(14743): DEBUG: elapsed 0 / 4 D/BufferPoolAccessor2.0(14743): bufferpool2 0x75e76f69c8 : 5(20480 size) total buffers - 4(16384 size) used buffers - 260/265 (recycle/alloc) - 2/521 (fetch/transfer) D/AudioRecord(14743): stop(37): mActive:1 D/AudioRecord(14743): stop(37): mActive:0 I/chatty (14743): uid=10081(com.llfbandit.record_example) pool-3-thread-1 identical 1 line D/AudioRecord(14743): stop(37): mActive:0 V/MediaWriter(14743): Track event err/info msg:101, trackId:1, type:1000,val:0 I/MPEG4Writer(14743): Received total/0-length (257/0) buffers and encoded 257 frames. - Audio I/MPEG4Writer(14743): Audio track drift time: 0 us D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] MediaCodec discarded an unknown buffer I/chatty (14743): uid=10081(com.llfbandit.record_example) MediaCodec_loop identical 1 line D/CCodecBufferChannel(14743): [c2.android.aac.encoder#840] MediaCodec discarded an unknown buffer D/MPEG4Writer(14743): reset() D/MPEG4Writer(14743): Audio track stopping. Stop source D/MPEG4Writer(14743): Audio track source stopping D/MPEG4Writer(14743): Audio track source stopped D/MPEG4Writer(14743): Audio track stopped. Status:0. Stop source I/hw-BpHwBinder(14743): onLastStrongRef automatically unlinking death recipients D/MPEG4Writer(14743): 0 chunks are written in the last batch D/MPEG4Writer(14743): WriterThread stopped. Status:0 I/MPEG4Writer(14743): Adjust the moov start time from 0 us -> 0 us I/MPEG4Writer(14743): MOOV atom was written to the file D/MPEG4Writer(14743): release() D/MPEG4Writer(14743): ftruncate mPreAllocateFileEndOffset:100794 mOffset:1741 mMdatEndOffset:98342 diff:2452 D/MPEG4Writer(14743): MP4WtrCtrlHlpLooper stopped D/MPEG4Writer(14743): Top 5 write durations(microseconds): #1:73 #2:90 #3:92 #4:92 #5:94 D/MPEG4Writer(14743): reset() D/MPEG4Writer(14743): Audio track stopping. Stop source E/MPEG4Writer(14743): Stop() called but track is not started or stopped I/flutter (14743): Recorded file path: /data/user/0/com.llfbandit.record_example/app_flutter/audio_1725971964649.m4a I/AudioManager(14743): In isBluetoothScoOn(), calling application: com.llfbandit.record_example V/MediaPlayer(14743): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false V/MediaPlayer(14743): cleanDrmObj: mDrmObj=null mDrmSessionId=null D/BufferPoolAccessor2.0(14743): bufferpool2 0x75e76f69c8 : 0(0 size) total buffers - 0(0 size) used buffers - 296/301 (recycle/alloc) - 3/592 (fetch/transfer) D/BufferPoolAccessor2.0(14743): evictor expired: 1, evicted: 1 D/BufferPoolAccessor2.0(14743): bufferpool2 0x75e76f69c8 : 0(0 size) total buffers - 0(0 size) used buffers - 296/301 (recycle/alloc) - 3/592 (fetch/transfer) D/BufferPoolAccessor2.0(14743): Destruction - bufferpool2 0x75e76f69c8 cached: 0/0M, 0/0% in use; allocs: 301, 98% recycled; transfers: 592, 99% unfetched D/BufferPoolAccessor2.0(14743): evictor expired: 1, evicted: 0

darajava commented 1 month ago

@felixmede @llfbandit I can confirm that this issue is happening with one of my users on Android OnePlus 6T OxygenOS 11.1.1.2

Downgrading to:

  record: 5.1.0
  record_android: 1.2.4

fixes the issue

felixmede commented 1 week ago

It seems to be fixed for me with android_record 1.3.0