Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScreenSource why rotate display #1438

Closed
LiPengfei0106 opened this issue Mar 19, 2024 · 2 comments
Closed

ScreenSource why rotate display #1438

LiPengfei0106 opened this issue Mar 19, 2024 · 2 comments

Comments

@LiPengfei0106
Copy link
Contributor

https://github.com/pedroSG94/RootEncoder/blob/master/library/src/main/java/com/pedro/library/util/sources/video/ScreenSource.kt

override fun start(surfaceTexture: SurfaceTexture) {
    this.surfaceTexture = surfaceTexture
    if (!isRunning()) {
      val dpi = context.resources.displayMetrics.densityDpi
      val flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
      //Adapt MediaProjection render to stream resolution
      val shouldRotate = width > height
      val displayWidth = if (shouldRotate) height else width
      val displayHeight = if (shouldRotate) width else height
      if (shouldRotate) {
        surfaceTexture.setDefaultBufferSize(height, width)
      }
      handlerThread.start()
      val mediaProjectionCallback = object : MediaProjection.Callback() {}
      mediaProjection.registerCallback(mediaProjectionCallback, Handler(handlerThread.looper))

      val callback = object : VirtualDisplay.Callback() {}
      virtualDisplay = mediaProjection.createVirtualDisplay("ScreenSource",
        displayWidth, displayHeight, dpi, flags,
        Surface(surfaceTexture), callback, Handler(handlerThread.looper)
      )
    }
  }

Displaywidth height is always greater than displaywidth. This will cause the landscape screen to be stretched.

@pedroSG94
Copy link
Owner

Hello,

This should be fixed here (I had no time to test it well yet):
#1439

You can test it and let me know if the problem is solved. Also, you can suggest changes if you find a better way to implement this.

@pedroSG94
Copy link
Owner

Closed as complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants