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 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 62 int32_t GetAVCastController(const std::string& sessionId, std::shared_ptr<AVCastController>& castController); 63 64 int32_t GetAVCastControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override; 65 #endif 66 67 int32_t RegisterSessionListener(const sptr<ISessionListener>& listener) override; 68 69 int32_t RegisterSessionListenerForAllUsers(const sptr<ISessionListener>& listener) override; 70 71 int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override; 72 73 int32_t SendSystemControlCommand(const AVControlCommand& command) override; 74 75 int32_t RegisterClientDeathObserver(const sptr<IClientDeath>& observer) override; 76 77 int32_t CastAudio(const SessionToken& token, 78 const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override; 79 80 int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) override; 81 ProcessCastAudioCommand(const RemoteServiceCommand command,const std::string & input,std::string & output)82 int32_t ProcessCastAudioCommand(const RemoteServiceCommand command, const std::string& input, 83 std::string& output) override 84 { 85 return AVSESSION_SUCCESS; 86 } 87 88 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 89 int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes); 90 91 int32_t StopCastDiscovery(); 92 93 int32_t SetDiscoverable(const bool enable); 94 95 int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize); 96 97 int32_t StopDeviceLogging(); 98 99 int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) override; 100 101 int32_t StopCast(const SessionToken& sessionToken) override; 102 checkEnableCast(bool enable)103 int32_t checkEnableCast(bool enable) override 104 { 105 return AVSESSION_SUCCESS; 106 } 107 #endif 108 109 int32_t Close(void) override; 110 111 private: 112 void UnMarshallingAVQueueInfos(MessageParcel &reply, std::vector<AVQueueInfo>& avQueueInfos); 113 void BufferToAVQueueInfoImg(const char *buffer, std::vector<AVQueueInfo>& avQueueInfos); 114 static inline BrokerDelegator<AVSessionServiceProxy> delegator_; 115 std::mutex createControllerMutex_; 116 }; 117 } // namespace OHOS 118 #endif // OHOS_AVSESSION_SERVICE_PROXY_H 119