@@ -10,6 +10,7 @@ import android.view.WindowManager
1010import androidx.annotation.RequiresApi
1111import androidx.test.uiautomator.UiDevice
1212import com.kaspersky.kaspresso.logger.UiTestLogger
13+ import com.kaspersky.kaspresso.params.Resolution
1314import com.kaspersky.kaspresso.params.VideoParams
1415import java.io.File
1516import 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 }
0 commit comments