|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * See the NOTICE file distributed with this work for additional |
| 5 | + * information regarding copyright ownership. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.appium.java_client.mac; |
| 18 | + |
| 19 | +import com.google.common.collect.ImmutableMap; |
| 20 | +import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions; |
| 21 | + |
| 22 | +import java.time.Duration; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +import static java.util.Optional.ofNullable; |
| 26 | + |
| 27 | +public class Mac2StartScreenRecordingOptions |
| 28 | + extends BaseStartScreenRecordingOptions<Mac2StartScreenRecordingOptions> { |
| 29 | + private Integer fps; |
| 30 | + private String videoFilter; |
| 31 | + private String preset; |
| 32 | + private Boolean captureCursor; |
| 33 | + private Boolean captureClicks; |
| 34 | + private Integer deviceId; |
| 35 | + |
| 36 | + public static Mac2StartScreenRecordingOptions startScreenRecordingOptions() { |
| 37 | + return new Mac2StartScreenRecordingOptions(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * The count of frames per second in the resulting video. |
| 42 | + * Increasing fps value also increases the size of the resulting |
| 43 | + * video file and the CPU usage. |
| 44 | + * |
| 45 | + * @param fps The actual frames per second value. |
| 46 | + * The default value is 15. |
| 47 | + * @return self instance for chaining. |
| 48 | + */ |
| 49 | + public Mac2StartScreenRecordingOptions withFps(int fps) { |
| 50 | + this.fps = fps; |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Whether to capture the mouse cursor while recording |
| 56 | + * the screen. Disabled by default. |
| 57 | + * |
| 58 | + * @return self instance for chaining. |
| 59 | + */ |
| 60 | + public Mac2StartScreenRecordingOptions enableCursorCapture() { |
| 61 | + this.captureCursor = true; |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Whether to capture the click gestures while recording |
| 67 | + * the screen. Disabled by default. |
| 68 | + * |
| 69 | + * @return self instance for chaining. |
| 70 | + */ |
| 71 | + public Mac2StartScreenRecordingOptions enableClicksCapture() { |
| 72 | + this.captureClicks = true; |
| 73 | + return this; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Screen device index to use for the recording. |
| 78 | + * The list of available devices could be retrieved using |
| 79 | + * `ffmpeg -f avfoundation -list_devices true -i` command. |
| 80 | + * This option is mandatory and must be always provided. |
| 81 | + * |
| 82 | + * @param deviceId The valid screen device identifier. |
| 83 | + * @return self instance for chaining. |
| 84 | + */ |
| 85 | + public Mac2StartScreenRecordingOptions withDeviceId(Integer deviceId) { |
| 86 | + this.deviceId = deviceId; |
| 87 | + return this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * The video filter spec to apply for ffmpeg. |
| 92 | + * See https://trac.ffmpeg.org/wiki/FilteringGuide for more details on the possible values. |
| 93 | + * Example: Set it to `scale=ifnot(gte(iw\,1024)\,iw\,1024):-2` in order to limit the video width |
| 94 | + * to 1024px. The height will be adjusted automatically to match the actual screen aspect ratio. |
| 95 | + * |
| 96 | + * @param videoFilter Valid ffmpeg video filter spec string. |
| 97 | + * @return self instance for chaining. |
| 98 | + */ |
| 99 | + public Mac2StartScreenRecordingOptions withVideoFilter(String videoFilter) { |
| 100 | + this.videoFilter = videoFilter; |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * A preset is a collection of options that will provide a certain encoding speed to compression ratio. |
| 106 | + * A slower preset will provide better compression (compression is quality per filesize). |
| 107 | + * This means that, for example, if you target a certain file size or constant bit rate, you will |
| 108 | + * achieve better quality with a slower preset. Read https://trac.ffmpeg.org/wiki/Encode/H.264 |
| 109 | + * for more details. |
| 110 | + * |
| 111 | + * @param preset One of the supported encoding presets. Possible values are: |
| 112 | + * - ultrafast |
| 113 | + * - superfast |
| 114 | + * - veryfast (default) |
| 115 | + * - faster |
| 116 | + * - fast |
| 117 | + * - medium |
| 118 | + * - slow |
| 119 | + * - slower |
| 120 | + * - veryslow |
| 121 | + * @return self instance for chaining. |
| 122 | + */ |
| 123 | + public Mac2StartScreenRecordingOptions withPreset(String preset) { |
| 124 | + this.preset = preset; |
| 125 | + return this; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * The maximum recording time. The default value is 600 seconds (10 minutes). |
| 130 | + * The minimum time resolution unit is one second. |
| 131 | + * |
| 132 | + * @param timeLimit The actual time limit of the recorded video. |
| 133 | + * @return self instance for chaining. |
| 134 | + */ |
| 135 | + @Override |
| 136 | + public Mac2StartScreenRecordingOptions withTimeLimit(Duration timeLimit) { |
| 137 | + return super.withTimeLimit(timeLimit); |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public Map<String, Object> build() { |
| 142 | + final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); |
| 143 | + builder.putAll(super.build()); |
| 144 | + ofNullable(fps).map(x -> builder.put("fps", x)); |
| 145 | + ofNullable(preset).map(x -> builder.put("preset", x)); |
| 146 | + ofNullable(videoFilter).map(x -> builder.put("videoFilter", x)); |
| 147 | + ofNullable(captureClicks).map(x -> builder.put("captureClicks", x)); |
| 148 | + ofNullable(captureCursor).map(x -> builder.put("captureCursor", x)); |
| 149 | + ofNullable(deviceId).map(x -> builder.put("deviceId", x)); |
| 150 | + return builder.build(); |
| 151 | + } |
| 152 | +} |
0 commit comments