180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef HW_CAST_PROVIDER_H 1780922886Sopenharmony_ci#define HW_CAST_PROVIDER_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <mutex> 2080922886Sopenharmony_ci#include "cast_session_manager.h" 2180922886Sopenharmony_ci#include "i_avcast_controller_proxy.h" 2280922886Sopenharmony_ci#include "i_cast_session.h" 2380922886Sopenharmony_ci#include "i_stream_player.h" 2480922886Sopenharmony_ci#include "i_cast_session_manager_listener.h" 2580922886Sopenharmony_ci#include "hw_cast_provider_session.h" 2680922886Sopenharmony_ci#include "avsession_info.h" 2780922886Sopenharmony_ci#include "av_cast_provider.h" 2880922886Sopenharmony_ci 2980922886Sopenharmony_cinamespace OHOS::AVSession { 3080922886Sopenharmony_ciclass HwCastProvider : public AVCastProvider, public CastEngine::ICastSessionManagerListener, 3180922886Sopenharmony_ci public std::enable_shared_from_this<HwCastProvider> { 3280922886Sopenharmony_cipublic: 3380922886Sopenharmony_ci HwCastProvider() = default; 3480922886Sopenharmony_ci ~HwCastProvider() override; 3580922886Sopenharmony_ci 3680922886Sopenharmony_ci void Init() override; 3780922886Sopenharmony_ci int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) override; 3880922886Sopenharmony_ci int32_t StopDeviceLogging() override; 3980922886Sopenharmony_ci bool StartDiscovery(int castCapability, std::vector<std::string> drmSchemes) override; 4080922886Sopenharmony_ci void StopDiscovery() override; 4180922886Sopenharmony_ci int32_t SetDiscoverable(const bool enable) override; 4280922886Sopenharmony_ci void Release() override; 4380922886Sopenharmony_ci int StartCastSession() override; 4480922886Sopenharmony_ci void StopCastSession(int castId) override; 4580922886Sopenharmony_ci bool AddCastDevice(int castId, DeviceInfo deviceInfo) override; 4680922886Sopenharmony_ci bool RemoveCastDevice(int castId, DeviceInfo deviceInfo) override; 4780922886Sopenharmony_ci std::shared_ptr<IAVCastControllerProxy> GetRemoteController(int castId) override; 4880922886Sopenharmony_ci bool RegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) override; 4980922886Sopenharmony_ci bool UnRegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) override; 5080922886Sopenharmony_ci bool RegisterCastSessionStateListener(int castId, std::shared_ptr<IAVCastSessionStateListener> listener) override; 5180922886Sopenharmony_ci bool UnRegisterCastSessionStateListener(int castId, std::shared_ptr<IAVCastSessionStateListener> listener) override; 5280922886Sopenharmony_ci 5380922886Sopenharmony_ci void OnDeviceFound(const std::vector<CastEngine::CastRemoteDevice> &deviceList) override; 5480922886Sopenharmony_ci void OnLogEvent(const int32_t eventId, const int64_t param) override; 5580922886Sopenharmony_ci void OnDeviceOffline(const std::string &deviceId) override; 5680922886Sopenharmony_ci void OnSessionCreated(const std::shared_ptr<CastEngine::ICastSession> &castSession) override; 5780922886Sopenharmony_ci void OnServiceDied() override; 5880922886Sopenharmony_ci bool SetStreamState(int32_t castId, DeviceInfo deviceInfo) override; 5980922886Sopenharmony_ci int GetMirrorCastId() override; 6080922886Sopenharmony_ci bool GetRemoteNetWorkId(int32_t castId, std::string deviceId, std::string &networkId) override; 6180922886Sopenharmony_ci 6280922886Sopenharmony_ciprivate: 6380922886Sopenharmony_ci static const int maxCastSessionSize = 256; 6480922886Sopenharmony_ci std::vector<bool> castFlag_ = std::vector<bool>(maxCastSessionSize, false); 6580922886Sopenharmony_ci std::map<int, std::shared_ptr<HwCastProviderSession>> hwCastProviderSessionMap_; 6680922886Sopenharmony_ci std::map<int, std::shared_ptr<IAVCastControllerProxy>> avCastControllerMap_; 6780922886Sopenharmony_ci std::vector<std::shared_ptr<IAVCastStateListener>> castStateListenerList_; 6880922886Sopenharmony_ci std::recursive_mutex mutexLock_; 6980922886Sopenharmony_ci bool isRelease_ = false; 7080922886Sopenharmony_ci int mirrorCastId = -1; 7180922886Sopenharmony_ci 7280922886Sopenharmony_ci const int32_t deviceStateConnection = 4; 7380922886Sopenharmony_ci std::map<CastEngine::CapabilityType, int32_t> castPlusTypeToAVSessionType_ = { 7480922886Sopenharmony_ci {CastEngine::CapabilityType::CAST_PLUS, ProtocolType::TYPE_CAST_PLUS_STREAM}, 7580922886Sopenharmony_ci {CastEngine::CapabilityType::DLNA, ProtocolType::TYPE_DLNA}, 7680922886Sopenharmony_ci {CastEngine::CapabilityType::CAST_AND_DLNA, ProtocolType::TYPE_CAST_PLUS_STREAM | ProtocolType::TYPE_DLNA} 7780922886Sopenharmony_ci }; 7880922886Sopenharmony_ci}; 7980922886Sopenharmony_ci} // namespace OHOS::AVSession 8080922886Sopenharmony_ci 8180922886Sopenharmony_ci#endif