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 SCREEN_CAPTURE_ADAPTER_IMPL_H
17 #define SCREEN_CAPTURE_ADAPTER_IMPL_H
18 
19 #include "screen_capture.h"
20 #include "screen_capture_adapter.h"
21 
22 namespace OHOS::NWeb {
23 class OHScreenCaptureCallback : public OHOS::Media::ScreenCaptureCallBack {
24 public:
OHScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackAdapter> & callback)25     OHScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackAdapter>& callback) : callback_(callback) {}
26     virtual ~OHScreenCaptureCallback() = default;
27 
28     void OnError(OHOS::Media::ScreenCaptureErrorType errorType, int32_t errorCode) override;
29 
30     void OnAudioBufferAvailable(bool isReady, OHOS::Media::AudioCaptureSourceType type) override;
31 
32     void OnVideoBufferAvailable(bool isReady) override;
33 
34     void OnStateChange(OHOS::Media::AVScreenCaptureStateCode stateCode) override;
35 
36 private:
37     std::shared_ptr<ScreenCaptureCallbackAdapter> callback_;
38 };
39 
40 class ScreenCaptureAdapterImpl : public ScreenCaptureAdapter {
41 public:
42     ScreenCaptureAdapterImpl() = default;
43     ~ScreenCaptureAdapterImpl() override;
44 
45     int32_t Init(const std::shared_ptr<ScreenCaptureConfigAdapter> config) override;
46 
47     int32_t SetMicrophoneEnable(bool enable) override;
48 
49     int32_t StartCapture() override;
50 
51     int32_t StopCapture() override;
52 
53     int32_t SetCaptureCallback(const std::shared_ptr<ScreenCaptureCallbackAdapter> callback) override;
54 
55     std::shared_ptr<SurfaceBufferAdapter> AcquireVideoBuffer() override;
56 
57     int32_t ReleaseVideoBuffer() override;
58 
59 private:
60     void Release();
61 
62 private:
63     std::shared_ptr<Media::ScreenCapture> screenCapture_ = nullptr;
64     std::shared_ptr<Media::ScreenCaptureCallBack> screenCaptureCallback_ = nullptr;
65 };
66 
67 }  // namespace OHOS::NWeb
68 
69 #endif  // SCREEN_CAPTURE_ADAPTER_IMPL_H
70