• 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_MOCK_H
16 #define SCREEN_CAPTURE_MOCK_H
17 
18 #include <fcntl.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <securec.h>
22 #include <string>
23 #include <thread>
24 #include <cstdio>
25 #include "gtest/gtest.h"
26 #include "screen_capture.h"
27 #include "unittest_log.h"
28 #include "media_errors.h"
29 #include "display_manager.h"
30 
31 namespace OHOS {
32 namespace Media {
33 namespace ScreenCaptureTestParam {
34     constexpr uint32_t RECORDER_TIME = 3;
35 } // namespace ScreenCaptureTestParam
36 
37 class ScreenCaptureCallBackMock : public NoCopyable {
38 public:
39     virtual void OnError(int32_t errorCode) = 0;
40     virtual void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) = 0;
41     virtual void OnVideoBufferAvailable(bool isReady) = 0;
42 };
43 
44 class ScreenCaptureMock {
45 public:
46     virtual ~ScreenCaptureMock() = default;
47     virtual int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBackMock>& callback) = 0;
48     virtual int32_t Init(AVScreenCaptureConfig config) = 0;
49     virtual int32_t StartScreenCapture() = 0;
50     virtual int32_t StopScreenCapture() = 0;
51     virtual int32_t Release() = 0;
52     virtual int32_t SetMicrophoneEnabled(bool isMicrophone) = 0;
53     virtual int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type) = 0;
54     virtual sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, OHOS::Rect &damage) = 0;
55     virtual int32_t ReleaseAudioBuffer(AudioCaptureSourceType type) = 0;
56     virtual int32_t ReleaseVideoBuffer() = 0;
57 };
58 
59 class __attribute__((visibility("default"))) ScreenCaptureMockFactory {
60 public:
61     static std::shared_ptr<ScreenCaptureMock> CreateScreenCapture();
62 private:
63     ScreenCaptureMockFactory() = delete;
64     ~ScreenCaptureMockFactory() = delete;
65 };
66 } // namespace Media
67 } // namespace OHOS
68 #endif