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