diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 23:51:37 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 23:51:37 +0000 |
commit | 601a35fc79af90f67952ef79ba4d126efd58b17f (patch) | |
tree | 1c7fe70d8051f48d37f600f3edc1bf65616eb1e6 | |
parent | 6f5c3c59ebab3b4f807a04e0781f525144e14630 (diff) | |
download | chromium_src-601a35fc79af90f67952ef79ba4d126efd58b17f.zip chromium_src-601a35fc79af90f67952ef79ba4d126efd58b17f.tar.gz chromium_src-601a35fc79af90f67952ef79ba4d126efd58b17f.tar.bz2 |
Merge 237531 "Fix DesktopCaptureDevice to handle inverted frames."
> Fix DesktopCaptureDevice to handle inverted frames.
>
> Previously DesktopCaptureDevice was passing inverted frames to
> OnIncomingCapturedFrame() as is, and it would crash the browser.
>
> BUG=306876
>
> Review URL: https://codereview.chromium.org/77623002
TBR=sergeyu@chromium.org
Review URL: https://codereview.chromium.org/113453002
git-svn-id: svn://svn.chromium.org/chrome/branches/1700/src@240220 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/renderer_host/media/desktop_capture_device.cc | 10 | ||||
-rw-r--r-- | content/browser/renderer_host/media/video_capture_controller.cc | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/content/browser/renderer_host/media/desktop_capture_device.cc b/content/browser/renderer_host/media/desktop_capture_device.cc index 6303f21..5072841 100644 --- a/content/browser/renderer_host/media/desktop_capture_device.cc +++ b/content/browser/renderer_host/media/desktop_capture_device.cc @@ -180,11 +180,19 @@ void DesktopCaptureDevice::Core::OnCaptureCompleted( size_t output_bytes = output_size.width() * output_size.height() * webrtc::DesktopFrame::kBytesPerPixel; const uint8_t* output_data = NULL; + bool flip_vertically = false; if (frame->size().equals(output_size)) { // If the captured frame matches the output size, we can return the pixel // data directly, without scaling. output_data = frame->data(); + + // If the |frame| generated by the screen capturer is inverted then we need + // to adjust |output_data| to point at the beginning of the buffer instead + // of the first row. + flip_vertically = frame->stride() < 0; + if (flip_vertically) + output_data += frame->stride() * (frame->size().height() - 1); } else { // Otherwise we need to down-scale and/or letterbox to the target format. @@ -212,7 +220,7 @@ void DesktopCaptureDevice::Core::OnCaptureCompleted( if (client_) { client_->OnIncomingCapturedFrame(output_data, output_bytes, - base::Time::Now(), 0, false, false); + base::Time::Now(), 0, flip_vertically, false); } } diff --git a/content/browser/renderer_host/media/video_capture_controller.cc b/content/browser/renderer_host/media/video_capture_controller.cc index 40e94bd..3c1b629 100644 --- a/content/browser/renderer_host/media/video_capture_controller.cc +++ b/content/browser/renderer_host/media/video_capture_controller.cc @@ -273,11 +273,19 @@ void VideoCaptureController::VideoCaptureDeviceClient::OnIncomingCapturedFrame( int destination_width = frame_info_.width; int destination_height = frame_info_.height; libyuv::FourCC origin_colorspace = libyuv::FOURCC_ANY; + + // When rotating by 90 and 270 degrees swap |flip_horiz| and |flip_vert| + // because ConvertToI420() flips image before rotation, while + // OnIncomingCapturedFrame() interface assumes that rotation happens before + // flips. + if (rotation == 90 || rotation == 270) + std::swap(flip_horiz, flip_vert); + // Assuming rotation happens first and flips next, we can consolidate both // vertical and horizontal flips together with rotation into two variables: - // new_rotation = (rotation + 180 * vertical_flip) modulo 360 + // new_rotation = (rotation + 180 * horizontal_flip) modulo 360 // new_vertical_flip = horizontal_flip XOR vertical_flip - int new_rotation_angle = (rotation + 180 * flip_vert) % 360; + int new_rotation_angle = (rotation + 180 * flip_horiz) % 360; libyuv::RotationMode rotation_mode = libyuv::kRotate0; if (new_rotation_angle == 90) rotation_mode = libyuv::kRotate90; |