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

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: 727f973e fischman@ comments 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 (buffers_[i].buffer->size() <
140 // until wjia unifies VideoFrameBuffer and media::VideoFrame. 140 media::VideoFrame::AllocationSize(frame->format(),
141 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), 141 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 COMPILE_ASSERT(media::VideoFrame::kYPlane == 0, y_plane_should_be_0);
147 COMPILE_ASSERT(media::VideoFrame::kUPlane == 1, u_plane_should_be_1);
148 COMPILE_ASSERT(media::VideoFrame::kVPlane == 2, v_plane_should_be_2);
149 for (size_t j = 0; j < media::VideoFrame::NumPlanes(frame->format());
150 ++j) {
151 const uint8* src = frame->data(j);
152 const size_t row_bytes = frame->row_bytes(j);
153 const size_t src_stride = frame->stride(j);
154 for (int k = 0; k < frame->rows(j); ++k) {
155 memcpy(dst, src, row_bytes);
156 dst += row_bytes;
157 src += src_stride;
158 }
Ami GONE FROM CHROMIUM 2013/09/13 00:26:35 I missed that this removes stride padding(!).
159 }
144 buffers_[i].in_use = true; 160 buffers_[i].in_use = true;
145 platform_video_capture_->FeedBuffer(buffer);
146 host()->SendUnsolicitedReply(pp_resource(), 161 host()->SendUnsolicitedReply(pp_resource(),
147 PpapiPluginMsg_VideoCapture_OnBufferReady(i)); 162 PpapiPluginMsg_VideoCapture_OnBufferReady(i));
148 return; 163 return;
149 } 164 }
150 } 165 }
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 } 166 }
156 167
157 void PepperVideoCaptureHost::OnDeviceInfoReceived( 168 void PepperVideoCaptureHost::OnDeviceInfoReceived(
158 media::VideoCapture* capture, 169 media::VideoCapture* capture,
159 const media::VideoCaptureParams& device_info) { 170 const media::VideoCaptureParams& device_info) {
160 PP_VideoCaptureDeviceInfo_Dev info = { 171 PP_VideoCaptureDeviceInfo_Dev info = {
161 static_cast<uint32_t>(device_info.width), 172 static_cast<uint32_t>(device_info.width),
162 static_cast<uint32_t>(device_info.height), 173 static_cast<uint32_t>(device_info.height),
163 static_cast<uint32_t>(device_info.frame_rate) 174 static_cast<uint32_t>(device_info.frame_rate)
164 }; 175 };
165 ReleaseBuffers(); 176 ReleaseBuffers();
166 177
167 // YUV 4:2:0 178 const size_t size = media::VideoFrame::AllocationSize(
168 int uv_width = info.width / 2; 179 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 180
172 ppapi::proxy::ResourceMessageReplyParams params(pp_resource(), 0); 181 ppapi::proxy::ResourceMessageReplyParams params(pp_resource(), 0);
173 182
174 // Allocate buffers. We keep a reference to them, that is released in 183 // 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 184 // ReleaseBuffers. In the mean time, we prepare the resource and handle here
176 // for sending below. 185 // for sending below.
177 std::vector<HostResource> buffer_host_resources; 186 std::vector<HostResource> buffer_host_resources;
178 buffers_.reserve(buffer_count_hint_); 187 buffers_.reserve(buffer_count_hint_);
179 ppapi::ResourceTracker* tracker = 188 ppapi::ResourceTracker* tracker =
180 HostGlobals::Get()->GetResourceTracker(); 189 HostGlobals::Get()->GetResourceTracker();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 PepperVideoCaptureHost::BufferInfo::BufferInfo() 423 PepperVideoCaptureHost::BufferInfo::BufferInfo()
415 : in_use(false), 424 : in_use(false),
416 data(NULL), 425 data(NULL),
417 buffer() { 426 buffer() {
418 } 427 }
419 428
420 PepperVideoCaptureHost::BufferInfo::~BufferInfo() { 429 PepperVideoCaptureHost::BufferInfo::~BufferInfo() {
421 } 430 }
422 431
423 } // namespace content 432 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698