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_CAPI_MOCK_H 16 #define SCREEN_CAPTURE_CAPI_MOCK_H 17 18 #include "native_avscreen_capture.h" 19 #include "screen_capture_mock.h" 20 21 namespace OHOS { 22 namespace Media { 23 class ScreenCaptureCapiMock : public ScreenCaptureMock { 24 public: ScreenCaptureCapiMock(OH_AVScreenCapture * screencapture)25 explicit ScreenCaptureCapiMock(OH_AVScreenCapture* screencapture) : screenCapture_(screencapture) {} 26 ~ScreenCaptureCapiMock() = default; 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, 44 OHOS::Media::AudioCaptureSourceType type) override; 45 sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t ×tamp, OHOS::Rect &damage) override; 46 int32_t ReleaseAudioBuffer(OHOS::Media::AudioCaptureSourceType type) override; 47 int32_t ReleaseVideoBuffer() override; 48 int32_t ExcludeWindowContent(int32_t *windowIDs, int32_t windowCount) override; 49 int32_t ExcludeAudioContent(AVScreenCaptureFilterableAudioContent audioType) override; IsErrorCallbackEnabled()50 bool IsErrorCallbackEnabled() override 51 { 52 return isErrorCallbackEnabled_; 53 } IsDataCallbackEnabled()54 bool IsDataCallbackEnabled() override 55 { 56 return isDataCallbackEnabled_; 57 } IsStateChangeCallbackEnabled()58 bool IsStateChangeCallbackEnabled() override 59 { 60 return isStateChangeCallbackEnabled_; 61 } IsCaptureContentChangeCallbackEnabled()62 bool IsCaptureContentChangeCallbackEnabled() override 63 { 64 return isCaptureContentChangeCallbackEnabled_; 65 } 66 int32_t CreateCaptureStrategy() override; 67 int32_t StrategyForKeepCaptureDuringCall(bool value) override; 68 int32_t SetCaptureStrategy() override; 69 int32_t ReleaseCaptureStrategy() override; 70 int32_t SetCanvasFollowRotationStrategy(bool value) override; 71 int32_t StrategyForBFramesEncoding(bool value) override; 72 int32_t StrategyForPrivacyMaskMode(int32_t value) override; 73 int32_t StrategyForPickerPopUp(bool value) override; 74 int32_t StrategyForFillMode(AVScreenCaptureFillMode value) override; 75 private: 76 static void SetScreenCaptureCallback(OH_AVScreenCapture *screencapture, 77 std::shared_ptr<ScreenCaptureCallbackMock> cb); 78 static std::shared_ptr<ScreenCaptureCallbackMock> GetCallback(OH_AVScreenCapture *screenCapture); 79 static void DelCallback(OH_AVScreenCapture *screenCapture); 80 static void OnError(OH_AVScreenCapture *screenCapture, int32_t errorCode); 81 static void OnAudioBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady, OH_AudioCaptureSourceType type); 82 static void OnVideoBufferAvailable(OH_AVScreenCapture *screenCapture, bool isReady); 83 static void OnErrorNew(OH_AVScreenCapture *screenCapture, int32_t errorCode, void *userData); 84 static void OnBufferAvailable(OH_AVScreenCapture *screenCapture, OH_AVBuffer *buffer, 85 OH_AVScreenCaptureBufferType bufferType, int64_t timestamp, void *userData); 86 static void OnStateChange(struct OH_AVScreenCapture *capture, 87 OH_AVScreenCaptureStateCode stateCode, void *userData); 88 static void OnCaptureContentChanged(struct OH_AVScreenCapture *capture, OH_AVScreenCaptureContentChangedEvent 89 event, OH_Rect* area, void *userData); 90 static void OnDisplaySelected(struct OH_AVScreenCapture *capture, uint64_t displayId, void *userData); 91 OH_AVScreenCaptureConfig Convert(AVScreenCaptureConfig config); 92 93 int32_t GetCaptureContentChangeCallback(const bool isCaptureContentChangeCallbackEnabled); 94 95 static std::mutex mutex_; 96 static std::map<OH_AVScreenCapture *, std::shared_ptr<ScreenCaptureCallbackMock>> mockCbMap_; 97 98 OH_AVScreenCapture* screenCapture_ = nullptr; 99 bool isErrorCallbackEnabled_ = false; 100 bool isDataCallbackEnabled_ = false; 101 bool isStateChangeCallbackEnabled_ = false; 102 bool isCaptureContentChangeCallbackEnabled_ = false; 103 struct OH_AVScreenCapture_ContentFilter *contentFilter_ = nullptr; 104 OH_AVScreenCapture_CaptureStrategy *strategy_ = nullptr; 105 OHNativeWindow* nativeWindow_ = nullptr; 106 }; 107 } // namespace Media 108 } // namespace OHOS 109 #endif