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 } | 22 } |
21 | 23 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 best_format->width = desired.width; | 73 best_format->width = desired.width; |
72 best_format->height = desired.height; | 74 best_format->height = desired.height; |
73 best_format->fourcc = cricket::FOURCC_I420; | 75 best_format->fourcc = cricket::FOURCC_I420; |
74 best_format->interval = desired.interval; | 76 best_format->interval = desired.interval; |
75 return true; | 77 return true; |
76 } | 78 } |
77 | 79 |
78 void WebRtcVideoCapturerAdapter::OnFrameCaptured( | 80 void WebRtcVideoCapturerAdapter::OnFrameCaptured( |
79 const scoped_refptr<media::VideoFrame>& frame) { | 81 const scoped_refptr<media::VideoFrame>& frame) { |
80 DCHECK(media::VideoFrame::I420 == frame->format() || | 82 DCHECK(media::VideoFrame::I420 == frame->format() || |
81 media::VideoFrame::YV12 == frame->format()); | 83 media::VideoFrame::YV12 == frame->format() || |
84 media::VideoFrame::NATIVE_TEXTURE == frame->format()); | |
82 if (first_frame_timestamp_ == media::kNoTimestamp()) | 85 if (first_frame_timestamp_ == media::kNoTimestamp()) |
83 first_frame_timestamp_ = frame->timestamp(); | 86 first_frame_timestamp_ = frame->timestamp(); |
84 | 87 |
85 cricket::CapturedFrame captured_frame; | 88 cricket::CapturedFrame captured_frame; |
86 captured_frame.width = frame->visible_rect().width(); | 89 captured_frame.width = frame->visible_rect().width(); |
87 captured_frame.height = frame->visible_rect().height(); | 90 captured_frame.height = frame->visible_rect().height(); |
88 // cricket::CapturedFrame time is in nanoseconds. | 91 // cricket::CapturedFrame time is in nanoseconds. |
89 captured_frame.elapsed_time = | 92 captured_frame.elapsed_time = |
90 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * | 93 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * |
91 base::Time::kNanosecondsPerMicrosecond; | 94 base::Time::kNanosecondsPerMicrosecond; |
92 captured_frame.time_stamp = frame->timestamp().InMicroseconds() * | 95 captured_frame.time_stamp = frame->timestamp().InMicroseconds() * |
93 base::Time::kNanosecondsPerMicrosecond; | 96 base::Time::kNanosecondsPerMicrosecond; |
94 captured_frame.pixel_height = 1; | 97 captured_frame.pixel_height = 1; |
95 captured_frame.pixel_width = 1; | 98 captured_frame.pixel_width = 1; |
96 | 99 |
97 // TODO(perkj): | 100 // TODO(perkj): |
Ami GONE FROM CHROMIUM
2014/05/12 19:59:12
I guess this comment now belongs at l.110?
wuchengli
2014/05/13 07:28:53
Done.
| |
98 // Libjingle expects contiguous layout of image planes as input. | 101 // Libjingle expects contiguous layout of image planes as input. |
99 // The only format where that is true in Chrome is I420 where the | 102 // The only format where that is true in Chrome is I420 where the |
100 // coded_size == visible_rect().size(). | 103 // coded_size == visible_rect().size(). |
101 if (frame->format() != media::VideoFrame::I420 || | 104 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
102 frame->coded_size() != frame->visible_rect().size()) { | 105 webrtc::RefCountImpl<NativeHandleImpl>* handle = |
Ami GONE FROM CHROMIUM
2014/05/12 19:59:12
no need for the intermediate variable?
wuchengli
2014/05/13 07:28:53
Done.
| |
106 new webrtc::RefCountImpl<NativeHandleImpl>(frame.get()); | |
107 captured_frame.handle = handle; | |
108 } else if (frame->format() != media::VideoFrame::I420 || | |
109 frame->coded_size() != frame->visible_rect().size()) { | |
103 // Cropping and or switching UV planes is needed. | 110 // Cropping and or switching UV planes is needed. |
104 UpdateI420Buffer(frame); | 111 UpdateI420Buffer(frame); |
105 captured_frame.data = buffer_; | 112 captured_frame.data = buffer_; |
106 captured_frame.data_size = buffer_size_; | 113 captured_frame.data_size = buffer_size_; |
107 captured_frame.fourcc = cricket::FOURCC_I420; | 114 captured_frame.fourcc = cricket::FOURCC_I420; |
108 } else { | 115 } else { |
109 captured_frame.fourcc = media::VideoFrame::I420 == frame->format() ? | 116 captured_frame.fourcc = media::VideoFrame::I420 == frame->format() ? |
110 cricket::FOURCC_I420 : cricket::FOURCC_YV12; | 117 cricket::FOURCC_I420 : cricket::FOURCC_YV12; |
111 captured_frame.data = frame->data(0); | 118 captured_frame.data = frame->data(0); |
112 captured_frame.data_size = | 119 captured_frame.data_size = |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 dst_stride_y, | 173 dst_stride_y, |
167 dst_u, | 174 dst_u, |
168 dst_halfwidth, | 175 dst_halfwidth, |
169 dst_v, | 176 dst_v, |
170 dst_halfwidth, | 177 dst_halfwidth, |
171 dst_width, | 178 dst_width, |
172 dst_height); | 179 dst_height); |
173 } | 180 } |
174 | 181 |
175 } // namespace content | 182 } // namespace content |
OLD | NEW |