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

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

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reuse VASurface Created 5 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_device_client.h" 5 #include "content/browser/renderer_host/media/video_capture_device_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/browser/compositor/image_transport_factory.h" 10 #include "content/browser/compositor/image_transport_factory.h"
11 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 11 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
13 #include "content/browser/gpu/gpu_data_manager_impl.h" 13 #include "content/browser/gpu/gpu_data_manager_impl.h"
14 #include "content/browser/renderer_host/gpu_jpeg_decoder.h"
14 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" 15 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
15 #include "content/browser/renderer_host/media/video_capture_controller.h" 16 #include "content/browser/renderer_host/media/video_capture_controller.h"
16 #include "content/common/gpu/client/context_provider_command_buffer.h" 17 #include "content/common/gpu/client/context_provider_command_buffer.h"
17 #include "content/common/gpu/client/gl_helper.h" 18 #include "content/common/gpu/client/gl_helper.h"
18 #include "content/common/gpu/client/gpu_channel_host.h" 19 #include "content/common/gpu/client/gpu_channel_host.h"
19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 20 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
20 #include "content/common/gpu/gpu_process_launch_causes.h" 21 #include "content/common/gpu/gpu_process_launch_causes.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "gpu/command_buffer/common/mailbox_holder.h" 23 #include "gpu/command_buffer/common/mailbox_holder.h"
23 #include "media/base/bind_to_current_loop.h" 24 #include "media/base/bind_to_current_loop.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 pool_(pool), 114 pool_(pool),
114 buffer_handle_(pool_->GetBufferHandle(buffer_id).Pass()) { 115 buffer_handle_(pool_->GetBufferHandle(buffer_id).Pass()) {
115 DCHECK(pool_.get()); 116 DCHECK(pool_.get());
116 } 117 }
117 int id() const override { return id_; } 118 int id() const override { return id_; }
118 size_t size() const override { return buffer_handle_->size(); } 119 size_t size() const override { return buffer_handle_->size(); }
119 void* data() override { return buffer_handle_->data(); } 120 void* data() override { return buffer_handle_->data(); }
120 ClientBuffer AsClientBuffer() override { 121 ClientBuffer AsClientBuffer() override {
121 return buffer_handle_->AsClientBuffer(); 122 return buffer_handle_->AsClientBuffer();
122 } 123 }
124 base::SharedMemoryHandle AsPlatformHandle() override {
125 return buffer_handle_->AsPlatformHandle();
126 }
123 127
124 private: 128 private:
125 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } 129 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
126 130
127 const int id_; 131 const int id_;
128 const scoped_refptr<VideoCaptureBufferPool> pool_; 132 const scoped_refptr<VideoCaptureBufferPool> pool_;
129 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; 133 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_;
130 }; 134 };
131 135
132 // Internal ref-counted class wrapping an incoming GpuMemoryBuffer into a 136 // Internal ref-counted class wrapping an incoming GpuMemoryBuffer into a
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 194
191 VideoCaptureDeviceClient::VideoCaptureDeviceClient( 195 VideoCaptureDeviceClient::VideoCaptureDeviceClient(
192 const base::WeakPtr<VideoCaptureController>& controller, 196 const base::WeakPtr<VideoCaptureController>& controller,
193 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, 197 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool,
194 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner) 198 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner)
195 : controller_(controller), 199 : controller_(controller),
196 buffer_pool_(buffer_pool), 200 buffer_pool_(buffer_pool),
197 capture_task_runner_(capture_task_runner), 201 capture_task_runner_(capture_task_runner),
198 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) { 202 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {
199 DCHECK_CURRENTLY_ON(BrowserThread::IO); 203 DCHECK_CURRENTLY_ON(BrowserThread::IO);
204 if (GpuJpegDecoder::Supported()) {
205 external_jpeg_decoder_.reset(new GpuJpegDecoder(
206 this,
207 base::Bind(
208 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
209 controller_)));
210 }
200 } 211 }
201 212
202 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {} 213 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
214 }
203 215
204 void VideoCaptureDeviceClient::OnIncomingCapturedData( 216 void VideoCaptureDeviceClient::OnIncomingCapturedData(
205 const uint8* data, 217 const uint8* data,
206 int length, 218 int length,
207 const VideoCaptureFormat& frame_format, 219 const VideoCaptureFormat& frame_format,
208 int rotation, 220 int rotation,
209 const base::TimeTicks& timestamp) { 221 const base::TimeTicks& timestamp) {
210 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); 222 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData");
211 223
212 if (last_captured_pixel_format_ != frame_format.pixel_format) { 224 if (last_captured_pixel_format_ != frame_format.pixel_format) {
213 OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString( 225 OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString(
214 frame_format.pixel_format)); 226 frame_format.pixel_format));
215 last_captured_pixel_format_ = frame_format.pixel_format; 227 last_captured_pixel_format_ = frame_format.pixel_format;
228
229 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
230 external_jpeg_decoder_)
mcasas 2015/05/07 00:59:03 With this condition, we would be calling external
wuchengli 2015/05/07 06:23:14 Not every incoming frame. Only when format changes
kcwu 2015/05/08 14:42:42 This only happens when pixel_format becomes from n
kcwu 2015/05/08 14:42:42 Acknowledged.
231 ignore_result(external_jpeg_decoder_->Initialize());
wuchengli 2015/05/04 14:14:41 Why not set |external_jpeg_decoder_| to NULL if In
wuchengli 2015/05/06 07:59:18 As discussed, if Initialize fails, there will be n
kcwu 2015/05/08 14:42:42 Done.
kcwu 2015/05/08 14:42:42 Done.
216 } 232 }
217 233
218 if (!frame_format.IsValid()) 234 if (!frame_format.IsValid())
219 return; 235 return;
220 236
237 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
238 external_jpeg_decoder_) {
mcasas 2015/05/07 00:59:03 nit: Merge all conditions in lines l.237-238.
kcwu 2015/05/08 14:42:42 Acknowledged. This is changed to no fallback.
239 if (external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format,
240 rotation, timestamp))
241 return;
242 }
243
221 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest 244 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest
222 // bit decomposition of {width, height}, grabbing the odd and even parts. 245 // bit decomposition of {width, height}, grabbing the odd and even parts.
223 const int chopped_width = frame_format.frame_size.width() & 1; 246 const int chopped_width = frame_format.frame_size.width() & 1;
224 const int chopped_height = frame_format.frame_size.height() & 1; 247 const int chopped_height = frame_format.frame_size.height() & 1;
225 const int new_unrotated_width = frame_format.frame_size.width() & ~1; 248 const int new_unrotated_width = frame_format.frame_size.width() & ~1;
226 const int new_unrotated_height = frame_format.frame_size.height() & ~1; 249 const int new_unrotated_height = frame_format.frame_size.height() & ~1;
227 250
228 int destination_width = new_unrotated_width; 251 int destination_width = new_unrotated_width;
229 int destination_height = new_unrotated_height; 252 int destination_height = new_unrotated_height;
230 if (rotation == 90 || rotation == 270) { 253 if (rotation == 90 || rotation == 270) {
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( 687 void VideoCaptureDeviceClient::TextureWrapHelper::OnError(
665 const std::string& message) { 688 const std::string& message) {
666 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 689 DCHECK(capture_task_runner_->BelongsToCurrentThread());
667 DLOG(ERROR) << message; 690 DLOG(ERROR) << message;
668 BrowserThread::PostTask( 691 BrowserThread::PostTask(
669 BrowserThread::IO, FROM_HERE, 692 BrowserThread::IO, FROM_HERE,
670 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); 693 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_));
671 } 694 }
672 695
673 } // namespace content 696 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698