1 /*
2  * Copyright (c) 2022-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 OHOS_AVSESSION_PROXY_H
17 #define OHOS_AVSESSION_PROXY_H
18 
19 #include <mutex>
20 
21 #include "iav_session.h"
22 #include "iremote_proxy.h"
23 #include "want_agent.h"
24 #include "avcall_meta_data.h"
25 #include "avcall_state.h"
26 #include "avsession_log.h"
27 #include "avsession_errors.h"
28 #include "avmeta_data.h"
29 #include "avplayback_state.h"
30 #include "avmedia_description.h"
31 #include "avqueue_item.h"
32 #include "ipc_skeleton.h"
33 
34 namespace OHOS::AVSession {
35 class AVSessionProxy : public IRemoteProxy<IAVSession> {
36 public:
37     explicit AVSessionProxy(const sptr<IRemoteObject>& impl);
38 
39     ~AVSessionProxy() override;
40 
41     std::string GetSessionId() override;
42 
43     std::string GetSessionType() override;
44 
45     int32_t SetAVCallMetaData(const AVCallMetaData& avCallMetaData) override;
46 
47     int32_t SetAVCallState(const AVCallState& avCallState) override;
48 
49     int32_t GetAVMetaData(AVMetaData& meta) override;
50 
51     int32_t SetAVMetaData(const AVMetaData& meta) override;
52 
53     int32_t GetAVPlaybackState(AVPlaybackState& state) override;
54 
55     int32_t SetAVPlaybackState(const AVPlaybackState& state) override;
56 
57     int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) override;
58 
59     int32_t SetAVQueueItems(const std::vector<AVQueueItem>& items) override;
60 
61     int32_t GetAVQueueTitle(std::string& title) override;
62 
63     int32_t SetAVQueueTitle(const std::string& title) override;
64 
65     int32_t SetLaunchAbility(const AbilityRuntime::WantAgent::WantAgent& ability) override;
66 
67     int32_t GetExtras(AAFwk::WantParams& extras) override;
68 
69     int32_t SetExtras(const AAFwk::WantParams& extras) override;
70 
71     std::shared_ptr<AVSessionController> GetController() override;
72 
73 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
74     std::shared_ptr<AVCastController> GetAVCastController() override;
75 
76     int32_t StartCastDisplayListener() override;
77 
78     int32_t StopCastDisplayListener() override;
79 
80     int32_t GetAllCastDisplays(std::vector<CastDisplayInfo>& castDisplays) override;
81 #endif
82 
83     int32_t RegisterCallback(const std::shared_ptr<AVSessionCallback>& callback) override;
84 
85     int32_t Activate() override;
86 
87     int32_t Deactivate() override;
88 
89     bool IsActive() override;
90 
91     int32_t Destroy() override;
92 
93     int32_t AddSupportCommand(const int32_t cmd) override;
94 
95     int32_t DeleteSupportCommand(const int32_t cmd) override;
96 
97     int32_t SetSessionEvent(const std::string& event, const AAFwk::WantParams& args) override;
98 
99 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
100     int32_t ReleaseCast() override;
101 #endif
102 
103 protected:
104     int32_t RegisterCallbackInner(const sptr<IAVSessionCallback>& callback) override;
105     sptr<IRemoteObject> GetControllerInner() override;
106 
107 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
108     sptr<IRemoteObject> GetAVCastControllerInner() override;
109 #endif
110 
111 private:
112     int32_t GetPixelMapBuffer(AVMetaData& metaData, MessageParcel& data);
113     sptr<IAVSessionCallback> callback_;
114     static inline BrokerDelegator<AVSessionProxy> delegator_;
115     bool isDestroyed_ = {};
116     std::shared_ptr<AVSessionController> controller_;
117     const size_t defaultIpcCapacity = 1048576; // Increase the IPC default capacity(200K) to 1M
118     std::mutex setMetadataLock_;
119     std::mutex setPlaybackLock_;
120     std::mutex setCommandLock_;
121     std::mutex isDestroyedLock_;
122 
123 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
124     std::shared_ptr<AVCastController> castController_;
125 #endif
126 };
127 }
128 #endif // OHOS_AVSESSION_PROXY_H