RootEncoder
RootEncoder copied to clipboard
Android 13 Stream preview rotation issue
Hello,
I have an issue with the camera preview rotation since Android 13.
Here is on Android 10 (P30 Pro) :
And here is on Android 13 (Pixel 4A):
(The white rectangles are here to hide some sensitive information)
After the stream start, the preview gets back to landscape on the preview and the stream is OK.
Here is the code :
fun initCamera(context: Context, openGlView: OpenGlView, quality: Quality) {
job = CoroutineScope(Dispatchers.Main + Job())
contextApp = context
setView(openGlView)
camera2Base = RtmpCamera2(openGlView, connectCheckerRtmp)
camera2Base?.replaceView(openGlView)
camera2Base?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
setForce(CodecUtil.Force.SOFTWARE, CodecUtil.Force.FIRST_COMPATIBLE_FOUND)
} else {
setForce(CodecUtil.Force.FIRST_COMPATIBLE_FOUND, CodecUtil.Force.FIRST_COMPATIBLE_FOUND)
}
val rotation = CameraHelper.getCameraOrientation(contextApp)
prepareVideo(quality.x, quality.y, 30, getBitrate(quality), 1, rotation)
}
}
private fun startStreamRtp(endpoint: String) {
if (camera2Base?.isStreaming == false) {
camera2Base?.setLogs(false)
camera2Base?.setAuthorization(user, password)
camera2Base?.setReTries(10)
camera2Base?.apply {
prepareAudio()
val rotation = CameraHelper.getCameraOrientation(applicationContext)
prepareVideo(quality.x, quality.y, 30, getBitrate(quality), 1, rotation)
startStream(endpoint)
}
} else {
showNotification("You are already streaming :(")
}
}
Is there anyone with the same issue?
Thanks
Hello,
Same issue, even if I force the rotation
prepareVideo(quality.x, quality.y, 30, getBitrate(quality), 1, 180)
The rotation Rotation is not taken into account on the first init I can't find why :(
Any idea @pedroSG94 ? :)
Thanks !
Hello @Goule @pedroSG94
I have temporary fix for this bug, I still can't explain the main reason of this bug but delaying the preview works for me.
viewLifecycleOwner.lifecycleScope.launch {
delay(1000)
service?.startPreview()
}
It's a dirty fix, but it may give a clue about this bug, what do you think @pedroSG94 ?
Hello,
About the problem above:
Hello,
Same issue, even if I force the rotation
prepareVideo(quality.x, quality.y, 30, getBitrate(quality), 1, 180)
The rotation Rotation is not taken into account on the first init I can't find why :(
Any idea @pedroSG94 ? :)
Thanks !
I'm not sure if it is the problem with the incomplete code to know lifecycle used but I think that the problem is that you need set rotation to startPreview method or rotation will be the default one until you call startStream
I have temporary fix for this bug, I still can't explain the main reason of this bug but delaying the preview works for me.
About this one. Without a code reference to know where you are doing the call, remember that startPreview must be called after surfaceChanged callback like I do in my examples (waiting for your view to inflate totally). Also, use always a resolution provided by getResolutionsBack() or getResolutionsFront(). If you want a vertical size you must change rotation value never switch resolution values. I recommend you check this example to make sure that you are doing lifecycle correctly: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/tree/master/app/src/main/java/com/pedro/rtpstreamer/rotation This example support screen rotation while streaming. Compile my app and check if you have the same problem with my example. If not, maybe you are doing a mistake