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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 &crop_width, &crop_height, &crop_x, &crop_y, | 129 &crop_width, &crop_height, &crop_x, &crop_y, |
130 &translated_camera_time_us)) { | 130 &translated_camera_time_us)) { |
131 return; | 131 return; |
132 } | 132 } |
133 | 133 |
134 // Return |frame| directly if it is texture backed, because there is no | 134 // Return |frame| directly if it is texture backed, because there is no |
135 // cropping support for texture yet. See http://crbug/503653. | 135 // cropping support for texture yet. See http://crbug/503653. |
136 // Return |frame| directly if it is GpuMemoryBuffer backed, as we want to | 136 // Return |frame| directly if it is GpuMemoryBuffer backed, as we want to |
137 // keep the frame on native buffers. | 137 // keep the frame on native buffers. |
138 if (frame->HasTextures() || | 138 if (frame->HasTextures() || |
139 frame->storage_type() == | 139 frame->storage_type() == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS) { |
140 media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS) { | |
141 OnFrame(cricket::WebRtcVideoFrame( | 140 OnFrame(cricket::WebRtcVideoFrame( |
142 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame), | 141 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame), |
143 webrtc::kVideoRotation_0, translated_camera_time_us), | 142 webrtc::kVideoRotation_0, translated_camera_time_us), |
144 orig_width, orig_height); | 143 orig_width, orig_height); |
145 return; | 144 return; |
146 } | 145 } |
147 | 146 |
148 // Create a centered cropped visible rect that preservers aspect ratio for | 147 // Translate crop rectangle from natural size to visible size. |
149 // cropped natural size. | 148 gfx::Rect cropped_visible_rect( |
150 gfx::Rect visible_rect = frame->visible_rect(); | 149 frame->visible_rect().x() + |
151 visible_rect.ClampToCenteredSize(gfx::Size( | 150 crop_x * frame->visible_rect().width() / orig_width, |
152 visible_rect.width() * adapted_width / orig_width, | 151 frame->visible_rect().y() + |
153 visible_rect.height() * adapted_height / orig_height)); | 152 crop_y * frame->visible_rect().height() / orig_height, |
153 crop_width * frame->visible_rect().width() / orig_width, | |
154 crop_height * frame->visible_rect().height() / orig_height); | |
154 | 155 |
155 const gfx::Size adapted_size(adapted_width, adapted_height); | 156 const gfx::Size adapted_size(adapted_width, adapted_height); |
156 scoped_refptr<media::VideoFrame> video_frame = | 157 scoped_refptr<media::VideoFrame> video_frame = |
nisse-chromium (ooo August 14)
2016/09/09 09:06:57
It would more readable to write
frame = media::
magjed_chromium
2016/09/09 10:26:32
I agree it's confusing with multiple frames, but I
| |
157 media::VideoFrame::WrapVideoFrame(frame, frame->format(), | 158 media::VideoFrame::WrapVideoFrame(frame, frame->format(), |
158 visible_rect, adapted_size); | 159 cropped_visible_rect, adapted_size); |
159 if (!video_frame) | 160 if (!video_frame) |
160 return; | 161 return; |
161 | 162 |
162 video_frame->AddDestructionObserver(base::Bind(&ReleaseOriginalFrame, frame)); | 163 video_frame->AddDestructionObserver(base::Bind(&ReleaseOriginalFrame, frame)); |
163 | 164 |
164 // If no scaling is needed, return a wrapped version of |frame| directly. | 165 // If no scaling is needed, return a wrapped version of |frame| directly. |
165 if (video_frame->natural_size() == video_frame->visible_rect().size()) { | 166 if (video_frame->natural_size() == video_frame->visible_rect().size()) { |
166 OnFrame(cricket::WebRtcVideoFrame( | 167 OnFrame(cricket::WebRtcVideoFrame( |
167 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame), | 168 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(video_frame), |
168 webrtc::kVideoRotation_0, translated_camera_time_us), | 169 webrtc::kVideoRotation_0, translated_camera_time_us), |
(...skipping 22 matching lines...) Expand all Loading... | |
191 scaled_frame->stride(media::VideoFrame::kVPlane), | 192 scaled_frame->stride(media::VideoFrame::kVPlane), |
192 adapted_width, adapted_height, libyuv::kFilterBilinear); | 193 adapted_width, adapted_height, libyuv::kFilterBilinear); |
193 | 194 |
194 OnFrame(cricket::WebRtcVideoFrame( | 195 OnFrame(cricket::WebRtcVideoFrame( |
195 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(scaled_frame), | 196 new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(scaled_frame), |
196 webrtc::kVideoRotation_0, translated_camera_time_us), | 197 webrtc::kVideoRotation_0, translated_camera_time_us), |
197 orig_width, orig_height); | 198 orig_width, orig_height); |
198 } | 199 } |
199 | 200 |
200 } // namespace content | 201 } // namespace content |
OLD | NEW |