Skip to content

Commit abe3783

Browse files
authored
ISSUE-706: Allow video recording resolution override (#707)
1 parent 4955b3a commit abe3783

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/recorder/VideoRecordingThread.kt

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.view.WindowManager
1010
import androidx.annotation.RequiresApi
1111
import androidx.test.uiautomator.UiDevice
1212
import com.kaspersky.kaspresso.logger.UiTestLogger
13+
import com.kaspersky.kaspresso.params.Resolution
1314
import com.kaspersky.kaspresso.params.VideoParams
1415
import java.io.File
1516
import kotlin.math.min
@@ -42,30 +43,9 @@ class VideoRecordingThread(
4243
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
4344
private fun startVideoRecordingWithRespectToCodecCapabilities() {
4445
try {
45-
val codecInfo = MediaCodecList(MediaCodecList.ALL_CODECS).codecInfos
46-
.filter { it.isEncoder }
47-
.find { it.name.contains("h264") }!!
48-
val videoCapabilities = codecInfo.getCapabilitiesForType(codecInfo.supportedTypes.find { it.contains("avc") }).videoCapabilities
49-
// codec width and heights are for landscape mode
50-
val codecHeight = videoCapabilities.supportedWidths.upper
51-
val codecWidth = videoCapabilities.supportedHeights.upper
52-
53-
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
54-
instrumentation.targetContext
55-
.getSystemService(DisplayManager::class.java)
56-
.getDisplay(Display.DEFAULT_DISPLAY)
57-
} else {
58-
(instrumentation.targetContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager?)?.defaultDisplay!!
59-
}
60-
val displayWidth = display.width
61-
val displayHeight = display.height
62-
63-
val width = min(displayWidth, codecWidth)
64-
val height = min(displayHeight, codecHeight)
65-
66-
logger.d("Display resolution: ${displayWidth}x$displayHeight; supported codec resolution: ${codecWidth}x$codecHeight")
67-
logger.d("Starting video recording with resolution ${width}x$height")
68-
execShellCommand("screenrecord --bit-rate ${params.bitRate} --size ${width}x$height --bugreport ${file.absolutePath}")
46+
val resolution = getResolution()
47+
logger.d("Starting video recording with resolution ${resolution.width}x${resolution.height}")
48+
execShellCommand("screenrecord --bit-rate ${params.bitRate} --size ${resolution.width}x${resolution.height} --bugreport ${file.absolutePath}")
6949
} catch (ex: Throwable) {
7050
logger.e(
7151
"Failed to start video recording with respect to resolution supported by codec. Using native resolution. " +
@@ -78,6 +58,38 @@ class VideoRecordingThread(
7858
}
7959
}
8060

61+
private fun getResolution(): Resolution {
62+
if (params.resolutionOverride != null) {
63+
logger.d("Using video resolution override=${params.resolutionOverride}")
64+
return params.resolutionOverride
65+
}
66+
67+
val codecInfo = MediaCodecList(MediaCodecList.ALL_CODECS).codecInfos
68+
.filter { it.isEncoder }
69+
.find { it.name.contains("h264") }!!
70+
val videoCapabilities = codecInfo.getCapabilitiesForType(codecInfo.supportedTypes.find { it.contains("avc") }).videoCapabilities
71+
// codec width and heights are for landscape mode
72+
val codecHeight = videoCapabilities.supportedWidths.upper
73+
val codecWidth = videoCapabilities.supportedHeights.upper
74+
75+
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
76+
instrumentation.targetContext
77+
.getSystemService(DisplayManager::class.java)
78+
.getDisplay(Display.DEFAULT_DISPLAY)
79+
} else {
80+
(instrumentation.targetContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager?)?.defaultDisplay!!
81+
}
82+
val displayWidth = display.width
83+
val displayHeight = display.height
84+
85+
val width = min(displayWidth, codecWidth)
86+
val height = min(displayHeight, codecHeight)
87+
88+
logger.d("Display resolution: ${displayWidth}x$displayHeight; supported codec resolution: ${codecWidth}x$codecHeight")
89+
90+
return Resolution(width = width, height = height)
91+
}
92+
8193
fun killRecordingProcess() {
8294
execShellCommand("pkill -l INT screenrecord")
8395
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.kaspersky.kaspresso.params
2+
3+
data class Resolution(
4+
val width: Int,
5+
val height: Int,
6+
)

kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/VideoParams.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package com.kaspersky.kaspresso.params
33
class VideoParams(
44
val startRecordingTimeMs: Long = 3_000L,
55
val stopRecordingTimeMs: Long = 2_000L,
6-
val bitRate: Int = 1_000_000
6+
val bitRate: Int = 1_000_000,
7+
val resolutionOverride: Resolution? = null,
78
)

0 commit comments

Comments
 (0)