• 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 
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 
CreateScreenCapture(OHOS::AudioStandard::AppInfo & appInfo)56 bool TestScreenCapture::CreateScreenCapture(OHOS::AudioStandard::AppInfo& appInfo)
57 {
58     screenCapture = ScreenCaptureFactory::CreateScreenCapture(appInfo);
59     if (screenCapture == nullptr) {
60         return false;
61     }
62     return true;
63 }
64 
SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack> & callback)65 int32_t TestScreenCapture::SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack>& callback)
66 {
67     if (screenCapture == nullptr) {
68         return MSERR_INVALID_OPERATION;
69     }
70     return screenCapture->SetScreenCaptureCallback(callback);
71 }
72 
Init(AVScreenCaptureConfig config)73 int32_t TestScreenCapture::Init(AVScreenCaptureConfig config)
74 {
75     if (screenCapture == nullptr) {
76         return MSERR_INVALID_OPERATION;
77     }
78     return screenCapture->Init(config);
79 }
80 
StartScreenCapture()81 int32_t TestScreenCapture::StartScreenCapture()
82 {
83     if (screenCapture == nullptr) {
84         return MSERR_INVALID_OPERATION;
85     }
86     return screenCapture->StartScreenCapture();
87 }
88 
StopScreenCapture()89 int32_t TestScreenCapture::StopScreenCapture()
90 {
91     if (screenCapture == nullptr) {
92         return MSERR_INVALID_OPERATION;
93     }
94     return screenCapture->StopScreenCapture();
95 }
96 
Release()97 int32_t TestScreenCapture::Release()
98 {
99     if (screenCapture == nullptr) {
100         return MSERR_INVALID_OPERATION;
101     }
102     screenCapture->Release();
103     screenCapture = nullptr;
104     return MSERR_OK;
105 }
106 
SetMicrophoneEnabled(bool isMicrophone)107 int32_t TestScreenCapture::SetMicrophoneEnabled(bool isMicrophone)
108 {
109     if (screenCapture == nullptr) {
110         return MSERR_INVALID_OPERATION;
111     }
112     return screenCapture->SetMicrophoneEnabled(isMicrophone);
113 }
114 
ResizeCanvas(int32_t width,int32_t height)115 int32_t TestScreenCapture::ResizeCanvas(int32_t width, int32_t height)
116 {
117     if (screenCapture == nullptr) {
118         return MSERR_INVALID_OPERATION;
119     }
120     return screenCapture->ResizeCanvas(width, height);
121 }
122 
UpdateSurface(sptr<Surface> surface)123 int32_t TestScreenCapture::UpdateSurface(sptr<Surface> surface)
124 {
125     if (screenCapture == nullptr) {
126         return MSERR_INVALID_OPERATION;
127     }
128     return screenCapture->UpdateSurface(surface);
129 }
130 
SkipPrivacyMode(std::vector<uint64_t> & windowIDsVec)131 int32_t TestScreenCapture::SkipPrivacyMode(std::vector<uint64_t> &windowIDsVec)
132 {
133     if (screenCapture == nullptr) {
134         return MSERR_INVALID_OPERATION;
135     }
136     return screenCapture->SkipPrivacyMode(windowIDsVec);
137 }
138 
SetMaxFrameRate(int32_t frameRate)139 int32_t TestScreenCapture::SetMaxFrameRate(int32_t frameRate)
140 {
141     if (screenCapture == nullptr) {
142         return MSERR_INVALID_OPERATION;
143     }
144     return screenCapture->SetMaxVideoFrameRate(frameRate);
145 }
146 
SetCanvasRotation(bool canvasRotation)147 int32_t TestScreenCapture::SetCanvasRotation(bool canvasRotation)
148 {
149     if (screenCapture == nullptr) {
150         return MSERR_INVALID_OPERATION;
151     }
152     return screenCapture->SetCanvasRotation(canvasRotation);
153 }
154 
ShowCursor(bool showCursor)155 int32_t TestScreenCapture::ShowCursor(bool showCursor)
156 {
157     if (screenCapture == nullptr) {
158         return MSERR_INVALID_OPERATION;
159     }
160     return screenCapture->ShowCursor(showCursor);
161 }
162 
AcquireAudioBuffer(std::shared_ptr<AudioBuffer> & audioBuffer,AudioCaptureSourceType type)163 int32_t TestScreenCapture::AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type)
164 {
165     if (screenCapture == nullptr) {
166         return MSERR_INVALID_OPERATION;
167     }
168     return screenCapture->AcquireAudioBuffer(audioBuffer, type);
169 }
170 
AcquireVideoBuffer(int32_t & fence,int64_t & timestamp,Rect & damage)171 sptr<OHOS::SurfaceBuffer> TestScreenCapture::AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, Rect &damage)
172 {
173     if (screenCapture == nullptr) {
174         cout << "error! screenCapture == nullptr!" << endl;
175         return nullptr;
176     }
177     return screenCapture->AcquireVideoBuffer(fence, timestamp, damage);
178 }
179 
ReleaseAudioBuffer(AudioCaptureSourceType type)180 int32_t TestScreenCapture::ReleaseAudioBuffer(AudioCaptureSourceType type)
181 {
182     if (screenCapture == nullptr) {
183         return MSERR_INVALID_OPERATION;
184     }
185     return screenCapture->ReleaseAudioBuffer(type);
186 }
187 
ReleaseVideoBuffer()188 int32_t TestScreenCapture::ReleaseVideoBuffer()
189 {
190     if (screenCapture == nullptr) {
191         return MSERR_INVALID_OPERATION;
192     }
193     return screenCapture->ReleaseVideoBuffer();
194 }
195