1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SCREEN_CAPTURE_ADAPTER_H 17 #define SCREEN_CAPTURE_ADAPTER_H 18 19 #include <list> 20 #include <memory> 21 #include <string> 22 23 #include "graphic_adapter.h" 24 25 namespace OHOS::NWeb { 26 27 enum class CaptureModeAdapter : int32_t { 28 /* capture home screen */ 29 CAPTURE_HOME_SCREEN = 0, 30 /* capture a specified screen */ 31 CAPTURE_SPECIFIED_SCREEN = 1, 32 /* capture a specified window */ 33 CAPTURE_SPECIFIED_WINDOW = 2, 34 CAPTURE_INVAILD = -1 35 }; 36 37 enum class DataTypeAdapter : int32_t { 38 /* YUV/RGBA/PCM, etc. original stream */ 39 ORIGINAL_STREAM_DATA_TYPE = 0, 40 /* h264/AAC, etc. encoded stream */ 41 ENCODED_STREAM_DATA_TYPE = 1, 42 /* mp4 file */ 43 CAPTURE_FILE_DATA_TYPE = 2, 44 INVAILD_DATA_TYPE = -1 45 }; 46 47 enum class AudioCaptureSourceTypeAdapter : int32_t { 48 /* Invalid audio source */ 49 SOURCE_INVALID = -1, 50 /* Default audio source */ 51 SOURCE_DEFAULT = 0, 52 /* Microphone */ 53 MIC = 1, 54 /* inner all PlayBack */ 55 ALL_PLAYBACK = 2, 56 /* inner app PlayBack */ 57 APP_PLAYBACK = 3, 58 }; 59 60 enum class AudioCodecFormatAdapter : int32_t { 61 /* Default format */ 62 AUDIO_DEFAULT = 0, 63 /* Advanced Audio Coding Low Complexity (AAC-LC) */ 64 AAC_LC = 3, 65 /* Invalid value */ 66 AUDIO_CODEC_FORMAT_BUTT, 67 }; 68 69 enum class VideoSourceTypeAdapter : int32_t { 70 /* Unsupported App Usage. */ 71 /* YUV video data provided through graphic */ 72 VIDEO_SOURCE_SURFACE_YUV = 0, 73 /* Raw encoded data provided through graphic */ 74 VIDEO_SOURCE_SURFACE_ES, 75 /* RGBA video data provided through graphic */ 76 VIDEO_SOURCE_SURFACE_RGBA, 77 /* Invalid value */ 78 VIDEO_SOURCE_BUTT 79 }; 80 81 enum class VideoCodecFormatAdapter : int32_t { 82 /* Default format */ 83 VIDEO_DEFAULT = 0, 84 /* H.264 */ 85 H264 = 2, 86 /* H.265/HEVC */ 87 H265 = 4, 88 /* MPEG4 */ 89 MPEG4 = 6, 90 /* VP8 */ 91 VP8 = 8, 92 /* VP9 */ 93 VP9 = 10, 94 /* Invalid format */ 95 VIDEO_CODEC_FORMAT_BUTT, 96 }; 97 98 enum class ContainerFormatTypeAdapter : int32_t { 99 /* Audio format type -- m4a */ 100 CFT_MPEG_4A_TYPE = 0, 101 /* Video format type -- mp4 */ 102 CFT_MPEG_4_TYPE = 1, 103 /* Invalid format */ 104 CFT_BUTT, 105 }; 106 107 enum class ScreenCaptureStateCodeAdapter : int32_t { 108 /* Screen capture state INVALID */ 109 SCREEN_CAPTURE_STATE_INVLID = -1, 110 /* Screen capture started by user */ 111 SCREEN_CAPTURE_STATE_STARTED = 0, 112 /* Screen capture canceled by user */ 113 SCREEN_CAPTURE_STATE_CANCELED = 1, 114 /* ScreenCapture stopped by user */ 115 SCREEN_CAPTURE_STATE_STOPPED_BY_USER = 2, 116 /* ScreenCapture interrupted by other screen capture */ 117 SCREEN_CAPTURE_STATE_INTERRUPTED_BY_OTHER = 3, 118 /* ScreenCapture stopped by SIM call */ 119 SCREEN_CAPTURE_STATE_STOPPED_BY_CALL = 4, 120 /* Microphone is temporarily unavailable */ 121 SCREEN_CAPTURE_STATE_MIC_UNAVAILABLE = 5, 122 /* Microphone is muted by user */ 123 SCREEN_CAPTURE_STATE_MIC_MUTED_BY_USER = 6, 124 /* Microphone is unmuted by user */ 125 SCREEN_CAPTURE_STATE_MIC_UNMUTED_BY_USER = 7, 126 /* Current captured screen has private window */ 127 SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE = 8, 128 /* Private window disappeared on current captured screen*/ 129 SCREEN_CAPTURE_STATE_EXIT_PRIVATE_SCENE = 9, 130 }; 131 132 class AudioCaptureInfoAdapter { 133 public: 134 AudioCaptureInfoAdapter() = default; 135 136 virtual ~AudioCaptureInfoAdapter() = default; 137 138 /* Audio capture sample rate info */ 139 virtual int32_t GetAudioSampleRate() = 0; 140 141 /* Audio capture channel info */ 142 virtual int32_t GetAudioChannels() = 0; 143 144 /* Audio capture source type */ 145 virtual AudioCaptureSourceTypeAdapter GetAudioSource() = 0; 146 }; 147 148 class AudioEncInfoAdapter { 149 public: 150 AudioEncInfoAdapter() = default; 151 152 virtual ~AudioEncInfoAdapter() = default; 153 154 /* Audio encoder bitrate */ 155 virtual int32_t GetAudioBitrate() = 0; 156 157 /* Audio codec format */ 158 virtual AudioCodecFormatAdapter GetAudioCodecformat() = 0; 159 }; 160 161 class AudioInfoAdapter { 162 public: 163 AudioInfoAdapter() = default; 164 165 virtual ~AudioInfoAdapter() = default; 166 167 /* Audio capture info of microphone */ 168 virtual std::shared_ptr<AudioCaptureInfoAdapter> GetMicCapInfo() = 0; 169 170 /* Audio capture info of inner */ 171 virtual std::shared_ptr<AudioCaptureInfoAdapter> GetInnerCapInfo() = 0; 172 173 /* Audio encoder info, no need to set, while dataType = ORIGINAL_STREAM_DATA_TYPE */ 174 virtual std::shared_ptr<AudioEncInfoAdapter> GetAudioEncInfo() = 0; 175 }; 176 177 class VideoCaptureInfoAdapter { 178 public: 179 VideoCaptureInfoAdapter() = default; 180 181 virtual ~VideoCaptureInfoAdapter() = default; 182 183 /* Display id, should be set while captureMode = CAPTURE_SPECIFIED_SCREEN */ 184 virtual uint64_t GetDisplayId() = 0; 185 186 /* The ids of mission, should be set while captureMode = CAPTURE_SPECIFIED_WINDOW */ 187 virtual std::list<int32_t> GetTaskIDs() = 0; 188 189 /* Video frame width of avscreeencapture */ 190 virtual int32_t GetVideoFrameWidth() = 0; 191 192 /* Video frame height of avscreeencapture */ 193 virtual int32_t GetVideoFrameHeight() = 0; 194 195 /* Video source type of avscreeencapture */ 196 virtual VideoSourceTypeAdapter GetVideoSourceType() = 0; 197 }; 198 199 class VideoEncInfoAdapter { 200 public: 201 VideoEncInfoAdapter() = default; 202 203 virtual ~VideoEncInfoAdapter() = default; 204 205 /* Video encoder format */ 206 virtual VideoCodecFormatAdapter GetVideoCodecFormat() = 0; 207 208 /* Video encoder bitrate */ 209 virtual int32_t GetVideoBitrate() = 0; 210 211 /* Video encoder frame rate */ 212 virtual int32_t GetVideoFrameRate() = 0; 213 }; 214 215 class VideoInfoAdapter { 216 public: 217 VideoInfoAdapter() = default; 218 219 virtual ~VideoInfoAdapter() = default; 220 221 /* Video capture info */ 222 virtual std::shared_ptr<VideoCaptureInfoAdapter> GetVideoCapInfo() = 0; 223 224 /* Video encoder info */ 225 virtual std::shared_ptr<VideoEncInfoAdapter> GetVideoEncInfo() = 0; 226 }; 227 228 class RecorderInfoAdapter { 229 public: 230 RecorderInfoAdapter() = default; 231 232 virtual ~RecorderInfoAdapter() = default; 233 234 /* Recorder file url */ 235 virtual std::string GetUrl() = 0; 236 237 /* Recorder file format */ 238 virtual ContainerFormatTypeAdapter GetFileFormat() = 0; 239 }; 240 241 class ScreenCaptureConfigAdapter { 242 public: 243 ScreenCaptureConfigAdapter() = default; 244 245 virtual ~ScreenCaptureConfigAdapter() = default; 246 247 virtual CaptureModeAdapter GetCaptureMode() = 0; 248 249 virtual DataTypeAdapter GetDataType() = 0; 250 251 virtual std::shared_ptr<AudioInfoAdapter> GetAudioInfo() = 0; 252 253 virtual std::shared_ptr<VideoInfoAdapter> GetVideoInfo() = 0; 254 255 virtual std::shared_ptr<RecorderInfoAdapter> GetRecorderInfo() = 0; 256 }; 257 258 class ScreenCaptureCallbackAdapter { 259 public: 260 ScreenCaptureCallbackAdapter() = default; 261 262 virtual ~ScreenCaptureCallbackAdapter() = default; 263 264 virtual void OnError(int32_t errorCode) = 0; 265 266 virtual void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceTypeAdapter type) = 0; 267 268 virtual void OnVideoBufferAvailable(bool isReady) = 0; 269 OnStateChange(ScreenCaptureStateCodeAdapter stateCode)270 virtual void OnStateChange(ScreenCaptureStateCodeAdapter stateCode) {} 271 }; 272 273 class ScreenCaptureAdapter { 274 public: 275 ScreenCaptureAdapter() = default; 276 277 virtual ~ScreenCaptureAdapter() = default; 278 279 virtual int32_t Init(const std::shared_ptr<ScreenCaptureConfigAdapter> config) = 0; 280 281 virtual int32_t SetMicrophoneEnable(bool enable) = 0; 282 283 virtual int32_t StartCapture() = 0; 284 285 virtual int32_t StopCapture() = 0; 286 287 virtual int32_t SetCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackAdapter> callback) = 0; 288 289 virtual std::shared_ptr<SurfaceBufferAdapter> AcquireVideoBuffer() = 0; 290 291 virtual int32_t ReleaseVideoBuffer() = 0; 292 }; 293 294 } // namespace OHOS::NWeb 295 296 #endif // SCREEN_CAPTURE_ADAPTER_H 297