pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.56k stars 773 forks source link

Repeatedly Creating RtspServerStream and Encountering 'Create VideoEncoder failed' Issue #1471

Open Mett-Barr opened 6 months ago

Mett-Barr commented 6 months ago

Hello, my current requirement involves creating independently managed RtspServerStreams in different scenarios. Initially, the first eight creations and usages of the streams went without any issues. However, issues start occurring from the ninth creation onwards. Each time I use it after that, and especially when calling prepareVideo(), I encounter the following problems:

2024-05-06 11:26:52.272 VideoEncoder             I  3 encoders found
2024-05-06 11:26:52.272 VideoEncoder             I  Encoder OMX.MTK.VIDEO.ENCODER.AVC
2024-05-06 11:26:52.272 VideoEncoder             I  Color supported: 2130706944
2024-05-06 11:26:52.273 VideoEncoder             I  Color supported: 2130708361
2024-05-06 11:26:52.273 VideoEncoder             I  Encoder selected OMX.MTK.VIDEO.ENCODER.AVC
2024-05-06 11:26:52.279 OMXClient                I  IOmx service obtained
2024-05-06 11:26:52.279 ACodec                   E  Unable to instantiate codec 'OMX.MTK.VIDEO.ENCODER.AVC' with err 0xfffffff4.
2024-05-06 11:26:52.279 ACodec                   E  signalError(omxError 0xfffffff4, internalError -12)
2024-05-06 11:26:52.280 MediaCodec               E  Codec reported err 0xfffffff4, actionCode 0, while in state 1
2024-05-06 11:26:52.288 MediaCodec-JNI           W  try to release MediaCodec from JMediaCodec::~JMediaCodec()...
2024-05-06 11:26:52.288 MediaCodec-JNI           W  done releasing MediaCodec from JMediaCodec::~JMediaCodec().
2024-05-06 11:26:52.290 VideoEncoder             E  Create VideoEncoder failed.
                                                    android.media.MediaCodec$CodecException: Failed to initialize OMX.MTK.VIDEO.ENCODER.AVC, error 0xfffffff4
                                                        at android.media.MediaCodec.native_setup(Native Method)
                                                        at android.media.MediaCodec.<init>(MediaCodec.java:1864)
                                                        at android.media.MediaCodec.createByCodecName(MediaCodec.java:1842)
                                                        at com.pedro.encoder.video.VideoEncoder.prepareVideoEncoder(VideoEncoder.java:108)
                                                        at com.pedro.library.base.StreamBase.prepareVideo(StreamBase.kt:115)
                                                        at com.pedro.library.base.StreamBase.prepareVideo$default(StreamBase.kt:103)

2024-05-06 11:26:52.290 VideoEncoder             I  stopped
2024-05-06 11:26:52.290 AudioEncoder             I  stopped
2024-05-06 11:26:52.297 AudioEncoder             I  2 encoders found
2024-05-06 11:26:52.297 AudioEncoder             I  Encoder selected c2.android.aac.encoder
2024-05-06 11:26:52.300 CCodec                   D  allocate(c2.android.aac.encoder)
2024-05-06 11:26:52.303 CCodec                   I  Created component [c2.android.aac.encoder]

I've attempted to call stopPreview() and stopRecord() after closing the previous RtspServerStream (as calling stopStream() and release() leads to crashes currently). However, I still face the 'Create VideoEncoder failed' issue. Could there be a step that I'm missing? Thank you for your help.

pedroSG94 commented 6 months ago

Hello,

Are you calling release method when RtspServerStream is not needed anymore?

rtspServerStream.release()