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

Fix PIP mode orientation #160

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
package io.github.thibaultbee.streampack.internal.utils.extensions

import android.content.Context
import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import android.hardware.display.DisplayManager
import android.util.Size
import android.view.Display
import android.view.Surface
import androidx.core.content.ContextCompat
import androidx.core.view.DisplayCompat
import io.github.thibaultbee.streampack.R
import io.github.thibaultbee.streampack.internal.muxers.ts.data.TsServiceInfo
import io.github.thibaultbee.streampack.utils.OrientationUtils
Expand Down Expand Up @@ -53,7 +54,19 @@ val Context.deviceOrientation: Int
* @return true if the device is in portrait, otherwise false
*/
val Context.isDevicePortrait: Boolean
get() = resources.configuration.orientation == ORIENTATION_PORTRAIT
get() {
val display = ContextCompat.getDisplayOrDefault(this)
val mode = DisplayCompat.getMode(this, display)
val naturalResolution = Size(mode.physicalWidth, mode.physicalHeight)
val naturalIsPortrait = naturalResolution.isPortrait
return when (display.rotation) {
Surface.ROTATION_0 -> naturalIsPortrait
Surface.ROTATION_90 -> !naturalIsPortrait
Surface.ROTATION_180 -> naturalIsPortrait
Surface.ROTATION_270 -> !naturalIsPortrait
else -> naturalIsPortrait
}
}


/**
Expand All @@ -62,7 +75,7 @@ val Context.isDevicePortrait: Boolean
* @return true if the device is in landscape, otherwise false
*/
val Context.isDeviceLandscape: Boolean
get() = resources.configuration.orientation == ORIENTATION_LANDSCAPE
get() = !isDevicePortrait

val Context.defaultTsServiceInfo
get() = TsServiceInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ class PreviewView @JvmOverloads constructor(
set(value) {
stopPreviewInternal()
value?.let {
lifecycleScope?.launch {
startPreviewInternal(it, it.camera, size)
}
startPreviewIfReady(it, size, true)
}
field = value
}
Expand Down Expand Up @@ -269,7 +267,7 @@ class PreviewView @JvmOverloads constructor(

lifecycleScope?.launch {
startPreviewInternal(streamer, streamer.camera, targetViewSize)
} ?: throw IllegalStateException("LifecycleScope is not available")
} ?: Logger.w(TAG, "Trying to start preview but lifecycle scope is not available")
} catch (e: Exception) {
if (shouldFailSilently) {
Logger.w(TAG, e.toString(), e)
Expand Down
4 changes: 2 additions & 2 deletions demos/camera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
implementation project(':extension-rtmp')
implementation project(':extension-srt')

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation "androidx.core:core-ktx:${androidxCoreVersion}"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
Expand All @@ -66,5 +66,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
4 changes: 2 additions & 2 deletions demos/screenrecorder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
implementation project(':extension-srt')

implementation "androidx.core:core-ktx:${androidxCoreVersion}"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
Expand All @@ -62,5 +62,5 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}