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