1 // Copyright (c) 2020 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // 30 // --------------------------------------------------------------------------- 31 // 32 // The contents of this file must follow a specific format in order to 33 // support the CEF translator tool. See the translator.README.txt file in the 34 // tools directory for more information. 35 // 36 37 #ifndef CEF_INCLUDE_CEF_MEDIA_ROUTER_H_ 38 #define CEF_INCLUDE_CEF_MEDIA_ROUTER_H_ 39 #pragma once 40 41 #include <vector> 42 #include "include/cef_base.h" 43 #include "include/cef_callback.h" 44 #include "include/cef_registration.h" 45 46 class CefMediaObserver; 47 class CefMediaRoute; 48 class CefMediaRouteCreateCallback; 49 class CefMediaSink; 50 class CefMediaSinkDeviceInfoCallback; 51 class CefMediaSource; 52 53 /// 54 // Supports discovery of and communication with media devices on the local 55 // network via the Cast and DIAL protocols. The methods of this class may be 56 // called on any browser process thread unless otherwise indicated. 57 /// 58 /*--cef(source=library)--*/ 59 class CefMediaRouter : public virtual CefBaseRefCounted { 60 public: 61 /// 62 // Returns the MediaRouter object associated with the global request context. 63 // If |callback| is non-NULL it will be executed asnychronously on the UI 64 // thread after the manager's storage has been initialized. Equivalent to 65 // calling CefRequestContext::GetGlobalContext()->GetMediaRouter(). 66 /// 67 /*--cef(optional_param=callback)--*/ 68 static CefRefPtr<CefMediaRouter> GetGlobalMediaRouter( 69 CefRefPtr<CefCompletionCallback> callback); 70 71 /// 72 // Add an observer for MediaRouter events. The observer will remain registered 73 // until the returned Registration object is destroyed. 74 /// 75 /*--cef()--*/ 76 virtual CefRefPtr<CefRegistration> AddObserver( 77 CefRefPtr<CefMediaObserver> observer) = 0; 78 79 /// 80 // Returns a MediaSource object for the specified media source URN. Supported 81 // URN schemes include "cast:" and "dial:", and will be already known by the 82 // client application (e.g. "cast:<appId>?clientId=<clientId>"). 83 /// 84 /*--cef()--*/ 85 virtual CefRefPtr<CefMediaSource> GetSource(const CefString& urn) = 0; 86 87 /// 88 // Trigger an asynchronous call to CefMediaObserver::OnSinks on all 89 // registered observers. 90 /// 91 /*--cef()--*/ 92 virtual void NotifyCurrentSinks() = 0; 93 94 /// 95 // Create a new route between |source| and |sink|. Source and sink must be 96 // valid, compatible (as reported by CefMediaSink::IsCompatibleWith), and a 97 // route between them must not already exist. |callback| will be executed 98 // on success or failure. If route creation succeeds it will also trigger an 99 // asynchronous call to CefMediaObserver::OnRoutes on all registered 100 // observers. 101 /// 102 /*--cef()--*/ 103 virtual void CreateRoute(CefRefPtr<CefMediaSource> source, 104 CefRefPtr<CefMediaSink> sink, 105 CefRefPtr<CefMediaRouteCreateCallback> callback) = 0; 106 107 /// 108 // Trigger an asynchronous call to CefMediaObserver::OnRoutes on all 109 // registered observers. 110 /// 111 /*--cef()--*/ 112 virtual void NotifyCurrentRoutes() = 0; 113 }; 114 115 /// 116 // Implemented by the client to observe MediaRouter events and registered via 117 // CefMediaRouter::AddObserver. The methods of this class will be called on the 118 // browser process UI thread. 119 /// 120 /*--cef(source=client)--*/ 121 class CefMediaObserver : public virtual CefBaseRefCounted { 122 public: 123 typedef cef_media_route_connection_state_t ConnectionState; 124 125 /// 126 // The list of available media sinks has changed or 127 // CefMediaRouter::NotifyCurrentSinks was called. 128 /// 129 /*--cef()--*/ 130 virtual void OnSinks(const std::vector<CefRefPtr<CefMediaSink>>& sinks) = 0; 131 132 /// 133 // The list of available media routes has changed or 134 // CefMediaRouter::NotifyCurrentRoutes was called. 135 /// 136 /*--cef()--*/ 137 virtual void OnRoutes( 138 const std::vector<CefRefPtr<CefMediaRoute>>& routes) = 0; 139 140 /// 141 // The connection state of |route| has changed. 142 /// 143 /*--cef()--*/ 144 virtual void OnRouteStateChanged(CefRefPtr<CefMediaRoute> route, 145 ConnectionState state) = 0; 146 147 /// 148 // A message was recieved over |route|. |message| is only valid for 149 // the scope of this callback and should be copied if necessary. 150 /// 151 /*--cef()--*/ 152 virtual void OnRouteMessageReceived(CefRefPtr<CefMediaRoute> route, 153 const void* message, 154 size_t message_size) = 0; 155 }; 156 157 /// 158 // Represents the route between a media source and sink. Instances of this 159 // object are created via CefMediaRouter::CreateRoute and retrieved via 160 // CefMediaObserver::OnRoutes. Contains the status and metadata of a 161 // routing operation. The methods of this class may be called on any browser 162 // process thread unless otherwise indicated. 163 /// 164 /*--cef(source=library)--*/ 165 class CefMediaRoute : public virtual CefBaseRefCounted { 166 public: 167 /// 168 // Returns the ID for this route. 169 /// 170 /*--cef()--*/ 171 virtual CefString GetId() = 0; 172 173 /// 174 // Returns the source associated with this route. 175 /// 176 /*--cef()--*/ 177 virtual CefRefPtr<CefMediaSource> GetSource() = 0; 178 179 /// 180 // Returns the sink associated with this route. 181 /// 182 /*--cef()--*/ 183 virtual CefRefPtr<CefMediaSink> GetSink() = 0; 184 185 /// 186 // Send a message over this route. |message| will be copied if necessary. 187 /// 188 /*--cef()--*/ 189 virtual void SendRouteMessage(const void* message, size_t message_size) = 0; 190 191 /// 192 // Terminate this route. Will result in an asynchronous call to 193 // CefMediaObserver::OnRoutes on all registered observers. 194 /// 195 /*--cef()--*/ 196 virtual void Terminate() = 0; 197 }; 198 199 /// 200 // Callback interface for CefMediaRouter::CreateRoute. The methods of this 201 // class will be called on the browser process UI thread. 202 /// 203 /*--cef(source=client)--*/ 204 class CefMediaRouteCreateCallback : public virtual CefBaseRefCounted { 205 public: 206 typedef cef_media_route_create_result_t RouteCreateResult; 207 208 /// 209 // Method that will be executed when the route creation has finished. |result| 210 // will be CEF_MRCR_OK if the route creation succeeded. |error| will be a 211 // description of the error if the route creation failed. |route| is the 212 // resulting route, or empty if the route creation failed. 213 /// 214 /*--cef(optional_param=error,optional_param=route)--*/ 215 virtual void OnMediaRouteCreateFinished(RouteCreateResult result, 216 const CefString& error, 217 CefRefPtr<CefMediaRoute> route) = 0; 218 }; 219 220 /// 221 // Represents a sink to which media can be routed. Instances of this object are 222 // retrieved via CefMediaObserver::OnSinks. The methods of this class may 223 // be called on any browser process thread unless otherwise indicated. 224 /// 225 /*--cef(source=library)--*/ 226 class CefMediaSink : public virtual CefBaseRefCounted { 227 public: 228 typedef cef_media_sink_icon_type_t IconType; 229 230 /// 231 // Returns the ID for this sink. 232 /// 233 /*--cef()--*/ 234 virtual CefString GetId() = 0; 235 236 /// 237 // Returns the name of this sink. 238 /// 239 /*--cef()--*/ 240 virtual CefString GetName() = 0; 241 242 /// 243 // Returns the description of this sink. 244 /// 245 /*--cef()--*/ 246 virtual CefString GetDescription() = 0; 247 248 /// 249 // Returns the icon type for this sink. 250 /// 251 /*--cef(default_retval=CEF_MSIT_GENERIC)--*/ 252 virtual IconType GetIconType() = 0; 253 254 /// 255 // Asynchronously retrieves device info. 256 /// 257 /*--cef()--*/ 258 virtual void GetDeviceInfo( 259 CefRefPtr<CefMediaSinkDeviceInfoCallback> callback) = 0; 260 261 /// 262 // Returns true if this sink accepts content via Cast. 263 /// 264 /*--cef()--*/ 265 virtual bool IsCastSink() = 0; 266 267 /// 268 // Returns true if this sink accepts content via DIAL. 269 /// 270 /*--cef()--*/ 271 virtual bool IsDialSink() = 0; 272 273 /// 274 // Returns true if this sink is compatible with |source|. 275 /// 276 /*--cef()--*/ 277 virtual bool IsCompatibleWith(CefRefPtr<CefMediaSource> source) = 0; 278 }; 279 280 /// 281 // Callback interface for CefMediaSink::GetDeviceInfo. The methods of this 282 // class will be called on the browser process UI thread. 283 /// 284 /*--cef(source=client)--*/ 285 class CefMediaSinkDeviceInfoCallback : public virtual CefBaseRefCounted { 286 public: 287 /// 288 // Method that will be executed asyncronously once device information has been 289 // retrieved. 290 /// 291 /*--cef()--*/ 292 virtual void OnMediaSinkDeviceInfo( 293 const CefMediaSinkDeviceInfo& device_info) = 0; 294 }; 295 296 /// 297 // Represents a source from which media can be routed. Instances of this object 298 // are retrieved via CefMediaRouter::GetSource. The methods of this class may be 299 // called on any browser process thread unless otherwise indicated. 300 /// 301 /*--cef(source=library)--*/ 302 class CefMediaSource : public virtual CefBaseRefCounted { 303 public: 304 /// 305 // Returns the ID (media source URN or URL) for this source. 306 /// 307 /*--cef()--*/ 308 virtual CefString GetId() = 0; 309 310 /// 311 // Returns true if this source outputs its content via Cast. 312 /// 313 /*--cef()--*/ 314 virtual bool IsCastSource() = 0; 315 316 /// 317 // Returns true if this source outputs its content via DIAL. 318 /// 319 /*--cef()--*/ 320 virtual bool IsDialSource() = 0; 321 }; 322 323 #endif // CEF_INCLUDE_CEF_MEDIA_ROUTER_H_ 324