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

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: Adressed comments. Created 5 years, 11 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
« no previous file with comments | « no previous file | content/browser/renderer_host/media/video_capture_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8bf7ddc1609b50dbd89eb60ae31037100f800561 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(int serial_id,
+ 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,15 +244,14 @@ 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,
scoped_ptr<VideoCaptureController> controller);
~DeviceEntry();
+ const int serial_id;
const MediaStreamType stream_type;
const std::string id;
@@ -244,9 +261,39 @@ 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;
+ // Currently opened devices. The device may or may not be started.
DeviceEntries devices_;
+ // Class used for queuing request for starting a device.
+ class CaptureDeviceStartRequest {
+ public:
+ CaptureDeviceStartRequest(
+ int serial_id,
+ media::VideoCaptureSessionId session_id,
+ const media::VideoCaptureParams& params);
+ int serial_id() const { return serial_id_;}
+ media::VideoCaptureSessionId session_id() const { return session_id_; }
+ media::VideoCaptureParams params() const { return params_; }
+
+ // Set to true if the device should be stopped before it has successfully
+ // been started.
+ bool abort_start() const { return abort_start_; }
+ void set_abort_start() { abort_start_ = true; }
+
+ private:
+ const int serial_id_;
+ const media::VideoCaptureSessionId session_id_;
+ const media::VideoCaptureParams params_;
+ // Set to true if the device should be stopped before it has successfully
+ // been started.
+ bool abort_start_;
+ };
+
+ typedef std::list<CaptureDeviceStartRequest> DeviceStartQueue;
+ 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_;
« no previous file with comments | « no previous file | content/browser/renderer_host/media/video_capture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698