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

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

Powered by Google App Engine
This is Rietveld 408576698