Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Bug related to the preview.

Open
#1,689 0 comments 0 reactions 0 assignees View on GitHub

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
Tech stack
android, kotlin

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()
    }
}

18_12_24.txt

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pedroSG94/RootEncoder

All issues in pedroSG94/RootEncoder

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.