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

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

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi's nits addressed Created 5 years, 9 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
« no previous file with comments | « content/renderer/pepper/pepper_video_capture_host.h ('k') | media/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/media/media_stream_video_source.h"
7 #include "content/renderer/pepper/host_globals.h" 8 #include "content/renderer/pepper/host_globals.h"
8 #include "content/renderer/pepper/pepper_media_device_manager.h" 9 #include "content/renderer/pepper/pepper_media_device_manager.h"
9 #include "content/renderer/pepper/pepper_platform_video_capture.h" 10 #include "content/renderer/pepper/pepper_platform_video_capture.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
11 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" 12 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
12 #include "content/renderer/render_frame_impl.h" 13 #include "content/renderer/render_frame_impl.h"
13 #include "media/base/limits.h" 14 #include "media/base/limits.h"
14 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
15 #include "ppapi/host/dispatch_host_message.h" 16 #include "ppapi/host/dispatch_host_message.h"
16 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // conflicting "master" resolution), or because the browser failed to start 114 // conflicting "master" resolution), or because the browser failed to start
114 // the capture. 115 // the capture.
115 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true); 116 SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true);
116 host()->SendUnsolicitedReply( 117 host()->SendUnsolicitedReply(
117 pp_resource(), 118 pp_resource(),
118 PpapiPluginMsg_VideoCapture_OnError( 119 PpapiPluginMsg_VideoCapture_OnError(
119 static_cast<uint32_t>(PP_ERROR_FAILED))); 120 static_cast<uint32_t>(PP_ERROR_FAILED)));
120 } 121 }
121 122
122 void PepperVideoCaptureHost::OnFrameReady( 123 void PepperVideoCaptureHost::OnFrameReady(
123 const scoped_refptr<media::VideoFrame>& frame, 124 const scoped_refptr<media::VideoFrame>& frame) {
124 media::VideoCaptureFormat format) {
125 DCHECK(frame.get()); 125 DCHECK(frame.get());
126 126
127 if (alloc_size_ != frame->coded_size() || buffers_.empty()) { 127 if (alloc_size_ != frame->visible_rect().size() || buffers_.empty()) {
128 AllocBuffers(frame->coded_size(), format.frame_rate); 128 alloc_size_ = frame->visible_rect().size();
129 alloc_size_ = frame->coded_size(); 129 double frame_rate;
130 int rounded_frame_rate;
131 if (frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE,
132 &frame_rate))
133 rounded_frame_rate = static_cast<int>(frame_rate + 0.5 /* round */);
134 else
135 rounded_frame_rate = MediaStreamVideoSource::kUnknownFrameRate;
136 AllocBuffers(alloc_size_, rounded_frame_rate);
130 } 137 }
131 138
132 for (uint32_t i = 0; i < buffers_.size(); ++i) { 139 for (uint32_t i = 0; i < buffers_.size(); ++i) {
133 if (!buffers_[i].in_use) { 140 if (!buffers_[i].in_use) {
134 DCHECK_EQ(frame->format(), media::VideoFrame::I420); 141 DCHECK_EQ(frame->format(), media::VideoFrame::I420);
135 if (buffers_[i].buffer->size() < 142 if (buffers_[i].buffer->size() <
136 media::VideoFrame::AllocationSize(frame->format(), 143 media::VideoFrame::AllocationSize(frame->format(), alloc_size_)) {
137 frame->coded_size())) {
138 // TODO(ihf): handle size mismatches gracefully here. 144 // TODO(ihf): handle size mismatches gracefully here.
139 return; 145 return;
140 } 146 }
141 uint8* dst = reinterpret_cast<uint8*>(buffers_[i].data); 147 uint8* dst = reinterpret_cast<uint8*>(buffers_[i].data);
142 static_assert(media::VideoFrame::kYPlane == 0, "y plane should be 0"); 148 static_assert(media::VideoFrame::kYPlane == 0, "y plane should be 0");
143 static_assert(media::VideoFrame::kUPlane == 1, "u plane should be 1"); 149 static_assert(media::VideoFrame::kUPlane == 1, "u plane should be 1");
144 static_assert(media::VideoFrame::kVPlane == 2, "v plane should be 2"); 150 static_assert(media::VideoFrame::kVPlane == 2, "v plane should be 2");
145 for (size_t j = 0; j < media::VideoFrame::NumPlanes(frame->format()); 151 for (size_t j = 0; j < media::VideoFrame::NumPlanes(frame->format());
146 ++j) { 152 ++j) {
147 const uint8* src = frame->data(j); 153 const uint8* src = frame->visible_data(j);
148 const size_t row_bytes = frame->row_bytes(j); 154 const size_t row_bytes = frame->row_bytes(j);
149 const size_t src_stride = frame->stride(j); 155 const size_t src_stride = frame->stride(j);
150 for (int k = 0; k < frame->rows(j); ++k) { 156 for (int k = 0; k < frame->rows(j); ++k) {
151 memcpy(dst, src, row_bytes); 157 memcpy(dst, src, row_bytes);
152 dst += row_bytes; 158 dst += row_bytes;
153 src += src_stride; 159 src += src_stride;
154 } 160 }
155 } 161 }
156 buffers_[i].in_use = true; 162 buffers_[i].in_use = true;
157 host()->SendUnsolicitedReply( 163 host()->SendUnsolicitedReply(
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 420 }
415 421
416 PepperVideoCaptureHost::BufferInfo::BufferInfo() 422 PepperVideoCaptureHost::BufferInfo::BufferInfo()
417 : in_use(false), data(NULL), buffer() { 423 : in_use(false), data(NULL), buffer() {
418 } 424 }
419 425
420 PepperVideoCaptureHost::BufferInfo::~BufferInfo() { 426 PepperVideoCaptureHost::BufferInfo::~BufferInfo() {
421 } 427 }
422 428
423 } // namespace content 429 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_capture_host.h ('k') | media/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698