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/canvas_capture_handler.h" | 5 #include "content/renderer/media/canvas_capture_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "content/public/renderer/render_thread.h" | 14 #include "content/public/renderer/render_thread.h" |
15 #include "content/renderer/media/media_stream_video_capturer_source.h" | 15 #include "content/renderer/media/media_stream_video_capturer_source.h" |
16 #include "content/renderer/media/media_stream_video_source.h" | 16 #include "content/renderer/media/media_stream_video_source.h" |
17 #include "content/renderer/media/media_stream_video_track.h" | 17 #include "content/renderer/media/media_stream_video_track.h" |
18 #include "content/renderer/media/webrtc_uma_histograms.h" | 18 #include "content/renderer/media/webrtc_uma_histograms.h" |
19 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
21 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/libyuv/include/libyuv.h" | 22 #include "third_party/libyuv/include/libyuv.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 using media::VideoFrame; |
| 27 |
26 static void CopyAlphaChannelIntoVideoFrame( | 28 static void CopyAlphaChannelIntoVideoFrame( |
27 const uint8_t* const source, | 29 const uint8_t* const source_data, |
28 const scoped_refptr<media::VideoFrame>& dest_frame) { | 30 const gfx::Size& source_size, |
29 const gfx::Size& size = dest_frame->coded_size(); | 31 const scoped_refptr<VideoFrame>& dest_frame) { |
30 const int stride = dest_frame->stride(media::VideoFrame::kAPlane); | 32 const int dest_stride = dest_frame->stride(VideoFrame::kAPlane); |
31 | 33 if (dest_stride == source_size.width()) { |
32 if (stride == size.width()) { | 34 for (int p = 0; p < source_size.GetArea(); ++p) { |
33 for (int p = 0; p < size.GetArea(); ++p) | 35 dest_frame->visible_data(VideoFrame::kAPlane)[p] = source_data[p * 4 + 3]; |
34 dest_frame->data(media::VideoFrame::kAPlane)[p] = source[p * 4 + 3]; | 36 } |
35 return; | 37 return; |
36 } | 38 } |
37 | 39 |
38 // Copy apha values one-by-one if the destination stride != source width. | 40 // Copy alpha values one-by-one if the destination stride != source width. |
39 for (int h = 0; h < size.height(); ++h) { | 41 for (int h = 0; h < source_size.height(); ++h) { |
40 const uint8_t* const src_ptr = &source[4 * h * size.width()]; | 42 const uint8_t* const src_ptr = &source_data[4 * h * source_size.width()]; |
41 uint8_t* dest_ptr = | 43 uint8_t* dest_ptr = |
42 &dest_frame->data(media::VideoFrame::kAPlane)[h * stride]; | 44 &dest_frame->visible_data(VideoFrame::kAPlane)[h * dest_stride]; |
43 for (int pixel_index = 0; pixel_index < 4 * size.width(); pixel_index += 4) | 45 for (int pixel = 0; pixel < 4 * source_size.width(); pixel += 4) |
44 *(dest_ptr++) = src_ptr[pixel_index + 3]; | 46 *(dest_ptr++) = src_ptr[pixel + 3]; |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 } // namespace | 50 } // namespace |
49 | 51 |
50 namespace content { | 52 namespace content { |
51 | 53 |
52 // Implementation VideoCapturerSource that is owned by | 54 // Implementation VideoCapturerSource that is owned by |
53 // MediaStreamVideoCapturerSource and delegates the Start/Stop calls to | 55 // MediaStreamVideoCapturerSource and delegates the Start/Stop calls to |
54 // CanvasCaptureHandler. | 56 // CanvasCaptureHandler. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 243 } |
242 | 244 |
243 const bool isOpaque = image->isOpaque(); | 245 const bool isOpaque = image->isOpaque(); |
244 const base::TimeTicks timestamp = base::TimeTicks::Now(); | 246 const base::TimeTicks timestamp = base::TimeTicks::Now(); |
245 scoped_refptr<media::VideoFrame> video_frame = frame_pool_.CreateFrame( | 247 scoped_refptr<media::VideoFrame> video_frame = frame_pool_.CreateFrame( |
246 isOpaque ? media::PIXEL_FORMAT_I420 : media::PIXEL_FORMAT_YV12A, size, | 248 isOpaque ? media::PIXEL_FORMAT_I420 : media::PIXEL_FORMAT_YV12A, size, |
247 gfx::Rect(size), size, timestamp - base::TimeTicks()); | 249 gfx::Rect(size), size, timestamp - base::TimeTicks()); |
248 DCHECK(video_frame); | 250 DCHECK(video_frame); |
249 | 251 |
250 libyuv::ARGBToI420(temp_data_.data(), row_bytes_, | 252 libyuv::ARGBToI420(temp_data_.data(), row_bytes_, |
251 video_frame->data(media::VideoFrame::kYPlane), | 253 video_frame->visible_data(media::VideoFrame::kYPlane), |
252 video_frame->stride(media::VideoFrame::kYPlane), | 254 video_frame->stride(media::VideoFrame::kYPlane), |
253 video_frame->data(media::VideoFrame::kUPlane), | 255 video_frame->visible_data(media::VideoFrame::kUPlane), |
254 video_frame->stride(media::VideoFrame::kUPlane), | 256 video_frame->stride(media::VideoFrame::kUPlane), |
255 video_frame->data(media::VideoFrame::kVPlane), | 257 video_frame->visible_data(media::VideoFrame::kVPlane), |
256 video_frame->stride(media::VideoFrame::kVPlane), | 258 video_frame->stride(media::VideoFrame::kVPlane), |
257 size.width(), size.height()); | 259 size.width(), size.height()); |
258 if (!isOpaque) { | 260 if (!isOpaque) { |
259 // TODO(emircan): Use https://code.google.com/p/libyuv/issues/detail?id=572 | 261 // TODO(emircan): Use https://code.google.com/p/libyuv/issues/detail?id=572 |
260 // when it becomes available. | 262 // when it becomes available. |
261 CopyAlphaChannelIntoVideoFrame(temp_data_.data(), video_frame); | 263 CopyAlphaChannelIntoVideoFrame(temp_data_.data(), size, video_frame); |
262 } | 264 } |
263 | 265 |
264 last_frame_ = video_frame; | 266 last_frame_ = video_frame; |
265 io_task_runner_->PostTask( | 267 io_task_runner_->PostTask( |
266 FROM_HERE, | 268 FROM_HERE, |
267 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate:: | 269 base::Bind(&CanvasCaptureHandler::CanvasCaptureHandlerDelegate:: |
268 SendNewFrameOnIOThread, | 270 SendNewFrameOnIOThread, |
269 delegate_->GetWeakPtrForIOThread(), video_frame, timestamp)); | 271 delegate_->GetWeakPtrForIOThread(), video_frame, timestamp)); |
270 } | 272 } |
271 | 273 |
(...skipping 13 matching lines...) Expand all Loading... |
285 | 287 |
286 web_track->initialize(webkit_source); | 288 web_track->initialize(webkit_source); |
287 blink::WebMediaConstraints constraints; | 289 blink::WebMediaConstraints constraints; |
288 constraints.initialize(); | 290 constraints.initialize(); |
289 web_track->setExtraData(new MediaStreamVideoTrack( | 291 web_track->setExtraData(new MediaStreamVideoTrack( |
290 media_stream_source.release(), constraints, | 292 media_stream_source.release(), constraints, |
291 MediaStreamVideoSource::ConstraintsCallback(), true)); | 293 MediaStreamVideoSource::ConstraintsCallback(), true)); |
292 } | 294 } |
293 | 295 |
294 } // namespace content | 296 } // namespace content |
OLD | NEW |