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 AV_CAST_PROVIDER_H
17 #define AV_CAST_PROVIDER_H
18 
19 #include "cast_engine_common.h"
20 #include "i_avcast_state_listener.h"
21 #include "avsession_descriptor.h"
22 #include "i_avcast_controller_proxy.h"
23 
24 namespace OHOS::AVSession {
25 class AVCastProvider {
26 public:
27     /**
28      * @brief Construct AVCastProvider object.
29      *
30      * @since 10
31     */
32     AVCastProvider() = default;
33 
34     /**
35      * @brief Deconstruct AVCastProvider object.
36      *
37      * @since 10
38     */
39     virtual ~AVCastProvider() = default;
40 
41     /**
42      * @brief Initialize AVCastProvider object.
43      *
44      * @return {int32_t} Returns whether init successfully.
45      * @since 10
46     */
47     virtual int32_t Init() = 0;
48 
49     /**
50      * Transmission fd
51      *
52      * @param fd file descriptor
53      * @param maxSize file max size
54      * @return Returns whether the fd was transport successfully
55      * @since 13
56     */
57     virtual int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) = 0;
58 
59     /**
60      * Stop transmission fd
61      *
62      * @return Returns whether stop transport successfully
63      * @since 13
64     */
65     virtual int32_t StopDeviceLogging() = 0;
66 
67     /**
68      * @brief Start searching for sink end devices.
69      *
70      * @param { int } castCapability - The type of device want to discover.
71      * @return { bool } Whether the device discovery operation was successful.
72      * @since 10
73     */
74     virtual bool StartDiscovery(int castCapability, std::vector<std::string> drmSchemes) = 0;
75 
76     /**
77      * @brief Stop Discovering Devices
78      *
79      * @since 10
80     */
81     virtual void StopDiscovery() = 0;
82 
83     /**
84      * @brief Used on the Sink end to set whether it can be discovered or not.
85      *
86      * @param { const bool } enable - whether the sink device can be discovered or not.
87      * @return { int32_t } Whether the operation was successful
88      * @since 10
89     */
90     virtual int32_t SetDiscoverable(const bool enable) = 0;
91 
92     /**
93      * @brief Release AVCastProvider object.
94      *
95      * @since 10
96     */
97     virtual void Release() = 0;
98 
99     /**
100      * @brief Register listener for AVCast state callback event.
101      *
102      * @param { std::shared_ptr<IAVCastStateListener> } listener - Register the pointer.
103      * @return { bool } Whether the operation was successful.
104      * @since 10
105     */
106     virtual bool RegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) = 0;
107 
108     /**
109      * @brief Unregister listener for AVCast state callback event.
110      *
111      * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - The pointer want unregistered.
112      * @return { bool } Whether the operation was successful.
113      * @since 10
114     */
115     virtual bool UnRegisterCastStateListener(std::shared_ptr<IAVCastStateListener> listener) = 0;
116 
117     /**
118      * @brief Notify CastEngine to add (connect) remote devices.
119      *
120      * @param { int32_t } castId - Find the corresponding provider through this ID.
121      * @param { DeviceInfo } deviceInfo - Devices to be connected.
122      * @return { bool } Whether the operation was successful.
123      * @since 10
124     */
125     virtual bool AddCastDevice(int castId, DeviceInfo deviceInfo) = 0;
126 
127     /**
128      * @brief Notify CastEngine to remove (disconnect) remote devices.
129      *
130      * @param { int32_t } castId - Find the corresponding provider through this ID.
131      * @param { OutputDeviceInfo } outputDeviceInfo - Devices to be disconnected.
132      * @return { bool } Whether the operation was successful.
133      * @since 10
134     */
135     virtual bool RemoveCastDevice(int castId, DeviceInfo deviceInfo) = 0;
136 
137     /**
138      * @brief Start cast process.
139      *
140      * @return { int } Whether the operation was successful.
141      * @since 10
142     */
143     virtual int StartCastSession() = 0;
144 
145     /**
146      * @brief Stop cast process.
147      *
148      * @param { int } castId - The ID corresponding to the provider that needs to be stopped.
149      * @since 10
150     */
151     virtual void StopCastSession(int castId) = 0;
152 
153     /**
154      * @brief Get the cast controller specified by castHandle.
155      *
156      * @param { int } castId - castId corresponding to cast engine session.
157      * @return { std::shared_ptr<IAVCastControllerProxy> } Obtained cast controller.
158      * @since 10
159     */
160     virtual std::shared_ptr<IAVCastControllerProxy> GetRemoteController(int castId) = 0;
161 
162     /**
163      * @brief Register listener for AVCast session state callback event.
164      *
165      * @param { int } castId - The ID corresponding to the provider.
166      * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function.
167      * @return { bool } Whether the operation was successful.
168      * @since 10
169     */
170     virtual bool RegisterCastSessionStateListener(int castId,
171         std::shared_ptr<IAVCastSessionStateListener> listener) = 0;
172 
173     /**
174      * @brief Unregister listener for AVCast session state callback event.
175      *
176      * @param { int } castId - The ID corresponding to the provider.
177      * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function.
178      * @return { bool } Whether the operation was successful.
179      * @since 10
180     */
181     virtual bool UnRegisterCastSessionStateListener(int castId,
182         std::shared_ptr<IAVCastSessionStateListener> listener) = 0;
183 
184     /**
185      * @brief set allconnect state.
186      *
187      * @param { int64_t } castHandle const - The ID corresponding to the castprovider.
188      * @param { DeviceInfo } cast deviceinfo - The deviceinfo to the castprovider.
189      * @return { bool } Whether the operation was successful.
190      * @since 11
191     */
192     virtual bool SetStreamState(int64_t castHandle, DeviceInfo deviceInfo) = 0;
193 
194     /**
195      * @brief get mirror castHandle.
196      *
197      * @return { int64_t } mirror castHandle.
198      * @since 11
199     */
200     virtual int64_t GetMirrorCastHandle() = 0;
201 
202     /**
203      * @brief get remote networkId.
204      *
205      * @param { int32_t } castHandle const - The ID corresponding to the castprovider.
206      * @param { string } cast deviceId - The deviceId give cast+ to get remote networkId.
207      * @param { string } cast networkId - The networkId to transmit remote networkId.
208      * @return { bool } Whether the operation was successful.
209      * @since 11
210     */
211     virtual bool GetRemoteNetWorkId(int32_t castId, std::string deviceId, std::string &networkId) = 0;
212 
213     /**
214      * @brief get protocol type.
215      *
216      * @param { uint32_t } cast protocol type - The type of cast protocol.
217      * @return { int32_t } The type of avsession protocol.
218      * @since 13
219     */
220     virtual int32_t GetProtocolType(uint32_t castProtocolType) = 0;
221 };
222 } // namespace OHOS::AVSession
223 #endif
224