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 #ifndef TEST_SCREEN_CAPTURE_H 17 #define TEST_SCREEN_CAPTURE_H 18 19 #include <fcntl.h> 20 #include <thread> 21 #include <cstdio> 22 #include <iostream> 23 #include "nativetoken_kit.h" 24 #include "accesstoken_kit.h" 25 #include "token_setproc.h" 26 #include "screen_capture.h" 27 #include "aw_common.h" 28 #include "media_errors.h" 29 30 namespace OHOS { 31 namespace Media { 32 #define RETURN_IF(cond, ret, ...) \ 33 do { \ 34 if (!(cond)) { \ 35 return ret; \ 36 } \ 37 } while (0) 38 39 class TestScreenCapture : public NoCopyable { 40 public: 41 TestScreenCapture(); 42 ~TestScreenCapture(); 43 std::shared_ptr<ScreenCapture> screenCapture = nullptr; 44 bool CreateScreenCapture(); 45 int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack>& callback); 46 int32_t Init(AVScreenCaptureConfig config); 47 int32_t StartScreenCapture(); 48 int32_t StopScreenCapture(); 49 int32_t Release(); 50 int32_t SetMicrophoneEnabled(bool isMicrophone); 51 int32_t SetCanvasRotation(bool canvasRotation); 52 int32_t ResizeCanvas(int32_t width, int32_t height); 53 int32_t SkipPrivacyMode(std::vector<uint64_t> &windowIDsVec); 54 int32_t SetMaxFrameRate(int32_t frameRate); 55 int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type); 56 sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t ×tamp, Rect &damage); 57 int32_t ReleaseAudioBuffer(AudioCaptureSourceType type); 58 int32_t ReleaseVideoBuffer(); 59 }; 60 61 class TestScreenCaptureCallbackTest : public ScreenCaptureCallBack, public NoCopyable { 62 public: TestScreenCaptureCallbackTest()63 TestScreenCaptureCallbackTest() {} 64 ~TestScreenCaptureCallbackTest() = default; 65 std::shared_ptr<TestScreenCapture> screenCapture; 66 void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override; 67 void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override; 68 void OnVideoBufferAvailable(bool isReady) override; 69 }; 70 } // namespace Media 71 } // namespace OHOS 72 #endif 73