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 "test_screen_capture.h"
17 #include <sync_fence.h>
18 #include "securec.h"
19
20 using namespace std;
21 using namespace OHOS;
22 using namespace OHOS::Media;
23
OnError(ScreenCaptureErrorType errorType,int32_t errorCode)24 void TestScreenCaptureCallbackTest::OnError(ScreenCaptureErrorType errorType, int32_t errorCode)
25 {
26 cout << "Error received, errorType: " << errorType << " errorCode: " << errorCode << endl;
27 }
28
OnAudioBufferAvailable(bool isReady,AudioCaptureSourceType type)29 void TestScreenCaptureCallbackTest::OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type)
30 {
31 cout << "OnAudioBufferAvailable received: " << isReady << ", AudioCaptureSourceType: " << type << endl;
32 }
33
OnVideoBufferAvailable(bool isReady)34 void TestScreenCaptureCallbackTest::OnVideoBufferAvailable(bool isReady)
35 {
36 cout << "OnVideoBufferAvailable received: " << isReady << endl;
37 }
38
TestScreenCapture()39 TestScreenCapture::TestScreenCapture()
40 {
41 }
42
~TestScreenCapture()43 TestScreenCapture::~TestScreenCapture()
44 {
45 }
46
CreateScreenCapture()47 bool TestScreenCapture::CreateScreenCapture()
48 {
49 screenCapture = ScreenCaptureFactory::CreateScreenCapture();
50 if (screenCapture == nullptr) {
51 return false;
52 }
53 return true;
54 }
55
SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack> & callback)56 int32_t TestScreenCapture::SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack>& callback)
57 {
58 if (screenCapture == nullptr) {
59 return MSERR_INVALID_OPERATION;
60 }
61 return screenCapture->SetScreenCaptureCallback(callback);
62 }
63
Init(AVScreenCaptureConfig config)64 int32_t TestScreenCapture::Init(AVScreenCaptureConfig config)
65 {
66 if (screenCapture == nullptr) {
67 return MSERR_INVALID_OPERATION;
68 }
69 return screenCapture->Init(config);
70 }
71
StartScreenCapture()72 int32_t TestScreenCapture::StartScreenCapture()
73 {
74 if (screenCapture == nullptr) {
75 return MSERR_INVALID_OPERATION;
76 }
77 return screenCapture->StartScreenCapture();
78 }
79
StopScreenCapture()80 int32_t TestScreenCapture::StopScreenCapture()
81 {
82 if (screenCapture == nullptr) {
83 return MSERR_INVALID_OPERATION;
84 }
85 return screenCapture->StopScreenCapture();
86 }
87
Release()88 int32_t TestScreenCapture::Release()
89 {
90 if (screenCapture == nullptr) {
91 return MSERR_INVALID_OPERATION;
92 }
93 screenCapture->Release();
94 screenCapture = nullptr;
95 return MSERR_OK;
96 }
97
SetMicrophoneEnabled(bool isMicrophone)98 int32_t TestScreenCapture::SetMicrophoneEnabled(bool isMicrophone)
99 {
100 if (screenCapture == nullptr) {
101 return MSERR_INVALID_OPERATION;
102 }
103 return screenCapture->SetMicrophoneEnabled(isMicrophone);
104 }
105
ResizeCanvas(int32_t width,int32_t height)106 int32_t TestScreenCapture::ResizeCanvas(int32_t width, int32_t height)
107 {
108 if (screenCapture == nullptr) {
109 return MSERR_INVALID_OPERATION;
110 }
111 return screenCapture->ResizeCanvas(width, height);
112 }
113
SkipPrivacyMode(std::vector<uint64_t> & windowIDsVec)114 int32_t TestScreenCapture::SkipPrivacyMode(std::vector<uint64_t> &windowIDsVec)
115 {
116 if (screenCapture == nullptr) {
117 return MSERR_INVALID_OPERATION;
118 }
119 return screenCapture->SkipPrivacyMode(windowIDsVec);
120 }
121
SetMaxFrameRate(int32_t frameRate)122 int32_t TestScreenCapture::SetMaxFrameRate(int32_t frameRate)
123 {
124 if (screenCapture == nullptr) {
125 return MSERR_INVALID_OPERATION;
126 }
127 return screenCapture->SetMaxVideoFrameRate(frameRate);
128 }
129
SetCanvasRotation(bool canvasRotation)130 int32_t TestScreenCapture::SetCanvasRotation(bool canvasRotation)
131 {
132 if (screenCapture == nullptr) {
133 return MSERR_INVALID_OPERATION;
134 }
135 return screenCapture->SetCanvasRotation(canvasRotation);
136 }
137
AcquireAudioBuffer(std::shared_ptr<AudioBuffer> & audioBuffer,AudioCaptureSourceType type)138 int32_t TestScreenCapture::AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type)
139 {
140 if (screenCapture == nullptr) {
141 return MSERR_INVALID_OPERATION;
142 }
143 return screenCapture->AcquireAudioBuffer(audioBuffer, type);
144 }
145
AcquireVideoBuffer(int32_t & fence,int64_t & timestamp,Rect & damage)146 sptr<OHOS::SurfaceBuffer> TestScreenCapture::AcquireVideoBuffer(int32_t &fence, int64_t ×tamp, Rect &damage)
147 {
148 if (screenCapture == nullptr) {
149 cout << "error! screenCapture == nullptr!" << endl;
150 return nullptr;
151 }
152 return screenCapture->AcquireVideoBuffer(fence, timestamp, damage);
153 }
154
ReleaseAudioBuffer(AudioCaptureSourceType type)155 int32_t TestScreenCapture::ReleaseAudioBuffer(AudioCaptureSourceType type)
156 {
157 if (screenCapture == nullptr) {
158 return MSERR_INVALID_OPERATION;
159 }
160 return screenCapture->ReleaseAudioBuffer(type);
161 }
162
ReleaseVideoBuffer()163 int32_t TestScreenCapture::ReleaseVideoBuffer()
164 {
165 if (screenCapture == nullptr) {
166 return MSERR_INVALID_OPERATION;
167 }
168 return screenCapture->ReleaseVideoBuffer();
169 }
170