@@ -64,8 +64,8 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
6464 private var streamOrientation = 0
6565 private var previewWidth = 0
6666 private var previewHeight = 0
67- private var previewOrientation = 0
6867 private var isPortrait = false
68+ private var isPortraitPreview = false
6969 private var orientationForced = OrientationForced .NONE
7070 private val filterQueue: BlockingQueue <Filter > = LinkedBlockingQueue ()
7171 private val threadQueue = LinkedBlockingQueue <Runnable >()
@@ -85,7 +85,7 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
8585 private val sensorRotationManager = SensorRotationManager (context, true , true ) { orientation, isPortrait ->
8686 if (autoHandleOrientation && shouldHandleOrientation) {
8787 setCameraOrientation(orientation)
88- this . isPortrait = isPortrait
88+ setIsPortrait( isPortrait)
8989 }
9090 }
9191
@@ -220,7 +220,7 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
220220 if (surfaceManager.isReady && mainRender.isReady()) {
221221 surfaceManager.makeCurrent()
222222 mainRender.updateFrame()
223- mainRender.drawOffScreen()
223+ mainRender.drawOffScreen(false )
224224 surfaceManager.swapBuffer()
225225 }
226226
@@ -239,6 +239,11 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
239239 OrientationForced .LANDSCAPE -> false
240240 OrientationForced .NONE -> isPortrait
241241 }
242+ val orientationPreview = when (orientationForced) {
243+ OrientationForced .PORTRAIT -> true
244+ OrientationForced .LANDSCAPE -> false
245+ OrientationForced .NONE -> isPortraitPreview
246+ }
242247 // render VideoEncoder (stream and record)
243248 if (surfaceManagerEncoder.isReady && mainRender.isReady() && ! limitFps) {
244249 val w = if (muteVideo) 0 else encoderWidth
@@ -270,8 +275,13 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
270275 if (surfaceManagerPreview.isReady && mainRender.isReady() && ! limitFps) {
271276 val w = if (previewWidth == 0 ) encoderWidth else previewWidth
272277 val h = if (previewHeight == 0 ) encoderHeight else previewHeight
278+ if (surfaceManager.isReady && mainRender.isReady()) {
279+ surfaceManager.makeCurrent()
280+ mainRender.drawOffScreen(true )
281+ surfaceManager.swapBuffer()
282+ }
273283 surfaceManagerPreview.makeCurrent()
274- mainRender.drawScreenPreview(w, h, orientation , aspectRatioMode, previewOrientation ,
284+ mainRender.drawScreenPreview(w, h, orientationPreview , aspectRatioMode, 0 ,
275285 isPreviewVerticalFlip, isPreviewHorizontalFlip)
276286 surfaceManagerPreview.swapBuffer()
277287 }
@@ -332,17 +342,30 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
332342 }
333343
334344 fun setIsPortrait (isPortrait : Boolean ) {
335- this .isPortrait = isPortrait
345+ setPreviewIsPortrait(isPortrait)
346+ setStreamIsPortrait(isPortrait)
347+ }
348+
349+ fun setPreviewIsPortrait (isPortrait : Boolean ) {
350+ this .isPortraitPreview = isPortrait
336351 }
337352
338- fun setPreviewRotation ( orientation : Int ) {
339- this .previewOrientation = orientation
353+ fun setStreamIsPortrait ( isPortrait : Boolean ) {
354+ this .isPortrait = isPortrait
340355 }
341356
342357 fun setCameraOrientation (orientation : Int ) {
343358 mainRender.setCameraRotation(orientation)
344359 }
345360
361+ fun setCameraPreviewOrientation (orientation : Int ) {
362+ mainRender.setCameraRotationPreview(orientation)
363+ }
364+
365+ fun setCameraStreamOrientation (orientation : Int ) {
366+ mainRender.setCameraRotationStream(orientation)
367+ }
368+
346369 override fun setFilter (filterPosition : Int , baseFilterRender : BaseFilterRender ) {
347370 filterQueue.add(Filter (FilterAction .SET_INDEX , filterPosition, baseFilterRender))
348371 }
@@ -372,7 +395,7 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
372395 }
373396
374397 override fun setRotation (rotation : Int ) {
375- mainRender.setCameraRotation (rotation)
398+ setCameraOrientation (rotation)
376399 }
377400
378401 override fun forceFpsLimit (fps : Int ) {
0 commit comments