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 ScreenCaptureNativeCallbackMock; 23 class ScreenCaptureNativeMock : public ScreenCaptureMock { 24 public: ScreenCaptureNativeMock(std::shared_ptr<ScreenCapture> screencapture)25 explicit ScreenCaptureNativeMock(std::shared_ptr<ScreenCapture> screencapture) : screenCapture_(screencapture) {} 26 ~ScreenCaptureNativeMock(); 27 int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBackMock>& callback, 28 const bool isErrorCallBackEnabled, const bool isDataCallBackEnabled, 29 const bool isStateChangeCallBackEnabled) override; 30 int32_t Init(AVScreenCaptureConfig config) override; 31 int32_t StartScreenCapture() override; 32 int32_t StartScreenCaptureWithSurface(const std::any& value) override; 33 int32_t StopScreenCapture() override; 34 int32_t StartScreenRecording() override; 35 int32_t StopScreenRecording() override; 36 int32_t Release() override; 37 int32_t SetMicrophoneEnabled(bool isMicrophone) override; 38 int32_t SetCanvasRotation(bool canvasRotation) override; 39 int32_t ResizeCanvas(int32_t width, int32_t height) override; 40 int32_t SkipPrivacyMode(int32_t *windowIDs, int32_t windowCount) override; 41 int32_t SetMaxVideoFrameRate(int32_t frameRate) override; 42 int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type) override; 43 sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t ×tamp, OHOS::Rect &damage) override; 44 int32_t ReleaseAudioBuffer(AudioCaptureSourceType type) override; 45 int32_t ReleaseVideoBuffer() override; 46 int32_t ExcludeWindowContent(int32_t *windowIDs, int32_t windowCount) override; 47 int32_t ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType) override; IsStateChangeCallBackEnabled()48 bool IsStateChangeCallBackEnabled() override 49 { 50 return isStateChangeCallBackEnabled_; 51 } 52 private: 53 std::shared_ptr<ScreenCapture> screenCapture_ = nullptr; 54 std::shared_ptr<ScreenCaptureCallBack> cb_; 55 bool isStateChangeCallBackEnabled_ = false; 56 }; 57 58 class ScreenCaptureNativeCallbackMock : public ScreenCaptureCallBack, public NoCopyable { 59 public: ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallBackMock> cb,std::weak_ptr<ScreenCapture> vd)60 ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallBackMock> cb, 61 std::weak_ptr<ScreenCapture> vd) : mockCb_(cb), screenCapture_(vd) {} ~ScreenCaptureNativeCallbackMock()62 ~ScreenCaptureNativeCallbackMock() 63 { 64 mockCb_ = nullptr; 65 } 66 void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override; 67 void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override; 68 void OnVideoBufferAvailable(bool isReady) override; 69 void OnStateChange(AVScreenCaptureStateCode stateCode) override; 70 void OnRelease(); 71 72 private: 73 std::shared_ptr<ScreenCaptureCallBackMock> mockCb_ = nullptr; 74 std::weak_ptr<ScreenCapture> screenCapture_; 75 std::mutex mutex_; 76 }; 77 } // namespace Media 78 } // namespace OHOS 79 #endif