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, const bool isCaptureContentChangeCallbackEnabled) 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 UpdateSurface(const std::any& surface) override; 41 int32_t SkipPrivacyMode(int32_t *windowIDs, int32_t windowCount) override; 42 int32_t SetMaxVideoFrameRate(int32_t frameRate) override; 43 int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type) override; 44 sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t ×tamp, OHOS::Rect &damage) override; 45 int32_t ReleaseAudioBuffer(AudioCaptureSourceType type) override; 46 int32_t ReleaseVideoBuffer() override; 47 int32_t ExcludeWindowContent(int32_t *windowIDs, int32_t windowCount) override; 48 int32_t ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType) override; IsStateChangeCallbackEnabled()49 bool IsStateChangeCallbackEnabled() override 50 { 51 return isStateChangeCallbackEnabled_; 52 } IsCaptureContentChangeCallbackEnabled()53 bool IsCaptureContentChangeCallbackEnabled() override 54 { 55 return isCaptureContentChangeCallbackEnabled_; 56 } 57 int32_t CreateCaptureStrategy() override; 58 int32_t StrategyForKeepCaptureDuringCall(bool value) override; 59 int32_t SetCaptureStrategy() override; 60 int32_t ReleaseCaptureStrategy() override; 61 int32_t SetCanvasFollowRotationStrategy(bool value) override; 62 int32_t StrategyForBFramesEncoding(bool value) override; 63 int32_t StrategyForPrivacyMaskMode(int32_t value) override; 64 int32_t StrategyForPickerPopUp(bool value) override; 65 int32_t StrategyForFillMode(AVScreenCaptureFillMode value) override; 66 private: 67 std::shared_ptr<ScreenCapture> screenCapture_ = nullptr; 68 std::shared_ptr<ScreenCaptureCallBack> cb_; 69 bool isStateChangeCallbackEnabled_ = false; 70 bool isCaptureContentChangeCallbackEnabled_ = false; 71 ScreenCaptureStrategy strategy_; 72 }; 73 74 class ScreenCaptureNativeCallbackMock : public ScreenCaptureCallBack, public NoCopyable { 75 public: ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallbackMock> cb,std::weak_ptr<ScreenCapture> vd)76 ScreenCaptureNativeCallbackMock(std::shared_ptr<ScreenCaptureCallbackMock> cb, 77 std::weak_ptr<ScreenCapture> vd) : mockCb_(cb), screenCapture_(vd) {} ~ScreenCaptureNativeCallbackMock()78 ~ScreenCaptureNativeCallbackMock() 79 { 80 mockCb_ = nullptr; 81 } 82 void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override; 83 void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override; 84 void OnVideoBufferAvailable(bool isReady) override; 85 void OnStateChange(AVScreenCaptureStateCode stateCode) override; 86 void OnCaptureContentChanged(AVScreenCaptureContentChangedEvent event, ScreenCaptureRect* area) override; 87 void OnDisplaySelected(uint64_t displayId) override; 88 void OnRelease(); 89 90 private: 91 std::shared_ptr<ScreenCaptureCallbackMock> mockCb_ = nullptr; 92 std::weak_ptr<ScreenCapture> screenCapture_; 93 std::mutex mutex_; 94 }; 95 } // namespace Media 96 } // namespace OHOS 97 #endif