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

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

Issue 2583603002: [Mojo Video Capture] Split OnIncomingCapturedVideoFrame() to OnNewBuffer() + OnFrameReadyInBuffer() (Closed)
Patch Set: Improve naming and fix Android background issue Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/media/video_capture_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_frame_receiver.h" 54 #include "media/capture/video/video_frame_receiver.h"
55 #include "media/capture/video_capture_types.h" 55 #include "media/capture/video_capture_types.h"
56 56
57 namespace media {
58 class FrameBufferPool;
59 }
60
61 namespace content { 57 namespace content {
62 58
63 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver { 59 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver {
64 public: 60 public:
65 VideoCaptureController(); 61 VideoCaptureController();
66 ~VideoCaptureController() override; 62 ~VideoCaptureController() override;
67 63
68 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); 64 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread();
69 65
70 // Factory code creating instances of VideoCaptureController may optionally 66 // Factory code creating instances of VideoCaptureController may optionally
71 // set a FrameBufferPool. Setting the host is done in this method
72 // separate from the constructor to allow clients to create and use instances
73 // before they can provide the observer. (This is the case with
74 // VideoCaptureManager).
75 void SetFrameBufferPool(
76 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool);
77
78 // Factory code creating instances of VideoCaptureController may optionally
79 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in 67 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in
80 // this method separate from the constructor to allow clients to create and 68 // this method separate from the constructor to allow clients to create and
81 // use instances before they can provide the observer. (This is the case with 69 // use instances before they can provide the observer. (This is the case with
82 // VideoCaptureManager). 70 // VideoCaptureManager).
83 void SetConsumerFeedbackObserver( 71 void SetConsumerFeedbackObserver(
84 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); 72 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer);
85 73
86 // Start video capturing and try to use the resolution specified in |params|. 74 // Start video capturing and try to use the resolution specified in |params|.
87 // Buffers will be shared to the client as necessary. The client will continue 75 // Buffers will be shared to the client as necessary. The client will continue
88 // to receive frames from the device until RemoveClient() is called. 76 // to receive frames from the device until RemoveClient() is called.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 VideoCaptureControllerEventHandler* event_handler, 116 VideoCaptureControllerEventHandler* event_handler,
129 int buffer_id, 117 int buffer_id,
130 const gpu::SyncToken& sync_token, 118 const gpu::SyncToken& sync_token,
131 double consumer_resource_utilization); 119 double consumer_resource_utilization);
132 120
133 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; 121 const media::VideoCaptureFormat& GetVideoCaptureFormat() const;
134 122
135 bool has_received_frames() const { return has_received_frames_; } 123 bool has_received_frames() const { return has_received_frames_; }
136 124
137 // Implementation of media::VideoFrameReceiver interface: 125 // Implementation of media::VideoFrameReceiver interface:
138 void OnIncomingCapturedVideoFrame( 126 void OnNewBufferHandle(
139 media::VideoCaptureDevice::Client::Buffer buffer, 127 int buffer_id,
140 scoped_refptr<media::VideoFrame> frame) override; 128 std::unique_ptr<media::BufferHandleProvider> handle_provider) override;
129 void OnFrameReadyInBuffer(
130 int buffer_id,
131 int frame_feedback_id,
132 std::unique_ptr<media::Ownership> buffer_read_permission,
133 media::mojom::VideoFrameInfoPtr frame_info) override;
134 void OnBufferRetired(int buffer_id) override;
141 void OnError() override; 135 void OnError() override;
142 void OnLog(const std::string& message) override; 136 void OnLog(const std::string& message) override;
143 void OnBufferDestroyed(int buffer_id_to_drop) override;
144 137
145 private: 138 private:
146 struct ControllerClient; 139 struct ControllerClient;
147 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 140 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
148 141
149 class BufferState { 142 class BufferState {
150 public: 143 public:
151 explicit BufferState( 144 explicit BufferState(
152 int buffer_id, 145 int buffer_id,
153 int frame_feedback_id,
154 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, 146 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer,
155 media::FrameBufferPool* frame_buffer_pool); 147 mojo::ScopedSharedBufferHandle handle);
148 BufferState(BufferState&& other);
156 ~BufferState(); 149 ~BufferState();
157 BufferState(const BufferState& other); 150 BufferState& operator=(BufferState&& other);
151
152 int buffer_id() const { return buffer_id_; }
153 bool is_retired() const { return is_retired_; }
154 void set_read_permission(
155 std::unique_ptr<media::Ownership> buffer_read_permission);
156 void set_frame_feedback_id(int frame_feedback_id);
157 void set_is_retired() { is_retired_ = true; }
158 void RecordConsumerUtilization(double utilization); 158 void RecordConsumerUtilization(double utilization);
159 void IncreaseConsumerCount(); 159 void IncreaseConsumerCount();
160 void DecreaseConsumerCount(); 160 void DecreaseConsumerCount();
161 bool HasZeroConsumerHoldCount(); 161 bool HasZeroConsumerHoldCount();
162 mojo::ScopedSharedBufferHandle CreateHandleCopy();
162 void SetConsumerFeedbackObserver( 163 void SetConsumerFeedbackObserver(
163 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); 164 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer);
164 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool);
165 165
166 private: 166 private:
167 const int buffer_id_; 167 int buffer_id_;
168 const int frame_feedback_id_; 168 bool is_retired_ = false;
169 int frame_feedback_id_;
169 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; 170 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_;
170 media::FrameBufferPool* frame_buffer_pool_; 171 mojo::ScopedSharedBufferHandle buffer_handle_;
171 double max_consumer_utilization_; 172 double max_consumer_utilization_;
172 int consumer_hold_count_; 173 int consumer_hold_count_;
174 std::unique_ptr<media::Ownership> buffer_read_permission_;
173 }; 175 };
174 176
175 // Find a client of |id| and |handler| in |clients|. 177 // Find a client of |id| and |handler| in |clients|.
176 ControllerClient* FindClient(VideoCaptureControllerID id, 178 ControllerClient* FindClient(VideoCaptureControllerID id,
177 VideoCaptureControllerEventHandler* handler, 179 VideoCaptureControllerEventHandler* handler,
178 const ControllerClients& clients); 180 const ControllerClients& clients);
179 181
180 // Find a client of |session_id| in |clients|. 182 // Find a client of |session_id| in |clients|.
181 ControllerClient* FindClient(int session_id, 183 ControllerClient* FindClient(int session_id,
182 const ControllerClients& clients); 184 const ControllerClients& clients);
183 185
184 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; 186 void OnClientFinishedConsumingBuffer(ControllerClient* client,
187 int buffer_id,
188 double consumer_resource_utilization);
189 void ReleaseBufferState(
190 const std::vector<BufferState>::iterator& buffer_state_iter);
185 191
186 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> 192 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver>
187 consumer_feedback_observer_; 193 consumer_feedback_observer_;
188 194
189 std::map<int, BufferState> buffer_id_to_state_map_; 195 std::vector<BufferState> buffer_states_;
190 196
191 // All clients served by this controller. 197 // All clients served by this controller.
192 ControllerClients controller_clients_; 198 ControllerClients controller_clients_;
193 199
194 // 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
195 // state which stops the flow of data to clients. 201 // state which stops the flow of data to clients.
196 VideoCaptureState state_; 202 VideoCaptureState state_;
197 203
198 // 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.
199 bool has_received_frames_; 205 bool has_received_frames_;
200 206
201 media::VideoCaptureFormat video_capture_format_; 207 media::VideoCaptureFormat video_capture_format_;
202 208
203 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 209 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
204 210
205 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 211 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
206 }; 212 };
207 213
208 } // namespace content 214 } // namespace content
209 215
210 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 216 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/media/video_capture_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698