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.57k stars 776 forks source link

java.lang.NullPointerException: getSurface(...) must not be null #1603

Open orzlenmo opened 1 month ago

orzlenmo commented 1 month ago

When I use GenericFromFile and push local files, I get java.lang.NullPointerException: getSurface(...) must not be null I can confirm that I have implemented the method according to the steps in the document, surfaceView = OpenGlView(context!!) bindingFloatWindow?.frameSurfaceView?.addView(surfaceView) genericFromFile = GenericFromFile(openGlView, this, this, this) It sometimes works, but sometimes it doesn't, and the above error will appear

微信截图_20241013114136

pedroSG94 commented 1 month ago

Hello,

Are you doing the startStream after the preview is inflated like in the example? (Using the onSurfaceChanged callback)

Can you share the code where you are doing startStream?

orzlenmo commented 1 month ago

微信截图_20241013141331

I added a callback but did not do anything. Because my OpenGlView preview interface is on a float window, when I call startstream, the above error is reported directly. Here is the startStream method

微信截图_20241013141744

pedroSG94 commented 1 month ago

No matter if you are in a float window. You need wait until that callback is called or the surface will be null or invalid. You can try add a delay to start stream but it is not a secure way to do it

orzlenmo commented 1 month ago

I can confirm that my startStream event is executed after surfaceChanged:Surface(name=null)/@0xf77b5a8 has been executed and has a value. Does it have anything to do with the activity where the float is located?

pedroSG94 commented 1 month ago

I'm not sure about it but that surface is not ready for some reason. Maybe the surface is created, destroyed and re created. You can check if the surface if ready using this:

surfaceView.holder.surface.isValid

Also, remember that if your preview was detroyed and you need use a different preview you need change the preview:

//go to background, no preview available
genericFromFile.replaceView(context)
//the preview object changed, replace preview with the new view
genericFromFile.replaceView(openglView)

I can help you more if you are able to share a full code example.

orzlenmo commented 1 month ago

This is the log I printed. Can you help me analyze it? Thanks to the author 微信截图_20241013151959

orzlenmo commented 1 month ago

This is the status judgment when the push starts, showing that it is ready 微信截图_20241013152515

pedroSG94 commented 1 month ago

I will need a full code example to reproduce the error. Can you share me a minimal code example? You can share it using email if you want: pedrossgg1994@gmail.com

orzlenmo commented 1 month ago

It's not that I don't want to post it, it's that my apk is hooked through xposed. This OpenGlView uses the acitivity environment intercepted by the host app, and then a floating window pops up on it. It has been working fine before, but suddenly the host app has been updated. I used your library to push the stream. All the codes are normal, but this problem occurred when I started pushing the stream. So I want to ask you whether it is related to the opengl environment of the app used.

pedroSG94 commented 1 month ago

I did a fix for it: https://github.com/pedroSG94/RootEncoder/pull/1604 Try with this commit:

  implementation 'com.github.pedroSG94.RootEncoder:library:fix~opengl-start-SNAPSHOT'
orzlenmo commented 1 month ago

我对此进行了修复: #1604 尝试使用此提交:

  implementation 'com.github.pedroSG94.RootEncoder:library:fix~opengl-start-SNAPSHOT'

I used this version but it still doesn't work. The following two pictures are new errors. Later, I no longer used the previous host activity. I changed an activity to display the OpenGlView on the floating window. Finally, it will not crash. I don't know why some phones crash on which activity. But I really appreciate your answer. 微信截图_20241014152319 微信截图_20241014152328

pedroSG94 commented 1 month ago

Hello,

Thank you for the report. It is interesting, the library is not able to get shaders resources. Please, help me to solve the error since I'm not able to reproduce it. I added a new commit that could resolve this error:

  implementation 'com.github.pedroSG94.RootEncoder:library:f0b9aa3fcb'
orzlenmo commented 1 month ago

Same error as before 微信截图_20241014174355

pedroSG94 commented 1 month ago

Do you still have resources not found error like before?

orzlenmo commented 1 month ago

I used it for nearly a year without any problems. Recently, the host app of the xposed hook seemed to have been hot-updated, which started to cause this problem on some models. After I changed the activity, it became normal. So I suggest you ignore this problem, because it is indeed a problem that only occurs with unconventional apps.

pedroSG94 commented 1 month ago

Hello,

I will ignore this issue until someone find a way to share a code example to reproduce the error. Marked as help wanted