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

Side by Side Diff: content/renderer/media/video_track_recorder.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 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/video_track_recorder.h" 5 #include "content/renderer/media/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/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "media/base/video_frame.h" 16 #include "media/base/video_frame.h"
17 #include "media/base/video_util.h"
17 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
18 19
19 extern "C" { 20 extern "C" {
20 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide 21 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide
21 // backwards compatibility for legacy applications using the library. 22 // backwards compatibility for legacy applications using the library.
22 #define VPX_CODEC_DISABLE_COMPAT 1 23 #define VPX_CODEC_DISABLE_COMPAT 1
23 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" 24 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h"
24 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" 25 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
25 } 26 }
26 27
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 origin_task_runner_ = base::MessageLoop::current()->task_runner(); 180 origin_task_runner_ = base::MessageLoop::current()->task_runner();
180 DCHECK(origin_task_runner_->BelongsToCurrentThread()); 181 DCHECK(origin_task_runner_->BelongsToCurrentThread());
181 if (paused_) 182 if (paused_)
182 return; 183 return;
183 encoding_thread_->task_runner()->PostTask( 184 encoding_thread_->task_runner()->PostTask(
184 FROM_HERE, base::Bind(&VpxEncoder::EncodeOnEncodingThread, 185 FROM_HERE, base::Bind(&VpxEncoder::EncodeOnEncodingThread,
185 this, frame, capture_timestamp)); 186 this, frame, capture_timestamp));
186 } 187 }
187 188
188 void VideoTrackRecorder::VpxEncoder::EncodeOnEncodingThread( 189 void VideoTrackRecorder::VpxEncoder::EncodeOnEncodingThread(
189 const scoped_refptr<VideoFrame>& frame, 190 const scoped_refptr<VideoFrame>& video_frame,
190 base::TimeTicks capture_timestamp) { 191 base::TimeTicks capture_timestamp) {
191 TRACE_EVENT0("video", 192 TRACE_EVENT0("video",
192 "VideoTrackRecorder::VpxEncoder::EncodeOnEncodingThread"); 193 "VideoTrackRecorder::VpxEncoder::EncodeOnEncodingThread");
193 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); 194 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread());
194 195
196 if (!(video_frame->format() == media::PIXEL_FORMAT_I420 ||
197 video_frame->format() == media::PIXEL_FORMAT_YV12 ||
198 video_frame->format() == media::PIXEL_FORMAT_YV12A)) {
199 NOTREACHED();
200 return;
201 }
202 scoped_refptr<media::VideoFrame> frame = video_frame;
203 // Drop alpha channel since we do not support it yet.
204 if (frame->format() == media::PIXEL_FORMAT_YV12A)
205 frame = media::WrapAsI420VideoFrame(video_frame);
206
195 const gfx::Size frame_size = frame->visible_rect().size(); 207 const gfx::Size frame_size = frame->visible_rect().size();
196 if (!IsInitialized() || 208 if (!IsInitialized() ||
197 gfx::Size(codec_config_.g_w, codec_config_.g_h) != frame_size) { 209 gfx::Size(codec_config_.g_w, codec_config_.g_h) != frame_size) {
198 ConfigureEncoding(frame_size); 210 ConfigureEncoding(frame_size);
199 } 211 }
200 212
201 vpx_image_t vpx_image; 213 vpx_image_t vpx_image;
202 vpx_image_t* const result = vpx_img_wrap(&vpx_image, 214 vpx_image_t* const result = vpx_img_wrap(&vpx_image,
203 VPX_IMG_FMT_I420, 215 VPX_IMG_FMT_I420,
204 frame_size.width(), 216 frame_size.width(),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 encoder_->set_paused(false); 413 encoder_->set_paused(false);
402 } 414 }
403 415
404 void VideoTrackRecorder::OnVideoFrameForTesting( 416 void VideoTrackRecorder::OnVideoFrameForTesting(
405 const scoped_refptr<media::VideoFrame>& frame, 417 const scoped_refptr<media::VideoFrame>& frame,
406 base::TimeTicks timestamp) { 418 base::TimeTicks timestamp) {
407 encoder_->StartFrameEncode(frame, timestamp); 419 encoder_->StartFrameEncode(frame, timestamp);
408 } 420 }
409 421
410 } // namespace content 422 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_track_adapter.cc ('k') | content/renderer/media/webmediaplayer_ms.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698