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

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

Issue 2573223002: [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: mcasas comments 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
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_gpu_jpeg_decoder.h" 5 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
22 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h" 22 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h"
23 #include "mojo/public/cpp/system/platform_handle.h"
23 24
24 namespace content { 25 namespace content {
25 26
26 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder( 27 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder(
27 const DecodeDoneCB& decode_done_cb) 28 const DecodeDoneCB& decode_done_cb)
28 : decode_done_cb_(decode_done_cb), 29 : decode_done_cb_(decode_done_cb),
29 next_bitstream_buffer_id_(0), 30 next_bitstream_buffer_id_(0),
30 in_buffer_id_(media::JpegDecodeAccelerator::kInvalidBitstreamBufferId), 31 in_buffer_id_(media::JpegDecodeAccelerator::kInvalidBitstreamBufferId),
31 decoder_status_(INIT_PENDING) {} 32 decoder_status_(INIT_PENDING) {}
32 33
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 base::AutoLock lock(lock_); 75 base::AutoLock lock(lock_);
75 return decoder_status_; 76 return decoder_status_;
76 } 77 }
77 78
78 void VideoCaptureGpuJpegDecoder::DecodeCapturedData( 79 void VideoCaptureGpuJpegDecoder::DecodeCapturedData(
79 const uint8_t* data, 80 const uint8_t* data,
80 size_t in_buffer_size, 81 size_t in_buffer_size,
81 const media::VideoCaptureFormat& frame_format, 82 const media::VideoCaptureFormat& frame_format,
82 base::TimeTicks reference_time, 83 base::TimeTicks reference_time,
83 base::TimeDelta timestamp, 84 base::TimeDelta timestamp,
84 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> out_buffer) { 85 media::VideoCaptureDevice::Client::Buffer out_buffer) {
85 DCHECK(CalledOnValidThread()); 86 DCHECK(CalledOnValidThread());
86 DCHECK(decoder_); 87 DCHECK(decoder_);
87 88
88 TRACE_EVENT_ASYNC_BEGIN0("jpeg", "VideoCaptureGpuJpegDecoder decoding", 89 TRACE_EVENT_ASYNC_BEGIN0("jpeg", "VideoCaptureGpuJpegDecoder decoding",
89 next_bitstream_buffer_id_); 90 next_bitstream_buffer_id_);
90 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::DecodeCapturedData"); 91 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::DecodeCapturedData");
91 92
92 // TODO(kcwu): enqueue decode requests in case decoding is not fast enough 93 // TODO(kcwu): enqueue decode requests in case decoding is not fast enough
93 // (say, if decoding time is longer than 16ms for 60fps 4k image) 94 // (say, if decoding time is longer than 16ms for 60fps 4k image)
94 { 95 {
(...skipping 19 matching lines...) Expand all
114 } 115 }
115 memcpy(in_shared_memory_->memory(), data, in_buffer_size); 116 memcpy(in_shared_memory_->memory(), data, in_buffer_size);
116 117
117 // No need to lock for |in_buffer_id_| since IsDecoding_Locked() is false. 118 // No need to lock for |in_buffer_id_| since IsDecoding_Locked() is false.
118 in_buffer_id_ = next_bitstream_buffer_id_; 119 in_buffer_id_ = next_bitstream_buffer_id_;
119 media::BitstreamBuffer in_buffer(in_buffer_id_, in_shared_memory_->handle(), 120 media::BitstreamBuffer in_buffer(in_buffer_id_, in_shared_memory_->handle(),
120 in_buffer_size); 121 in_buffer_size);
121 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. 122 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer.
122 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; 123 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF;
123 124
124 #if defined(OS_POSIX) && !defined(OS_MACOSX) 125 // The APIs of |decoder_| and |decode_done_cb_| require us to wrap the
126 // |out_buffer| in a VideoFrame.
125 const gfx::Size dimensions = frame_format.frame_size; 127 const gfx::Size dimensions = frame_format.frame_size;
126 base::SharedMemoryHandle out_handle = out_buffer->AsPlatformFile(); 128 std::unique_ptr<media::VideoCaptureBufferHandle> out_buffer_access =
129 out_buffer.handle_provider()->GetHandleForInProcessAccess();
130 base::SharedMemoryHandle memory_handle;
131 size_t memory_size = 0;
132 bool read_only_flag = false;
133 const MojoResult result = mojo::UnwrapSharedMemoryHandle(
134 out_buffer.handle_provider()->GetHandleForInterProcessTransit(),
135 &memory_handle, &memory_size, &read_only_flag);
136 DCHECK_EQ(MOJO_RESULT_OK, result);
137 DCHECK_GT(memory_size, 0u);
127 scoped_refptr<media::VideoFrame> out_frame = 138 scoped_refptr<media::VideoFrame> out_frame =
128 media::VideoFrame::WrapExternalSharedMemory( 139 media::VideoFrame::WrapExternalSharedMemory(
129 media::PIXEL_FORMAT_I420, // format 140 media::PIXEL_FORMAT_I420, // format
130 dimensions, // coded_size 141 dimensions, // coded_size
131 gfx::Rect(dimensions), // visible_rect 142 gfx::Rect(dimensions), // visible_rect
132 dimensions, // natural_size 143 dimensions, // natural_size
133 static_cast<uint8_t*>(out_buffer->data()), // data 144 out_buffer_access->data(), // data
134 out_buffer->mapped_size(), // data_size 145 out_buffer_access->mapped_size(), // data_size
135 out_handle, // handle 146 std::move(memory_handle), // handle
136 0, // shared_memory_offset 147 0, // shared_memory_offset
137 timestamp); // timestamp 148 timestamp); // timestamp
138 if (!out_frame) { 149 if (!out_frame) {
139 base::AutoLock lock(lock_); 150 base::AutoLock lock(lock_);
140 decoder_status_ = FAILED; 151 decoder_status_ = FAILED;
141 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed"; 152 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed";
142 return; 153 return;
143 } 154 }
144 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 155 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
145 frame_format.frame_rate); 156 frame_format.frame_rate);
146 157
147 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, 158 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME,
148 reference_time); 159 reference_time);
149 160
150 { 161 {
151 base::AutoLock lock(lock_); 162 base::AutoLock lock(lock_);
152 decode_done_closure_ = 163 decode_done_closure_ =
153 base::Bind(decode_done_cb_, base::Passed(&out_buffer), out_frame); 164 base::Bind(decode_done_cb_, base::Passed(&out_buffer), out_frame);
154 } 165 }
155 decoder_->Decode(in_buffer, std::move(out_frame)); 166 decoder_->Decode(in_buffer, std::move(out_frame));
156 #else
157 NOTREACHED();
158 #endif
159 } 167 }
160 168
161 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) { 169 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) {
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); 170 DCHECK_CURRENTLY_ON(BrowserThread::IO);
163 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady"); 171 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady");
164 base::AutoLock lock(lock_); 172 base::AutoLock lock(lock_);
165 173
166 if (!IsDecoding_Locked()) { 174 if (!IsDecoding_Locked()) {
167 LOG(ERROR) << "Got decode response while not decoding"; 175 LOG(ERROR) << "Got decode response while not decoding";
168 return; 176 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 lock_.AssertAcquired(); 258 lock_.AssertAcquired();
251 return !decode_done_closure_.is_null(); 259 return !decode_done_closure_.is_null();
252 } 260 }
253 261
254 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { 262 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() {
255 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", 263 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess",
256 decoder_status_ == INIT_PASSED); 264 decoder_status_ == INIT_PASSED);
257 } 265 }
258 266
259 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698