• 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_NATIVE_MOCK_H
16 #define SCREEN_CAPTURE_NATIVE_MOCK_H
17 
18 #include "screen_capture_mock.h"
19 
20 namespace OHOS {
21 namespace Media {
22 class ScreenCaptureNativeMock : public ScreenCaptureMock {
23 public:
ScreenCaptureNativeMock(std::shared_ptr<ScreenCapture> screencapture)24     explicit ScreenCaptureNativeMock(std::shared_ptr<ScreenCapture> screencapture) : screenCapture_(screencapture) {}
25     ~ScreenCaptureNativeMock() = default;
26     int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBackMock>& callback) override;
27     int32_t Init(AVScreenCaptureConfig config) override;
28     int32_t StartScreenCapture() override;
29     int32_t StopScreenCapture() override;
30     int32_t Release() override;
31     int32_t SetMicrophoneEnabled(bool isMicrophone) override;
32     int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type) override;
33     sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, OHOS::Rect &damage) override;
34     int32_t ReleaseAudioBuffer(AudioCaptureSourceType type) override;
35     int32_t ReleaseVideoBuffer() override;
36 
37 private:
38     std::shared_ptr<ScreenCapture> screenCapture_ = nullptr;
39     AVScreenCaptureConfig config_;
40 };
41 
42 class ScreenCaptureNativeCallbackMock : public ScreenCaptureCallBack, public NoCopyable {
43 public:
ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallBackMock> cb,std::weak_ptr<ScreenCapture> vd)44     ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallBackMock> cb,
45         std::weak_ptr<ScreenCapture> vd) : mockCb_(cb), screenCapture_(vd) {}
~ScreenCaptureNativeCallbackMock()46     ~ScreenCaptureNativeCallbackMock()
47     {
48         mockCb_ = nullptr;
49     }
50     void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override;
51     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override;
52     void OnVideoBufferAvailable(bool isReady) override;
53 
54 private:
55     std::shared_ptr<ScreenCaptureCallBackMock> mockCb_ = nullptr;
56     std::weak_ptr<ScreenCapture> screenCapture_;
57 };
58 } // namespace Media
59 } // namespace OHOS
60 #endif