Chromium Code Reviews| 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 "content/renderer/media/webrtc/webrtc_video_frame_adapter.h" | 10 #include "content/renderer/media/webrtc/webrtc_video_frame_adapter.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 cricket::VideoFrame* CreateAliasedFrame( | 64 cricket::VideoFrame* CreateAliasedFrame( |
| 65 const cricket::CapturedFrame* input_frame, | 65 const cricket::CapturedFrame* input_frame, |
| 66 int cropped_input_width, | 66 int cropped_input_width, |
| 67 int cropped_input_height, | 67 int cropped_input_height, |
| 68 int output_width, | 68 int output_width, |
| 69 int output_height) const override { | 69 int output_height) const override { |
| 70 // Check that captured_frame is actually our frame. | 70 // Check that captured_frame is actually our frame. |
| 71 DCHECK(input_frame == &captured_frame_); | 71 DCHECK(input_frame == &captured_frame_); |
| 72 DCHECK(frame_.get()); | 72 DCHECK(frame_.get()); |
| 73 | 73 |
| 74 const int64_t timestamp_ns = frame_->timestamp().InMicroseconds() * | |
| 75 base::Time::kNanosecondsPerMicrosecond; | |
| 76 | |
| 77 // Return |frame_| directly if it is texture backed, because there is no | |
| 78 // cropping support for texture yet. See http://crbug/503653. | |
| 79 if (frame_->HasTextures()) { | |
| 80 return new cricket::WebRtcVideoFrame( | |
| 81 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame_), | |
| 82 captured_frame_.elapsed_time, timestamp_ns); | |
| 83 } | |
| 84 | |
| 74 // Create a centered cropped visible rect that preservers aspect ratio for | 85 // Create a centered cropped visible rect that preservers aspect ratio for |
| 75 // cropped natural size. | 86 // cropped natural size. |
| 76 gfx::Rect visible_rect = frame_->visible_rect(); | 87 gfx::Rect visible_rect = frame_->visible_rect(); |
| 77 visible_rect.ClampToCenteredSize(gfx::Size( | 88 visible_rect.ClampToCenteredSize(gfx::Size( |
| 78 visible_rect.width() * cropped_input_width / input_frame->width, | 89 visible_rect.width() * cropped_input_width / input_frame->width, |
| 79 visible_rect.height() * cropped_input_height / input_frame->height)); | 90 visible_rect.height() * cropped_input_height / input_frame->height)); |
| 80 | 91 |
| 81 const gfx::Size output_size(output_width, output_height); | 92 const gfx::Size output_size(output_width, output_height); |
| 82 scoped_refptr<media::VideoFrame> video_frame = | 93 scoped_refptr<media::VideoFrame> video_frame = |
| 83 media::VideoFrame::WrapVideoFrame(frame_, visible_rect, output_size); | 94 media::VideoFrame::WrapVideoFrame(frame_, visible_rect, output_size); |
| 84 video_frame->AddDestructionObserver( | 95 video_frame->AddDestructionObserver( |
| 85 base::Bind(&ReleaseOriginalFrame, frame_)); | 96 base::Bind(&ReleaseOriginalFrame, frame_)); |
| 86 | 97 |
| 87 const int64_t timestamp_ns = frame_->timestamp().InMicroseconds() * | |
| 88 base::Time::kNanosecondsPerMicrosecond; | |
| 89 | |
| 90 // If no scaling is needed, return a wrapped version of |frame_| directly. | 98 // If no scaling is needed, return a wrapped version of |frame_| directly. |
| 91 if (video_frame->natural_size() == video_frame->visible_rect().size()) { | 99 if (video_frame->natural_size() == video_frame->visible_rect().size()) { |
| 92 return new cricket::WebRtcVideoFrame( | 100 return new cricket::WebRtcVideoFrame( |
| 93 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame), | 101 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame), |
| 94 captured_frame_.elapsed_time, timestamp_ns); | 102 captured_frame_.elapsed_time, timestamp_ns); |
| 95 } | 103 } |
| 96 | 104 |
| 97 // We need to scale the frame before we hand it over to cricket. | 105 // We need to scale the frame before we hand it over to cricket. |
| 98 scoped_refptr<media::VideoFrame> scaled_frame = | 106 scoped_refptr<media::VideoFrame> scaled_frame = |
| 99 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size, | 107 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 best_format->height = desired.height; | 209 best_format->height = desired.height; |
| 202 best_format->fourcc = cricket::FOURCC_I420; | 210 best_format->fourcc = cricket::FOURCC_I420; |
| 203 best_format->interval = desired.interval; | 211 best_format->interval = desired.interval; |
| 204 return true; | 212 return true; |
| 205 } | 213 } |
| 206 | 214 |
| 207 void WebRtcVideoCapturerAdapter::OnFrameCaptured( | 215 void WebRtcVideoCapturerAdapter::OnFrameCaptured( |
| 208 const scoped_refptr<media::VideoFrame>& frame) { | 216 const scoped_refptr<media::VideoFrame>& frame) { |
| 209 DCHECK(thread_checker_.CalledOnValidThread()); | 217 DCHECK(thread_checker_.CalledOnValidThread()); |
| 210 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); | 218 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); |
| 211 if (!(media::VideoFrame::I420 == frame->format() || | 219 if (!((frame->IsMappable() && (frame->format() == media::VideoFrame::I420 || |
| 212 media::VideoFrame::YV12 == frame->format())) { | 220 frame->format() == media::VideoFrame::YV12)) || |
| 213 // Some types of sources support textures as output. Since connecting | 221 frame->HasTextures())) { |
|
mcasas
2015/06/26 00:18:32
Is l.221 correct? I thought with this CL we can ac
emircan
2015/06/26 19:47:09
Correct. The initial ! applies to both statements.
| |
| 214 // sources and sinks do not check the format, we need to just ignore | 222 // Since connecting sources and sinks do not check the format, we need to |
| 215 // formats that we can not handle. | 223 // just ignore formats that we can not handle. |
| 216 NOTREACHED(); | 224 NOTREACHED(); |
| 217 return; | 225 return; |
| 218 } | 226 } |
| 219 | 227 |
| 220 if (first_frame_timestamp_ == media::kNoTimestamp()) | 228 if (first_frame_timestamp_ == media::kNoTimestamp()) |
| 221 first_frame_timestamp_ = frame->timestamp(); | 229 first_frame_timestamp_ = frame->timestamp(); |
| 222 | 230 |
| 223 const int64 elapsed_time = | 231 const int64 elapsed_time = |
| 224 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * | 232 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * |
| 225 base::Time::kNanosecondsPerMicrosecond; | 233 base::Time::kNanosecondsPerMicrosecond; |
| 226 | 234 |
| 227 // Inject the frame via the VideoFrameFractory. | 235 // Inject the frame via the VideoFrameFractory. |
| 228 DCHECK(frame_factory_ == frame_factory()); | 236 DCHECK(frame_factory_ == frame_factory()); |
|
mcasas
2015/06/26 00:18:32
DCHECK_EQ?
what exactly is this line testing for?
emircan
2015/06/26 19:47:09
l.152 passes the ownership of the frame_factory_ t
mcasas
2015/06/26 23:52:56
Ugh, there is a
MediaVideoFrameFactory* frame_fac
emircan
2015/06/27 00:37:16
The method used from |MediaVideoFrameFactory* fram
| |
| 229 frame_factory_->SetFrame(frame, elapsed_time); | 237 frame_factory_->SetFrame(frame, elapsed_time); |
| 230 | 238 |
| 231 // This signals to libJingle that a new VideoFrame is available. | 239 // This signals to libJingle that a new VideoFrame is available. |
| 232 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); | 240 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); |
| 233 | 241 |
| 234 frame_factory_->ReleaseFrame(); // Release the frame ASAP. | 242 frame_factory_->ReleaseFrame(); // Release the frame ASAP. |
| 235 } | 243 } |
| 236 | 244 |
| 237 } // namespace content | 245 } // namespace content |
| OLD | NEW |