Bug related to the preview.
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 15/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- audio-video-rtc, mobile
Research direction
Start with the reporter's surfaceCreated, surfaceChanged and surfaceDestroyed callbacks, which call prepareVideo, startStream, switchCamera, startPreview and stopPreview on RtspServerCamera2. The attached log file is not in the payload, so it must be fetched from the issue page. Done means identifying why the preview intermittently stays black on Android 11 and either fixing the lifecycle ordering or confirming it is a device issue, with a reproduction note.
Written by the indexing model from the issue text.
Description
Hi!
Could you please help me with an issue? I'm encountering an intermittent bug related to the preview.
About 3 out of 10 times, the preview shows a "black screen." I've attached the logs and code for reference.
Android 11
Hardware acceleration is enabled by default.
class RTSPFragment : Fragment(), ConnectChecker, ClientListener,
SurfaceHolder.Callback {
private lateinit var binding: FragmentRTSPBinding
private lateinit var surfaceView: OpenGlView
private lateinit var rtspServerCamera: RtspServerCamera2
private var clickCount = 0
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentRTSPBinding.inflate(inflater, container, false)
return binding.root
}
@SuppressLint("SimpleDateFormat")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
surfaceView = binding.surfaceViewCam2
surfaceView.holder.addCallback(this)
rtspServerCamera = RtspServerCamera2(surfaceView, this, 8554)
rtspServerCamera.streamClient.setOnlyVideo(true)
rtspServerCamera.streamClient.setClientListener(this)
rtspServerCamera.streamClient.setAuthorization("admin", "admin")
rtspServerCamera.setVideoCodec(VideoCodec.H264)
surfaceView.setIsStreamHorizontalFlip(true)
lifecycleScope.launch {
try {
while (true) {
binding.overlayTimeRtsp.text = SimpleDateFormat("HH:mm:ss").format(Date())
delay(500)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
binding.logoCameraActivity.setOnClickListener{
clickCount++
if (clickCount >= 20) {
findNavController().navigate(R.id.action_rtsp_to_login)
clickCount = 0
}
}
}
private fun prepare(): Boolean {
Log.d("CameraActivity", "prepare: front ${rtspServerCamera.resolutionsFront} back ${rtspServerCamera.resolutionsBack}")
val prepared = rtspServerCamera.prepareVideo(1280, 720, 24, 2000 * 1024, 90)
return prepared
}
override fun onAuthError() {
Log.i("@@@@", "Auth error")
}
override fun onAuthSuccess() {
Log.i("@@@@", "Auth success")
}
override fun onConnectionFailed(reason: String) {
Log.i("@@@@", "Connection failed")
}
override fun onConnectionStarted(url: String) {
Log.i("@@@@", "Connection started")
}
override fun onConnectionSuccess() {
Log.i("@@@@", "Connection success")
}
override fun onDisconnect() {
Log.i("@@@@", "Client disconnect")
}
override fun onClientConnected(client: ServerClient) {
Log.i("@@@@", "Client connected")
}
override fun onClientDisconnected(client: ServerClient) {
Log.i("@@@@", "Client disconnected")
}
override fun surfaceCreated(holder: SurfaceHolder) {
if(prepare())
rtspServerCamera.startStream()
rtspServerCamera.switchCamera("0")
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
if (!holder.surface.isValid)
Log.e("@@@@", "Surface is invalid!")
if (!rtspServerCamera.isOnPreview)
rtspServerCamera.startPreview()
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
Log.i("@@@@", "Surface destroyed")
if (rtspServerCamera.isStreaming) {
rtspServerCamera.stopStream()
}
if (rtspServerCamera.isOnPreview)
rtspServerCamera.stopPreview()
}
}
- Dominant language
- Kotlin
- Stars
- 3k
- Forks
- 946
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 9
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pedroSG94/RootEncoder
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
pedroSG94/RootEncoder#2213 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pedroSG94/RootEncoder#2207 · 1 reaction ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2203 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
pedroSG94/RootEncoder#2192 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2177 · 44 comments ·
Maintainers usually reply within 2 days
All issues in pedroSG94/RootEncoder
Similar issues
-
[BUG] Navigation drawer drops library-name suffixes without ellipsis (1.0.8, NVIDIA Shield)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
damontecres/Wholphin#2069 ·
Maintainers usually reply within 1 day
-
Android (vision-camera-location): HybridLocationManager never quits its HandlerThread on disposeOpen
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
margelo/react-native-vision-camera#4217 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
saisaharsh3/Leftovers#13 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 67/100
navikt/esyfo-narmesteleder#700 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nightscout/AndroidAPS#5280 ·
Maintainers usually reply within 1 day