Commit aca43aa3 authored by magjed's avatar magjed Committed by Commit bot

Fix crop bug in WebRtcVideoCapturerAdapter

In the current code, CPU adaptation does not work correctly. It should
scale to the adapted resolution, but it crops instead. The result looks
like zoomed in video. This bug was introduced in
https://codereview.chromium.org/2270723002/.

This CL fixes the cropping logic.

BUG=chromium:635592

Review-Url: https://codereview.chromium.org/2323573004
Cr-Commit-Position: refs/heads/master@{#417549}
parent de6470c2
...@@ -136,8 +136,7 @@ void WebRtcVideoCapturerAdapter::OnFrameCaptured( ...@@ -136,8 +136,7 @@ void WebRtcVideoCapturerAdapter::OnFrameCaptured(
// Return |frame| directly if it is GpuMemoryBuffer backed, as we want to // Return |frame| directly if it is GpuMemoryBuffer backed, as we want to
// keep the frame on native buffers. // keep the frame on native buffers.
if (frame->HasTextures() || if (frame->HasTextures() ||
frame->storage_type() == frame->storage_type() == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS) {
media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS) {
OnFrame(cricket::WebRtcVideoFrame( OnFrame(cricket::WebRtcVideoFrame(
new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame), new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame),
webrtc::kVideoRotation_0, translated_camera_time_us), webrtc::kVideoRotation_0, translated_camera_time_us),
...@@ -145,17 +144,19 @@ void WebRtcVideoCapturerAdapter::OnFrameCaptured( ...@@ -145,17 +144,19 @@ void WebRtcVideoCapturerAdapter::OnFrameCaptured(
return; return;
} }
// Create a centered cropped visible rect that preservers aspect ratio for // Translate crop rectangle from natural size to visible size.
// cropped natural size. gfx::Rect cropped_visible_rect(
gfx::Rect visible_rect = frame->visible_rect(); frame->visible_rect().x() +
visible_rect.ClampToCenteredSize(gfx::Size( crop_x * frame->visible_rect().width() / orig_width,
visible_rect.width() * adapted_width / orig_width, frame->visible_rect().y() +
visible_rect.height() * adapted_height / orig_height)); crop_y * frame->visible_rect().height() / orig_height,
crop_width * frame->visible_rect().width() / orig_width,
crop_height * frame->visible_rect().height() / orig_height);
const gfx::Size adapted_size(adapted_width, adapted_height); const gfx::Size adapted_size(adapted_width, adapted_height);
scoped_refptr<media::VideoFrame> video_frame = scoped_refptr<media::VideoFrame> video_frame =
media::VideoFrame::WrapVideoFrame(frame, frame->format(), media::VideoFrame::WrapVideoFrame(frame, frame->format(),
visible_rect, adapted_size); cropped_visible_rect, adapted_size);
if (!video_frame) if (!video_frame)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment