Chromium Code Reviews| 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/skia_paint_canvas.h" |
| 20 #include "cc/paint/paint_surface.h" | |
| 21 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" | 20 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 21 #include "content/renderer/render_thread_impl.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 22 #include "media/base/bind_to_current_loop.h" |
| 24 #include "media/base/video_frame.h" | 23 #include "media/base/video_frame.h" |
| 25 #include "media/base/video_util.h" | 24 #include "media/base/video_util.h" |
| 26 #include "media/filters/context_3d.h" | 25 #include "media/filters/context_3d.h" |
| 27 #include "media/renderers/skcanvas_video_renderer.h" | 26 #include "media/renderers/skcanvas_video_renderer.h" |
| 28 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 27 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 29 #include "skia/ext/platform_canvas.h" | 28 #include "skia/ext/platform_canvas.h" |
| 30 #include "third_party/libyuv/include/libyuv.h" | 29 #include "third_party/libyuv/include/libyuv.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 | 234 |
| 236 // This callback should be exercised on IO thread. | 235 // This callback should be exercised on IO thread. |
| 237 const OnEncodedVideoCB on_encoded_video_callback_; | 236 const OnEncodedVideoCB on_encoded_video_callback_; |
| 238 | 237 |
| 239 // Target bitrate for video encoding. If 0, a standard bitrate is used. | 238 // Target bitrate for video encoding. If 0, a standard bitrate is used. |
| 240 const int32_t bits_per_second_; | 239 const int32_t bits_per_second_; |
| 241 | 240 |
| 242 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by | 241 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by |
| 243 // textures). Created on-demand on |main_task_runner_|. | 242 // textures). Created on-demand on |main_task_runner_|. |
| 244 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; | 243 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; |
| 245 sk_sp<cc::PaintSurface> surface_; | 244 SkBitmap bitmap_; |
| 245 std::unique_ptr<cc::PaintCanvas> canvas_; | |
| 246 | 246 |
| 247 DISALLOW_COPY_AND_ASSIGN(Encoder); | 247 DISALLOW_COPY_AND_ASSIGN(Encoder); |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 void VideoTrackRecorder::Encoder::StartFrameEncode( | 250 void VideoTrackRecorder::Encoder::StartFrameEncode( |
| 251 const scoped_refptr<VideoFrame>& video_frame, | 251 const scoped_refptr<VideoFrame>& video_frame, |
| 252 base::TimeTicks capture_timestamp) { | 252 base::TimeTicks capture_timestamp) { |
| 253 // Cache the thread sending frames on first frame arrival. | 253 // Cache the thread sending frames on first frame arrival. |
| 254 if (!origin_task_runner_.get()) | 254 if (!origin_task_runner_.get()) |
| 255 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 255 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 frame = media::VideoFrame::CreateFrame( | 306 frame = media::VideoFrame::CreateFrame( |
| 307 media::PIXEL_FORMAT_I420, video_frame->coded_size(), | 307 media::PIXEL_FORMAT_I420, video_frame->coded_size(), |
| 308 video_frame->visible_rect(), video_frame->natural_size(), | 308 video_frame->visible_rect(), video_frame->natural_size(), |
| 309 video_frame->timestamp()); | 309 video_frame->timestamp()); |
| 310 | 310 |
| 311 const SkImageInfo info = SkImageInfo::MakeN32( | 311 const SkImageInfo info = SkImageInfo::MakeN32( |
| 312 frame->visible_rect().width(), frame->visible_rect().height(), | 312 frame->visible_rect().width(), frame->visible_rect().height(), |
| 313 kOpaque_SkAlphaType); | 313 kOpaque_SkAlphaType); |
| 314 | 314 |
| 315 // Create |surface_| if it doesn't exist or incoming resolution has changed. | 315 // Create |surface_| if it doesn't exist or incoming resolution has changed. |
| 316 if (!surface_ || surface_->width() != info.width() || | 316 if (!canvas_ || canvas_->imageInfo().width() != info.width() || |
|
Khushal
2017/03/28 20:57:42
The bug was that the bitmap would have the pixels
| |
| 317 surface_->height() != info.height()) { | 317 canvas_->imageInfo().height() != info.height()) { |
| 318 surface_ = cc::PaintSurface::MakeRaster(info); | 318 bitmap_.allocPixels(info); |
| 319 canvas_ = base::MakeUnique<cc::SkiaPaintCanvas>(bitmap_); | |
| 319 } | 320 } |
| 320 if (!video_renderer_) | 321 if (!video_renderer_) |
| 321 video_renderer_.reset(new media::SkCanvasVideoRenderer); | 322 video_renderer_.reset(new media::SkCanvasVideoRenderer); |
| 322 | 323 |
| 323 DCHECK(context_provider->ContextGL()); | 324 DCHECK(context_provider->ContextGL()); |
| 324 video_renderer_->Copy(video_frame.get(), surface_->getCanvas(), | 325 video_renderer_->Copy(video_frame.get(), canvas_.get(), |
| 325 media::Context3D(context_provider->ContextGL(), | 326 media::Context3D(context_provider->ContextGL(), |
| 326 context_provider->GrContext())); | 327 context_provider->GrContext())); |
| 327 | 328 |
| 328 SkPixmap pixmap; | 329 SkPixmap pixmap; |
| 329 if (!cc::ToPixmap(surface_->getCanvas(), &pixmap)) { | 330 if (!bitmap_.peekPixels(&pixmap)) { |
| 330 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; | 331 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; |
| 331 return; | 332 return; |
| 332 } | 333 } |
| 333 // TODO(mcasas): Use the incoming frame's rotation when | 334 // TODO(mcasas): Use the incoming frame's rotation when |
| 334 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. | 335 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. |
| 335 const libyuv::RotationMode source_rotation = libyuv::kRotate0; | 336 const libyuv::RotationMode source_rotation = libyuv::kRotate0; |
| 336 const uint32 source_pixel_format = | 337 const uint32 source_pixel_format = |
| 337 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR | 338 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR |
| 338 : libyuv::FOURCC_ARGB; | 339 : libyuv::FOURCC_ARGB; |
| 339 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), | 340 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), | 1336 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), |
| 1336 false); | 1337 false); |
| 1337 } | 1338 } |
| 1338 | 1339 |
| 1339 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { | 1340 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { |
| 1340 DCHECK(encoder_); | 1341 DCHECK(encoder_); |
| 1341 return encoder_->CanEncodeAlphaChannel(); | 1342 return encoder_->CanEncodeAlphaChannel(); |
| 1342 } | 1343 } |
| 1343 | 1344 |
| 1344 } // namespace content | 1345 } // namespace content |
| OLD | NEW |