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