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 * Transmission fd 59 * 60 * @param fd file descriptor 61 * @param maxSize file max size 62 * @return Returns whether the fd was transport successfully 63 * @since 13 64 */ 65 virtual int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) = 0; 66 67 /** 68 * Stop transmission fd 69 * 70 * @return Returns whether stop transport successfully 71 * @since 13 72 */ 73 virtual int32_t StopDeviceLogging() = 0; 74 75 /** 76 * @brief Starting to discover devices. 77 * 78 * @param { int32_t } castDeviceCapability - The type of device want to discover. 79 * @return { int32_t } Whether the device discovery operation was successful. 80 * @since 10 81 */ 82 virtual int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes) = 0; 83 84 /** 85 * @brief Stop Discovering Devices 86 * 87 * @return { int32_t } Whether the stop operation was successful 88 * @since 10 89 */ 90 virtual int32_t StopCastDiscovery() = 0; 91 92 /** 93 * @brief Used on the Sink end to set whether it can be discovered or not. 94 * 95 * @param { const bool } enable - whether the sink device can be discovered or not. 96 * @return { int32_t } Whether the operation was successful 97 * @since 10 98 */ 99 virtual int32_t SetDiscoverable(const bool enable) = 0; 100 101 /** 102 * @brief Notify Router that the device has been discovered (device is available). 103 * 104 * @param { OutputDeviceInfo } castOutputDeviceInfo - Discovered device infos. 105 * @return { int32_t } Whether the notify operation was successful. 106 * @since 10 107 */ 108 virtual int32_t OnDeviceAvailable(OutputDeviceInfo& castOutputDeviceInfo) = 0; 109 110 /** 111 * @brief Listen for the event of device logging. 112 * 113 * @param { DeviceLogEventCode } eventId - Event ID. 114 * @param { int64_t } int64_t - Param. 115 * @since 13 116 */ 117 virtual int32_t OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) = 0; 118 119 /** 120 * @brief Notify Router that the device is offline. 121 * 122 * @param { std::string& } deviceId - Offlined device ID. 123 * @return { int32_t } Whether the notify operation was successful. 124 * @since 10 125 */ 126 virtual int32_t OnDeviceOffline(const std::string& deviceId) = 0; 127 128 /** 129 * @brief Release current cast session. 130 * 131 * @since 10 132 */ 133 virtual void ReleaseCurrentCastSession() = 0; 134 135 /** 136 * @brief Notify Router that the cast session has created. 137 * 138 * @param { int32_t } castId - Cast id for AVRouter's control. 139 * @return { int32_t } Whether the notify operation was successful. 140 * @since 10 141 */ 142 virtual int32_t OnCastSessionCreated(const int32_t castId) = 0; 143 144 /** 145 * @brief Notify Router that the the cast engine servie has died. 146 * 147 * @param { int32_t } providerId - Provider ID corresponding to cast engine service. 148 * @return { int32_t } Whether the notify operation was successful. 149 * @since 10 150 */ 151 virtual int32_t OnCastServerDied(int32_t providerId) = 0; 152 153 /** 154 * @brief Get the cast controller specified by castHandle. 155 * 156 * @param { const int64_t } castHandle - castHandle 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(const int64_t castHandle) = 0; 161 162 /** 163 * @brief Start cast process. 164 * 165 * @param { OutputDeviceInfo } outputDeviceInfo - Output device ready for use. 166 * @param { std::shared_ptr<IAVCastSessionStateListener > } callback - Callback function. 167 * @return { int64_t } ID returned after successful start of cast. 168 * @since 10 169 */ 170 virtual int64_t StartCast(const OutputDeviceInfo& outputDeviceInfo, 171 std::map<std::string, std::string>& serviceNameMapState) = 0; 172 173 /** 174 * @brief Notify CastEngine to add (connect) remote devices. 175 * 176 * @param { int32_t } castId - Find the corresponding provider through this ID. 177 * @param { OutputDeviceInfo } outputDeviceInfo - Devices to be connected. 178 * @return { int32_t } Whether the operation was successful. 179 * @since 10 180 */ 181 virtual int32_t AddDevice(const int32_t castId, const OutputDeviceInfo& outputDeviceInfo) = 0; 182 183 /** 184 * @brief Stop cast process. 185 * 186 * @param { const int64_t } castHandle - The ID corresponding to the provider that needs to be stopped. 187 * @param { int32_t } removeTimes - The remove times. 188 * @return { int32_t } Whether the operation was successful. 189 * @since 10 190 */ 191 virtual int32_t StopCast(const int64_t castHandle, int32_t removeTimes) = 0; 192 193 /** 194 * @brief Stop cast session process. 195 * 196 * @param { const int64_t } castHandle - The ID corresponding to the provider that needs to be stopped. 197 * @return { int32_t } Whether the operation was successful. 198 * @since 10 199 */ 200 virtual int32_t StopCastSession(const int64_t castHandle) = 0; 201 202 /** 203 * @brief Listen for AVRouter Callback event. 204 * 205 * @param { int64_t } castHandleconst - The ID corresponding to the provider. 206 * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function. 207 * @return { int32_t } Whether the operation was successful. 208 * @since 10 209 */ 210 virtual int32_t RegisterCallback(int64_t castHandleconst, 211 std::shared_ptr<IAVCastSessionStateListener> callback) = 0; 212 213 /** 214 * @brief Cancel listening for AVRouter Callback event. 215 * 216 * @param { int64_t } castHandleconst - The ID corresponding to the provider. 217 * @param { std::shared_ptr<IAVCastSessionStateListener> } callback - Callback function. 218 * @return { int32_t } Whether the operation was successful. 219 * @since 10 220 */ 221 virtual int32_t UnRegisterCallback(int64_t castHandleconst, 222 std::shared_ptr<IAVCastSessionStateListener> callback) = 0; 223 224 /** 225 * @brief set allconnect state. 226 * 227 * @param { int64_t } castHandle const - The ID corresponding to the provider. 228 * @param { DeviceInfo } cast deviceinfo - The deviceinfo to the castprovider. 229 * @return { int32_t } Whether the operation was successful. 230 * @since 11 231 */ 232 virtual int32_t SetServiceAllConnectState(int64_t castHandle, DeviceInfo deviceInfo) = 0; 233 234 /** 235 * @brief get remote networkId. 236 * 237 * @param { int64_t } castHandle const - The ID corresponding to the castprovider. 238 * @param { string } cast deviceId - The deviceId give cast+ to get remote networkId. 239 * @param { string } cast networkId - The networkId to transmit remote networkId. 240 * @return { int32_t } Whether the operation was successful. 241 * @since 11 242 */ 243 virtual int32_t GetRemoteNetWorkId(int64_t castHandle, std::string deviceId, std::string &networkId) = 0; 244 #endif 245 }; 246 } // namespace OHOS::AVSession 247 #endif // OHOS_AVROUTER_H 248