| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc/webrtc_video_capturer_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "content/renderer/media/native_handle_impl.h" |
| 10 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 11 #include "third_party/libyuv/include/libyuv/convert.h" | 12 #include "third_party/libyuv/include/libyuv/convert.h" |
| 13 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 | 16 |
| 15 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast) | 17 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast) |
| 16 : is_screencast_(is_screencast), | 18 : is_screencast_(is_screencast), |
| 17 running_(false), | 19 running_(false), |
| 18 buffer_(NULL), | 20 buffer_(NULL), |
| 19 buffer_size_(0) { | 21 buffer_size_(0) { |
| 20 thread_checker_.DetachFromThread(); | 22 thread_checker_.DetachFromThread(); |
| 21 } | 23 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 best_format->height = desired.height; | 80 best_format->height = desired.height; |
| 79 best_format->fourcc = cricket::FOURCC_I420; | 81 best_format->fourcc = cricket::FOURCC_I420; |
| 80 best_format->interval = desired.interval; | 82 best_format->interval = desired.interval; |
| 81 return true; | 83 return true; |
| 82 } | 84 } |
| 83 | 85 |
| 84 void WebRtcVideoCapturerAdapter::OnFrameCaptured( | 86 void WebRtcVideoCapturerAdapter::OnFrameCaptured( |
| 85 const scoped_refptr<media::VideoFrame>& frame) { | 87 const scoped_refptr<media::VideoFrame>& frame) { |
| 86 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 DCHECK(media::VideoFrame::I420 == frame->format() || | 89 DCHECK(media::VideoFrame::I420 == frame->format() || |
| 88 media::VideoFrame::YV12 == frame->format()); | 90 media::VideoFrame::YV12 == frame->format() || |
| 91 media::VideoFrame::NATIVE_TEXTURE == frame->format()); |
| 89 if (first_frame_timestamp_ == media::kNoTimestamp()) | 92 if (first_frame_timestamp_ == media::kNoTimestamp()) |
| 90 first_frame_timestamp_ = frame->timestamp(); | 93 first_frame_timestamp_ = frame->timestamp(); |
| 91 | 94 |
| 92 cricket::CapturedFrame captured_frame; | 95 cricket::CapturedFrame captured_frame; |
| 93 captured_frame.width = frame->visible_rect().width(); | 96 captured_frame.width = frame->visible_rect().width(); |
| 94 captured_frame.height = frame->visible_rect().height(); | 97 captured_frame.height = frame->visible_rect().height(); |
| 95 // cricket::CapturedFrame time is in nanoseconds. | 98 // cricket::CapturedFrame time is in nanoseconds. |
| 96 captured_frame.elapsed_time = | 99 captured_frame.elapsed_time = |
| 97 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * | 100 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * |
| 98 base::Time::kNanosecondsPerMicrosecond; | 101 base::Time::kNanosecondsPerMicrosecond; |
| 99 captured_frame.time_stamp = frame->timestamp().InMicroseconds() * | 102 captured_frame.time_stamp = frame->timestamp().InMicroseconds() * |
| 100 base::Time::kNanosecondsPerMicrosecond; | 103 base::Time::kNanosecondsPerMicrosecond; |
| 101 captured_frame.pixel_height = 1; | 104 captured_frame.pixel_height = 1; |
| 102 captured_frame.pixel_width = 1; | 105 captured_frame.pixel_width = 1; |
| 103 | 106 |
| 104 // TODO(perkj): | 107 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 105 // Libjingle expects contiguous layout of image planes as input. | 108 captured_frame.handle = |
| 106 // The only format where that is true in Chrome is I420 where the | 109 new webrtc::RefCountImpl<NativeHandleImpl>(frame.get()); |
| 107 // coded_size == visible_rect().size(). | 110 } else if (frame->format() != media::VideoFrame::I420 || |
| 108 if (frame->format() != media::VideoFrame::I420 || | 111 frame->coded_size() != frame->visible_rect().size()) { |
| 109 frame->coded_size() != frame->visible_rect().size()) { | |
| 110 // Cropping and or switching UV planes is needed. | 112 // Cropping and or switching UV planes is needed. |
| 113 // TODO(perkj): |
| 114 // Libjingle expects contiguous layout of image planes as input. |
| 115 // The only format where that is true in Chrome is I420 where the |
| 116 // coded_size == visible_rect().size(). |
| 111 UpdateI420Buffer(frame); | 117 UpdateI420Buffer(frame); |
| 112 captured_frame.data = buffer_; | 118 captured_frame.data = buffer_; |
| 113 captured_frame.data_size = buffer_size_; | 119 captured_frame.data_size = buffer_size_; |
| 114 captured_frame.fourcc = cricket::FOURCC_I420; | 120 captured_frame.fourcc = cricket::FOURCC_I420; |
| 115 } else { | 121 } else { |
| 116 captured_frame.fourcc = media::VideoFrame::I420 == frame->format() ? | 122 captured_frame.fourcc = media::VideoFrame::I420 == frame->format() ? |
| 117 cricket::FOURCC_I420 : cricket::FOURCC_YV12; | 123 cricket::FOURCC_I420 : cricket::FOURCC_YV12; |
| 118 captured_frame.data = frame->data(0); | 124 captured_frame.data = frame->data(0); |
| 119 captured_frame.data_size = | 125 captured_frame.data_size = |
| 120 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); | 126 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 dst_stride_y, | 180 dst_stride_y, |
| 175 dst_u, | 181 dst_u, |
| 176 dst_halfwidth, | 182 dst_halfwidth, |
| 177 dst_v, | 183 dst_v, |
| 178 dst_halfwidth, | 184 dst_halfwidth, |
| 179 dst_width, | 185 dst_width, |
| 180 dst_height); | 186 dst_height); |
| 181 } | 187 } |
| 182 | 188 |
| 183 } // namespace content | 189 } // namespace content |
| OLD | NEW |