• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SendCustomData(const AAFwk::WantParams& data) override;
66 
67     int32_t SetLaunchAbility(const AbilityRuntime::WantAgent::WantAgent& ability) override;
68 
69     int32_t GetExtras(AAFwk::WantParams& extras) override;
70 
71     int32_t SetExtras(const AAFwk::WantParams& extras) override;
72 
73     std::shared_ptr<AVSessionController> GetController() override;
74 
75 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
76     std::shared_ptr<AVCastController> GetAVCastController() override;
77 
78     int32_t StartCastDisplayListener() override;
79 
80     int32_t StopCastDisplayListener() override;
81 
82     int32_t GetAllCastDisplays(std::vector<CastDisplayInfo>& castDisplays) override;
83 #endif
84 
85     int32_t RegisterCallback(const std::shared_ptr<AVSessionCallback>& callback) override;
86 
87     int32_t Activate() override;
88 
89     int32_t Deactivate() override;
90 
91     bool IsActive() override;
92 
93     int32_t Destroy() override;
94 
95     int32_t AddSupportCommand(const int32_t cmd) override;
96 
97     int32_t DeleteSupportCommand(const int32_t cmd) override;
98 
99     int32_t SetSessionEvent(const std::string& event, const AAFwk::WantParams& args) override;
100 
101     int32_t UpdateAVQueueInfo(const AVQueueInfo& info) override;
102 
103 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
104     int32_t ReleaseCast(bool continuePlay = false) override;
105 #endif
106 
107 protected:
108     int32_t RegisterCallbackInner(const sptr<IAVSessionCallback>& callback) override;
109     sptr<IRemoteObject> GetControllerInner() override;
110 
111 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
112     sptr<IRemoteObject> GetAVCastControllerInner() override;
113 #endif
114 
115 private:
116     sptr<IAVSessionCallback> callback_;
117     static inline BrokerDelegator<AVSessionProxy> delegator_;
118     bool isDestroyed_ = {};
119     std::shared_ptr<AVSessionController> controller_;
120     const size_t defaultIpcCapacity = 1048576; // Increase the IPC default capacity(200K) to 1M
121     std::mutex setMetadataLock_;
122     std::mutex setPlaybackLock_;
123     std::mutex setCommandLock_;
124     std::mutex isDestroyedLock_;
125 
126 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
127     std::shared_ptr<AVCastController> castController_;
128 #endif
129 };
130 }
131 #endif // OHOS_AVSESSION_PROXY_H