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 #ifndef SCREEN_CAPTURE_CAPI_MOCK_H
16 #define SCREEN_CAPTURE_CAPI_MOCK_H
17 
18 #include "native_avscreen_capture.h"
19 #include "screen_capture_mock.h"
20 
21 namespace OHOS {
22 namespace Media {
23 class ScreenCaptureCapiMock : public ScreenCaptureMock {
24 public:
ScreenCaptureCapiMock(OH_AVScreenCapture * screencapture)25     explicit ScreenCaptureCapiMock(OH_AVScreenCapture* screencapture) : screenCapture_(screencapture) {}
26     ~ScreenCaptureCapiMock() = default;
27     int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBackMock>& callback,
28         const bool isErrorCallBackEnabled, const bool isDataCallBackEnabled,
29         const bool isStateChangeCallBackEnabled) override;
30     int32_t Init(AVScreenCaptureConfig config) override;
31     int32_t StartScreenCapture() override;
32     int32_t StartScreenCaptureWithSurface(const std::any& value) override;
33     int32_t StopScreenCapture() override;
34     int32_t StartScreenRecording() override;
35     int32_t StopScreenRecording() override;
36     int32_t Release() override;
37     int32_t SetMicrophoneEnabled(bool isMicrophone) override;
38     int32_t SetCanvasRotation(bool canvasRotation) override;
39     int32_t ResizeCanvas(int32_t width, int32_t height) override;
40     int32_t SkipPrivacyMode(int32_t *windowIDs, int32_t windowCount) override;
41     int32_t SetMaxVideoFrameRate(int32_t frameRate) override;
42     int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer,
43         OHOS::Media::AudioCaptureSourceType type) override;
44     sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, OHOS::Rect &damage) override;
45     int32_t ReleaseAudioBuffer(OHOS::Media::AudioCaptureSourceType type) override;
46     int32_t ReleaseVideoBuffer() override;
47     int32_t ExcludeWindowContent(int32_t *windowIDs, int32_t windowCount) override;
48     int32_t ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType) override;
IsErrorCallBackEnabled()49     bool IsErrorCallBackEnabled() override
50     {
51         return isErrorCallBackEnabled_;
52     }
IsDataCallBackEnabled()53     bool IsDataCallBackEnabled() override
54     {
55         return isDataCallBackEnabled_;
56     }
IsStateChangeCallBackEnabled()57     bool IsStateChangeCallBackEnabled() override
58     {
59         return isStateChangeCallBackEnabled_;
60     }
61 private:
62     static void SetScreenCaptureCallback(OH_AVScreenCapture *screencapture,
63         std::shared_ptr<ScreenCaptureCallBackMock> cb);
64     static std::shared_ptr<ScreenCaptureCallBackMock> GetCallback(OH_AVScreenCapture *screenCapture);
65     static void DelCallback(OH_AVScreenCapture *screenCapture);
66     static void OnError(OH_AVScreenCapture *screenCapture, int32_t errorCode);
67     static void OnAudioBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady, OH_AudioCaptureSourceType type);
68     static void OnVideoBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady);
69     static void OnErrorNew(OH_AVScreenCapture *screenCapture, int32_t errorCode, void *userData);
70     static void OnBufferAvailable(OH_AVScreenCapture *screenCapture, OH_AVBuffer *buffer,
71         OH_AVScreenCaptureBufferType bufferType, int64_t timestamp, void *userData);
72     static void OnStateChange(struct OH_AVScreenCapture *capture,
73         OH_AVScreenCaptureStateCode stateCode, void *userData);
74     OH_AVScreenCaptureConfig Convert(AVScreenCaptureConfig config);
75 
76     static std::mutex mutex_;
77     static std::map<OH_AVScreenCapture *, std::shared_ptr<ScreenCaptureCallBackMock>> mockCbMap_;
78 
79     OH_AVScreenCapture* screenCapture_ = nullptr;
80     bool isErrorCallBackEnabled_ = false;
81     bool isDataCallBackEnabled_ = false;
82     bool isStateChangeCallBackEnabled_ = false;
83     struct OH_AVScreenCapture_ContentFilter *contentFilter_ = nullptr;
84 };
85 } // namespace Media
86 } // namespace OHOS
87 #endif