Files
platform-external-webrtc/modules/desktop_capture/mac/desktop_frame_iosurface.mm
Julien Isorce bb005b6b96 Make ScreenCapturerMac more robust when using IOSurface
The issue is visible when reconfiguring the screen arrangement while
sharing the displays. Can sometimes be seen right after starting the
screen sharing.

Indeed CaptureFrame can be called at any time so TakeLatestFrameForDisplay
should always return a valid frame and the call should not empty the
internal container.

Also add missing teardown in the provider on failure case.

Bug: webrtc:8652
Change-Id: Ice151c1da92b9ad2b86ca9368d30d9d21114e53e
Reviewed-on: https://webrtc-review.googlesource.com/69420
Commit-Queue: Zijie He <zijiehe@chromium.org>
Reviewed-by: Zijie He <zijiehe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#22846}
2018-04-12 23:04:58 +00:00

62 lines
2.2 KiB
Plaintext

/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/desktop_capture/mac/desktop_frame_iosurface.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
namespace webrtc {
// static
std::unique_ptr<DesktopFrameIOSurface> DesktopFrameIOSurface::Wrap(
rtc::ScopedCFTypeRef<IOSurfaceRef> io_surface) {
if (!io_surface) {
return nullptr;
}
IOSurfaceIncrementUseCount(io_surface.get());
IOReturn status = IOSurfaceLock(io_surface.get(), kIOSurfaceLockReadOnly, nullptr);
if (status != kIOReturnSuccess) {
RTC_LOG(LS_ERROR) << "Failed to lock the IOSurface with status " << status;
IOSurfaceDecrementUseCount(io_surface.get());
return nullptr;
}
// Verify that the image has 32-bit depth.
int bytes_per_pixel = IOSurfaceGetBytesPerElement(io_surface.get());
if (bytes_per_pixel != DesktopFrame::kBytesPerPixel) {
RTC_LOG(LS_ERROR) << "CGDisplayStream handler returned IOSurface with " << (8 * bytes_per_pixel)
<< " bits per pixel. Only 32-bit depth is supported.";
IOSurfaceUnlock(io_surface.get(), kIOSurfaceLockReadOnly, nullptr);
IOSurfaceDecrementUseCount(io_surface.get());
return nullptr;
}
return std::unique_ptr<DesktopFrameIOSurface>(new DesktopFrameIOSurface(io_surface));
}
DesktopFrameIOSurface::DesktopFrameIOSurface(rtc::ScopedCFTypeRef<IOSurfaceRef> io_surface)
: DesktopFrame(
DesktopSize(IOSurfaceGetWidth(io_surface.get()), IOSurfaceGetHeight(io_surface.get())),
IOSurfaceGetBytesPerRow(io_surface.get()),
static_cast<uint8_t*>(IOSurfaceGetBaseAddress(io_surface.get())),
nullptr),
io_surface_(io_surface) {
RTC_DCHECK(io_surface_);
}
DesktopFrameIOSurface::~DesktopFrameIOSurface() {
IOSurfaceUnlock(io_surface_.get(), kIOSurfaceLockReadOnly, nullptr);
IOSurfaceDecrementUseCount(io_surface_.get());
}
} // namespace webrtc