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

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

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fixes for failing bots Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 a VideoCaptureDevice and all 5 // VideoCaptureController is the glue between a VideoCaptureDevice and all
6 // VideoCaptureHosts that have connected to it. A controller exists on behalf of 6 // VideoCaptureHosts that have connected to it. A controller exists on behalf of
7 // one (and only one) VideoCaptureDevice; both are owned by the 7 // one (and only one) VideoCaptureDevice; both are owned by the
8 // VideoCaptureManager. 8 // VideoCaptureManager.
9 // 9 //
10 // The VideoCaptureController is responsible for: 10 // The VideoCaptureController is responsible for:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include <memory> 44 #include <memory>
45 45
46 #include "base/compiler_specific.h" 46 #include "base/compiler_specific.h"
47 #include "base/macros.h" 47 #include "base/macros.h"
48 #include "base/memory/ref_counted.h" 48 #include "base/memory/ref_counted.h"
49 #include "base/memory/weak_ptr.h" 49 #include "base/memory/weak_ptr.h"
50 #include "base/process/process.h" 50 #include "base/process/process.h"
51 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 51 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
52 #include "content/common/content_export.h" 52 #include "content/common/content_export.h"
53 #include "content/common/media/video_capture.h" 53 #include "content/common/media/video_capture.h"
54 #include "media/capture/video/video_capture_device_client.h"
54 #include "media/capture/video/video_frame_receiver.h" 55 #include "media/capture/video/video_frame_receiver.h"
55 #include "media/capture/video_capture_types.h" 56 #include "media/capture/video_capture_types.h"
56 57
57 namespace media { 58 namespace media {
58 class VideoCaptureBufferPool; 59 class VideoCaptureBufferPool;
59 } 60 }
60 61
61 namespace content { 62 namespace content {
62 63
63 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver { 64 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver {
64 public: 65 public:
65 // |max_buffers| is the maximum number of video frame buffers in-flight at any 66 // |max_buffers| is the maximum number of video frame buffers in-flight at any
66 // one time. This value should be based on the logical capacity of the 67 // one time. This value should be based on the logical capacity of the
67 // capture pipeline, and not on hardware performance. For example, tab 68 // capture pipeline, and not on hardware performance. For example, tab
68 // capture requires more buffers than webcam capture because the pipeline is 69 // capture requires more buffers than webcam capture because the pipeline is
69 // longer (it includes read-backs pending in the GPU pipeline). 70 // longer (it includes read-backs pending in the GPU pipeline).
70 explicit VideoCaptureController(int max_buffers); 71 explicit VideoCaptureController(int max_buffers);
71 ~VideoCaptureController() override; 72 ~VideoCaptureController() override;
72 73
73 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); 74 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread();
74 75
76 // Factory code creating instances of VideoCaptureController may optionally
77 // set a FrameReceiverObserver. Setting the observer is done in this method
78 // separate from the constructor to allow clients to create and use instances
79 // before they can provide the observer. (This is the case with
80 // VideoCaptureManager).
81 void SetFrameReceiverObserver(
82 media::FrameReceiverObserver* frame_receiver_observer);
83
75 // Return a new VideoCaptureDeviceClient to forward capture events to this 84 // Return a new VideoCaptureDeviceClient to forward capture events to this
76 // instance. 85 // instance.
77 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); 86 std::unique_ptr<media::VideoCaptureDeviceClient> NewDeviceClient();
78 87
79 // Start video capturing and try to use the resolution specified in |params|. 88 // Start video capturing and try to use the resolution specified in |params|.
80 // Buffers will be shared to the client as necessary. The client will continue 89 // Buffers will be shared to the client as necessary. The client will continue
81 // to receive frames from the device until RemoveClient() is called. 90 // to receive frames from the device until RemoveClient() is called.
82 void AddClient(VideoCaptureControllerID id, 91 void AddClient(VideoCaptureControllerID id,
83 VideoCaptureControllerEventHandler* event_handler, 92 VideoCaptureControllerEventHandler* event_handler,
84 media::VideoCaptureSessionId session_id, 93 media::VideoCaptureSessionId session_id,
85 const media::VideoCaptureParams& params); 94 const media::VideoCaptureParams& params);
86 95
87 // Stop video capture. This will take back all buffers held by by 96 // Stop video capture. This will take back all buffers held by by
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 141 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
133 scoped_refptr<media::VideoFrame> frame) override; 142 scoped_refptr<media::VideoFrame> frame) override;
134 void OnError() override; 143 void OnError() override;
135 void OnLog(const std::string& message) override; 144 void OnLog(const std::string& message) override;
136 void OnBufferDestroyed(int buffer_id_to_drop) override; 145 void OnBufferDestroyed(int buffer_id_to_drop) override;
137 146
138 private: 147 private:
139 struct ControllerClient; 148 struct ControllerClient;
140 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 149 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
141 150
151 class BufferState {
152 public:
153 BufferState();
miu 2016/12/01 05:25:17 IIRC, you don't need the zero-arg constructor if y
chfremer 2016/12/02 01:28:28 Done.
154 explicit BufferState(
155 int buffer_id,
156 media::FrameReceiverObserver* frame_receiver_observer,
157 const scoped_refptr<media::VideoCaptureBufferPool>& buffer_pool,
158 const scoped_refptr<media::VideoFrame>& frame);
159 BufferState(BufferState&& other);
160 ~BufferState();
161 BufferState& operator=(BufferState&& other);
162 void RecordConsumerUtilization(double utilization);
163 void IncreaseConsumerCount();
164 void DecreaseConsumerCount();
165 bool HasZeroConsumerHoldCount();
166
167 private:
168 int buffer_id_;
miu 2016/12/01 05:25:17 If you can eliminate the zero-arg ctor, several of
chfremer 2016/12/02 01:28:28 Done.
169 media::FrameReceiverObserver* frame_receiver_observer_;
170 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
171 scoped_refptr<media::VideoFrame> frame_;
172 double max_consumer_utilization_;
173 int consumer_hold_count_;
174 };
175
142 // Notify renderer that a new buffer has been created. 176 // Notify renderer that a new buffer has been created.
143 void DoNewBufferOnIOThread(ControllerClient* client, 177 void DoNewBufferOnIOThread(ControllerClient* client,
144 media::VideoCaptureDevice::Client::Buffer* buffer, 178 media::VideoCaptureDevice::Client::Buffer* buffer,
145 const scoped_refptr<media::VideoFrame>& frame); 179 const scoped_refptr<media::VideoFrame>& frame);
146 180
147 // Find a client of |id| and |handler| in |clients|. 181 // Find a client of |id| and |handler| in |clients|.
148 ControllerClient* FindClient(VideoCaptureControllerID id, 182 ControllerClient* FindClient(VideoCaptureControllerID id,
149 VideoCaptureControllerEventHandler* handler, 183 VideoCaptureControllerEventHandler* handler,
150 const ControllerClients& clients); 184 const ControllerClients& clients);
151 185
152 // Find a client of |session_id| in |clients|. 186 // Find a client of |session_id| in |clients|.
153 ControllerClient* FindClient(int session_id, 187 ControllerClient* FindClient(int session_id,
154 const ControllerClients& clients); 188 const ControllerClients& clients);
155 189
156 // The pool of shared-memory buffers used for capturing. 190 // The pool of shared-memory buffers used for capturing.
157 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; 191 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
158 192
193 media::FrameReceiverObserver* frame_receiver_observer_;
194
195 std::map<int, BufferState> buffer_id_to_state_map_;
miu 2016/12/01 05:25:17 naming nit: Up to you, but |buffer_states_| or |bu
chfremer 2016/12/02 01:28:28 I could live with |buffer_states_|, but I prefer |
196
159 // All clients served by this controller. 197 // All clients served by this controller.
160 ControllerClients controller_clients_; 198 ControllerClients controller_clients_;
161 199
162 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing 200 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing
163 // state which stops the flow of data to clients. 201 // state which stops the flow of data to clients.
164 VideoCaptureState state_; 202 VideoCaptureState state_;
165 203
166 // True if the controller has received a video frame from the device. 204 // True if the controller has received a video frame from the device.
167 bool has_received_frames_; 205 bool has_received_frames_;
168 206
169 media::VideoCaptureFormat video_capture_format_; 207 media::VideoCaptureFormat video_capture_format_;
170 208
171 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 209 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
172 210
173 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 211 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
174 }; 212 };
175 213
176 } // namespace content 214 } // namespace content
177 215
178 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 216 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698