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_LISTENER_PROXY_H
17 #define SCREEN_CAPTURE_LISTENER_PROXY_H
18 
19 #include "i_standard_screen_capture_listener.h"
20 #include "media_death_recipient.h"
21 #include "screen_capture.h"
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class ScreenCaptureListenerCallback : public ScreenCaptureCallBack, public NoCopyable {
27 public:
28     explicit ScreenCaptureListenerCallback(const sptr<IStandardScreenCaptureListener> &listener);
29     virtual ~ScreenCaptureListenerCallback();
30 
31     void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override;
32     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override;
33     void OnVideoBufferAvailable(bool isReady) override;
34     void OnStateChange(AVScreenCaptureStateCode stateCode) override;
Stop()35     void Stop()
36     {
37         isStopped_ = true;
38     }
39 
40 private:
41     sptr<IStandardScreenCaptureListener> listener_ = nullptr;
42     std::atomic<bool> isStopped_ = false;
43 };
44 
45 class ScreenCaptureListenerProxy : public IRemoteProxy<IStandardScreenCaptureListener>, public NoCopyable {
46 public:
47     explicit ScreenCaptureListenerProxy(const sptr<IRemoteObject> &impl);
48     virtual ~ScreenCaptureListenerProxy();
49 
50     void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override;
51     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override;
52     void OnVideoBufferAvailable(bool isReady) override;
53     void OnStateChange(AVScreenCaptureStateCode stateCode) override;
54 
55 private:
56     static inline BrokerDelegator<ScreenCaptureListenerProxy> delegator_;
57 };
58 } // namespace Media
59 } // namespace OHOS
60 #endif // SCREEN_CAPTURE_LISTENER_PROXY_H