Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc

Issue 1093223006: WebRtcVideoCapturerAdapter mods for Texture-backed VideoFrames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gpu/command_buffer/common/mailbox_holder.h"
magjed_chromium 2015/04/24 07:35:34 Why is this include needed?
mcasas 2015/04/24 18:34:29 Removed. (It was a remnant of intermediate PSs).
10 #include "media/base/video_frame.h" 11 #include "media/base/video_frame.h"
11 #include "media/base/video_frame_pool.h" 12 #include "media/base/video_frame_pool.h"
12 #include "third_party/libjingle/source/talk/media/base/videoframefactory.h" 13 #include "third_party/libjingle/source/talk/media/base/videoframefactory.h"
13 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" 14 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h"
14 #include "third_party/libyuv/include/libyuv/convert_from.h" 15 #include "third_party/libyuv/include/libyuv/convert_from.h"
15 #include "third_party/libyuv/include/libyuv/scale.h" 16 #include "third_party/libyuv/include/libyuv/scale.h"
16 #include "third_party/webrtc/common_video/interface/video_frame_buffer.h" 17 #include "third_party/webrtc/common_video/interface/video_frame_buffer.h"
17 #include "third_party/webrtc/common_video/rotation.h" 18 #include "third_party/webrtc/common_video/rotation.h"
18 19
19 namespace content { 20 namespace content {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 cricket::VideoFrame* CreateAliasedFrame( 113 cricket::VideoFrame* CreateAliasedFrame(
113 const cricket::CapturedFrame* input_frame, 114 const cricket::CapturedFrame* input_frame,
114 int cropped_input_width, 115 int cropped_input_width,
115 int cropped_input_height, 116 int cropped_input_height,
116 int output_width, 117 int output_width,
117 int output_height) const override { 118 int output_height) const override {
118 // Check that captured_frame is actually our frame. 119 // Check that captured_frame is actually our frame.
119 DCHECK(input_frame == &captured_frame_); 120 DCHECK(input_frame == &captured_frame_);
120 DCHECK(frame_.get()); 121 DCHECK(frame_.get());
121 122
123 const int64_t timestamp_ns = frame_->timestamp().InMicroseconds() *
124 base::Time::kNanosecondsPerMicrosecond;
125
126 if (frame_->format() == media::VideoFrame::NATIVE_TEXTURE) {
127 return new cricket::WebRtcVideoFrame(
128 new rtc::RefCountedObject<VideoFrameWrapper>(frame_),
129 captured_frame_.elapsed_time, timestamp_ns);
130 }
131
122 // Create a centered cropped visible rect that preservers aspect ratio for 132 // Create a centered cropped visible rect that preservers aspect ratio for
123 // cropped natural size. 133 // cropped natural size.
124 gfx::Rect visible_rect = frame_->visible_rect(); 134 gfx::Rect visible_rect = frame_->visible_rect();
125 visible_rect.ClampToCenteredSize(gfx::Size( 135 visible_rect.ClampToCenteredSize(gfx::Size(
126 visible_rect.width() * cropped_input_width / input_frame->width, 136 visible_rect.width() * cropped_input_width / input_frame->width,
127 visible_rect.height() * cropped_input_height / input_frame->height)); 137 visible_rect.height() * cropped_input_height / input_frame->height));
128 138
129 const gfx::Size output_size(output_width, output_height); 139 const gfx::Size output_size(output_width, output_height);
130 scoped_refptr<media::VideoFrame> video_frame = 140 scoped_refptr<media::VideoFrame> video_frame =
131 media::VideoFrame::WrapVideoFrame( 141 media::VideoFrame::WrapVideoFrame(
132 frame_, visible_rect, output_size, 142 frame_, visible_rect, output_size,
133 base::Bind(&ReleaseOriginalFrame, frame_)); 143 base::Bind(&ReleaseOriginalFrame, frame_));
134 144
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. 145 // If no scaling is needed, return a wrapped version of |frame_| directly.
139 if (video_frame->natural_size() == video_frame->visible_rect().size()) { 146 if (video_frame->natural_size() == video_frame->visible_rect().size()) {
140 return new cricket::WebRtcVideoFrame( 147 return new cricket::WebRtcVideoFrame(
141 new rtc::RefCountedObject<VideoFrameWrapper>(video_frame), 148 new rtc::RefCountedObject<VideoFrameWrapper>(video_frame),
142 captured_frame_.elapsed_time, timestamp_ns); 149 captured_frame_.elapsed_time, timestamp_ns);
143 } 150 }
144 151
145 // We need to scale the frame before we hand it over to cricket. 152 // We need to scale the frame before we hand it over to cricket.
146 scoped_refptr<media::VideoFrame> scaled_frame = 153 scoped_refptr<media::VideoFrame> scaled_frame =
147 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size, 154 scaled_frame_pool_.CreateFrame(media::VideoFrame::I420, output_size,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 best_format->fourcc = cricket::FOURCC_I420; 257 best_format->fourcc = cricket::FOURCC_I420;
251 best_format->interval = desired.interval; 258 best_format->interval = desired.interval;
252 return true; 259 return true;
253 } 260 }
254 261
255 void WebRtcVideoCapturerAdapter::OnFrameCaptured( 262 void WebRtcVideoCapturerAdapter::OnFrameCaptured(
256 const scoped_refptr<media::VideoFrame>& frame) { 263 const scoped_refptr<media::VideoFrame>& frame) {
257 DCHECK(thread_checker_.CalledOnValidThread()); 264 DCHECK(thread_checker_.CalledOnValidThread());
258 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured"); 265 TRACE_EVENT0("video", "WebRtcVideoCapturerAdapter::OnFrameCaptured");
259 if (!(media::VideoFrame::I420 == frame->format() || 266 if (!(media::VideoFrame::I420 == frame->format() ||
260 media::VideoFrame::YV12 == frame->format())) { 267 media::VideoFrame::YV12 == frame->format() ||
261 // Some types of sources support textures as output. Since connecting 268 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(); 269 NOTREACHED();
265 return; 270 return;
266 } 271 }
267 272
268 if (first_frame_timestamp_ == media::kNoTimestamp()) 273 if (first_frame_timestamp_ == media::kNoTimestamp())
269 first_frame_timestamp_ = frame->timestamp(); 274 first_frame_timestamp_ = frame->timestamp();
270 275
271 const int64 elapsed_time = 276 const int64 elapsed_time =
272 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() * 277 (frame->timestamp() - first_frame_timestamp_).InMicroseconds() *
273 base::Time::kNanosecondsPerMicrosecond; 278 base::Time::kNanosecondsPerMicrosecond;
274 279
275 // Inject the frame via the VideoFrameFractory. 280 // Inject the frame via the VideoFrameFractory.
276 DCHECK(frame_factory_ == frame_factory()); 281 DCHECK(frame_factory_ == frame_factory());
277 frame_factory_->SetFrame(frame, elapsed_time); 282 frame_factory_->SetFrame(frame, elapsed_time);
278 283
279 // This signals to libJingle that a new VideoFrame is available. 284 // This signals to libJingle that a new VideoFrame is available.
280 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); 285 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame());
281 286
282 frame_factory_->ReleaseFrame(); // Release the frame ASAP. 287 frame_factory_->ReleaseFrame(); // Release the frame ASAP.
283 } 288 }
284 289
285 } // namespace content 290 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698