• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_AVROUTER_H
17 #define OHOS_AVROUTER_H
18 
19 #include "avsession_descriptor.h"
20 #include "avsession_info.h"
21 #include "i_avsession_service_listener.h"
22 
23 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
24 #include "i_avcast_controller_proxy.h"
25 #endif
26 
27 /**
28  * @brief Router is a part related to cast media
29  * @since 10
30  */
31 namespace OHOS::AVSession {
32 class AVRouter {
33 public:
34     /**
35      * Get AVRouter instance.
36      *
37      * @return AVRouter instance.
38      * @since 10
39     */
40     static AVRouter& GetInstance();
41 
42     /**
43      * Get AVRouter instance.
44      * @param { AVSessionService* } servicePtr - The pointer of avsession service.
45      * @since 10
46     */
47     virtual void Init(IAVSessionServiceListener *servicePtr) = 0;
48 
49 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
50     /**
51      * @brief Starting to discover devices.
52      *
53      * @param { int32_t } castDeviceCapability - The type of device want to discover.
54      * @return { int32_t } Whether the device discovery operation was successful.
55      * @since 10
56     */
57     virtual int32_t StartCastDiscovery(int32_t castDeviceCapability) = 0;
58 
59     /**
60      * @brief Stop Discovering Devices
61      *
62      * @return { int32_t } Whether the stop operation was successful
63      * @since 10
64     */
65     virtual int32_t StopCastDiscovery() = 0;
66 
67     /**
68      * @brief Used on the Sink end to set whether it can be discovered or not.
69      *
70      * @param { const bool } enable - whether the sink device can be discovered or not.
71      * @return { int32_t } Whether the operation was successful
72      * @since 10
73     */
74     virtual int32_t SetDiscoverable(const bool enable) = 0;
75 
76     /**
77      * @brief Notify Router that the device has been discovered (device is available).
78      *
79      * @param { OutputDeviceInfo } castOutputDeviceInfo - Discovered device infos.
80      * @return { int32_t } Whether the notify operation was successful.
81      * @since 10
82     */
83     virtual int32_t OnDeviceAvailable(OutputDeviceInfo& castOutputDeviceInfo) = 0;
84 
85     /**
86      * @brief Notify Router that the device is offline.
87      *
88      * @param { std::string& } deviceId - Offlined device ID.
89      * @return { int32_t } Whether the notify operation was successful.
90      * @since 10
91     */
92     virtual int32_t OnDeviceOffline(const std::string& deviceId) = 0;
93 
94     /**
95      * @brief Release current cast session.
96      *
97      * @since 10
98     */
99     virtual void ReleaseCurrentCastSession() = 0;
100 
101     /**
102      * @brief Notify Router that the cast session has created.
103      *
104      * @param { int32_t } castId - Cast id for AVRouter's control.
105      * @return { int32_t } Whether the notify operation was successful.
106      * @since 10
107     */
108     virtual int32_t OnCastSessionCreated(const int32_t castId) = 0;
109 
110     /**
111      * @brief Notify Router that the the cast engine servie has died.
112      *
113      * @param { int32_t } providerId - Provider ID corresponding to cast engine service.
114      * @return { int32_t } Whether the notify operation was successful.
115      * @since 10
116     */
117     virtual int32_t OnCastServerDied(int32_t providerId) = 0;
118 
119     /**
120      * @brief Get the cast controller specified by castHandle.
121      *
122      * @param { const int64_t } castHandle - castHandle corresponding to cast engine session.
123      * @return { std::shared_ptr<IAVCastControllerProxy> } Obtained cast controller.
124      * @since 10
125     */
126     virtual std::shared_ptr<IAVCastControllerProxy> GetRemoteController(const int64_t castHandle) = 0;
127 
128     /**
129      * @brief Start cast process.
130      *
131      * @param { OutputDeviceInfo } outputDeviceInfo - Output device ready for use.
132      * @return { int64_t } ID returned after successful start of cast.
133      * @since 10
134     */
135     virtual int64_t StartCast(const OutputDeviceInfo& outputDeviceInfo) = 0;
136 
137     /**
138      * @brief Notify CastEngine to add (connect) remote devices.
139      *
140      * @param { int32_t } castId - Find the corresponding provider through this ID.
141      * @param { OutputDeviceInfo } outputDeviceInfo - Devices to be connected.
142      * @return { int32_t } Whether the operation was successful.
143      * @since 10
144     */
145     virtual int32_t AddDevice(const int32_t castId, const OutputDeviceInfo& outputDeviceInfo) = 0;
146 
147     /**
148      * @brief Stop cast process.
149      *
150      * @param { const int64_t } castHandle - The ID corresponding to the provider that needs to be stopped.
151      * @return { int32_t } Whether the operation was successful.
152      * @since 10
153     */
154     virtual int32_t StopCast(const int64_t castHandle) = 0;
155 
156     /**
157      * @brief Stop cast session process.
158      *
159      * @param { const int64_t } castHandle - The ID corresponding to the provider that needs to be stopped.
160      * @return { int32_t } Whether the operation was successful.
161      * @since 10
162     */
163     virtual int32_t StopCastSession(const int64_t castHandle) = 0;
164 
165     /**
166      * @brief Listen for AVRouter Callback event.
167      *
168      * @param { int64_t } castHandleconst - The ID corresponding to the provider.
169      * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function.
170      * @return { int32_t } Whether the operation was successful.
171      * @since 10
172     */
173     virtual int32_t RegisterCallback(int64_t castHandleconst,
174         std::shared_ptr<IAVCastSessionStateListener> callback) = 0;
175 
176     /**
177      * @brief Cancel listening for AVRouter Callback event.
178      *
179      * @param { int64_t } castHandleconst - The ID corresponding to the provider.
180      * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function.
181      * @return { int32_t } Whether the operation was successful.
182      * @since 10
183     */
184     virtual int32_t UnRegisterCallback(int64_t castHandleconst,
185         std::shared_ptr<IAVCastSessionStateListener> callback) = 0;
186 #endif
187 };
188 } // namespace OHOS::AVSession
189 #endif // OHOS_AVROUTER_H
190