Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1315)

Unified Diff: content/browser/renderer_host/media/video_capture_manager.h

Issue 2738763002: [Mojo Video Capture] Introduce abstraction BuildableVideoCaptureDevice (Closed)
Patch Set: Rebase to Feb 10th and change similarity to 10 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/video_capture_manager.h
diff --git a/content/browser/renderer_host/media/video_capture_manager.h b/content/browser/renderer_host/media/video_capture_manager.h
index 7aa6b59e98f0beef2917083e18df58f9241a2390..3a7727a5f6fb5122375c695ecabbb0397bacb836 100644
--- a/content/browser/renderer_host/media/video_capture_manager.h
+++ b/content/browser/renderer_host/media/video_capture_manager.h
@@ -26,6 +26,7 @@
#include "base/threading/thread_checker.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h"
+#include "content/browser/renderer_host/media/buildable_video_capture_device.h"
#include "content/browser/renderer_host/media/media_stream_provider.h"
#include "content/browser/renderer_host/media/video_capture_controller_event_handler.h"
#include "content/common/content_export.h"
@@ -42,9 +43,11 @@
namespace content {
class VideoCaptureController;
class VideoCaptureControllerEventHandler;
+class VideoCaptureDeviceEntry;
// VideoCaptureManager opens/closes and start/stops video capture devices.
-class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
+class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider,
+ public BuildableDeviceCallbacks {
public:
using VideoCaptureDevice = media::VideoCaptureDevice;
@@ -196,6 +199,14 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
base::Callback<void(const media::VideoCaptureDeviceDescriptors&)>;
void EnumerateDevices(const EnumerationCallback& client_callback);
+ // BuildableDeviceCallbacks implementation:
+ bool LookupDeviceDescriptor(
+ const std::string& id,
+ media::VideoCaptureDeviceDescriptor* descriptor) override;
+ void OnDeviceAboutToStart(media::VideoFacingMode facing_mode) override;
+ void OnDeviceStarted(VideoCaptureDeviceEntry* entry) override;
+ void OnDeviceStartFailed(VideoCaptureDeviceEntry* entry) override;
+
// Retrieves camera calibration information for a particular device. Returns
// nullopt_t if the |device_id| is not found or camera calibration information
// is not available for the device. Camera calibration is cached during
@@ -205,11 +216,10 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
private:
class CaptureDeviceStartRequest;
- struct DeviceEntry;
struct DeviceInfo;
using SessionMap = std::map<media::VideoCaptureSessionId, MediaStreamDevice>;
- using DeviceEntries = std::vector<std::unique_ptr<DeviceEntry>>;
+ using DeviceEntries = std::vector<scoped_refptr<VideoCaptureDeviceEntry>>;
using DeviceInfos = std::vector<DeviceInfo>;
using DeviceStartQueue = std::list<CaptureDeviceStartRequest>;
using VideoCaptureDeviceDescriptor = media::VideoCaptureDeviceDescriptor;
@@ -239,25 +249,29 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
// Checks to see if |entry| has no clients left on its controller. If so,
// remove it from the list of devices, and delete it asynchronously. |entry|
// may be freed by this function.
- void DestroyDeviceEntryIfNoClients(DeviceEntry* entry);
-
- // Finds a DeviceEntry in different ways: by |session_id|, by its |device_id|
- // and |type| (if it is already opened), by its |controller| or by its
- // |serial_id|. In all cases, if not found, nullptr is returned.
- DeviceEntry* GetDeviceEntryBySessionId(int session_id);
- DeviceEntry* GetDeviceEntryByTypeAndId(MediaStreamType type,
- const std::string& device_id) const;
- DeviceEntry* GetDeviceEntryByController(
+ void DestroyDeviceEntryIfNoClients(VideoCaptureDeviceEntry* entry);
+
+ // Finds a VideoCaptureDeviceEntry in different ways: by |session_id|, by its
+ // |device_id| and |type| (if it is already opened), by its |controller| or by
+ // its |serial_id|. In all cases, if not found, nullptr is returned.
+ VideoCaptureDeviceEntry* GetDeviceEntryBySessionId(int session_id);
+ VideoCaptureDeviceEntry* GetDeviceEntryByTypeAndId(
+ MediaStreamType type,
+ const std::string& device_id) const;
+ VideoCaptureDeviceEntry* GetDeviceEntryByController(
const VideoCaptureController* controller) const;
- DeviceEntry* GetDeviceEntryBySerialId(int serial_id) const;
+ VideoCaptureDeviceEntry* GetDeviceEntryBySerialId(int serial_id) const;
+ scoped_refptr<VideoCaptureDeviceEntry> GetDeviceEntrySharedRefBySerialId(
+ int serial_id) const;
// Finds the device info by |id| in |devices_info_cache_|, or nullptr.
DeviceInfo* GetDeviceInfoById(const std::string& id);
- // Finds a DeviceEntry entry for the indicated |capture_session_id|, creating
+ // Finds a VideoCaptureDeviceEntry entry for the indicated
+ // |capture_session_id|, creating
// a fresh one if necessary. Returns nullptr if said |capture_session_id| is
// invalid.
- DeviceEntry* GetOrCreateDeviceEntry(
+ VideoCaptureDeviceEntry* GetOrCreateDeviceEntry(
media::VideoCaptureSessionId capture_session_id,
const media::VideoCaptureParams& params);
@@ -268,51 +282,12 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
// request to start the device on the device thread unless there is
// another request pending start.
void QueueStartDevice(media::VideoCaptureSessionId session_id,
- DeviceEntry* entry,
+ VideoCaptureDeviceEntry* entry,
const media::VideoCaptureParams& params);
- void OnDeviceStarted(
- int serial_id,
- std::unique_ptr<VideoCaptureDevice> device);
- void DoStopDevice(DeviceEntry* entry);
+ void DoStopDevice(VideoCaptureDeviceEntry* entry);
void HandleQueuedStartRequest();
- // Creates and Starts a new VideoCaptureDevice. The resulting
- // VideoCaptureDevice is returned to the IO-thread and stored in
- // a DeviceEntry in |devices_|. Ownership of |client| passes to
- // the device.
- std::unique_ptr<VideoCaptureDevice> DoStartDeviceCaptureOnDeviceThread(
- const VideoCaptureDeviceDescriptor& descriptor,
- const media::VideoCaptureParams& params,
- std::unique_ptr<VideoCaptureDevice::Client> client);
-
- std::unique_ptr<VideoCaptureDevice> DoStartTabCaptureOnDeviceThread(
- const std::string& device_id,
- const media::VideoCaptureParams& params,
- std::unique_ptr<VideoCaptureDevice::Client> client);
-
- std::unique_ptr<VideoCaptureDevice> DoStartDesktopCaptureOnDeviceThread(
- const std::string& device_id,
- const media::VideoCaptureParams& params,
- std::unique_ptr<VideoCaptureDevice::Client> client);
-
- // Stops and destroys the VideoCaptureDevice held in |device|.
- void DoStopDeviceOnDeviceThread(std::unique_ptr<VideoCaptureDevice> device);
-
void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id);
- void SetDesktopCaptureWindowIdOnDeviceThread(
- media::VideoCaptureDevice* device,
- gfx::NativeViewId window_id);
-
- // Internal versions of the Image Capture public ones, for delayed execution.
- void DoGetPhotoCapabilities(
- VideoCaptureDevice::GetPhotoCapabilitiesCallback callback,
- VideoCaptureDevice* device);
- void DoSetPhotoOptions(
- VideoCaptureDevice::SetPhotoOptionsCallback callback,
- media::mojom::PhotoSettingsPtr settings,
- VideoCaptureDevice* device);
- void DoTakePhoto(VideoCaptureDevice::TakePhotoCallback callback,
- VideoCaptureDevice* device);
#if defined(OS_ANDROID)
void ReleaseDevices();
@@ -336,17 +311,15 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
// only on the IO thread.
SessionMap sessions_;
- // Currently opened DeviceEntry instances (each owning a VideoCaptureDevice -
- // VideoCaptureController pair). The device may or may not be started. This
- // member is only accessed on IO thread.
+ // Currently opened VideoCaptureDeviceEntry instances. The device may or may
+ // not be started. This member is only accessed on IO thread.
DeviceEntries devices_;
DeviceStartQueue device_start_queue_;
// Queue to keep photo-associated requests waiting for a device to initialize,
// bundles a session id integer and an associated photo-related request.
- std::list<std::pair<int, base::Callback<void(media::VideoCaptureDevice*)>>>
- photo_request_queue_;
+ std::list<std::pair<int, base::Closure>> photo_request_queue_;
// Device creation factory injected on construction from MediaStreamManager or
// from the test harness.

Powered by Google App Engine
This is Rietveld 408576698