• 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 #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>& cb) override;
28     int32_t Init(AVScreenCaptureConfig config) override;
29     int32_t StartScreenCapture() override;
30     int32_t StopScreenCapture() override;
31     int32_t Release() override;
32     int32_t SetMicrophoneEnabled(bool isMicrophone) override;
33     int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer,
34         OHOS::Media::AudioCaptureSourceType type) override;
35     sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, OHOS::Rect &damage) override;
36     int32_t ReleaseAudioBuffer(OHOS::Media::AudioCaptureSourceType type) override;
37     int32_t ReleaseVideoBuffer() override;
38 
39 private:
40     static void SetScreenCaptureCallback(OH_AVScreenCapture *screencapture,
41         std::shared_ptr<ScreenCaptureCallBackMock> cb);
42     static std::shared_ptr<ScreenCaptureCallBackMock> GetCallback(OH_AVScreenCapture *screenCapture);
43     static void DelCallback(OH_AVScreenCapture *screenCapture);
44     static void OnError(OH_AVScreenCapture *screenCapture, int32_t errorCode);
45     static void OnAudioBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady, OH_AudioCaptureSourceType type);
46     static void OnVideoBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady);
47     OH_AVScreenCaptureConfig Convert(AVScreenCaptureConfig config);
48 
49     static std::mutex mutex_;
50     static std::map<OH_AVScreenCapture *, std::shared_ptr<ScreenCaptureCallBackMock>> mockCbMap_;
51 
52     OH_AVScreenCapture* screenCapture_ = nullptr;
53     std::atomic<bool> isExit_ { false };
54     AVScreenCaptureConfig config_;
55 };
56 } // namespace Media
57 } // namespace OHOS
58 #endif