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

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

Issue 312803002: Android media: VideoFrame should not store so many sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mark OVERRIDE to fix build error Created 6 years, 6 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
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 #include "content/browser/renderer_host/media/video_capture_controller.h" 5 #include "content/browser/renderer_host/media/video_capture_controller.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h" 13 #include "base/metrics/sparse_histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "content/browser/compositor/image_transport_factory.h"
15 #include "content/browser/renderer_host/media/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/video_capture_manager.h" 17 #include "content/browser/renderer_host/media/video_capture_manager.h"
18 #include "content/common/gpu/client/gl_helper.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
18 #include "gpu/command_buffer/common/mailbox_holder.h" 20 #include "gpu/command_buffer/common/mailbox_holder.h"
19 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
20 #include "media/base/video_util.h" 22 #include "media/base/video_util.h"
21 #include "media/base/yuv_convert.h" 23 #include "media/base/yuv_convert.h"
22 #include "third_party/libyuv/include/libyuv.h" 24 #include "third_party/libyuv/include/libyuv.h"
23 25
24 using media::VideoCaptureFormat; 26 using media::VideoCaptureFormat;
25 27
26 namespace content { 28 namespace content {
(...skipping 19 matching lines...) Expand all
46 : Buffer(buffer_id, data, size), pool_(pool) { 48 : Buffer(buffer_id, data, size), pool_(pool) {
47 DCHECK(pool_); 49 DCHECK(pool_);
48 } 50 }
49 51
50 private: 52 private:
51 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } 53 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); }
52 54
53 const scoped_refptr<VideoCaptureBufferPool> pool_; 55 const scoped_refptr<VideoCaptureBufferPool> pool_;
54 }; 56 };
55 57
58 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
59 public:
60 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {}
61 virtual ~SyncPointClientImpl() {}
62 virtual uint32 InsertSyncPoint() OVERRIDE {
63 return gl_helper_->InsertSyncPoint();
64 }
65 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {
66 gl_helper_->WaitSyncPoint(sync_point);
67 }
68
69 private:
70 GLHelper* gl_helper_;
71 };
72
73 void ReturnVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
74 uint32 sync_point) {
75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
76 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
dshwang 2014/06/23 19:42:07 I found that android can not use ImageTransportFac
77 DCHECK(gl_helper);
78 gl_helper->WaitSyncPoint(sync_point);
79 SyncPointClientImpl client(gl_helper);
80 video_frame->UpdateReleaseSyncPoint(&client);
81 }
82
56 } // anonymous namespace 83 } // anonymous namespace
57 84
58 struct VideoCaptureController::ControllerClient { 85 struct VideoCaptureController::ControllerClient {
59 ControllerClient(const VideoCaptureControllerID& id, 86 ControllerClient(const VideoCaptureControllerID& id,
60 VideoCaptureControllerEventHandler* handler, 87 VideoCaptureControllerEventHandler* handler,
61 base::ProcessHandle render_process, 88 base::ProcessHandle render_process,
62 media::VideoCaptureSessionId session_id, 89 media::VideoCaptureSessionId session_id,
63 const media::VideoCaptureParams& params) 90 const media::VideoCaptureParams& params)
64 : controller_id(id), 91 : controller_id(id),
65 event_handler(handler), 92 event_handler(handler),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (client) { 269 if (client) {
243 client->session_closed = true; 270 client->session_closed = true;
244 client->event_handler->OnEnded(client->controller_id); 271 client->event_handler->OnEnded(client->controller_id);
245 } 272 }
246 } 273 }
247 274
248 void VideoCaptureController::ReturnBuffer( 275 void VideoCaptureController::ReturnBuffer(
249 const VideoCaptureControllerID& id, 276 const VideoCaptureControllerID& id,
250 VideoCaptureControllerEventHandler* event_handler, 277 VideoCaptureControllerEventHandler* event_handler,
251 int buffer_id, 278 int buffer_id,
252 const std::vector<uint32>& sync_points) { 279 uint32 sync_point) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); 280 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 281
255 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 282 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
256 283
257 // If this buffer is not held by this client, or this client doesn't exist 284 // If this buffer is not held by this client, or this client doesn't exist
258 // in controller, do nothing. 285 // in controller, do nothing.
259 ControllerClient::ActiveBufferMap::iterator iter; 286 ControllerClient::ActiveBufferMap::iterator iter;
260 if (!client || (iter = client->active_buffers.find(buffer_id)) == 287 if (!client || (iter = client->active_buffers.find(buffer_id)) ==
261 client->active_buffers.end()) { 288 client->active_buffers.end()) {
262 NOTREACHED(); 289 NOTREACHED();
263 return; 290 return;
264 } 291 }
265 scoped_refptr<media::VideoFrame> frame = iter->second; 292 scoped_refptr<media::VideoFrame> frame = iter->second;
266 client->active_buffers.erase(iter); 293 client->active_buffers.erase(iter);
294 buffer_pool_->RelinquishConsumerHold(buffer_id, 1);
267 295
268 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { 296 if (sync_point)
269 for (size_t i = 0; i < sync_points.size(); i++) 297 BrowserThread::PostTask(BrowserThread::UI,
270 frame->AppendReleaseSyncPoint(sync_points[i]); 298 FROM_HERE,
271 } 299 base::Bind(&ReturnVideoFrame, frame, sync_point));
272
273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1);
274 } 300 }
275 301
276 const media::VideoCaptureFormat& 302 const media::VideoCaptureFormat&
277 VideoCaptureController::GetVideoCaptureFormat() const { 303 VideoCaptureController::GetVideoCaptureFormat() const {
278 DCHECK_CURRENTLY_ON(BrowserThread::IO); 304 DCHECK_CURRENTLY_ON(BrowserThread::IO);
279 return video_capture_format_; 305 return video_capture_format_;
280 } 306 }
281 307
282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> 308 scoped_refptr<media::VideoCaptureDevice::Client::Buffer>
283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( 309 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer(
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 667 }
642 return NULL; 668 return NULL;
643 } 669 }
644 670
645 int VideoCaptureController::GetClientCount() { 671 int VideoCaptureController::GetClientCount() {
646 DCHECK_CURRENTLY_ON(BrowserThread::IO); 672 DCHECK_CURRENTLY_ON(BrowserThread::IO);
647 return controller_clients_.size(); 673 return controller_clients_.size();
648 } 674 }
649 675
650 } // namespace content 676 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698