Update MediaCaptureDevicesDispatcher for Chrome 35

See https://codereview.chromium.org/183743021
This commit is contained in:
Adam Roben 2014-06-26 16:31:32 -04:00
parent 5b788476a5
commit e003cc9a0a
2 changed files with 37 additions and 68 deletions

View file

@ -6,8 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/media_devices_monitor.h" #include "content/public/browser/media_capture_devices.h"
#include "content/public/common/desktop_media_id.h"
#include "content/public/common/media_stream_request.h" #include "content/public/common/media_stream_request.h"
namespace brightray { namespace brightray {
@ -30,6 +29,11 @@ const content::MediaStreamDevice* FindDeviceWithId(
return NULL; return NULL;
} }
const MediaStreamDevices& EmptyDevices() {
static MediaStreamDevices* devices = new MediaStreamDevices;
return *devices;
}
} // namespace } // namespace
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
@ -37,8 +41,7 @@ MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
} }
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
: devices_enumerated_(false), : is_device_enumeration_disabled_(false) {
is_device_enumeration_disabled_(false) {
// MediaCaptureDevicesDispatcher is a singleton. It should be created on // MediaCaptureDevicesDispatcher is a singleton. It should be created on
// UI thread. // UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@ -49,21 +52,17 @@ MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
const MediaStreamDevices& const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!is_device_enumeration_disabled_ && !devices_enumerated_) { if (is_device_enumeration_disabled_)
content::EnsureMonitorCaptureDevices(); return EmptyDevices();
devices_enumerated_ = true; return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
}
return audio_devices_;
} }
const MediaStreamDevices& const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!is_device_enumeration_disabled_ && !devices_enumerated_) { if (is_device_enumeration_disabled_)
content::EnsureMonitorCaptureDevices(); return EmptyDevices();
devices_enumerated_ = true; return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
}
return video_devices_;
} }
void MediaCaptureDevicesDispatcher::GetDefaultDevices( void MediaCaptureDevicesDispatcher::GetDefaultDevices(
@ -128,36 +127,33 @@ void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() {
is_device_enumeration_disabled_ = true; is_device_enumeration_disabled_ = true;
} }
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged( void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {
const content::MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread,
base::Unretained(this), devices));
} }
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged( void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {
const content::MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
base::Unretained(this), devices));
} }
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
int render_process_id, int render_process_id,
int render_view_id, int render_view_id,
int page_request_id, int page_request_id,
const GURL& security_origin,
const content::MediaStreamDevice& device, const content::MediaStreamDevice& device,
content::MediaRequestState state) { content::MediaRequestState state) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
} }
void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged( void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying(
int render_process_id, int render_view_id, int stream_id, int render_process_id,
bool is_playing, float power_dbfs, bool clipped) { int render_frame_id,
int stream_id,
const ReadPowerAndClipCallback& power_read_callback) {
}
void MediaCaptureDevicesDispatcher::OnAudioStreamStopped(
int render_process_id,
int render_frame_id,
int stream_id) {
} }
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(
@ -166,18 +162,4 @@ void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
} }
void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread(
const content::MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
devices_enumerated_ = true;
audio_devices_ = devices;
}
void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread(
const content::MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
devices_enumerated_ = true;
video_devices_ = devices;
}
} // namespace brightray } // namespace brightray

View file

@ -51,23 +51,24 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
void DisableDeviceEnumerationForTesting(); void DisableDeviceEnumerationForTesting();
// Overridden from content::MediaObserver: // Overridden from content::MediaObserver:
virtual void OnAudioCaptureDevicesChanged( virtual void OnAudioCaptureDevicesChanged() OVERRIDE;
const content::MediaStreamDevices& devices) OVERRIDE; virtual void OnVideoCaptureDevicesChanged() OVERRIDE;
virtual void OnVideoCaptureDevicesChanged(
const content::MediaStreamDevices& devices) OVERRIDE;
virtual void OnMediaRequestStateChanged( virtual void OnMediaRequestStateChanged(
int render_process_id, int render_process_id,
int render_view_id, int render_view_id,
int page_request_id, int page_request_id,
const GURL& security_origin,
const content::MediaStreamDevice& device, const content::MediaStreamDevice& device,
content::MediaRequestState state) OVERRIDE; content::MediaRequestState state) OVERRIDE;
virtual void OnAudioStreamPlayingChanged( virtual void OnAudioStreamPlaying(
int render_process_id, int render_process_id,
int render_view_id, int render_frame_id,
int stream_id, int stream_id,
bool is_playing, const ReadPowerAndClipCallback& power_read_callback) OVERRIDE;
float power_dBFS, virtual void OnAudioStreamStopped(
bool clipped) OVERRIDE; int render_process_id,
int render_frame_id,
int stream_id) OVERRIDE;
virtual void OnCreatingAudioStream(int render_process_id, virtual void OnCreatingAudioStream(int render_process_id,
int render_view_id) OVERRIDE; int render_view_id) OVERRIDE;
@ -77,20 +78,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
MediaCaptureDevicesDispatcher(); MediaCaptureDevicesDispatcher();
virtual ~MediaCaptureDevicesDispatcher(); virtual ~MediaCaptureDevicesDispatcher();
// Called by the MediaObserver() functions, executed on UI thread.
void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices);
void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices);
// A list of cached audio capture devices.
content::MediaStreamDevices audio_devices_;
// A list of cached video capture devices.
content::MediaStreamDevices video_devices_;
// Flag to indicate if device enumeration has been done/doing.
// Only accessed on UI thread.
bool devices_enumerated_;
// Flag used by unittests to disable device enumeration. // Flag used by unittests to disable device enumeration.
bool is_device_enumeration_disabled_; bool is_device_enumeration_disabled_;