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/memory/aligned_memory.h" | 8 #include "base/memory/aligned_memory.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 cricket::VideoFrame* CreateAliasedFrame( | 112 cricket::VideoFrame* CreateAliasedFrame( |
113 const cricket::CapturedFrame* input_frame, | 113 const cricket::CapturedFrame* input_frame, |
114 int cropped_input_width, | 114 int cropped_input_width, |
115 int cropped_input_height, | 115 int cropped_input_height, |
116 int output_width, | 116 int output_width, |
117 int output_height) const override { | 117 int output_height) const override { |
118 // Check that captured_frame is actually our frame. | 118 // Check that captured_frame is actually our frame. |
119 DCHECK(input_frame == &captured_frame_); | 119 DCHECK(input_frame == &captured_frame_); |
120 DCHECK(frame_.get()); | 120 DCHECK(frame_.get()); |
121 | 121 |
| 122 const int64_t timestamp_ns = frame_->timestamp().InMicroseconds() * |
| 123 base::Time::kNanosecondsPerMicrosecond; |
| 124 |
| 125 if (frame_->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 126 return new cricket::WebRtcVideoFrame( |
| 127 new rtc::RefCountedObject<VideoFrameWrapper>(frame_), |
| 128 captured_frame_.elapsed_time, timestamp_ns); |
| 129 } |
| 130 |
122 // Create a centered cropped visible rect that preservers aspect ratio for | 131 // Create a centered cropped visible rect that preservers aspect ratio for |
123 // cropped natural size. | 132 // cropped natural size. |
124 gfx::Rect visible_rect = frame_->visible_rect(); | 133 gfx::Rect visible_rect = frame_->visible_rect(); |
125 visible_rect.ClampToCenteredSize(gfx::Size( | 134 visible_rect.ClampToCenteredSize(gfx::Size( |
126 visible_rect.width() * cropped_input_width / input_frame->width, | 135 visible_rect.width() * cropped_input_width / input_frame->width, |
127 visible_rect.height() * cropped_input_height / input_frame->height)); | 136 visible_rect.height() * cropped_input_height / input_frame->height)); |
128 | 137 |
129 const gfx::Size output_size(output_width, output_height); | 138 const gfx::Size output_size(output_width, output_height); |
130 scoped_refptr<media::VideoFrame> video_frame = | 139 scoped_refptr<media::VideoFrame> video_frame = |
131 media::VideoFrame::WrapVideoFrame( | 140 media::VideoFrame::WrapVideoFrame( |
132 frame_, visible_rect, output_size, | 141 frame_, visible_rect, output_size, |
133 base::Bind(&ReleaseOriginalFrame, frame_)); | 142 base::Bind(&ReleaseOriginalFrame, frame_)); |
134 | 143 |
135 const int64_t timestamp_ns = frame_->timestamp().InMicroseconds() * | |
136 base::Time::kNanosecondsPerMicrosecond; | |
137 | |
138 // If no scaling is needed, return a wrapped version of |frame_| directly. | 144 // If no scaling is needed, return a wrapped version of |frame_| directly. |
139 if (video_frame->natural_size() == video_frame->visible_rect().size()) { | 145 if (video_frame->natural_size() == video_frame->visible_rect().size()) { |
140 return new cricket::WebRtcVideoFrame( | 146 return new cricket::WebRtcVideoFrame( |
141 new rtc::RefCountedObject<VideoFrameWrapper>(video_frame), | 147 new rtc::RefCountedObject<VideoFrameWrapper>(video_frame), |
142 captured_frame_.elapsed_time, timestamp_ns); | 148 captured_frame_.elapsed_time, timestamp_ns); |
143 } | 149 } |
144 | 150 |
145 // We need to scale the frame before we hand it over to cricket. | 151 // We need to scale the frame before we hand it over to cricket. |
146 scoped_refptr<media::VideoFrame> scaled_frame = | 152 scoped_refptr<media::VideoFrame> scaled_frame = |
147 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size, | 153 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 best_format->fourcc = cricket::FOURCC_I420; | 256 best_format->fourcc = cricket::FOURCC_I420; |
251 best_format->interval = desired.interval; | 257 best_format->interval = desired.interval; |
252 return true; | 258 return true; |
253 } | 259 } |
254 | 260 |
255 void WebRtcVideoCapturerAdapter::OnFrameCaptured( | 261 void WebRtcVideoCapturerAdapter::OnFrameCaptured( |
256 const scoped_refptr<media::VideoFrame>& frame) { | 262 const scoped_refptr<media::VideoFrame>& frame) { |
257 DCHECK(thread_checker_.CalledOnValidThread()); | 263 DCHECK(thread_checker_.CalledOnValidThread()); |
258 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); | 264 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); |
259 if (!(media::VideoFrame::I420 == frame->format() || | 265 if (!(media::VideoFrame::I420 == frame->format() || |
260 media::VideoFrame::YV12 == frame->format())) { | 266 media::VideoFrame::YV12 == frame->format() || |
261 // Some types of sources support textures as output. Since connecting | 267 media::VideoFrame::NATIVE_TEXTURE == frame->format())) { |
262 // sources and sinks do not check the format, we need to just ignore | |
263 // formats that we can not handle. | |
264 NOTREACHED(); | 268 NOTREACHED(); |
265 return; | 269 return; |
266 } | 270 } |
267 | 271 |
268 if (first_frame_timestamp_ == media::kNoTimestamp()) | 272 if (first_frame_timestamp_ == media::kNoTimestamp()) |
269 first_frame_timestamp_ = frame->timestamp(); | 273 first_frame_timestamp_ = frame->timestamp(); |
270 | 274 |
271 const int64 elapsed_time = | 275 const int64 elapsed_time = |
272 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * | 276 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * |
273 base::Time::kNanosecondsPerMicrosecond; | 277 base::Time::kNanosecondsPerMicrosecond; |
274 | 278 |
275 // Inject the frame via the VideoFrameFractory. | 279 // Inject the frame via the VideoFrameFractory. |
276 DCHECK(frame_factory_ == frame_factory()); | 280 DCHECK(frame_factory_ == frame_factory()); |
277 frame_factory_->SetFrame(frame, elapsed_time); | 281 frame_factory_->SetFrame(frame, elapsed_time); |
278 | 282 |
279 // This signals to libJingle that a new VideoFrame is available. | 283 // This signals to libJingle that a new VideoFrame is available. |
280 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); | 284 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); |
281 | 285 |
282 frame_factory_->ReleaseFrame(); // Release the frame ASAP. | 286 frame_factory_->ReleaseFrame(); // Release the frame ASAP. |
283 } | 287 } |
284 | 288 |
285 } // namespace content | 289 } // namespace content |
OLD | NEW |