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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.h

Issue 8417046: refactor video capture in browser process to support device sharing across multiple renderer proc... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // VideoCaptureController is the glue between VideoCaptureHost, 5 // VideoCaptureController is the glue between VideoCaptureHost,
6 // VideoCaptureManager and VideoCaptureDevice. 6 // VideoCaptureManager and VideoCaptureDevice.
7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and 7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and
8 // is responsible for keeping track of TransportDIBs and filling them with I420 8 // is responsible for keeping track of shared DIBs and filling them with I420
9 // video frames for IPC communication between VideoCaptureHost and 9 // video frames for IPC communication between VideoCaptureHost and
10 // VideoCaptureMessageFilter. 10 // VideoCaptureMessageFilter.
11 // It implements media::VideoCaptureDevice::EventHandler to get video frames 11 // It implements media::VideoCaptureDevice::EventHandler to get video frames
12 // from a VideoCaptureDevice object and do color conversion straight into the 12 // from a VideoCaptureDevice object and do color conversion straight into the
13 // TransportDIBs to avoid a memory copy. 13 // shared DIBs to avoid a memory copy.
14 // It serves multiple VideoCaptureControllerEventHandlers.
14 15
15 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 16 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
16 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 17 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
17 18
18 #include <list> 19 #include <list>
19 #include <map> 20 #include <map>
20 21
22 #include "base/compiler_specific.h"
21 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
22 #include "base/process.h" 24 #include "base/process.h"
23 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
24 #include "base/task.h" 26 #include "base/task.h"
25 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 27 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
28 #include "media/video/capture/video_capture.h"
26 #include "media/video/capture/video_capture_device.h" 29 #include "media/video/capture/video_capture_device.h"
27 #include "media/video/capture/video_capture_types.h" 30 #include "media/video/capture/video_capture_types.h"
28 #include "ui/gfx/surface/transport_dib.h"
29 31
30 namespace media_stream { 32 namespace media_stream {
31 class VideoCaptureManager; 33 class VideoCaptureManager;
32 } // namespace media_stream 34 } // namespace media_stream
33 35
34 class VideoCaptureController 36 class VideoCaptureController
35 : public base::RefCountedThreadSafe<VideoCaptureController>, 37 : public base::RefCountedThreadSafe<VideoCaptureController>,
36 public media::VideoCaptureDevice::EventHandler { 38 public media::VideoCaptureDevice::EventHandler {
37 public: 39 public:
38 VideoCaptureController( 40 VideoCaptureController(
39 const VideoCaptureControllerID& id,
40 base::ProcessHandle render_process,
41 VideoCaptureControllerEventHandler* event_handler,
42 media_stream::VideoCaptureManager* video_capture_manager); 41 media_stream::VideoCaptureManager* video_capture_manager);
43 virtual ~VideoCaptureController(); 42 virtual ~VideoCaptureController();
44 43
45 // Starts video capturing and tries to use the resolution specified in 44 // Start video capturing and try to use the resolution specified in
46 // params. 45 // |params|.
47 // When capturing has started VideoCaptureControllerEventHandler::OnFrameInfo 46 // When capturing has started, the |event_handler| receives a call OnFrameInfo
48 // is called with resolution that best matches the requested that the video 47 // with resolution that best matches the requested that the video
49 // capture device support. 48 // capture device support.
50 void StartCapture(const media::VideoCaptureParams& params); 49 void StartCapture(const VideoCaptureControllerID& id,
50 VideoCaptureControllerEventHandler* event_handler,
51 base::ProcessHandle render_process,
52 const media::VideoCaptureParams& params);
51 53
52 // Stop video capture. 54 // Stop video capture.
53 // When the capture is stopped and all TransportDIBS have been returned 55 // When the capture is stopped and all DIBs have been returned,
54 // VideoCaptureControllerEventHandler::OnReadyToDelete will be called. 56 // VideoCaptureControllerEventHandler::OnReadyToDelete will be called.
55 // |stopped_cb| may be NULL. But a non-NULL Closure can be used to get 57 // |force_buffer_return| allows controller to take back all buffers used
56 // a notification when the device is stopped, regardless of 58 // by |event_handler|.
57 // VideoCaptureController's state. 59 void StopCapture(const VideoCaptureControllerID& id,
58 void StopCapture(base::Closure stopped_cb); 60 VideoCaptureControllerEventHandler* event_handler,
61 bool force_buffer_return);
59 62
60 // Return a buffer previously given in 63 // Return a buffer previously given in
61 // VideoCaptureControllerEventHandler::OnBufferReady. 64 // VideoCaptureControllerEventHandler::OnBufferReady.
62 void ReturnBuffer(int buffer_id); 65 void ReturnBuffer(const VideoCaptureControllerID& id,
66 VideoCaptureControllerEventHandler* event_handler,
67 int buffer_id);
63 68
64 // Implement media::VideoCaptureDevice::EventHandler. 69 // Implement media::VideoCaptureDevice::EventHandler.
65 virtual void OnIncomingCapturedFrame(const uint8* data, 70 virtual void OnIncomingCapturedFrame(const uint8* data,
66 int length, 71 int length,
67 base::Time timestamp); 72 base::Time timestamp) OVERRIDE;
68 virtual void OnError(); 73 virtual void OnError() OVERRIDE;
69 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info); 74 virtual void OnFrameInfo(
75 const media::VideoCaptureDevice::Capability& info) OVERRIDE;
70 76
71 private: 77 private:
72 // Called by VideoCaptureManager when a device have been stopped. 78 struct ControllerClient;
73 void OnDeviceStopped(base::Closure stopped_cb); 79 typedef std::list<ControllerClient*> ControllerClients;
80
81 struct SharedDIB;
scherkus (not reviewing) 2011/11/01 02:18:38 nit: move this down to where SharedDIB is used
wjia(left Chromium) 2011/11/01 21:34:23 Done.
82
83 // Callback when manager has stopped device.
84 void OnDeviceStopped();
85
86 // Worker functions on IO thread.
87 void DoIncomingCapturedFrameOnIOThread(int buffer_id, base::Time timestamp);
88 void DoFrameInfoOnIOThread(const media::VideoCaptureDevice::Capability info);
89 void DoErrorOnIOThread();
90 void DoDeviceStateOnIOThread(bool in_use);
91 void DoDeviceStoppedOnIOThread();
92
93 // Send frame info and init buffers to |client|.
94 void SendFrameInfoAndBuffers(ControllerClient* client, int buffer_size);
95
96 // Helpers.
97 // Find a client of |id| and |handler| in |clients|.
98 ControllerClient* FindClient(
99 const VideoCaptureControllerID& id,
100 VideoCaptureControllerEventHandler* handler,
101 ControllerClients& clients);
102 // Decide what to do after kStopping state. Dependent on events, controller
103 // can stay in kStopping state, or go to kStopped, or restart capture.
104 void PostStopping();
105 // Check if any DIB is used by client.
106 bool ClientHasDIB();
74 107
75 // Lock to protect free_dibs_ and owned_dibs_. 108 // Lock to protect free_dibs_ and owned_dibs_.
76 base::Lock lock_; 109 base::Lock lock_;
77 // Handle to the render process that will receive the DIBs.
78 base::ProcessHandle render_handle_;
79 bool report_ready_to_delete_;
80 typedef std::list<int> DIBHandleList;
81 typedef std::map<int, base::SharedMemory*> DIBMap;
82 110
83 // Free DIBS that can be filled with video frames. 111 typedef std::list<int /*buffer_id*/> DIBHandleList;
112 // Free DIBs that can be filled with video frames.
113 // It can be modified on both IO and device threads.
84 DIBHandleList free_dibs_; 114 DIBHandleList free_dibs_;
scherkus (not reviewing) 2011/11/01 02:18:38 why do you still need free_dibs_? if I follow the
85 115
86 // All DIBS created by this object. 116 typedef std::map<int /*buffer_id*/, SharedDIB*> DIBMap;
117 // All DIBs created by this object.
118 // It's modified only on IO thread.
87 DIBMap owned_dibs_; 119 DIBMap owned_dibs_;
88 VideoCaptureControllerEventHandler* event_handler_;
89 120
90 // The parameter that was requested when starting the capture device. 121 // All clients served by this controller.
91 media::VideoCaptureParams params_; 122 ControllerClients controller_clients_;
92 123
93 // ID used for identifying this object. 124 // All clients waiting for service.
94 VideoCaptureControllerID id_; 125 ControllerClients pending_clients_;
126
127 // The parameter that currently used for the capturing.
128 media::VideoCaptureParams current_params_;
129
95 media::VideoCaptureDevice::Capability frame_info_; 130 media::VideoCaptureDevice::Capability frame_info_;
131 bool frame_info_available_;
96 132
97 media_stream::VideoCaptureManager* video_capture_manager_; 133 media_stream::VideoCaptureManager* video_capture_manager_;
98 134
135 bool device_in_use_;
136 media::VideoCapture::State state_;
137
99 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); 138 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController);
100 }; 139 };
101 140
102 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 141 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698