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

Side by Side Diff: content/renderer/pepper/pepper_video_capture_host.cc

Issue 23587018: Replace media::VideoCapture::VideoFrameBuffer with media::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 4fe79a572 Initial. Created 7 years, 3 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/renderer/pepper/pepper_video_capture_host.h" 5 #include "content/renderer/pepper/pepper_video_capture_host.h"
6 6
7 #include "content/renderer/pepper/host_globals.h" 7 #include "content/renderer/pepper/host_globals.h"
8 #include "content/renderer/pepper/pepper_media_device_manager.h" 8 #include "content/renderer/pepper/pepper_media_device_manager.h"
9 #include "content/renderer/pepper/pepper_platform_video_capture.h" 9 #include "content/renderer/pepper/pepper_platform_video_capture.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // conflicting "master" resolution), or because the browser failed to start 122 // conflicting "master" resolution), or because the browser failed to start
123 // the capture. 123 // the capture.
124 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true); 124 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true);
125 host()->SendUnsolicitedReply(pp_resource(), 125 host()->SendUnsolicitedReply(pp_resource(),
126 PpapiPluginMsg_VideoCapture_OnError(PP_ERROR_FAILED)); 126 PpapiPluginMsg_VideoCapture_OnError(PP_ERROR_FAILED));
127 } 127 }
128 128
129 void PepperVideoCaptureHost::OnRemoved(media::VideoCapture* capture) { 129 void PepperVideoCaptureHost::OnRemoved(media::VideoCapture* capture) {
130 } 130 }
131 131
132 void PepperVideoCaptureHost::OnBufferReady( 132 void PepperVideoCaptureHost::OnFrameReady(
133 media::VideoCapture* capture, 133 media::VideoCapture* capture,
134 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { 134 const scoped_refptr<media::VideoFrame>& frame) {
135 DCHECK(buffer.get()); 135 DCHECK(frame.get());
136 for (uint32_t i = 0; i < buffers_.size(); ++i) { 136 for (uint32_t i = 0; i < buffers_.size(); ++i) {
137 if (!buffers_[i].in_use) { 137 if (!buffers_[i].in_use) {
138 // TODO(ihf): Switch to a size calculation based on stride. 138 DCHECK_EQ(frame->format(), media::VideoFrame::I420);
139 // Stride is filled out now but not more meaningful than size 139 if (static_cast<size_t>(buffers_[i].buffer->size() <
miu 2013/09/12 03:01:58 Need to place the closing parenthesis of the stati
sheu 2013/09/12 18:47:43 Done.
140 // until wjia unifies VideoFrameBuffer and media::VideoFrame. 140 media::VideoFrame::AllocationSize(
141 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), 141 frame->format(), frame->coded_size()))) {
142 buffer->buffer_size); 142 // TODO(ihf): handle size mismatches gracefully here.
143 memcpy(buffers_[i].data, buffer->memory_pointer, size); 143 return;
144 }
145 uint8* dst = reinterpret_cast<uint8*>(buffers_[i].data);
146 for (size_t j = 0; j < media::VideoFrame::NumPlanes(frame->format());
147 ++j) {
ncarter (slow) 2013/09/11 18:04:56 This loop is correct, but it kind of opaquely reli
sheu 2013/09/11 19:28:10 I DCHECKED for I420 above, so this is safe for now
ncarter (slow) 2013/09/11 19:56:08 The I420 DCHECK is on the source. The thing that's
ilja 2013/09/12 01:31:43 It is not specified anywhere, but right now Flash
sheu 2013/09/12 18:47:43 Done.
148 const uint8* src = frame->data(j);
149 const size_t row_bytes = frame->row_bytes(j);
150 const size_t src_stride = frame->stride(j);
151 for (int k = 0; k < frame->rows(j); ++k) {
152 memcpy(dst, src, row_bytes);
153 dst += row_bytes;
154 src += src_stride;
155 }
156 }
144 buffers_[i].in_use = true; 157 buffers_[i].in_use = true;
145 platform_video_capture_->FeedBuffer(buffer);
146 host()->SendUnsolicitedReply(pp_resource(), 158 host()->SendUnsolicitedReply(pp_resource(),
147 PpapiPluginMsg_VideoCapture_OnBufferReady(i)); 159 PpapiPluginMsg_VideoCapture_OnBufferReady(i));
148 return; 160 return;
149 } 161 }
150 } 162 }
151
152 // No free slot, just discard the frame and tell the media layer it can
153 // re-use the buffer.
154 platform_video_capture_->FeedBuffer(buffer);
155 } 163 }
156 164
157 void PepperVideoCaptureHost::OnDeviceInfoReceived( 165 void PepperVideoCaptureHost::OnDeviceInfoReceived(
158 media::VideoCapture* capture, 166 media::VideoCapture* capture,
159 const media::VideoCaptureParams& device_info) { 167 const media::VideoCaptureParams& device_info) {
160 PP_VideoCaptureDeviceInfo_Dev info = { 168 PP_VideoCaptureDeviceInfo_Dev info = {
161 static_cast<uint32_t>(device_info.width), 169 static_cast<uint32_t>(device_info.width),
162 static_cast<uint32_t>(device_info.height), 170 static_cast<uint32_t>(device_info.height),
163 static_cast<uint32_t>(device_info.frame_rate) 171 static_cast<uint32_t>(device_info.frame_rate)
164 }; 172 };
165 ReleaseBuffers(); 173 ReleaseBuffers();
166 174
167 // YUV 4:2:0 175 const size_t size = media::VideoFrame::AllocationSize(
168 int uv_width = info.width / 2; 176 media::VideoFrame::I420, gfx::Size(info.width, info.height));
169 int uv_height = info.height / 2;
170 size_t size = info.width * info.height + 2 * uv_width * uv_height;
171 177
172 ppapi::proxy::ResourceMessageReplyParams params(pp_resource(), 0); 178 ppapi::proxy::ResourceMessageReplyParams params(pp_resource(), 0);
173 179
174 // Allocate buffers. We keep a reference to them, that is released in 180 // Allocate buffers. We keep a reference to them, that is released in
175 // ReleaseBuffers. In the mean time, we prepare the resource and handle here 181 // ReleaseBuffers. In the mean time, we prepare the resource and handle here
176 // for sending below. 182 // for sending below.
177 std::vector<HostResource> buffer_host_resources; 183 std::vector<HostResource> buffer_host_resources;
178 buffers_.reserve(buffer_count_hint_); 184 buffers_.reserve(buffer_count_hint_);
179 ppapi::ResourceTracker* tracker = 185 ppapi::ResourceTracker* tracker =
180 HostGlobals::Get()->GetResourceTracker(); 186 HostGlobals::Get()->GetResourceTracker();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 PepperVideoCaptureHost::BufferInfo::BufferInfo() 420 PepperVideoCaptureHost::BufferInfo::BufferInfo()
415 : in_use(false), 421 : in_use(false),
416 data(NULL), 422 data(NULL),
417 buffer() { 423 buffer() {
418 } 424 }
419 425
420 PepperVideoCaptureHost::BufferInfo::~BufferInfo() { 426 PepperVideoCaptureHost::BufferInfo::~BufferInfo() {
421 } 427 }
422 428
423 } // namespace content 429 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698