2013-07-31 18:08:45 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
|
|
|
#ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
|
|
|
|
#define BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "base/memory/singleton.h"
|
|
|
|
#include "content/public/browser/media_observer.h"
|
2013-10-07 20:13:01 +00:00
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2013-07-31 18:08:45 +00:00
|
|
|
#include "content/public/common/media_stream_request.h"
|
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
|
|
|
// This singleton is used to receive updates about media events from the content
|
|
|
|
// layer.
|
|
|
|
class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
|
|
|
public:
|
|
|
|
static MediaCaptureDevicesDispatcher* GetInstance();
|
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
// Methods for observers. Called on UI thread.
|
|
|
|
const content::MediaStreamDevices& GetAudioCaptureDevices();
|
|
|
|
const content::MediaStreamDevices& GetVideoCaptureDevices();
|
|
|
|
|
|
|
|
// Helper to get the default devices which can be used by the media request.
|
|
|
|
// Uses the first available devices if the default devices are not available.
|
|
|
|
// If the return list is empty, it means there is no available device on the
|
|
|
|
// OS.
|
|
|
|
// Called on the UI thread.
|
2013-07-31 18:08:45 +00:00
|
|
|
void GetDefaultDevices(bool audio,
|
|
|
|
bool video,
|
|
|
|
content::MediaStreamDevices* devices);
|
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
// Helpers for picking particular requested devices, identified by raw id.
|
|
|
|
// If the device requested is not available it will return NULL.
|
|
|
|
const content::MediaStreamDevice*
|
|
|
|
GetRequestedAudioDevice(const std::string& requested_audio_device_id);
|
|
|
|
const content::MediaStreamDevice*
|
|
|
|
GetRequestedVideoDevice(const std::string& requested_video_device_id);
|
|
|
|
|
|
|
|
// Returns the first available audio or video device, or NULL if no devices
|
|
|
|
// are available.
|
|
|
|
const content::MediaStreamDevice* GetFirstAvailableAudioDevice();
|
|
|
|
const content::MediaStreamDevice* GetFirstAvailableVideoDevice();
|
|
|
|
|
|
|
|
// Unittests that do not require actual device enumeration should call this
|
|
|
|
// API on the singleton. It is safe to call this multiple times on the
|
|
|
|
// signleton.
|
|
|
|
void DisableDeviceEnumerationForTesting();
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
// Overridden from content::MediaObserver:
|
2014-06-26 20:31:32 +00:00
|
|
|
virtual void OnAudioCaptureDevicesChanged() OVERRIDE;
|
|
|
|
virtual void OnVideoCaptureDevicesChanged() OVERRIDE;
|
2013-07-31 18:08:45 +00:00
|
|
|
virtual void OnMediaRequestStateChanged(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
2013-10-07 20:13:01 +00:00
|
|
|
int page_request_id,
|
2014-06-26 20:31:32 +00:00
|
|
|
const GURL& security_origin,
|
2013-07-31 18:08:45 +00:00
|
|
|
const content::MediaStreamDevice& device,
|
|
|
|
content::MediaRequestState state) OVERRIDE;
|
2014-06-26 20:31:32 +00:00
|
|
|
virtual void OnAudioStreamPlaying(
|
2013-07-31 18:08:45 +00:00
|
|
|
int render_process_id,
|
2014-06-26 20:31:32 +00:00
|
|
|
int render_frame_id,
|
2013-07-31 18:08:45 +00:00
|
|
|
int stream_id,
|
2014-06-26 20:31:32 +00:00
|
|
|
const ReadPowerAndClipCallback& power_read_callback) OVERRIDE;
|
|
|
|
virtual void OnAudioStreamStopped(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int stream_id) OVERRIDE;
|
2013-10-07 20:13:01 +00:00
|
|
|
virtual void OnCreatingAudioStream(int render_process_id,
|
|
|
|
int render_view_id) OVERRIDE;
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>;
|
|
|
|
|
|
|
|
MediaCaptureDevicesDispatcher();
|
|
|
|
virtual ~MediaCaptureDevicesDispatcher();
|
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
// Flag used by unittests to disable device enumeration.
|
|
|
|
bool is_device_enumeration_disabled_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher);
|
2013-07-31 18:08:45 +00:00
|
|
|
};
|
|
|
|
|
2013-11-17 23:56:07 +00:00
|
|
|
} // namespace brightray
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
#endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
|