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

Side by Side Diff: content/renderer/media/html_video_element_capturer_source.cc

Issue 2018183002: HTMLVideoElementCapturer: use SkSurface::MakeRaster ISO skia::CreatePlatformCanvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/html_video_element_capturer_source.h" 5 #include "content/renderer/media/html_video_element_capturer_source.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
11 #include "content/renderer/media/media_stream_video_source.h" 11 #include "content/renderer/media/media_stream_video_source.h"
12 #include "content/renderer/media/webrtc_uma_histograms.h" 12 #include "content/renderer/media/webrtc_uma_histograms.h"
13 #include "media/base/limits.h" 13 #include "media/base/limits.h"
14 #include "media/blink/webmediaplayer_impl.h" 14 #include "media/blink/webmediaplayer_impl.h"
15 #include "skia/ext/platform_canvas.h" 15 #include "skia/ext/platform_canvas.h"
16 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" 16 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
17 #include "third_party/WebKit/public/platform/WebRect.h" 17 #include "third_party/WebKit/public/platform/WebRect.h"
18 #include "third_party/WebKit/public/platform/WebSize.h" 18 #include "third_party/WebKit/public/platform/WebSize.h"
19 #include "third_party/libyuv/include/libyuv.h" 19 #include "third_party/libyuv/include/libyuv.h"
20 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "third_party/skia/include/core/SkSurface.h"
21 #include "third_party/skia/include/core/SkXfermode.h" 22 #include "third_party/skia/include/core/SkXfermode.h"
22 23
23 namespace { 24 namespace {
24 const float kMinFramesPerSecond = 1.0; 25 const float kMinFramesPerSecond = 1.0;
25 } // anonymous namespace 26 } // anonymous namespace
26 27
27 namespace content { 28 namespace content {
28 29
29 //static 30 //static
30 std::unique_ptr<HtmlVideoElementCapturerSource> 31 std::unique_ptr<HtmlVideoElementCapturerSource>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 << media::VideoCaptureFormat::ToString(params.requested_format); 86 << media::VideoCaptureFormat::ToString(params.requested_format);
86 DCHECK(params.requested_format.IsValid()); 87 DCHECK(params.requested_format.IsValid());
87 DCHECK(thread_checker_.CalledOnValidThread()); 88 DCHECK(thread_checker_.CalledOnValidThread());
88 89
89 running_callback_ = running_callback; 90 running_callback_ = running_callback;
90 if (!web_media_player_ || !web_media_player_->hasVideo()) { 91 if (!web_media_player_ || !web_media_player_->hasVideo()) {
91 running_callback_.Run(false); 92 running_callback_.Run(false);
92 return; 93 return;
93 } 94 }
94 const blink::WebSize resolution = web_media_player_->naturalSize(); 95 const blink::WebSize resolution = web_media_player_->naturalSize();
95 // TODO(mcasas): Don't use CreatePlatformCanvas here: http://crbug.com/615454. 96 surface_ =
96 canvas_ = sk_sp<SkCanvas>(skia::CreatePlatformCanvas(resolution.width, 97 SkSurface::MakeRasterN32Premul(resolution.width, resolution.height);
97 resolution.height, 98 if (!surface_) {
98 true /* is_opaque */,
99 0 /* data */,
100 skia::RETURN_NULL_ON_FAILURE));
101 if (!canvas_){
102 running_callback_.Run(false); 99 running_callback_.Run(false);
103 return; 100 return;
104 } 101 }
105 102
106 new_frame_callback_ = new_frame_callback; 103 new_frame_callback_ = new_frame_callback;
107 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond. 104 // Force |capture_frame_rate_| to be in between k{Min,Max}FramesPerSecond.
108 capture_frame_rate_ = 105 capture_frame_rate_ =
109 std::max(kMinFramesPerSecond, 106 std::max(kMinFramesPerSecond,
110 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond), 107 std::min(static_cast<float>(media::limits::kMaxFramesPerSecond),
111 params.requested_format.frame_rate)); 108 params.requested_format.frame_rate));
(...skipping 16 matching lines...) Expand all
128 DVLOG(3) << __FUNCTION__; 125 DVLOG(3) << __FUNCTION__;
129 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame"); 126 TRACE_EVENT0("video", "HtmlVideoElementCapturerSource::sendNewFrame");
130 DCHECK(thread_checker_.CalledOnValidThread()); 127 DCHECK(thread_checker_.CalledOnValidThread());
131 128
132 if (!web_media_player_ || new_frame_callback_.is_null()) 129 if (!web_media_player_ || new_frame_callback_.is_null())
133 return; 130 return;
134 131
135 const base::TimeTicks current_time = base::TimeTicks::Now(); 132 const base::TimeTicks current_time = base::TimeTicks::Now();
136 const blink::WebSize resolution = web_media_player_->naturalSize(); 133 const blink::WebSize resolution = web_media_player_->naturalSize();
137 134
135 SkCanvas* canvas = surface_->getCanvas();
138 web_media_player_->paint( 136 web_media_player_->paint(
139 canvas_.get(), blink::WebRect(0, 0, resolution.width, resolution.height), 137 canvas, blink::WebRect(0, 0, resolution.width, resolution.height),
140 0xFF /* alpha */, SkXfermode::kSrc_Mode); 138 0xFF /* alpha */, SkXfermode::kSrc_Mode);
141 DCHECK_NE(kUnknown_SkColorType, canvas_->imageInfo().colorType()); 139 DCHECK_NE(kUnknown_SkColorType, canvas->imageInfo().colorType());
142 DCHECK_EQ(canvas_->imageInfo().width(), resolution.width); 140 DCHECK_EQ(canvas->imageInfo().width(), resolution.width);
143 DCHECK_EQ(canvas_->imageInfo().height(), resolution.height); 141 DCHECK_EQ(canvas->imageInfo().height(), resolution.height);
144 142
145 const SkBitmap bitmap = skia::ReadPixels(canvas_.get()); 143 const SkBitmap bitmap = skia::ReadPixels(canvas);
Stephen White 2016/05/31 18:42:43 This may or may not be applicable, but note that n
mcasas 2016/05/31 18:49:36 Acknowledged. From this side, it'd be always a rea
146 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType()); 144 DCHECK_NE(kUnknown_SkColorType, bitmap.colorType());
147 DCHECK(!bitmap.drawsNothing()); 145 DCHECK(!bitmap.drawsNothing());
148 DCHECK(bitmap.getPixels()); 146 DCHECK(bitmap.getPixels());
149 if (bitmap.colorType() != kN32_SkColorType) { 147 if (bitmap.colorType() != kN32_SkColorType) {
150 DLOG(ERROR) << "Only supported capture format is ARGB"; 148 DLOG(ERROR) << "Only supported capture format is ARGB";
151 return; 149 return;
152 } 150 }
153 151
154 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame( 152 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame(
155 media::PIXEL_FORMAT_I420, resolution, gfx::Rect(resolution), resolution, 153 media::PIXEL_FORMAT_I420, resolution, gfx::Rect(resolution), resolution,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 next_capture_time_ = current_time; 188 next_capture_time_ = current_time;
191 } 189 }
192 // Schedule next capture. 190 // Schedule next capture.
193 base::MessageLoop::current()->PostDelayedTask( 191 base::MessageLoop::current()->PostDelayedTask(
194 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, 192 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame,
195 weak_factory_.GetWeakPtr()), 193 weak_factory_.GetWeakPtr()),
196 next_capture_time_ - current_time); 194 next_capture_time_ - current_time);
197 } 195 }
198 196
199 } // namespace content 197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698