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

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

Issue 8304017: enable video capture to support sharing across multiple renderer processes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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_controller.h
===================================================================
--- content/browser/renderer_host/media/video_capture_controller.h (revision 105502)
+++ content/browser/renderer_host/media/video_capture_controller.h (working copy)
@@ -5,12 +5,13 @@
// VideoCaptureController is the glue between VideoCaptureHost,
// VideoCaptureManager and VideoCaptureDevice.
// It provides functions for VideoCaptureHost to start a VideoCaptureDevice and
-// is responsible for keeping track of TransportDIBs and filling them with I420
+// is responsible for keeping track of shared DIBs and filling them with I420
// video frames for IPC communication between VideoCaptureHost and
// VideoCaptureMessageFilter.
// It implements media::VideoCaptureDevice::EventHandler to get video frames
// from a VideoCaptureDevice object and do color conversion straight into the
-// TransportDIBs to avoid a memory copy.
+// shared DIBs to avoid a memory copy.
+// It serves multiple VideoCaptureControllerEventHandlers.
#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
@@ -23,9 +24,9 @@
#include "base/synchronization/lock.h"
#include "base/task.h"
#include "content/browser/renderer_host/media/video_capture_controller_event_handler.h"
+#include "media/video/capture/video_capture.h"
#include "media/video/capture/video_capture_device.h"
#include "media/video/capture/video_capture_types.h"
-#include "ui/gfx/surface/transport_dib.h"
namespace media_stream {
class VideoCaptureManager;
@@ -36,30 +37,33 @@
public media::VideoCaptureDevice::EventHandler {
public:
VideoCaptureController(
- const VideoCaptureControllerID& id,
- base::ProcessHandle render_process,
- VideoCaptureControllerEventHandler* event_handler,
media_stream::VideoCaptureManager* video_capture_manager);
virtual ~VideoCaptureController();
- // Starts video capturing and tries to use the resolution specified in
- // params.
- // When capturing has started VideoCaptureControllerEventHandler::OnFrameInfo
- // is called with resolution that best matches the requested that the video
+ // Start video capturing and try to use the resolution specified in
+ // |params|.
+ // When capturing has started, the |event_handler| receives a call OnFrameInfo
+ // with resolution that best matches the requested that the video
// capture device support.
- void StartCapture(const media::VideoCaptureParams& params);
+ void StartCapture(const VideoCaptureControllerID& id,
+ VideoCaptureControllerEventHandler* event_handler,
+ base::ProcessHandle render_process,
+ const media::VideoCaptureParams& params);
// Stop video capture.
- // When the capture is stopped and all TransportDIBS have been returned
+ // When the capture is stopped and all DIBs have been returned,
// VideoCaptureControllerEventHandler::OnReadyToDelete will be called.
- // |stopped_cb| may be NULL. But a non-NULL Closure can be used to get
- // a notification when the device is stopped, regardless of
- // VideoCaptureController's state.
- void StopCapture(base::Closure stopped_cb);
+ // |force_buffer_return| allows controller to take back all buffers used
+ // by |event_handler|.
+ void StopCapture(const VideoCaptureControllerID& id,
+ VideoCaptureControllerEventHandler* event_handler,
+ bool force_buffer_return);
// Return a buffer previously given in
// VideoCaptureControllerEventHandler::OnBufferReady.
- void ReturnBuffer(int buffer_id);
+ void ReturnBuffer(const VideoCaptureControllerID& id,
+ VideoCaptureControllerEventHandler* event_handler,
+ int buffer_id);
// Implement media::VideoCaptureDevice::EventHandler.
virtual void OnIncomingCapturedFrame(const uint8* data,
@@ -67,35 +71,73 @@
base::Time timestamp);
virtual void OnError();
virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info);
+ virtual void OnDeviceState(bool in_use);
private:
- // Called by VideoCaptureManager when a device have been stopped.
- void OnDeviceStopped(base::Closure stopped_cb);
+ struct ControllerClient {
scherkus (not reviewing) 2011/10/19 18:02:21 nit: you can forward declare this and move the imp
wjia(left Chromium) 2011/10/21 00:56:13 Done.
+ ControllerClient(const VideoCaptureControllerID& id,
+ VideoCaptureControllerEventHandler* handler,
+ base::ProcessHandle render_process,
+ const media::VideoCaptureParams& params);
+ ~ControllerClient();
+ // ID used for identifying this object.
+ VideoCaptureControllerID controller_id;
+ VideoCaptureControllerEventHandler* event_handler;
+ // Handle to the render process that will receive the DIBs.
+ base::ProcessHandle render_process_handle;
+ const media::VideoCaptureParams parameters;
+ // Buffers used by this client.
+ std::list<int> buffers;
+ bool report_ready_to_delete;
perkj_chrome 2011/10/17 08:39:43 can you explain how report_ready_to_delete is used
wjia(left Chromium) 2011/10/21 00:56:13 When controller client calls StopCapture, but it h
+ };
+ typedef std::list<ControllerClient*> ControllerClients;
+
+ // Worker functions on IO thread.
+ void DoIncomingCapturedFrameOnIOThread(int buffer_id, base::Time timestamp);
+ void DoFrameInfoOnIOThread(const media::VideoCaptureDevice::Capability info);
+ void DoErrorOnIOThread();
+ void DoDeviceStateOnIOThread(bool in_use);
+
+ // Send frame info and init buffers to |client|.
+ void SendFrameInfoAndBuffers(ControllerClient* client);
+
+ // Helpers.
+ ControllerClients::iterator FindClient(
+ const VideoCaptureControllerID& id,
+ VideoCaptureControllerEventHandler* handler);
+
// Lock to protect free_dibs_ and owned_dibs_.
base::Lock lock_;
- // Handle to the render process that will receive the DIBs.
- base::ProcessHandle render_handle_;
- bool report_ready_to_delete_;
- typedef std::list<int> DIBHandleList;
- typedef std::map<int, base::SharedMemory*> DIBMap;
- // Free DIBS that can be filled with video frames.
+ typedef std::list<int /*buffer_id*/> DIBHandleList;
+ // Free DIBs that can be filled with video frames.
+ // Modified on both IO and device threads.
DIBHandleList free_dibs_;
- // All DIBS created by this object.
+ typedef std::map<int /*buffer_id*/, base::SharedMemory*> DIBMap;
+ // All DIBs created by this object.
+ // Modified on only IO thread.
perkj_chrome 2011/10/17 08:39:43 nit: sentence
wjia(left Chromium) 2011/10/21 00:56:13 Done.
DIBMap owned_dibs_;
- VideoCaptureControllerEventHandler* event_handler_;
+ typedef std::map<int /*buffer_id*/, int /*count*/> UsedDIBsCount;
+ // Keep count of clients to which a DIB has been sent.
+ // Modified on only IO thread.
+ UsedDIBsCount used_dibs_count_;
+
+ // All clients served by this controller.
+ ControllerClients controller_clients_;
+
// The parameter that was requested when starting the capture device.
media::VideoCaptureParams params_;
- // ID used for identifying this object.
- VideoCaptureControllerID id_;
media::VideoCaptureDevice::Capability frame_info_;
+ bool frame_info_available_;
media_stream::VideoCaptureManager* video_capture_manager_;
+ media::VideoCapture::State state_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController);
};

Powered by Google App Engine
This is Rietveld 408576698