Skip to content
Snippets Groups Projects
Commit 6add76f8 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

camera: use Size when relevant

Change-Id: I5021b5c5c7bf2438864c3e4c5eff1c45228d01dc
parent 9c83c298
No related branches found
No related tags found
No related merge requests found
......@@ -210,8 +210,8 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
}
private fun startNewGroup() {
val fragment = ContactPickerFragment.newInstance()
fragment.show(parentFragmentManager, ContactPickerFragment.TAG)
ContactPickerFragment.newInstance()
.show(parentFragmentManager, ContactPickerFragment.TAG)
binding!!.qrCode.visibility = View.GONE
//binding.newGroup.setVisibility(View.GONE);
setTabletQRLayout(false)
......
......@@ -31,6 +31,7 @@ import android.media.MediaRecorder
import android.media.projection.MediaProjection
import android.os.Build
import android.util.Log
import android.util.Size
import android.view.SurfaceHolder
import android.view.TextureView
import android.view.WindowManager
......@@ -145,7 +146,7 @@ class HardwareServiceImpl(
}
@Synchronized
override fun updateAudioState(state: CallStatus?, incomingCall: Boolean, isOngoingVideo: Boolean, isSpeakerOn: Boolean) {
override fun updateAudioState(state: CallStatus, incomingCall: Boolean, isOngoingVideo: Boolean, isSpeakerOn: Boolean) {
Log.d(TAG, "updateAudioState: Call state updated to $state Call is incoming: $incomingCall Call is video: $isOngoingVideo")
val callEnded = state == CallStatus.HUNGUP || state == CallStatus.FAILURE || state == CallStatus.OVER
try {
......@@ -171,7 +172,7 @@ class HardwareServiceImpl(
}
CallStatus.HOLD, CallStatus.UNHOLD, CallStatus.INACTIVE -> {
}
else -> closeAudioState()
else -> if (callEnded) closeAudioState()
}
} catch (e: Exception) {
Log.e(TAG, "Error updating audio state", e)
......@@ -184,7 +185,8 @@ class HardwareServiceImpl(
If it is a bluetooth device, it takes priority and does not play on speaker regardless. Otherwise, it returns mShouldSpeakerphone which was updated in updateaudiostate.
*/
override fun shouldPlaySpeaker(): Boolean {
return if (mBluetoothWrapper != null && mBluetoothWrapper!!.canBluetooth() && mBluetoothWrapper!!.isBTHeadsetConnected) false else mShouldSpeakerphone
val bt = mBluetoothWrapper
return if (bt != null && bt.canBluetooth() && bt.isBTHeadsetConnected) false else mShouldSpeakerphone
}
@Synchronized
......@@ -224,7 +226,8 @@ class HardwareServiceImpl(
private fun setAudioRouting(requestSpeakerOn: Boolean) {
// prioritize bluetooth by checking for bluetooth device first
if (mBluetoothWrapper != null && mBluetoothWrapper!!.canBluetooth() && mBluetoothWrapper!!.isBTHeadsetConnected) {
val bt = mBluetoothWrapper
if (bt != null && bt.canBluetooth() && bt.isBTHeadsetConnected) {
routeToBTHeadset()
} else if (!mAudioManager.isWiredHeadsetOn && mHasSpeakerPhone && requestSpeakerOn) {
routeToSpeaker()
......@@ -353,13 +356,14 @@ class HardwareServiceImpl(
val useLargerSize =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (Build.SUPPORTED_64_BIT_ABIS.isNotEmpty() || mPreferenceService.isHardwareAccelerationEnabled)
//int MIN_WIDTH = useLargerSize ? (useHD ? VIDEO_WIDTH_HD : VIDEO_WIDTH) : VIDEO_WIDTH_MIN;
val minVideoSize: Point = if (useLargerSize) parseResolution(mPreferenceService.resolution) else VIDEO_SIZE_LOW
val minVideoSize: Size = if (useLargerSize) parseResolution(mPreferenceService.resolution) else VIDEO_SIZE_LOW
cameraService.getCameraInfo(camId, formats, sizes, rates, minVideoSize, mContext)
}
private fun parseResolution(resolution: Int): Point {
private fun parseResolution(resolution: Int): Size {
return when (resolution) {
480 -> VIDEO_SIZE_DEFAULT
320 -> VIDEO_SIZE_LOW
480 -> VIDEO_SIZE_SD
720 -> VIDEO_SIZE_HD
1080 -> VIDEO_SIZE_FULL_HD
2160 -> VIDEO_SIZE_ULTRA_HD
......@@ -414,9 +418,7 @@ class HardwareServiceImpl(
videoParams.codec = null
}
}
Log.w(TAG,
"startCapture: id:$cam codec:${videoParams.codec} size:${videoParams.width}x${videoParams.height} rot${videoParams.rotation} hw:$useHardwareCodec bitrate:${mPreferenceService.bitrate}"
)
Log.w(TAG, "startCapture: id:$cam codec:${videoParams.codec} size:${videoParams.size} rot${videoParams.rotation} hw:$useHardwareCodec bitrate:${mPreferenceService.bitrate}")
videoParams.isCapturing = true
if (videoParams.id == CameraService.VideoDevices.SCREEN_SHARING) {
......@@ -457,8 +459,8 @@ class HardwareServiceImpl(
videoEvents.onNext(VideoEvent(
started = true,
w = videoParams.width,
h = videoParams.height,
w = videoParams.size.width,
h = videoParams.size.height,
rot = videoParams.rotation
))
}
......@@ -602,12 +604,13 @@ class HardwareServiceImpl(
}
companion object {
private val VIDEO_SIZE_LOW = Point(320, 240)
private val VIDEO_SIZE_DEFAULT = Point(720, 480)
private val VIDEO_SIZE_HD = Point(1280, 720)
private val VIDEO_SIZE_FULL_HD = Point(1920, 1080)
private val VIDEO_SIZE_ULTRA_HD = Point(3840, 2160)
val resolutions = listOf(VIDEO_SIZE_ULTRA_HD,VIDEO_SIZE_FULL_HD,VIDEO_SIZE_HD,VIDEO_SIZE_DEFAULT,VIDEO_SIZE_LOW)
private val VIDEO_SIZE_LOW = Size(320, 240)
private val VIDEO_SIZE_SD = Size(720, 480)
private val VIDEO_SIZE_HD = Size(1280, 720)
private val VIDEO_SIZE_FULL_HD = Size(1920, 1080)
private val VIDEO_SIZE_ULTRA_HD = Size(3840, 2160)
val VIDEO_SIZE_DEFAULT = VIDEO_SIZE_SD
val resolutions = listOf(VIDEO_SIZE_ULTRA_HD, VIDEO_SIZE_FULL_HD, VIDEO_SIZE_HD, VIDEO_SIZE_SD, VIDEO_SIZE_LOW)
private val TAG = HardwareServiceImpl::class.simpleName!!
private var mCameraPreviewSurface = WeakReference<TextureView>(null)
private var mCameraPreviewCall = WeakReference<Conference>(null)
......
@file:Suppress("NOTHING_TO_INLINE")
package cx.ring.utils
import android.util.Size
public inline fun Size.surface() = width * height
public inline fun Size.contains(w: Int, h: Int) = w < width && h < height
public inline fun Size.contains(s: Size) = contains(s.width, s.height)
public inline fun Size.flip(f: Boolean? = null) = if (f == null || f == true) Size(height, width) else this
public inline fun Size.round(n: Int = 16) = Size(width / n * n, height / n * n)
public inline fun Size.fitOrScale(w: Int, h: Int): Size {
val ra = height * w
val rb = width * h
return when {
(rb > ra) -> Size(ra / h, height)
else -> Size(width, rb / w)
}
}
public inline fun Size.fit(w: Int, h: Int) = if (contains(w, h)) Size(w, h) else fitOrScale(w, h)
public inline fun Size.fit(s: Size) = if (contains(s)) s else fitOrScale(s.width, s.height)
......@@ -64,13 +64,8 @@ abstract class HardwareService(
protected val audioStateSubject: Subject<AudioState> = BehaviorSubject.createDefault(STATE_INTERNAL)
protected val connectivityEvents: Subject<Boolean> = BehaviorSubject.create()
fun getVideoEvents(): Observable<VideoEvent> {
return videoEvents
}
fun getBluetoothEvents(): Observable<BluetoothEvent> {
return bluetoothEvents
}
fun getVideoEvents(): Observable<VideoEvent> = videoEvents
fun getBluetoothEvents(): Observable<BluetoothEvent> = bluetoothEvents
val audioState: Observable<AudioState>
get() = audioStateSubject
......@@ -79,7 +74,7 @@ abstract class HardwareService(
abstract fun initVideo(): Completable
abstract val isVideoAvailable: Boolean
abstract fun updateAudioState(state: CallStatus?, incomingCall: Boolean, isOngoingVideo: Boolean, isSpeakerOn: Boolean)
abstract fun updateAudioState(state: CallStatus, incomingCall: Boolean, isOngoingVideo: Boolean, isSpeakerOn: Boolean)
abstract fun closeAudioState()
abstract val isSpeakerphoneOn: Boolean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment