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" |
| 20 #include "cc/paint/paint_surface.h" |
19 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" | 21 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h" |
20 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
21 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
22 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
23 #include "media/base/video_util.h" | 25 #include "media/base/video_util.h" |
24 #include "media/filters/context_3d.h" | 26 #include "media/filters/context_3d.h" |
25 #include "media/renderers/skcanvas_video_renderer.h" | 27 #include "media/renderers/skcanvas_video_renderer.h" |
26 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 28 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
27 #include "skia/ext/platform_canvas.h" | 29 #include "skia/ext/platform_canvas.h" |
28 #include "third_party/libyuv/include/libyuv.h" | 30 #include "third_party/libyuv/include/libyuv.h" |
29 #include "third_party/skia/include/core/SkCanvas.h" | |
30 #include "third_party/skia/include/core/SkSurface.h" | |
31 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
32 | 32 |
33 #if BUILDFLAG(RTC_USE_H264) | 33 #if BUILDFLAG(RTC_USE_H264) |
34 #include "third_party/openh264/src/codec/api/svc/codec_api.h" | 34 #include "third_party/openh264/src/codec/api/svc/codec_api.h" |
35 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" | 35 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" |
36 #include "third_party/openh264/src/codec/api/svc/codec_def.h" | 36 #include "third_party/openh264/src/codec/api/svc/codec_def.h" |
37 #endif // #if BUILDFLAG(RTC_USE_H264) | 37 #endif // #if BUILDFLAG(RTC_USE_H264) |
38 | 38 |
39 extern "C" { | 39 extern "C" { |
40 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide | 40 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 // This callback should be exercised on IO thread. | 234 // This callback should be exercised on IO thread. |
235 const OnEncodedVideoCB on_encoded_video_callback_; | 235 const OnEncodedVideoCB on_encoded_video_callback_; |
236 | 236 |
237 // Target bitrate for video encoding. If 0, a standard bitrate is used. | 237 // Target bitrate for video encoding. If 0, a standard bitrate is used. |
238 const int32_t bits_per_second_; | 238 const int32_t bits_per_second_; |
239 | 239 |
240 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by | 240 // Used to retrieve incoming opaque VideoFrames (i.e. VideoFrames backed by |
241 // textures). Created on-demand on |main_task_runner_|. | 241 // textures). Created on-demand on |main_task_runner_|. |
242 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; | 242 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; |
243 sk_sp<SkSurface> surface_; | 243 sk_sp<cc::PaintSurface> surface_; |
244 | 244 |
245 DISALLOW_COPY_AND_ASSIGN(Encoder); | 245 DISALLOW_COPY_AND_ASSIGN(Encoder); |
246 }; | 246 }; |
247 | 247 |
248 void VideoTrackRecorder::Encoder::StartFrameEncode( | 248 void VideoTrackRecorder::Encoder::StartFrameEncode( |
249 const scoped_refptr<VideoFrame>& video_frame, | 249 const scoped_refptr<VideoFrame>& video_frame, |
250 base::TimeTicks capture_timestamp) { | 250 base::TimeTicks capture_timestamp) { |
251 // Cache the thread sending frames on first frame arrival. | 251 // Cache the thread sending frames on first frame arrival. |
252 if (!origin_task_runner_.get()) | 252 if (!origin_task_runner_.get()) |
253 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 253 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 video_frame->visible_rect(), video_frame->natural_size(), | 306 video_frame->visible_rect(), video_frame->natural_size(), |
307 video_frame->timestamp()); | 307 video_frame->timestamp()); |
308 | 308 |
309 const SkImageInfo info = SkImageInfo::MakeN32( | 309 const SkImageInfo info = SkImageInfo::MakeN32( |
310 frame->visible_rect().width(), frame->visible_rect().height(), | 310 frame->visible_rect().width(), frame->visible_rect().height(), |
311 kOpaque_SkAlphaType); | 311 kOpaque_SkAlphaType); |
312 | 312 |
313 // Create |surface_| if it doesn't exist or incoming resolution has changed. | 313 // Create |surface_| if it doesn't exist or incoming resolution has changed. |
314 if (!surface_ || surface_->width() != info.width() || | 314 if (!surface_ || surface_->width() != info.width() || |
315 surface_->height() != info.height()) { | 315 surface_->height() != info.height()) { |
316 surface_ = SkSurface::MakeRaster(info); | 316 surface_ = cc::PaintSurface::MakeRaster(info); |
317 } | 317 } |
318 if (!video_renderer_) | 318 if (!video_renderer_) |
319 video_renderer_.reset(new media::SkCanvasVideoRenderer); | 319 video_renderer_.reset(new media::SkCanvasVideoRenderer); |
320 | 320 |
321 DCHECK(context_provider->ContextGL()); | 321 DCHECK(context_provider->ContextGL()); |
322 video_renderer_->Copy(video_frame.get(), surface_->getCanvas(), | 322 video_renderer_->Copy(video_frame.get(), surface_->getCanvas(), |
323 media::Context3D(context_provider->ContextGL(), | 323 media::Context3D(context_provider->ContextGL(), |
324 context_provider->GrContext())); | 324 context_provider->GrContext())); |
325 | 325 |
326 SkPixmap pixmap; | 326 SkPixmap pixmap; |
327 if (!skia::GetWritablePixels(surface_->getCanvas(), &pixmap)) { | 327 if (!cc::ToPixmap(surface_->getCanvas(), &pixmap)) { |
328 DLOG(ERROR) << "Error trying to map SkSurface's pixels"; | 328 DLOG(ERROR) << "Error trying to map PaintSurface's pixels"; |
329 return; | 329 return; |
330 } | 330 } |
331 // TODO(mcasas): Use the incoming frame's rotation when | 331 // TODO(mcasas): Use the incoming frame's rotation when |
332 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. | 332 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6069 is closed. |
333 const libyuv::RotationMode source_rotation = libyuv::kRotate0; | 333 const libyuv::RotationMode source_rotation = libyuv::kRotate0; |
334 const uint32 source_pixel_format = | 334 const uint32 source_pixel_format = |
335 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR | 335 (kN32_SkColorType == kRGBA_8888_SkColorType) ? libyuv::FOURCC_ABGR |
336 : libyuv::FOURCC_ARGB; | 336 : libyuv::FOURCC_ARGB; |
337 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), | 337 if (libyuv::ConvertToI420(static_cast<uint8*>(pixmap.writable_addr()), |
338 pixmap.getSafeSize(), | 338 pixmap.getSafeSize(), |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 encoder_->SetPaused(paused_before_init_); | 1218 encoder_->SetPaused(paused_before_init_); |
1219 | 1219 |
1220 // StartFrameEncode() will be called on Render IO thread. | 1220 // StartFrameEncode() will be called on Render IO thread. |
1221 MediaStreamVideoSink::ConnectToTrack( | 1221 MediaStreamVideoSink::ConnectToTrack( |
1222 track_, | 1222 track_, |
1223 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), | 1223 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), |
1224 false); | 1224 false); |
1225 } | 1225 } |
1226 | 1226 |
1227 } // namespace content | 1227 } // namespace content |
OLD | NEW |