RtspServerStream using CameraPreview's Surface resulting in "video info is null"
Mett-Barr opened this issue · 5 comments
Due to the need for full control over the Camera, I am using RtspServerStream to treat the content of CameraPreview as the video source. While the CameraPreview displays successfully, RtspServerStream is unable to retrieve the content from the Surface. Is there something incorrect in the way I am using it?
Example URL : https://github.com/Mett-Barr/rtsp-test
Hello,
The problem is that you are not rendering the SurfaceTexture provided by VideoSource correctly.
You are rendering SurfaceTexture from the TextureView so you have a preview but no data in the stream.
You only need create a VideoSource like here:
https://github.com/pedroSG94/RootEncoder/blob/master/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt
In this case you need replace Camera2ApiManager with your CameraController.
After that, you can add your TextureView as preview with startPreview method like here:
https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/rotation/CameraFragment.kt#L106
You can use TextureView with TextureView.SurfaceTextureListener to replace SurfaceView with SurfaceHolder.Callback
Thank you for your response. Here is the current approach I'm using, and I'm unsure where the mistake lies:
- In TextureView.onSurfaceTextureAvailable, I confirm the SurfaceTexture is available and then instantiate the CameraController and CameraVideoSource.
- I execute CameraVideoSource.start(SurfaceTexture), and within the start() function, I call cameraController.openCamera, passing in the SurfaceTexture to ensure both are utilizing the same one.
- I use CameraVideoSource to construct the RtspServerStream.
- I sequentially execute prepareVideo, prepareAudio, startPreview(SurfaceTexture), and startStream.
I'm uncertain where the error in this design and usage lies. I've tried to mimic the operation of Camera2Source, and due to the need to use the video streaming side as a Server, I've replaced GenericStream with RtspServerStream to achieve this. Thank you very much for your help.
Hello,
First of all try to use RtspServerStream without a custom VideoSource to make sure that your code is working as expected, you can use Rotation example of the app module in RootEncoder project as guide. You also have a mini guide here:
https://github.com/pedroSG94/RootEncoder/wiki/StreamBase-(in-progress)#quick-start
After that, you only need create a class (your custom VideoSource) and set that source in the RtspServerStream constructor like the second code example of the mini guide.
You are miss understanding the way the library works:
1 - You don't need wait until TextureView is available, you only need wait for it to use the startPreview/stopPreview. So you can instantiate RtspServerStream, CameraController and CameraVideoSource and prepare video/audio before TextureView is ready and call startPreview when you receive onSurfaceTextureAvailable
2 - This is not the way the library works. VideoSource is a class where the library read video data to work but it is not related with the preview. The library copy data provided from VideoSource class to the TextureView used in startPreview method for you.
3 - Remember call release method when you are closing the activity to release properly. This basically stop all and release resources of RtspServerStream class
Thank you for your help; the issue has been resolved. I accidentally returned the wrong Boolean in VideoSource's override fun isRunning(), which prevented override fun start from executing. This problem has now been completely resolved. I am very grateful for your assistance.
Closing issue, you can reopen or open other issue if needed