1 /* 2 * Copyright (c) 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 #include "avcast_provider_manager.h" 17 #include "av_router.h" 18 #include "avsession_log.h" 19 namespace OHOS::AVSession { AVCastProviderManager()20AVCastProviderManager::AVCastProviderManager() 21 { 22 SLOGD("AVCastProviderManager construct"); 23 } 24 Init(int32_t providerId,std::shared_ptr<AVCastProvider> provider)25void AVCastProviderManager::Init(int32_t providerId, std::shared_ptr<AVCastProvider> provider) 26 { 27 providerId_ = providerId; 28 provider_ = provider; 29 } 30 OnDeviceAvailable(std::vector<DeviceInfo> deviceInfos)31void AVCastProviderManager::OnDeviceAvailable(std::vector<DeviceInfo> deviceInfos) 32 { 33 SLOGI("On device available"); 34 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 35 for (size_t i = 0; i < deviceInfos.size(); i++) { 36 deviceInfos[i].providerId_ = providerId_; 37 } 38 OutputDeviceInfo outputDeviceInfo; 39 outputDeviceInfo.deviceInfos_ = deviceInfos; 40 AVRouter::GetInstance().OnDeviceAvailable(outputDeviceInfo); 41 #endif 42 } 43 OnSessionNeedDestroy()44void AVCastProviderManager::OnSessionNeedDestroy() 45 { 46 SLOGI("On cast session need destroy"); 47 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 48 AVRouter::GetInstance().ReleaseCurrentCastSession(); 49 #endif 50 } 51 OnSessionCreated(const int32_t castId)52void AVCastProviderManager::OnSessionCreated(const int32_t castId) 53 { 54 SLOGI("On cast session created"); 55 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 56 AVRouter::GetInstance().OnCastSessionCreated(castId); 57 #endif 58 } 59 OnDeviceOffline(const std::string & deviceId)60void AVCastProviderManager::OnDeviceOffline(const std::string& deviceId) 61 { 62 SLOGI("On device offline"); 63 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 64 AVRouter::GetInstance().OnDeviceOffline(deviceId); 65 #endif 66 } 67 OnCastServerDied()68void AVCastProviderManager::OnCastServerDied() 69 { 70 SLOGI("On cast server died"); 71 #ifdef CASTPLUS_CAST_ENGINE_ENABLE 72 AVRouter::GetInstance().OnCastServerDied(providerId_); 73 #endif 74 } 75 } // namespace OHOS::AVSession 76