ThibaultBee / StreamPack

SRT/RTMP/RTMPS live streaming libraries for Android
https://thibaultbee.github.io/StreamPack/index.html
Apache License 2.0
175 stars 67 forks source link

Crash when stop RTMP publishing #57

Closed moliyadi closed 1 year ago

moliyadi commented 1 year ago

Hi, thank you for make this wonderful project, the part of SRT works very well, but there seems to be some problems in the part of RTMP, when I stop RTMP publishing, the app crashed, log like this:


11/14 23:58:46: Launching 'demo-camera' on smartisan OS105.
Install successfully finished in 3 s 498 ms.
$ adb shell am start -n "io.github.thibaultbee.streampack.sample/io.github.thibaultbee.streampack.app.ui.main.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 5910 on device 'smartisan-os105-b558c244'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/art: Late-enabling -Xcheck:jni
I/System: Daemon delayGCRequest, sDelayGCRequest=false, delay=true, sPendingGCRequest=false
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/CameraManagerGlobal: Connecting to camera service
W/CameraManagerGlobal: [soar.cts] ignore the status update of camera: 2
W/CameraManagerGlobal: [soar.cts] ignore the status update of camera: 3
W/DataBinding: Setting the fragment as the LifecycleOwner might cause memory leaks because views lives shorter than the Fragment. Consider using Fragment's view lifecycle
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
W/Utils: could not parse long range '175-174'
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
W/VideoCapabilities: Unsupported mime video/x-ms-wmv
W/VideoCapabilities: Unsupported mime video/x-ms-wmv
W/VideoCapabilities: Unsupported mime video/x-ms-wmv
W/VideoCapabilities: Unsupported mime video/divx
W/VideoCapabilities: Unsupported mime video/divx311
W/VideoCapabilities: Unsupported mime video/divx4
W/VideoCapabilities: Unsupported mime video/mp4v-esdp
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
I/VideoMediaCodecEncoder: Selected encoder OMX.qcom.video.encoder.avc
I/OMXClient: MuxOMX ctor
E/ACodec: found 1 codecs
E/ACodec: codec OMX.qcom.video.encoder.avc selected
I/MediaCodec: MediaCodec will operate in async mode
E/ACodec: [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -1010
I/ExtendedACodec: setupVideoEncoder()
W/ACodec: do not know color format 0x7fa30c04 = 2141391876
W/ACodec: do not know color format 0x7fa30c00 = 2141391872
W/ACodec: do not know color format 0x7f000789 = 2130708361
I/ACodec: setupAVCEncoderParameters with [profile: High] [level: Level51]
I/ACodec: [OMX.qcom.video.encoder.avc] cannot encode HDR static metadata. Ignoring.
I/ACodec: setupVideoEncoder succeeded
I/ExtendedACodec: [OMX.qcom.video.encoder.avc] configure, AMessage : AMessage(what = 'conf', target = 1) = {
      string mime = "video/avc"
      int32_t frame-rate = 30
      int32_t color-format = 2130708361
      int32_t profile = 8
      int32_t height = 1280
      int32_t width = 720
      int32_t bitrate = 2000000
      float i-frame-interval = 1.000000
      int32_t level = 32768
      int32_t encoder = 1
    }
W/ACodec: do not know color format 0x7f000789 = 2130708361
I/Adreno: QUALCOMM build                   : 54dba37, I1b6e53de78
    Build Date                       : 02/21/18
    OpenGL ES Shader Compiler Version: XE031.14.00.04
    Local Branch                     : 
    Remote Branch                    : quic/gfx-adreno.lnx.1.0.r9-rel
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
D/: SurfaceMonitor closed!
I/AudioMediaCodecEncoder: Selected encoder OMX.google.aac.encoder
I/OMXClient: MuxOMX ctor
E/ACodec: found 1 codecs
E/ACodec: codec OMX.google.aac.encoder selected
I/MediaCodec: MediaCodec will operate in async mode
D/StandaloneCoroutine: Streamer is created
D/OpenGLRenderer: RenderMonitor init!
D/OpenGLRenderer: RenderMonitor closed!
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
I/PreviewView: Starting on camera: 0
D/PreviewView: View finder size: 1080 x 2010
D/PreviewView: Selected preview size: 1920x1080
I/art: Do partial code cache collection, code=17KB, data=29KB
I/art: After code cache collection, code=17KB, data=29KB
I/art: Increasing code cache capacity to 128KB
D/AutoFitSurfaceView: Measured dimensions set: 1131 x 2010
W/art: Before Android 4.1, method double java.util.concurrent.ThreadLocalRandom.internalNextDouble(double, double) would have incorrectly overridden the package-private method in java.util.Random
W/art: Before Android 4.1, method int java.util.concurrent.ThreadLocalRandom.internalNextInt(int, int) would have incorrectly overridden the package-private method in java.util.Random
W/art: Before Android 4.1, method long java.util.concurrent.ThreadLocalRandom.internalNextLong(long, long) would have incorrectly overridden the package-private method in java.util.Random
I/CameraController: Supported FPS range list: [[15, 15], [20, 20], [24, 24], [7, 30], [30, 30], [10, 30]]
D/CameraController: Selected Fps range [30, 30]
I/System: Daemon delayGCRequest, sDelayGCRequest=true, delay=false, sPendingGCRequest=false
I/: Connection succeeded
D/ACodec: dataspace changed to 0x10c10000 (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) (R:2(Limited), S:1(BT709), T:3(SMPTE_170M))
I/: Format changed : {csd-1=java.nio.HeapByteBuffer[pos=0 lim=9 cap=9], mime=video/avc, frame-rate=30, width=720, height=1280, color-standard=1, color-range=2, bitrate=2000000, csd-0=java.nio.HeapByteBuffer[pos=0 lim=22 cap=22], color-transfer=3, max-bitrate=2000000}
I/: Format changed : {bitrate=128000, mime=audio/mp4a-latm, csd-0=java.nio.HeapByteBuffer[pos=0 lim=2 cap=2], channel-count=2, sample-rate=44100, max-bitrate=128000}
D/VideoMediaCodecEncoder: Not running
D/AudioMediaCodecEncoder: Not running
I/AudioMediaCodecEncoder: Selected encoder OMX.google.aac.encoder
I/OMXClient: MuxOMX ctor
E/ACodec: found 1 codecs
E/ACodec: codec OMX.google.aac.encoder selected
I/MediaCodec: MediaCodec will operate in async mode
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
I/VideoMediaCodecEncoder: Selected encoder OMX.qcom.video.encoder.avc
I/OMXClient: MuxOMX ctor
E/ACodec: found 1 codecs
E/ACodec: codec OMX.qcom.video.encoder.avc selected
I/MediaCodec: MediaCodec will operate in async mode
E/ACodec: [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -1010
I/ExtendedACodec: setupVideoEncoder()
W/ACodec: do not know color format 0x7fa30c04 = 2141391876
W/ACodec: do not know color format 0x7fa30c00 = 2141391872
W/ACodec: do not know color format 0x7f000789 = 2130708361
I/ACodec: setupAVCEncoderParameters with [profile: High] [level: Level51]
I/ACodec: [OMX.qcom.video.encoder.avc] cannot encode HDR static metadata. Ignoring.
I/ACodec: setupVideoEncoder succeeded
I/ExtendedACodec: [OMX.qcom.video.encoder.avc] configure, AMessage : AMessage(what = 'conf', target = 10) = {
      string mime = "video/avc"
      int32_t frame-rate = 30
      int32_t color-format = 2130708361
      int32_t profile = 8
      int32_t height = 1280
      int32_t width = 720
      int32_t bitrate = 2000000
      float i-frame-interval = 1.000000
      int32_t level = 32768
      int32_t encoder = 1
    }
W/ACodec: do not know color format 0x7f000789 = 2130708361
A/libc: Fatal signal 7 (SIGBUS), code 1, fault addr 0x7f617f72b1 in tid 5910 (reampack.sample)

I found if I comment outsocket.close() in RtmpProducer.kt, then no longer cause A/libc: Fatal signal 7 (SIGBUS), code 1, fault addr 0x7f617f72b1 in tid 5910 (reampack.sample) crash, but the socket was not closed, when start publish again, app crashed again.

I hope you can provide some help. Thanks.

ThibaultBee commented 1 year ago

Hi, From the crash trace, all I can see is: there is a crash in the native part. That's not enough information to start looking at it. Could you get all traces (not only the traces from your application)?

There has been a fix in the last version of StreamPack in the close of the RTMP socket. Which version do you use? Are you up to date?

moliyadi commented 1 year ago

Thank you for your reply, I found the problem, before rtmpdroid v1.0.4 I use this

var tcUrl = url
val index = url.lastIndexOf("/")
if (index > 0) {
      tcUrl = url.substring(0, index)
}
socket.connect("$url tcUrl=$tcUrl live=1 flashver=FMLE/3.0\\20(compatible;\\20FMSc/1.0)")

instead of

socket.connect("$url live=1 flashver=FMLE/3.0\\20(compatible;\\20FMSc/1.0)")

because earlier I tested that publish would fail if I didn't customize tcUrl.

But with the latest code, even if I don't manually specify tcUrl, the stream should work, thanks very much.

PS: I think it would be nice to improve rtmpdroid and support a custom tcUrl method, thanks.

ThibaultBee commented 1 year ago

Hi,

I made changes in connect(String) to avoid a crash on close or a memory loss. That explains the change of behavior. I guess I won't avoid to have that memory loss.

Why do you have to customize tcUrl? I also see that you directly call socket.connect the RtmpProducer does not satisfied you requirements?

moliyadi commented 1 year ago

Why do you have to customize tcUrl? I also see that you directly call socket.connect the RtmpProducer does not satisfied you requirements?

Because before rtmpdroid v1.0.4, there seems to be a problem with tcurl, which contains the stream part of the push stream url, like this:

publish url: rtmp://192.168.124.203:19350/live/aaaa

WX20221116-084305

Publishing a stream to the rtmp server(like SRS or ZLMediakit) using the request above would fail, so I set tcUrl manually.

But with the latest code, tcUrl seems to be working properly(liek this), so I remove the customization, thank you.

publish url: rtmp://192.168.124.203:19350/live/livestream

WX20221116-084355

ThibaultBee commented 1 year ago

Ok. I get why you needed to set tcUrl. Let's get back to your crash. It is a native crash so most of the stacktrace is not displayed. Could you get all traces from adb logcat (not only the traces from your application)?

ThibaultBee commented 1 year ago

Ok, this seems fixed. Please reopen the issue if it is not the case.