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

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: address reviewers' comments Created 6 years, 5 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/renderer_host/media/media_stream_manager.h" 15 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/video_capture_manager.h" 16 #include "content/browser/renderer_host/media/video_capture_manager.h"
17 #include "content/common/gpu/client/gl_helper.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "gpu/command_buffer/common/mailbox_holder.h" 19 #include "gpu/command_buffer/common/mailbox_holder.h"
19 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
20 #include "media/base/video_util.h" 21 #include "media/base/video_util.h"
21 #include "media/base/yuv_convert.h" 22 #include "media/base/yuv_convert.h"
22 #include "third_party/libyuv/include/libyuv.h" 23 #include "third_party/libyuv/include/libyuv.h"
23 24
25 #if defined(OS_ANDROID)
26 #include "content/browser/renderer_host/image_transport_factory_android.h"
27 #else
28 #include "content/browser/compositor/image_transport_factory.h"
29 #endif
30
24 using media::VideoCaptureFormat; 31 using media::VideoCaptureFormat;
25 32
26 namespace content { 33 namespace content {
27 34
28 namespace { 35 namespace {
29 36
30 static const int kInfiniteRatio = 99999; 37 static const int kInfiniteRatio = 99999;
31 38
32 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ 39 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \
33 UMA_HISTOGRAM_SPARSE_SLOWLY( \ 40 UMA_HISTOGRAM_SPARSE_SLOWLY( \
(...skipping 12 matching lines...) Expand all
46 : Buffer(buffer_id, data, size), pool_(pool) { 53 : Buffer(buffer_id, data, size), pool_(pool) {
47 DCHECK(pool_); 54 DCHECK(pool_);
48 } 55 }
49 56
50 private: 57 private:
51 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); } 58 virtual ~PoolBuffer() { pool_->RelinquishProducerReservation(id()); }
52 59
53 const scoped_refptr<VideoCaptureBufferPool> pool_; 60 const scoped_refptr<VideoCaptureBufferPool> pool_;
54 }; 61 };
55 62
63 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
64 public:
65 explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {}
66 virtual ~SyncPointClientImpl() {}
67 virtual uint32 InsertSyncPoint() OVERRIDE {
68 return gl_helper_->InsertSyncPoint();
69 }
70 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {
71 gl_helper_->WaitSyncPoint(sync_point);
72 }
73
74 private:
75 GLHelper* gl_helper_;
76 };
77
78 void ReturnVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
79 uint32 sync_point) {
80 DCHECK_CURRENTLY_ON(BrowserThread::UI);
81 #if defined(OS_ANDROID)
82 GLHelper* gl_helper =
83 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
84 #else
85 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
86 #endif
87 DCHECK(gl_helper);
88 // UpdateReleaseSyncPoint() creates a new sync_point using |gl_helper|, so
89 // wait the given |sync_point| using |gl_helper|.
dshwang 2014/07/10 21:44:25 sievers@, add a comment
90 gl_helper->WaitSyncPoint(sync_point);
91 SyncPointClientImpl client(gl_helper);
92 video_frame->UpdateReleaseSyncPoint(&client);
93 }
94
56 } // anonymous namespace 95 } // anonymous namespace
57 96
58 struct VideoCaptureController::ControllerClient { 97 struct VideoCaptureController::ControllerClient {
59 ControllerClient(const VideoCaptureControllerID& id, 98 ControllerClient(const VideoCaptureControllerID& id,
60 VideoCaptureControllerEventHandler* handler, 99 VideoCaptureControllerEventHandler* handler,
61 base::ProcessHandle render_process, 100 base::ProcessHandle render_process,
62 media::VideoCaptureSessionId session_id, 101 media::VideoCaptureSessionId session_id,
63 const media::VideoCaptureParams& params) 102 const media::VideoCaptureParams& params)
64 : controller_id(id), 103 : controller_id(id),
65 event_handler(handler), 104 event_handler(handler),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (client) { 281 if (client) {
243 client->session_closed = true; 282 client->session_closed = true;
244 client->event_handler->OnEnded(client->controller_id); 283 client->event_handler->OnEnded(client->controller_id);
245 } 284 }
246 } 285 }
247 286
248 void VideoCaptureController::ReturnBuffer( 287 void VideoCaptureController::ReturnBuffer(
249 const VideoCaptureControllerID& id, 288 const VideoCaptureControllerID& id,
250 VideoCaptureControllerEventHandler* event_handler, 289 VideoCaptureControllerEventHandler* event_handler,
251 int buffer_id, 290 int buffer_id,
252 const std::vector<uint32>& sync_points) { 291 uint32 sync_point) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); 292 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 293
255 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 294 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
256 295
257 // If this buffer is not held by this client, or this client doesn't exist 296 // If this buffer is not held by this client, or this client doesn't exist
258 // in controller, do nothing. 297 // in controller, do nothing.
259 ControllerClient::ActiveBufferMap::iterator iter; 298 ControllerClient::ActiveBufferMap::iterator iter;
260 if (!client || (iter = client->active_buffers.find(buffer_id)) == 299 if (!client || (iter = client->active_buffers.find(buffer_id)) ==
261 client->active_buffers.end()) { 300 client->active_buffers.end()) {
262 NOTREACHED(); 301 NOTREACHED();
263 return; 302 return;
264 } 303 }
265 scoped_refptr<media::VideoFrame> frame = iter->second; 304 scoped_refptr<media::VideoFrame> frame = iter->second;
266 client->active_buffers.erase(iter); 305 client->active_buffers.erase(iter);
306 buffer_pool_->RelinquishConsumerHold(buffer_id, 1);
267 307
268 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { 308 if (sync_point)
269 for (size_t i = 0; i < sync_points.size(); i++) 309 BrowserThread::PostTask(BrowserThread::UI,
270 frame->AppendReleaseSyncPoint(sync_points[i]); 310 FROM_HERE,
271 } 311 base::Bind(&ReturnVideoFrame, frame, sync_point));
272
273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1);
274 } 312 }
275 313
276 const media::VideoCaptureFormat& 314 const media::VideoCaptureFormat&
277 VideoCaptureController::GetVideoCaptureFormat() const { 315 VideoCaptureController::GetVideoCaptureFormat() const {
278 DCHECK_CURRENTLY_ON(BrowserThread::IO); 316 DCHECK_CURRENTLY_ON(BrowserThread::IO);
279 return video_capture_format_; 317 return video_capture_format_;
280 } 318 }
281 319
282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> 320 scoped_refptr<media::VideoCaptureDevice::Client::Buffer>
283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( 321 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer(
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 679 }
642 return NULL; 680 return NULL;
643 } 681 }
644 682
645 int VideoCaptureController::GetClientCount() { 683 int VideoCaptureController::GetClientCount() {
646 DCHECK_CURRENTLY_ON(BrowserThread::IO); 684 DCHECK_CURRENTLY_ON(BrowserThread::IO);
647 return controller_clients_.size(); 685 return controller_clients_.size();
648 } 686 }
649 687
650 } // namespace content 688 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698