From ea28f518d35694283ae3519375d6afbbabaf3acf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Oct 2014 11:07:29 +0800 Subject: [PATCH] Add handling of user media requests --- .../media/media_stream_devices_controller.cc | 49 +++++++++++++++++++ .../media/media_stream_devices_controller.h | 3 ++ 2 files changed, 52 insertions(+) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 2b7510939dd4..fc867f075b54 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -6,6 +6,7 @@ #include "browser/media/media_capture_devices_dispatcher.h" +#include "content/public/browser/desktop_media_id.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -47,6 +48,15 @@ MediaStreamDevicesController::~MediaStreamDevicesController() { } bool MediaStreamDevicesController::TakeAction() { + // Do special handling of desktop screen cast. + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || + request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + HandleUserMediaRequest(); + return true; + } + // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { Deny(); @@ -147,4 +157,43 @@ void MediaStreamDevicesController::Deny() { scoped_ptr()); } +void MediaStreamDevicesController::HandleUserMediaRequest() { + content::MediaStreamDevices devices; + + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_AUDIO_CAPTURE, "", "")); + } + if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_VIDEO_CAPTURE, "", "")); + } + if (request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_LOOPBACK_AUDIO_CAPTURE, "loopback", "System Audio")); + } + if (request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + content::DesktopMediaID screen_id; + // If the device id wasn't specified then this is a screen capture request + // (i.e. chooseDesktopMedia() API wasn't used to generate device id). + if (request_.requested_video_device_id.empty()) { + screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, + -1 /* kFullDesktopScreenId */); + } else { + screen_id = + content::DesktopMediaID::Parse(request_.requested_video_device_id); + } + + devices.push_back( + content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE, + screen_id.ToString(), "Screen")); + } + + callback_.Run( + devices, + devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : + content::MEDIA_DEVICE_OK, + scoped_ptr()); +} + } // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 9100fa4e27ee..e77af4770271 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -26,6 +26,9 @@ class MediaStreamDevicesController { void Deny(); private: + // Handle the request of desktop or tab screen cast. + void HandleUserMediaRequest(); + // The original request for access to devices. const content::MediaStreamRequest request_;