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