• 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_SERVICE_PROXY_H
17 #define OHOS_AVSESSION_SERVICE_PROXY_H
18 
19 #include "iavsession_service.h"
20 #include "iremote_proxy.h"
21 #include "av_session.h"
22 #include "avsession_controller.h"
23 #include "avsession_errors.h"
24 
25 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
26 #include "avcast_controller.h"
27 #endif
28 
29 namespace OHOS::AVSession {
30 class AVSessionServiceProxy : public IRemoteProxy<IAVSessionService> {
31 public:
32     explicit AVSessionServiceProxy(const sptr<IRemoteObject>& impl);
33 
34     std::shared_ptr<AVSession> CreateSession(const std::string& tag, int32_t type,
35                                              const AppExecFwk::ElementName& elementName);
36 
37     int32_t CreateSession(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName,
38                           std::shared_ptr<AVSession>& session);
39 
40     int32_t CreateSessionWithExtra(const std::string& tag, int32_t type, const std::string& extraInfo,
41                                    const AppExecFwk::ElementName& elementName, std::shared_ptr<AVSession>& session);
42 
43     sptr<IRemoteObject> CreateSessionInner(const std::string& tag, int32_t type,
44                                            const AppExecFwk::ElementName& elementName) override;
45 
46     int32_t CreateSessionInner(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName,
47                                sptr<IRemoteObject>& session) override;
48 
49     int32_t CreateSessionInnerWithExtra(const std::string& tag, int32_t type, const std::string& extraInfo,
50                                         const AppExecFwk::ElementName& elementName,
51                                         sptr<IRemoteObject>& session) override;
52 
53     int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) override;
54 
55     int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) override;
56 
57     int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) override;
58 
59     int32_t GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
60                                       std::vector<AVQueueInfo>& avQueueInfos) override;
61 
62     int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId) override;
63 
64     int32_t CreateController(const std::string& sessionId, std::shared_ptr<AVSessionController>& controller);
65 
66     int32_t CreateControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
67 
68 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
69     int32_t GetAVCastController(const std::string& sessionId, std::shared_ptr<AVCastController>& castController);
70 
71     int32_t GetAVCastControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
72 #endif
73 
74     int32_t RegisterSessionListener(const sptr<ISessionListener>& listener) override;
75 
76     int32_t RegisterSessionListenerForAllUsers(const sptr<ISessionListener>& listener) override;
77 
78     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override;
79 
80     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent, const AAFwk::Want &wantParam) override;
81 
82     int32_t SendSystemControlCommand(const AVControlCommand& command) override;
83 
84     int32_t RegisterClientDeathObserver(const sptr<IClientDeath>& observer) override;
85 
86     int32_t CastAudio(const SessionToken& token,
87                       const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
88 
89     int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
90 
ProcessCastAudioCommand(const RemoteServiceCommand command,const std::string & input,std::string & output)91     int32_t ProcessCastAudioCommand(const RemoteServiceCommand command, const std::string& input,
92                                     std::string& output) override
93     {
94         return AVSESSION_SUCCESS;
95     }
96 
97 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
98     int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes);
99 
100     int32_t StopCastDiscovery();
101 
102     int32_t SetDiscoverable(const bool enable);
103 
104     int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize);
105 
106     int32_t StopDeviceLogging();
107 
108     int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) override;
109 
110     int32_t StopCast(const SessionToken& sessionToken) override;
111 
checkEnableCast(bool enable)112     int32_t checkEnableCast(bool enable) override
113     {
114         return AVSESSION_SUCCESS;
115     }
116 #endif
117 
118     int32_t Close(void) override;
119 
120     int32_t GetDistributedSessionControllers(const DistributedSessionType& sessionType,
121         std::vector<std::shared_ptr<AVSessionController>>& sessionControllers);
122 
123     int32_t GetDistributedSessionControllersInner(const DistributedSessionType& sessionType,
124         std::vector<sptr<IRemoteObject>>& sessionControllers) override;
125 
126 private:
127     void UnMarshallingAVQueueInfos(MessageParcel &reply, std::vector<AVQueueInfo>& avQueueInfos);
128     void BufferToAVQueueInfoImg(const char *buffer, std::vector<AVQueueInfo>& avQueueInfos);
129     static inline BrokerDelegator<AVSessionServiceProxy> delegator_;
130     std::mutex createControllerMutex_;
131 };
132 } // namespace OHOS
133 #endif // OHOS_AVSESSION_SERVICE_PROXY_H
134