• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "screen_capture_capi_mock.h"
17 #include "native_mfmagic.h"
18 #include "external_window.h"
19 
20 using namespace std;
21 using namespace OHOS;
22 using namespace OHOS::Media;
23 using namespace testing::ext;
24 using namespace OHOS::Media::ScreenCaptureTestParam;
25 std::mutex ScreenCaptureCapiMock::mutex_;
26 std::map<OH_AVScreenCapture *, std::shared_ptr<ScreenCaptureCallbackMock>> ScreenCaptureCapiMock::mockCbMap_;
27 
28 typedef struct NativeWindow OHNativeWindow;
29 
OnError(OH_AVScreenCapture * screenCapture,int32_t errorCode)30 void ScreenCaptureCapiMock::OnError(OH_AVScreenCapture *screenCapture, int32_t errorCode)
31 {
32     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
33     if (mockCb != nullptr) {
34         mockCb->OnError(errorCode);
35     }
36 }
37 
OnAudioBufferAvailable(OH_AVScreenCapture * screenCapture,bool isReady,OH_AudioCaptureSourceType type)38 void ScreenCaptureCapiMock::OnAudioBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady,
39     OH_AudioCaptureSourceType type)
40 {
41     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
42     if (mockCb != nullptr) {
43         mockCb->OnAudioBufferAvailable(isReady, static_cast<AudioCaptureSourceType>(type));
44     }
45 }
46 
OnVideoBufferAvailable(OH_AVScreenCapture * screenCapture,bool isReady)47 void ScreenCaptureCapiMock::OnVideoBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady)
48 {
49     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
50     if (mockCb != nullptr) {
51         mockCb->OnVideoBufferAvailable(isReady);
52     }
53 }
54 
OnErrorNew(OH_AVScreenCapture * screenCapture,int32_t errorCode,void * userData)55 void ScreenCaptureCapiMock::OnErrorNew(OH_AVScreenCapture *screenCapture, int32_t errorCode, void *userData)
56 {
57     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
58     if (mockCb != nullptr) {
59         mockCb->OnError(errorCode, userData);
60     }
61 }
62 
OnBufferAvailable(OH_AVScreenCapture * screenCapture,OH_AVBuffer * buffer,OH_AVScreenCaptureBufferType bufferType,int64_t timestamp,void * userData)63 void ScreenCaptureCapiMock::OnBufferAvailable(OH_AVScreenCapture *screenCapture, OH_AVBuffer *buffer,
64     OH_AVScreenCaptureBufferType bufferType, int64_t timestamp, void *userData)
65 {
66     UNITTEST_CHECK_AND_RETURN_LOG(buffer != nullptr, "OH_AVBuffer buffer == nullptr");
67     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
68     if (mockCb != nullptr) {
69         mockCb->OnBufferAvailable(buffer->buffer_, static_cast<AVScreenCaptureBufferType>(bufferType), timestamp);
70     }
71 }
72 
OnStateChange(OH_AVScreenCapture * screenCapture,OH_AVScreenCaptureStateCode stateCode,void * userData)73 void ScreenCaptureCapiMock::OnStateChange(OH_AVScreenCapture *screenCapture,
74     OH_AVScreenCaptureStateCode stateCode, void *userData)
75 {
76     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
77     if (mockCb != nullptr) {
78         mockCb->OnStateChange(static_cast<AVScreenCaptureStateCode>(stateCode));
79     }
80 }
81 
OnCaptureContentChanged(OH_AVScreenCapture * screenCapture,OH_AVScreenCaptureContentChangedEvent event,OH_Rect * area,void * userData)82 void ScreenCaptureCapiMock::OnCaptureContentChanged(OH_AVScreenCapture *screenCapture,
83     OH_AVScreenCaptureContentChangedEvent event, OH_Rect* area, void *userData)
84 {
85     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
86     if (mockCb != nullptr) {
87         mockCb->OnCaptureContentChanged(static_cast<AVScreenCaptureContentChangedEvent>(event),
88             reinterpret_cast<ScreenCaptureRect*>(area));
89     }
90 }
91 
OnDisplaySelected(OH_AVScreenCapture * screenCapture,uint64_t displayId,void * userData)92 void ScreenCaptureCapiMock::OnDisplaySelected(OH_AVScreenCapture *screenCapture, uint64_t displayId, void *userData)
93 {
94     std::shared_ptr<ScreenCaptureCallbackMock> mockCb = GetCallback(screenCapture);
95     if (mockCb != nullptr) {
96         mockCb->OnDisplaySelected(displayId);
97     }
98 }
99 
Convert(AVScreenCaptureConfig config)100 OH_AVScreenCaptureConfig ScreenCaptureCapiMock::Convert(AVScreenCaptureConfig config)
101 {
102     OH_AVScreenCaptureConfig tempConfig;
103     tempConfig.captureMode = static_cast<OH_CaptureMode>(config.captureMode);
104     tempConfig.dataType = static_cast<OH_DataType>(config.dataType);
105     tempConfig.audioInfo.micCapInfo = {
106         .audioSampleRate = config.audioInfo.micCapInfo.audioSampleRate,
107         .audioChannels = config.audioInfo.micCapInfo.audioChannels,
108         .audioSource = static_cast<OH_AudioCaptureSourceType>(config.audioInfo.micCapInfo.audioSource)
109     };
110     tempConfig.audioInfo.innerCapInfo = {
111         .audioSampleRate = config.audioInfo.innerCapInfo.audioSampleRate,
112         .audioChannels = config.audioInfo.innerCapInfo.audioChannels,
113         .audioSource = static_cast<OH_AudioCaptureSourceType>(config.audioInfo.innerCapInfo.audioSource)
114     };
115     tempConfig.audioInfo.audioEncInfo.audioBitrate = config.audioInfo.audioEncInfo.audioBitrate;
116     tempConfig.audioInfo.audioEncInfo.audioCodecformat =
117         static_cast<OH_AudioCodecFormat>(config.audioInfo.audioEncInfo.audioCodecformat);
118     tempConfig.videoInfo.videoCapInfo.displayId = config.videoInfo.videoCapInfo.displayId;
119     std::list<int32_t> taskIds = config.videoInfo.videoCapInfo.taskIDs;
120     if (taskIds.size() > 0) {
121         int32_t *taskIds_temp = static_cast<int*>(malloc(sizeof(int)));
122         for (std::list<int32_t>::iterator its = taskIds.begin(); its != taskIds.end(); ++its) {
123             *taskIds_temp = *its;
124             taskIds_temp++;
125         }
126         tempConfig.videoInfo.videoCapInfo.missionIDs = taskIds_temp;
127     }
128     tempConfig.videoInfo.videoCapInfo.missionIDsLen = taskIds.size();
129     tempConfig.videoInfo.videoCapInfo.videoFrameWidth = config.videoInfo.videoCapInfo.videoFrameWidth;
130     tempConfig.videoInfo.videoCapInfo.videoFrameHeight = config.videoInfo.videoCapInfo.videoFrameHeight;
131     tempConfig.videoInfo.videoCapInfo.videoSource =
132         static_cast<OH_VideoSourceType>(config.videoInfo.videoCapInfo.videoSource);
133     tempConfig.videoInfo.videoEncInfo = {
134         .videoCodec = static_cast<OH_VideoCodecFormat>(config.videoInfo.videoEncInfo.videoCodec),
135         .videoBitrate = static_cast<OH_VideoCodecFormat>(config.videoInfo.videoEncInfo.videoBitrate),
136         .videoFrameRate = static_cast<OH_VideoCodecFormat>(config.videoInfo.videoEncInfo.videoFrameRate)
137     };
138     std::string url = config.recorderInfo.url;
139     if (!(url.empty())) {
140         tempConfig.recorderInfo.url = const_cast<char *>(config.recorderInfo.url.c_str());
141         tempConfig.recorderInfo.urlLen = config.recorderInfo.url.size();
142     }
143     if (config.recorderInfo.fileFormat == ContainerFormatType::CFT_MPEG_4A) {
144         tempConfig.recorderInfo.fileFormat = OH_ContainerFormatType::CFT_MPEG_4A;
145     } else if (config.recorderInfo.fileFormat == ContainerFormatType::CFT_MPEG_4) {
146         tempConfig.recorderInfo.fileFormat = OH_ContainerFormatType::CFT_MPEG_4;
147     }
148     return tempConfig;
149 }
150 
GetCallback(OH_AVScreenCapture * screenCapture)151 std::shared_ptr<ScreenCaptureCallbackMock> ScreenCaptureCapiMock::GetCallback(OH_AVScreenCapture *screenCapture)
152 {
153     std::lock_guard<std::mutex> lock(mutex_);
154     if (mockCbMap_.empty()) {
155         return nullptr;
156     }
157     if (mockCbMap_.find(screenCapture) != mockCbMap_.end()) {
158         return mockCbMap_.at(screenCapture);
159     }
160     return nullptr;
161 }
162 
DelCallback(OH_AVScreenCapture * screenCapture)163 void ScreenCaptureCapiMock::DelCallback(OH_AVScreenCapture *screenCapture)
164 {
165     std::lock_guard<std::mutex> lock(mutex_);
166     if (mockCbMap_.empty()) {
167         return;
168     }
169     auto it = mockCbMap_.find(screenCapture);
170     if (it != mockCbMap_.end()) {
171         mockCbMap_.erase(it);
172     }
173 }
174 
SetScreenCaptureCallback(OH_AVScreenCapture * screencapture,std::shared_ptr<ScreenCaptureCallbackMock> cb)175 void ScreenCaptureCapiMock::SetScreenCaptureCallback(OH_AVScreenCapture *screencapture,
176     std::shared_ptr<ScreenCaptureCallbackMock> cb)
177 {
178     std::lock_guard<std::mutex> lock(mutex_);
179     mockCbMap_[screencapture] = cb;
180 }
181 
GetCaptureContentChangeCallback(const bool isCaptureContentChangeCallbackEnabled)182 int32_t ScreenCaptureCapiMock::GetCaptureContentChangeCallback(const bool isCaptureContentChangeCallbackEnabled)
183 {
184     if (isCaptureContentChangeCallbackEnabled) {
185         MEDIA_LOGD("ScreenCaptureCapiMock SetCaptureContentChangedCallback");
186         isCaptureContentChangeCallbackEnabled_ = isCaptureContentChangeCallbackEnabled;
187         int32_t ret = OH_AVScreenCapture_SetCaptureContentChangedCallback(screenCapture_,
188             ScreenCaptureCapiMock::OnCaptureContentChanged, this);
189         if (ret != AV_SCREEN_CAPTURE_ERR_OK) {
190             MEDIA_LOGE("ScreenCaptureCapiMock SetCaptureContentChangedCallback failed, ret: %{public}d", ret);
191             return MSERR_UNKNOWN;
192         }
193     }
194     return MSERR_OK;
195 }
196 
SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackMock> & callback,const bool isErrorCallbackEnabled,const bool isDataCallbackEnabled,const bool isStateChangeCallbackEnabled,const bool isCaptureContentChangeCallbackEnabled)197 int32_t ScreenCaptureCapiMock::SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackMock>& callback,
198     const bool isErrorCallbackEnabled, const bool isDataCallbackEnabled, const bool isStateChangeCallbackEnabled,
199     const bool isCaptureContentChangeCallbackEnabled)
200 {
201     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
202     if (callback == nullptr) {
203         return MSERR_INVALID_OPERATION;
204     }
205     MEDIA_LOGD("ScreenCaptureCapiMock SetScreenCaptureCallback");
206     SetScreenCaptureCallback(screenCapture_, callback);
207     struct OH_AVScreenCaptureCallback ohCallback;
208     ohCallback.onError = ScreenCaptureCapiMock::OnError;
209     ohCallback.onAudioBufferAvailable = ScreenCaptureCapiMock::OnAudioBufferAvailable;
210     ohCallback.onVideoBufferAvailable = ScreenCaptureCapiMock::OnVideoBufferAvailable;
211     int ret = OH_AVScreenCapture_SetCallback(screenCapture_, ohCallback);
212     if (ret != AV_SCREEN_CAPTURE_ERR_OK) {
213         MEDIA_LOGE("ScreenCaptureCapiMock SetCallback failed, ret: %{public}d", ret);
214         return MSERR_UNKNOWN;
215     }
216     if (isErrorCallbackEnabled) {
217         MEDIA_LOGD("ScreenCaptureCapiMock SetErrorCallback");
218         isErrorCallbackEnabled_ = isErrorCallbackEnabled;
219         ret = OH_AVScreenCapture_SetErrorCallback(screenCapture_, ScreenCaptureCapiMock::OnErrorNew, this);
220         if (ret != AV_SCREEN_CAPTURE_ERR_OK) {
221             MEDIA_LOGE("ScreenCaptureCapiMock SetErrorCallback failed, ret: %{public}d", ret);
222             return MSERR_UNKNOWN;
223         }
224     }
225     if (isDataCallbackEnabled) {
226         MEDIA_LOGD("ScreenCaptureCapiMock SetDataCallback");
227         isDataCallbackEnabled_ = isDataCallbackEnabled;
228         ret = OH_AVScreenCapture_SetDataCallback(screenCapture_, ScreenCaptureCapiMock::OnBufferAvailable, this);
229         if (ret != AV_SCREEN_CAPTURE_ERR_OK) {
230             MEDIA_LOGE("ScreenCaptureCapiMock SetDataCallback failed, ret: %{public}d", ret);
231             return MSERR_UNKNOWN;
232         }
233     }
234     if (isStateChangeCallbackEnabled) {
235         MEDIA_LOGD("ScreenCaptureCapiMock SetStateCallback");
236         isStateChangeCallbackEnabled_ = isStateChangeCallbackEnabled;
237         ret = OH_AVScreenCapture_SetStateCallback(screenCapture_, ScreenCaptureCapiMock::OnStateChange, this);
238         if (ret != AV_SCREEN_CAPTURE_ERR_OK) {
239             MEDIA_LOGE("ScreenCaptureCapiMock SetStateCallback failed, ret: %{public}d", ret);
240             return MSERR_UNKNOWN;
241         }
242     }
243 
244     return GetCaptureContentChangeCallback(isCaptureContentChangeCallbackEnabled);
245 }
246 
StartScreenCapture()247 int32_t ScreenCaptureCapiMock::StartScreenCapture()
248 {
249     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
250     return OH_AVScreenCapture_StartScreenCapture(screenCapture_);
251 }
252 
StartScreenCaptureWithSurface(const std::any & value)253 int32_t ScreenCaptureCapiMock::StartScreenCaptureWithSurface(const std::any& value)
254 {
255     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
256     sptr<Surface> surface = std::any_cast<sptr<Surface>>(value);
257     OH_NativeWindow_CreateNativeWindowFromSurfaceId(surface->GetUniqueId(), &nativeWindow_);
258     return OH_AVScreenCapture_StartScreenCaptureWithSurface(screenCapture_, nativeWindow_);
259 }
260 
Init(AVScreenCaptureConfig config)261 int32_t ScreenCaptureCapiMock::Init(AVScreenCaptureConfig config)
262 {
263     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
264     OH_AVScreenCaptureConfig tempConfig = Convert(config);
265     return OH_AVScreenCapture_Init(screenCapture_, tempConfig);
266 }
267 
StopScreenCapture()268 int32_t ScreenCaptureCapiMock::StopScreenCapture()
269 {
270     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
271     return OH_AVScreenCapture_StopScreenCapture(screenCapture_);
272 }
273 
StartScreenRecording()274 int32_t ScreenCaptureCapiMock::StartScreenRecording()
275 {
276     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
277     return OH_AVScreenCapture_StartScreenRecording(screenCapture_);
278 }
279 
StopScreenRecording()280 int32_t ScreenCaptureCapiMock::StopScreenRecording()
281 {
282     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
283     return OH_AVScreenCapture_StopScreenRecording(screenCapture_);
284 }
285 
Release()286 int32_t ScreenCaptureCapiMock::Release()
287 {
288     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
289     DelCallback(screenCapture_);
290     if (nativeWindow_ != nullptr) {
291         OH_NativeWindow_DestroyNativeWindow(nativeWindow_);
292         nativeWindow_ = nullptr;
293     }
294     int32_t ret = OH_AVScreenCapture_Release(screenCapture_);
295     screenCapture_ = nullptr;
296     return ret;
297 }
298 
SetMicrophoneEnabled(bool isMicrophone)299 int32_t ScreenCaptureCapiMock::SetMicrophoneEnabled(bool isMicrophone)
300 {
301     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
302     return OH_AVScreenCapture_SetMicrophoneEnabled(screenCapture_, isMicrophone);
303 }
304 
SetCanvasRotation(bool canvasRotation)305 int32_t ScreenCaptureCapiMock::SetCanvasRotation(bool canvasRotation)
306 {
307     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
308     return OH_AVScreenCapture_SetCanvasRotation(screenCapture_, canvasRotation);
309 }
310 
ResizeCanvas(int32_t width,int32_t height)311 int32_t ScreenCaptureCapiMock::ResizeCanvas(int32_t width, int32_t height)
312 {
313     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
314     return OH_AVScreenCapture_ResizeCanvas(screenCapture_, width, height);
315 }
316 
UpdateSurface(const std::any & surface)317 int32_t ScreenCaptureCapiMock::UpdateSurface(const std::any& surface)
318 {
319     return MSERR_OK;
320 }
321 
SkipPrivacyMode(int32_t * windowIDs,int32_t windowCount)322 int32_t ScreenCaptureCapiMock::SkipPrivacyMode(int32_t *windowIDs, int32_t windowCount)
323 {
324     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
325     return OH_AVScreenCapture_SkipPrivacyMode(screenCapture_, windowIDs, windowCount);
326 }
327 
SetMaxVideoFrameRate(int32_t frameRate)328 int32_t ScreenCaptureCapiMock::SetMaxVideoFrameRate(int32_t frameRate)
329 {
330     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
331     return OH_AVScreenCapture_SetMaxVideoFrameRate(screenCapture_, frameRate);
332 }
333 
AcquireAudioBuffer(std::shared_ptr<AudioBuffer> & audioBuffer,AudioCaptureSourceType type)334 int32_t ScreenCaptureCapiMock::AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer,
335     AudioCaptureSourceType type)
336 {
337     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
338     OH_AudioBuffer *buffer = static_cast<OH_AudioBuffer *>(malloc(sizeof(OH_AudioBuffer)));
339     if (buffer == nullptr) {
340         return MSERR_INVALID_OPERATION;
341     }
342     auto t_type = static_cast<OH_AudioCaptureSourceType>(type);
343     int32_t ret = OH_AVScreenCapture_AcquireAudioBuffer(screenCapture_, &buffer, t_type);
344     if (ret == AV_SCREEN_CAPTURE_ERR_OK) {
345         // If ret is not AV_SCREEN_CAPTURE_ERR_OK, the object referenced by buffer is not initialized and can't be used.
346         audioBuffer =
347             std::make_shared<AudioBuffer>(buffer->buf, buffer->size, buffer->timestamp,
348                 static_cast<AudioCaptureSourceType>(buffer->type));
349     }
350     free(buffer);
351     buffer = nullptr;
352     return ret;
353 }
354 
AcquireVideoBuffer(int32_t & fence,int64_t & timestamp,OHOS::Rect & damage)355 sptr<OHOS::SurfaceBuffer> ScreenCaptureCapiMock::AcquireVideoBuffer(int32_t &fence, int64_t &timestamp,
356     OHOS::Rect &damage)
357 {
358     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, nullptr, "screenCapture_ == nullptr");
359     OH_Rect damage_ = {
360         .x = damage.x,
361         .y = damage.y,
362         .width = damage.w,
363         .height = damage.h,
364     };
365     OH_NativeBuffer* buffer = OH_AVScreenCapture_AcquireVideoBuffer(screenCapture_, &fence, &timestamp, &damage_);
366     sptr<OHOS::SurfaceBuffer> surfacebuffer;
367     if (buffer != nullptr) {
368         surfacebuffer =  OHOS::SurfaceBuffer::NativeBufferToSurfaceBuffer(buffer);
369     }
370     return surfacebuffer;
371 }
372 
ReleaseAudioBuffer(OHOS::Media::AudioCaptureSourceType type)373 int32_t ScreenCaptureCapiMock::ReleaseAudioBuffer(OHOS::Media::AudioCaptureSourceType type)
374 {
375     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
376     auto t_type = static_cast<OH_AudioCaptureSourceType>(type);
377     return OH_AVScreenCapture_ReleaseAudioBuffer(screenCapture_, t_type);
378 }
379 
ReleaseVideoBuffer()380 int32_t ScreenCaptureCapiMock::ReleaseVideoBuffer()
381 {
382     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
383     return OH_AVScreenCapture_ReleaseVideoBuffer(screenCapture_);
384 }
385 
ExcludeWindowContent(int32_t * windowIDs,int32_t windowCount)386 int32_t ScreenCaptureCapiMock::ExcludeWindowContent(int32_t *windowIDs, int32_t windowCount)
387 {
388     int32_t ret = MSERR_OK;
389     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
390     if (contentFilter_ != nullptr) {
391         ret = OH_AVScreenCapture_ReleaseContentFilter(contentFilter_);
392         UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "release content failed");
393     }
394     contentFilter_ = OH_AVScreenCapture_CreateContentFilter();
395     OH_AVScreenCapture_ContentFilter_AddWindowContent(contentFilter_, windowIDs, windowCount);
396     return OH_AVScreenCapture_ExcludeContent(screenCapture_, contentFilter_);
397 }
398 
ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType)399 int32_t ScreenCaptureCapiMock::ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType)
400 {
401     int32_t ret = MSERR_OK;
402     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
403     if (contentFilter_ != nullptr) {
404         ret = OH_AVScreenCapture_ReleaseContentFilter(contentFilter_);
405         UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "release content failed");
406     }
407     contentFilter_ = OH_AVScreenCapture_CreateContentFilter();
408     OH_AVScreenCapture_ContentFilter_AddAudioContent(contentFilter_,
409         static_cast<OH_AVScreenCaptureFilterableAudioContent>(audioType));
410     return OH_AVScreenCapture_ExcludeContent(screenCapture_, contentFilter_);
411 }
412 
CreateCaptureStrategy()413 int32_t ScreenCaptureCapiMock::CreateCaptureStrategy()
414 {
415     strategy_ = OH_AVScreenCapture_CreateCaptureStrategy();
416     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
417         "OH_AVScreenCapture_CreateCaptureStrategy failed");
418     return MSERR_OK;
419 }
420 
StrategyForKeepCaptureDuringCall(bool value)421 int32_t ScreenCaptureCapiMock::StrategyForKeepCaptureDuringCall(bool value)
422 {
423     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
424         "OH_AVScreenCapture_CreateCaptureStrategy failed");
425     return OH_AVScreenCapture_StrategyForKeepCaptureDuringCall(strategy_, value);
426 }
427 
SetCanvasFollowRotationStrategy(bool value)428 int32_t ScreenCaptureCapiMock::SetCanvasFollowRotationStrategy(bool value)
429 {
430     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
431         "OH_AVScreenCapture_StrategyForCanvasFollowRotation failed");
432     return OH_AVScreenCapture_StrategyForCanvasFollowRotation(strategy_, value);
433 }
434 
SetCaptureStrategy()435 int32_t ScreenCaptureCapiMock::SetCaptureStrategy()
436 {
437     UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr");
438     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
439         "OH_AVScreenCapture_CreateCaptureStrategy failed");
440     return OH_AVScreenCapture_SetCaptureStrategy(screenCapture_, strategy_);
441 }
442 
ReleaseCaptureStrategy()443 int32_t ScreenCaptureCapiMock::ReleaseCaptureStrategy()
444 {
445     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_INVALID_OPERATION, "strategy_ == nullptr");
446     return OH_AVScreenCapture_ReleaseCaptureStrategy(strategy_);
447 }
448 
StrategyForBFramesEncoding(bool value)449 int32_t ScreenCaptureCapiMock::StrategyForBFramesEncoding(bool value)
450 {
451     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
452         "OH_AVScreenCapture_CreateCaptureStrategy failed");
453     return OH_AVScreenCapture_StrategyForBFramesEncoding(strategy_, value);
454 }
455 
StrategyForPrivacyMaskMode(int32_t value)456 int32_t ScreenCaptureCapiMock::StrategyForPrivacyMaskMode(int32_t value)
457 {
458     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
459         "OH_AVScreenCapture_StrategyForPrivacyMaskMode failed");
460     return OH_AVScreenCapture_StrategyForPrivacyMaskMode(strategy_, value);
461 }
462 
StrategyForPickerPopUp(bool value)463 int32_t ScreenCaptureCapiMock::StrategyForPickerPopUp(bool value)
464 {
465     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN,
466         "OH_AVScreenCapture_CreateCaptureStrategy failed");
467     return OH_AVScreenCapture_StrategyForPickerPopUp(strategy_, value);
468 }
469 
StrategyForFillMode(AVScreenCaptureFillMode value)470 int32_t ScreenCaptureCapiMock::StrategyForFillMode(AVScreenCaptureFillMode value)
471 {
472     UNITTEST_CHECK_AND_RETURN_RET_LOG(strategy_ != nullptr, MSERR_UNKNOWN, "strategy_ == nullptr");
473     return OH_AVScreenCapture_StrategyForFillMode(strategy_, static_cast<OH_AVScreenCapture_FillMode>(value));
474 }