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

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

Issue 801363002: Queue commands to the Os to start a video device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comments. Created 6 years 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 58ed04b6be5e8040f65fca8f6a3ca006a32ff19a..f8bc4b35bde24acd3a85178f2f5d86f8987a6834 100644
--- a/content/browser/renderer_host/media/video_capture_manager.h
+++ b/content/browser/renderer_host/media/video_capture_manager.h
@@ -12,11 +12,13 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
+#include <list>
#include <map>
#include <set>
#include <string>
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/process/process_handle.h"
@@ -182,18 +184,34 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
const media::VideoCaptureDeviceInfos& old_device_info_cache,
scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot);
- // Creates and Starts a new VideoCaptureDevice, storing the result in
- // |entry->video_capture_device|. Ownership of |client| passes to
+ // Starting a capture device can take 1-2 seconds.
+ // To avoid multiple unnecessary start/stop commands to the OS, each start
+ // request is queued in |device_start_queue_|.
+ // QueueStartDevice creates a new entry in |device_start_queue_| and posts a
+ // request to start the device on the device thread unless there is
+ // another request pending start.
+ void QueueStartDevice(media::VideoCaptureSessionId session_id,
+ DeviceEntry* entry,
+ const media::VideoCaptureParams& params);
+ void OnDeviceStarted(DeviceEntry* device_entry,
+ scoped_ptr<media::VideoCaptureDevice> device);
+ void DoStopDevice(DeviceEntry* 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.
- void DoStartDeviceOnDeviceThread(
+ scoped_ptr<media::VideoCaptureDevice> DoStartDeviceOnDeviceThread(
media::VideoCaptureSessionId session_id,
- DeviceEntry* entry,
+ const std::string& device_id,
+ MediaStreamType stream_type,
const media::VideoCaptureParams& params,
scoped_ptr<media::VideoCaptureDevice::Client> client);
// Stops and destroys the VideoCaptureDevice held in
- // |entry->video_capture_device|.
- void DoStopDeviceOnDeviceThread(DeviceEntry* entry);
+ // |device|.
+ void DoStopDeviceOnDeviceThread(scoped_ptr<media::VideoCaptureDevice> device);
media::VideoCaptureDeviceInfo* FindDeviceInfoById(
const std::string& id,
@@ -226,9 +244,7 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
// when they are not used any longer.
//
// The set of currently started VideoCaptureDevice and VideoCaptureController
- // objects is only accessed from IO thread, though the DeviceEntry instances
- // themselves may visit to the device thread for device creation and
- // destruction.
+ // objects is only accessed from IO thread.
struct DeviceEntry {
DeviceEntry(MediaStreamType stream_type,
const std::string& id,
@@ -244,9 +260,24 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
// The capture device. Only used from the device thread.
scoped_ptr<media::VideoCaptureDevice> video_capture_device;
};
- typedef std::set<DeviceEntry*> DeviceEntries;
+ typedef ScopedVector<DeviceEntry> DeviceEntries;
tommi (sloooow) - chröme 2014/12/16 22:31:25 nit: empty line before this one
perkj_chrome 2014/12/17 10:14:10 Done.
+ // Currently opened devices. The device may or may not be started.
DeviceEntries devices_;
+ // Struct used for queing request for starting a device.
+ struct CaptureDeviceStartRequest {
+ CaptureDeviceStartRequest(
+ DeviceEntry* entry,
+ media::VideoCaptureSessionId session_id,
+ const media::VideoCaptureParams& params);
+
+ DeviceEntry* entry; // Owned by |devices_|
tommi (sloooow) - chröme 2014/12/16 22:31:25 do we use this pointer? (If it's only used for loo
perkj_chrome 2014/12/17 10:14:10 Well, its used in HandleQueuedStartRequest() but w
tommi (sloooow) - chröme 2014/12/17 14:46:12 What about making this pointer type a void* to mak
+ media::VideoCaptureSessionId session_id;
+ media::VideoCaptureParams params;
+ };
+ typedef std::list<CaptureDeviceStartRequest> DeviceStartQueue;
tommi (sloooow) - chröme 2014/12/16 22:31:25 nit: empty line above
perkj_chrome 2014/12/17 10:14:10 Done.
perkj_chrome 2014/12/17 10:14:10 Done.
+ DeviceStartQueue device_start_queue_;
+
// Device creation factory injected on construction from MediaStreamManager or
// from the test harness.
scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_;

Powered by Google App Engine
This is Rietveld 408576698