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

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc

Issue 1737253002: Handle Alpha channel in Canvas capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bbudge@ nit. Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media/webrtc/webrtc_video_capturer_adapter.h" 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/aligned_memory.h" 8 #include "base/memory/aligned_memory.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/renderer/media/webrtc/webrtc_video_frame_adapter.h" 10 #include "content/renderer/media/webrtc/webrtc_video_frame_adapter.h"
11 #include "media/base/timestamp_constants.h" 11 #include "media/base/timestamp_constants.h"
12 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
13 #include "media/base/video_frame_pool.h" 13 #include "media/base/video_frame_pool.h"
14 #include "media/base/video_util.h"
14 #include "third_party/libyuv/include/libyuv/convert_from.h" 15 #include "third_party/libyuv/include/libyuv/convert_from.h"
15 #include "third_party/libyuv/include/libyuv/scale.h" 16 #include "third_party/libyuv/include/libyuv/scale.h"
16 #include "third_party/webrtc/common_video/include/video_frame_buffer.h" 17 #include "third_party/webrtc/common_video/include/video_frame_buffer.h"
17 #include "third_party/webrtc/common_video/rotation.h" 18 #include "third_party/webrtc/common_video/rotation.h"
18 #include "third_party/webrtc/media/base/videoframefactory.h" 19 #include "third_party/webrtc/media/base/videoframefactory.h"
19 #include "third_party/webrtc/media/engine/webrtcvideoframe.h" 20 #include "third_party/webrtc/media/engine/webrtcvideoframe.h"
20 21
21 namespace content { 22 namespace content {
22 namespace { 23 namespace {
23 24
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 88
88 // Create a centered cropped visible rect that preservers aspect ratio for 89 // Create a centered cropped visible rect that preservers aspect ratio for
89 // cropped natural size. 90 // cropped natural size.
90 gfx::Rect visible_rect = frame_->visible_rect(); 91 gfx::Rect visible_rect = frame_->visible_rect();
91 visible_rect.ClampToCenteredSize(gfx::Size( 92 visible_rect.ClampToCenteredSize(gfx::Size(
92 visible_rect.width() * cropped_input_width / input_frame->width, 93 visible_rect.width() * cropped_input_width / input_frame->width,
93 visible_rect.height() * cropped_input_height / input_frame->height)); 94 visible_rect.height() * cropped_input_height / input_frame->height));
94 95
95 const gfx::Size output_size(output_width, output_height); 96 const gfx::Size output_size(output_width, output_height);
96 scoped_refptr<media::VideoFrame> video_frame = 97 scoped_refptr<media::VideoFrame> video_frame =
97 media::VideoFrame::WrapVideoFrame(frame_, visible_rect, output_size); 98 media::VideoFrame::WrapVideoFrame(frame_, frame_->format(),
99 visible_rect, output_size);
98 if (!video_frame) 100 if (!video_frame)
99 return nullptr; 101 return nullptr;
100 video_frame->AddDestructionObserver( 102 video_frame->AddDestructionObserver(
101 base::Bind(&ReleaseOriginalFrame, frame_)); 103 base::Bind(&ReleaseOriginalFrame, frame_));
102 104
103 // If no scaling is needed, return a wrapped version of |frame_| directly. 105 // If no scaling is needed, return a wrapped version of |frame_| directly.
104 if (video_frame->natural_size() == video_frame->visible_rect().size()) { 106 if (video_frame->natural_size() == video_frame->visible_rect().size()) {
105 return new cricket::WebRtcVideoFrame( 107 return new cricket::WebRtcVideoFrame(
106 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame), 108 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame),
107 timestamp_ns, webrtc::kVideoRotation_0); 109 timestamp_ns, webrtc::kVideoRotation_0);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // just use what is provided. 211 // just use what is provided.
210 // Use the desired format as the best format. 212 // Use the desired format as the best format.
211 best_format->width = desired.width; 213 best_format->width = desired.width;
212 best_format->height = desired.height; 214 best_format->height = desired.height;
213 best_format->fourcc = cricket::FOURCC_I420; 215 best_format->fourcc = cricket::FOURCC_I420;
214 best_format->interval = desired.interval; 216 best_format->interval = desired.interval;
215 return true; 217 return true;
216 } 218 }
217 219
218 void WebRtcVideoCapturerAdapter::OnFrameCaptured( 220 void WebRtcVideoCapturerAdapter::OnFrameCaptured(
219 const scoped_refptr<media::VideoFrame>& frame) { 221 const scoped_refptr<media::VideoFrame>& video_frame) {
220 DCHECK(thread_checker_.CalledOnValidThread()); 222 DCHECK(thread_checker_.CalledOnValidThread());
221 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); 223 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured");
222 if (!(frame->IsMappable() && (frame->format() == media::PIXEL_FORMAT_I420 || 224 if (!(video_frame->IsMappable() &&
223 frame->format() == media::PIXEL_FORMAT_YV12))) { 225 (video_frame->format() == media::PIXEL_FORMAT_I420 ||
226 video_frame->format() == media::PIXEL_FORMAT_YV12 ||
227 video_frame->format() == media::PIXEL_FORMAT_YV12A))) {
224 // Since connecting sources and sinks do not check the format, we need to 228 // Since connecting sources and sinks do not check the format, we need to
225 // just ignore formats that we can not handle. 229 // just ignore formats that we can not handle.
226 NOTREACHED(); 230 NOTREACHED();
227 return; 231 return;
228 } 232 }
233 scoped_refptr<media::VideoFrame> frame = video_frame;
234 // Drop alpha channel since we do not support it yet.
235 if (frame->format() == media::PIXEL_FORMAT_YV12A)
236 frame = media::WrapAsI420VideoFrame(video_frame);
229 237
230 // Inject the frame via the VideoFrameFactory of base class. 238 // Inject the frame via the VideoFrameFactory of base class.
231 MediaVideoFrameFactory* media_video_frame_factory = 239 MediaVideoFrameFactory* media_video_frame_factory =
232 reinterpret_cast<MediaVideoFrameFactory*>(frame_factory()); 240 reinterpret_cast<MediaVideoFrameFactory*>(frame_factory());
233 media_video_frame_factory->SetFrame(frame); 241 media_video_frame_factory->SetFrame(frame);
234 242
235 // This signals to libJingle that a new VideoFrame is available. 243 // This signals to libJingle that a new VideoFrame is available.
236 SignalFrameCaptured(this, media_video_frame_factory->GetCapturedFrame()); 244 SignalFrameCaptured(this, media_video_frame_factory->GetCapturedFrame());
237 245
238 media_video_frame_factory->ReleaseFrame(); // Release the frame ASAP. 246 media_video_frame_factory->ReleaseFrame(); // Release the frame ASAP.
239 } 247 }
240 248
241 } // namespace content 249 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webmediaplayer_ms.cc ('k') | content/renderer/pepper/pepper_media_stream_video_track_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698