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