HaishinKit/HaishinKit.kt

Invalid Buffer size

Closed this issue · 3 comments

Describe the bug

I have 2 applications one is the pubblish and the other is just the client. When I connect to stream in client i recive this:

FATAL EXCEPTION: com.haishinkit.codec.AudioCodec
Process: com.audioguiame.guidum, PID: 19985
java.lang.IllegalArgumentException: Invalid audio buffer size.
at android.media.AudioTrack.audioBuffSizeCheck(AudioTrack.java:1209)
at android.media.AudioTrack.(AudioTrack.java:615)
at android.media.AudioTrack.(AudioTrack.java:562)
at android.media.AudioTrack.(AudioTrack.java:516)
at android.media.AudioTrack.(AudioTrack.java:457)
at com.haishinkit.net.NetStream.createAudioTrack$haishinkit_release(NetStream.kt:152)
at com.haishinkit.rtmp.RtmpMuxer.onFormatChanged(RtmpMuxer.kt:262)
at com.haishinkit.codec.Codec.setOutputFormat(Codec.kt:170)
at com.haishinkit.codec.Codec.access$setOutputFormat(Codec.kt:18)
at com.haishinkit.codec.Codec$Callback.onOutputFormatChanged(Codec.kt:92)
at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1712)
at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1646)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)

We have this application in ios and is working well "pubblish" (ios, android) to ios client but with android receiving that.

To Reproduce

  1. Pubblish a stream
  2. Connect with Android client
  3. Crash with codec

Expected behavior

FATAL EXCEPTION: com.haishinkit.codec.AudioCodec
Process: com.audioguiame.guidum, PID: 19985
java.lang.IllegalArgumentException: Invalid audio buffer size.
at android.media.AudioTrack.audioBuffSizeCheck(AudioTrack.java:1209)
at android.media.AudioTrack.(AudioTrack.java:615)
at android.media.AudioTrack.(AudioTrack.java:562)
at android.media.AudioTrack.(AudioTrack.java:516)
at android.media.AudioTrack.(AudioTrack.java:457)
at com.haishinkit.net.NetStream.createAudioTrack$haishinkit_release(NetStream.kt:152)
at com.haishinkit.rtmp.RtmpMuxer.onFormatChanged(RtmpMuxer.kt:262)
at com.haishinkit.codec.Codec.setOutputFormat(Codec.kt:170)
at com.haishinkit.codec.Codec.access$setOutputFormat(Codec.kt:18)
at com.haishinkit.codec.Codec$Callback.onOutputFormatChanged(Codec.kt:92)
at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1712)
at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1646)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)

Version

0.11.1

Smartphone info.

No response

Additional context

No response

Screenshots

No response

Relevant log output

No response

Also i can see this: sampleRate=44100, channelCount=1, bufferSize=-2

  • bufferSize=-2 means AudioTrack.ERROR_BAD_VALUE.
    How can I reproduce it? I would like to know the device name and the version of Android you are using.

Hi @shogo4405,

Thanks for your response!
It happens with any android I tried with: Xiaomi Mi8 (Android 11), Xiaomi Redmi note 11 pro (Android 12) Redmi 8 (Android 10), Pixel Api 28, and pixel api 33.
If i emit from ios i get the samee error sampleRate=48000, channelCount=1, bufferSize=-2. If I emit from Android sampleRate=44100, channelCount=1, bufferSize=-2.
At the moment we solved in our server changing de codec and transforming in other pathe like /android/"code".
If i can help just tell me.