OLD | NEW |
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_recorder/video_track_recorder.h" | 5 #include "content/renderer/media_recorder/video_track_recorder.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "cc/paint/paint_canvas.h" | 19 #include "cc/paint/paint_canvas.h" |
20 #include "cc/paint/paint_surface.h" | 20 #include "cc/paint/skia_paint_canvas.h" |
21 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" | 21 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" |
22 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
23 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
24 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
25 #include "media/base/video_util.h" | 25 #include "media/base/video_util.h" |
26 #include "media/filters/context_3d.h" | 26 #include "media/filters/context_3d.h" |
27 #include "media/renderers/skcanvas_video_renderer.h" | 27 #include "media/renderers/skcanvas_video_renderer.h" |
28 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 28 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
29 #include "skia/ext/platform_canvas.h" | 29 #include "skia/ext/platform_canvas.h" |
30 #include "third_party/libyuv/include/libyuv.h" | 30 #include "third_party/libyuv/include/libyuv.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 // This callback should be exercised on IO thread. | 246 // This callback should be exercised on IO thread. |
247 const OnEncodedVideoCB on_encoded_video_callback_; | 247 const OnEncodedVideoCB on_encoded_video_callback_; |
248 | 248 |
249 // Target bitrate for video encoding. If 0, a standard bitrate is used. | 249 // Target bitrate for video encoding. If 0, a standard bitrate is used. |
250 const int32_t bits_per_second_; | 250 const int32_t bits_per_second_; |
251 | 251 |
252 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by | 252 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by |
253 // textures). Created on-demand on |main_task_runner_|. | 253 // textures). Created on-demand on |main_task_runner_|. |
254 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; | 254 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; |
255 sk_sp<cc::PaintSurface> surface_; | 255 std::unique_ptr<cc::PaintCanvas> canvas_; |
256 | 256 |
257 DISALLOW_COPY_AND_ASSIGN(Encoder); | 257 DISALLOW_COPY_AND_ASSIGN(Encoder); |
258 }; | 258 }; |
259 | 259 |
260 void VideoTrackRecorder::Encoder::StartFrameEncode( | 260 void VideoTrackRecorder::Encoder::StartFrameEncode( |
261 const scoped_refptr<VideoFrame>& video_frame, | 261 const scoped_refptr<VideoFrame>& video_frame, |
262 base::TimeTicks capture_timestamp) { | 262 base::TimeTicks capture_timestamp) { |
263 // Cache the thread sending frames on first frame arrival. | 263 // Cache the thread sending frames on first frame arrival. |
264 if (!origin_task_runner_.get()) | 264 if (!origin_task_runner_.get()) |
265 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 265 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 frame = media::VideoFrame::CreateFrame( | 316 frame = media::VideoFrame::CreateFrame( |
317 media::PIXEL_FORMAT_I420, video_frame->coded_size(), | 317 media::PIXEL_FORMAT_I420, video_frame->coded_size(), |
318 video_frame->visible_rect(), video_frame->natural_size(), | 318 video_frame->visible_rect(), video_frame->natural_size(), |
319 video_frame->timestamp()); | 319 video_frame->timestamp()); |
320 | 320 |
321 const SkImageInfo info = SkImageInfo::MakeN32( | 321 const SkImageInfo info = SkImageInfo::MakeN32( |
322 frame->visible_rect().width(), frame->visible_rect().height(), | 322 frame->visible_rect().width(), frame->visible_rect().height(), |
323 kOpaque_SkAlphaType); | 323 kOpaque_SkAlphaType); |
324 | 324 |
325 // Create |surface_| if it doesn't exist or incoming resolution has changed. | 325 // Create |surface_| if it doesn't exist or incoming resolution has changed. |
326 if (!surface_ || surface_->width() != info.width() || | 326 if (!canvas_ || canvas_->imageInfo().width() != info.width() || |
327 surface_->height() != info.height()) { | 327 canvas_->imageInfo().height() != info.height()) { |
328 surface_ = cc::PaintSurface::MakeRaster(info); | 328 canvas_ = cc::SkiaPaintCanvas::CreateRasterZeroed(info); |
329 } | 329 } |
330 if (!video_renderer_) | 330 if (!video_renderer_) |
331 video_renderer_.reset(new media::SkCanvasVideoRenderer); | 331 video_renderer_.reset(new media::SkCanvasVideoRenderer); |
332 | 332 |
333 DCHECK(context_provider->ContextGL()); | 333 DCHECK(context_provider->ContextGL()); |
334 video_renderer_->Copy(video_frame.get(), surface_->getCanvas(), | 334 video_renderer_->Copy(video_frame.get(), canvas_.get(), |
335 media::Context3D(context_provider->ContextGL(), | 335 media::Context3D(context_provider->ContextGL(), |
336 context_provider->GrContext())); | 336 context_provider->GrContext())); |
337 | 337 |
338 SkPixmap pixmap; | 338 SkPixmap pixmap; |
339 if (!cc::ToPixmap(surface_->getCanvas(), &pixmap)) { | 339 if (!cc::ToPixmap(canvas_.get(), &pixmap)) { |
340 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; | 340 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; |
341 return; | 341 return; |
342 } | 342 } |
343 // TODO(mcasas): Use the incoming frame's rotation when | 343 // TODO(mcasas): Use the incoming frame's rotation when |
344 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. | 344 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. |
345 const libyuv::RotationMode source_rotation = libyuv::kRotate0; | 345 const libyuv::RotationMode source_rotation = libyuv::kRotate0; |
346 const uint32 source_pixel_format = | 346 const uint32 source_pixel_format = |
347 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR | 347 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR |
348 : libyuv::FOURCC_ARGB; | 348 : libyuv::FOURCC_ARGB; |
349 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), | 349 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), | 1340 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), |
1341 false); | 1341 false); |
1342 } | 1342 } |
1343 | 1343 |
1344 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { | 1344 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { |
1345 DCHECK(encoder_); | 1345 DCHECK(encoder_); |
1346 return encoder_->CanEncodeAlphaChannel(); | 1346 return encoder_->CanEncodeAlphaChannel(); |
1347 } | 1347 } |
1348 | 1348 |
1349 } // namespace content | 1349 } // namespace content |
OLD | NEW |