cef/libcef_dll/cpptoc/media_router_cpptoc.cc
Marshall Greenblatt 03fd5b15da Add support for media device discovery and messaging (fixes issue #2900)
Chromium supports communication with media devices on the local network via
the Cast and DIAL protocols. This takes two primary forms:

1. Messaging, where strings representing state information are passed between
   the client and a dedicated receiver app on the media device. The receiver
   app communicates directly with an app-specific backend service to retrieve
   and possibly control media playback.
2. Tab/desktop mirroring, where the media contents are streamed directly from
   the browser to a generic streaming app on the media device and playback is
   controlled by the browser.

This change adds support for device discovery and messaging (but not
mirroring) with functionality exposed via the new CefMediaRouter interface.

To test: Navigate to http://tests/media_router in cefclient and follow the
on-screen instructions.
2020-03-27 15:54:39 -04:00

178 lines
5.1 KiB
C++

// Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=6b52fceffec99c0f274b5031266c20da5480d0c1$
//
#include "libcef_dll/cpptoc/media_router_cpptoc.h"
#include "libcef_dll/cpptoc/media_sink_cpptoc.h"
#include "libcef_dll/cpptoc/media_source_cpptoc.h"
#include "libcef_dll/cpptoc/registration_cpptoc.h"
#include "libcef_dll/ctocpp/media_observer_ctocpp.h"
#include "libcef_dll/ctocpp/media_route_create_callback_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_media_router_t* cef_media_router_get_global() {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefMediaRouter> _retval = CefMediaRouter::GetGlobalMediaRouter();
// Return type: refptr_same
return CefMediaRouterCppToC::Wrap(_retval);
}
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
struct _cef_registration_t* CEF_CALLBACK
media_router_add_observer(struct _cef_media_router_t* self,
struct _cef_media_observer_t* observer) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: observer; type: refptr_diff
DCHECK(observer);
if (!observer)
return NULL;
// Execute
CefRefPtr<CefRegistration> _retval =
CefMediaRouterCppToC::Get(self)->AddObserver(
CefMediaObserverCToCpp::Wrap(observer));
// Return type: refptr_same
return CefRegistrationCppToC::Wrap(_retval);
}
struct _cef_media_source_t* CEF_CALLBACK
media_router_get_source(struct _cef_media_router_t* self,
const cef_string_t* urn) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: urn; type: string_byref_const
DCHECK(urn);
if (!urn)
return NULL;
// Execute
CefRefPtr<CefMediaSource> _retval =
CefMediaRouterCppToC::Get(self)->GetSource(CefString(urn));
// Return type: refptr_same
return CefMediaSourceCppToC::Wrap(_retval);
}
void CEF_CALLBACK
media_router_notify_current_sinks(struct _cef_media_router_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefMediaRouterCppToC::Get(self)->NotifyCurrentSinks();
}
void CEF_CALLBACK
media_router_create_route(struct _cef_media_router_t* self,
struct _cef_media_source_t* source,
struct _cef_media_sink_t* sink,
struct _cef_media_route_create_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: source; type: refptr_same
DCHECK(source);
if (!source)
return;
// Verify param: sink; type: refptr_same
DCHECK(sink);
if (!sink)
return;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return;
// Execute
CefMediaRouterCppToC::Get(self)->CreateRoute(
CefMediaSourceCppToC::Unwrap(source), CefMediaSinkCppToC::Unwrap(sink),
CefMediaRouteCreateCallbackCToCpp::Wrap(callback));
}
void CEF_CALLBACK
media_router_notify_current_routes(struct _cef_media_router_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefMediaRouterCppToC::Get(self)->NotifyCurrentRoutes();
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefMediaRouterCppToC::CefMediaRouterCppToC() {
GetStruct()->add_observer = media_router_add_observer;
GetStruct()->get_source = media_router_get_source;
GetStruct()->notify_current_sinks = media_router_notify_current_sinks;
GetStruct()->create_route = media_router_create_route;
GetStruct()->notify_current_routes = media_router_notify_current_routes;
}
// DESTRUCTOR - Do not edit by hand.
CefMediaRouterCppToC::~CefMediaRouterCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefMediaRouter>
CefCppToCRefCounted<CefMediaRouterCppToC, CefMediaRouter, cef_media_router_t>::
UnwrapDerived(CefWrapperType type, cef_media_router_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefMediaRouterCppToC,
CefMediaRouter,
cef_media_router_t>::kWrapperType =
WT_MEDIA_ROUTER;