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     sptr<IRemoteObject> CreateSessionInner(const std::string& tag, int32_t type,
41                                            const AppExecFwk::ElementName& elementName) override;
42 
43     int32_t CreateSessionInner(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName,
44                                sptr<IRemoteObject>& session) override;
45 
46     int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) override;
47 
48     int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) override;
49 
50     int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) override;
51 
52     int32_t GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
53                                       std::vector<AVQueueInfo>& avQueueInfos) override;
54 
55     int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId) override;
56 
57     int32_t CreateController(const std::string& sessionId, std::shared_ptr<AVSessionController>& controller);
58 
59     int32_t CreateControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
60 
61     bool IsAudioPlaybackAllowed(const int32_t uid, const int32_t pid) override;
62 
63 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
64     int32_t GetAVCastController(const std::string& sessionId, std::shared_ptr<AVCastController>& castController);
65 
66     int32_t GetAVCastControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
67 #endif
68 
69     int32_t RegisterSessionListener(const sptr<ISessionListener>& listener) override;
70 
71     int32_t RegisterSessionListenerForAllUsers(const sptr<ISessionListener>& listener) override;
72 
73     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override;
74 
75     int32_t SendSystemControlCommand(const AVControlCommand& command) override;
76 
77     int32_t RegisterClientDeathObserver(const sptr<IClientDeath>& observer) override;
78 
79     int32_t CastAudio(const SessionToken& token,
80                       const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
81 
82     int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override;
83 
84     int32_t ProcessCastAudioCommand(const RemoteServiceCommand command, const std::string& input,
85                                     std::string& output) override
86     {
87         return AVSESSION_SUCCESS;
88     }
89 
90 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
91     int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes);
92 
93     int32_t StopCastDiscovery();
94 
95     int32_t SetDiscoverable(const bool enable);
96 
97     int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize);
98 
99     int32_t StopDeviceLogging();
100 
101     int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) override;
102 
103     int32_t StopCast(const SessionToken& sessionToken) override;
104 
105     int32_t checkEnableCast(bool enable) override
106     {
107         return AVSESSION_SUCCESS;
108     }
109 #endif
110 
111     int32_t Close(void) override;
112 
113 private:
114     void UnMarshallingAVQueueInfos(MessageParcel &reply, std::vector<AVQueueInfo>& avQueueInfos);
115     void BufferToAVQueueInfoImg(const char *buffer, std::vector<AVQueueInfo>& avQueueInfos);
116     static inline BrokerDelegator<AVSessionServiceProxy> delegator_;
117     std::mutex createControllerMutex_;
118 };
119 } // namespace OHOS
120 #endif // OHOS_AVSESSION_SERVICE_PROXY_H
121