Remove deprecated mac screencapture code.
We don't support pre-lion, so all this screencapture code is unnecessary. This also enables us to delete some code from rtc_base/macutils Bug: webrtc:6424 Change-Id: I4ef068e8d7b48de9370feee51399033a4d1ae1c3 Reviewed-on: https://webrtc-review.googlesource.com/3420 Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20104}
This commit is contained in:

committed by
Commit Bot

parent
a9a277185e
commit
3c0bbff27c
@ -95,11 +95,6 @@ MouseCursorMonitorMac::MouseCursorMonitorMac(
|
||||
full_screen_chrome_window_detector_(
|
||||
options.full_screen_chrome_window_detector()) {
|
||||
assert(window_id == kCGNullWindowID || screen_id == kInvalidScreenId);
|
||||
if (screen_id != kInvalidScreenId &&
|
||||
rtc::GetOSVersionName() < rtc::kMacOSLion) {
|
||||
// Single screen capture is not supported on pre OS X 10.7.
|
||||
screen_id_ = kFullDesktopScreenId;
|
||||
}
|
||||
}
|
||||
|
||||
MouseCursorMonitorMac::~MouseCursorMonitorMac() {}
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
#include <dlfcn.h>
|
||||
#include <OpenGL/CGLMacro.h>
|
||||
#include <OpenGL/OpenGL.h>
|
||||
|
||||
#include "modules/desktop_capture/desktop_capture_options.h"
|
||||
#include "modules/desktop_capture/desktop_capturer.h"
|
||||
@ -38,27 +36,6 @@
|
||||
#include "rtc_base/macutils.h"
|
||||
#include "rtc_base/timeutils.h"
|
||||
|
||||
// Once Chrome no longer supports OSX 10.8, everything within this
|
||||
// preprocessor block can be removed. https://crbug.com/579255
|
||||
#if !defined(MAC_OS_X_VERSION_10_9) || \
|
||||
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
|
||||
CG_EXTERN const CGRect* CGDisplayStreamUpdateGetRects(
|
||||
CGDisplayStreamUpdateRef updateRef,
|
||||
CGDisplayStreamUpdateRectType rectType,
|
||||
size_t* rectCount);
|
||||
CG_EXTERN CFRunLoopSourceRef
|
||||
CGDisplayStreamGetRunLoopSource(CGDisplayStreamRef displayStream);
|
||||
CG_EXTERN CGError CGDisplayStreamStop(CGDisplayStreamRef displayStream);
|
||||
CG_EXTERN CGError CGDisplayStreamStart(CGDisplayStreamRef displayStream);
|
||||
CG_EXTERN CGDisplayStreamRef
|
||||
CGDisplayStreamCreate(CGDirectDisplayID display,
|
||||
size_t outputWidth,
|
||||
size_t outputHeight,
|
||||
int32_t pixelFormat,
|
||||
CFDictionaryRef properties,
|
||||
CGDisplayStreamFrameAvailableHandler handler);
|
||||
#endif
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
@ -130,17 +107,6 @@ class DisplayStreamManager {
|
||||
bool ready_for_self_destruction_ = false;
|
||||
};
|
||||
|
||||
// Definitions used to dynamic-link to deprecated OS 10.6 functions.
|
||||
const char* kApplicationServicesLibraryName =
|
||||
"/System/Library/Frameworks/ApplicationServices.framework/"
|
||||
"ApplicationServices";
|
||||
typedef void* (*CGDisplayBaseAddressFunc)(CGDirectDisplayID);
|
||||
typedef size_t (*CGDisplayBytesPerRowFunc)(CGDirectDisplayID);
|
||||
typedef size_t (*CGDisplayBitsPerPixelFunc)(CGDirectDisplayID);
|
||||
const char* kOpenGlLibraryName =
|
||||
"/System/Library/Frameworks/OpenGL.framework/OpenGL";
|
||||
typedef CGLError (*CGLSetFullScreenFunc)(CGLContextObj);
|
||||
|
||||
// Standard Mac displays have 72dpi, but we report 96dpi for
|
||||
// consistency with Windows and Linux.
|
||||
const int kStandardDPI = 96;
|
||||
@ -290,14 +256,8 @@ class ScreenCapturerMac : public DesktopCapturer {
|
||||
bool SelectSource(SourceId id) override;
|
||||
|
||||
private:
|
||||
void GlBlitFast(const DesktopFrame& frame,
|
||||
const DesktopRegion& region);
|
||||
void GlBlitSlow(const DesktopFrame& frame);
|
||||
void CgBlitPreLion(const DesktopFrame& frame,
|
||||
const DesktopRegion& region);
|
||||
// Returns false if the selected screen is no longer valid.
|
||||
bool CgBlitPostLion(const DesktopFrame& frame,
|
||||
const DesktopRegion& region);
|
||||
bool CgBlit(const DesktopFrame& frame, const DesktopRegion& region);
|
||||
|
||||
// Called when the screen configuration is changed.
|
||||
void ScreenConfigurationChanged();
|
||||
@ -316,7 +276,6 @@ class ScreenCapturerMac : public DesktopCapturer {
|
||||
|
||||
Callback* callback_ = nullptr;
|
||||
|
||||
CGLContextObj cgl_context_ = nullptr;
|
||||
ScopedPixelBufferObject pixel_buffer_object_;
|
||||
|
||||
// Queue of the frames buffers.
|
||||
@ -345,14 +304,6 @@ class ScreenCapturerMac : public DesktopCapturer {
|
||||
// Monitoring display reconfiguration.
|
||||
rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_;
|
||||
|
||||
// Dynamically link to deprecated APIs for Mac OS X 10.6 support.
|
||||
void* app_services_library_ = nullptr;
|
||||
CGDisplayBaseAddressFunc cg_display_base_address_ = nullptr;
|
||||
CGDisplayBytesPerRowFunc cg_display_bytes_per_row_ = nullptr;
|
||||
CGDisplayBitsPerPixelFunc cg_display_bits_per_pixel_ = nullptr;
|
||||
void* opengl_library_ = nullptr;
|
||||
CGLSetFullScreenFunc cgl_set_full_screen_ = nullptr;
|
||||
|
||||
CGWindowID excluded_window_ = 0;
|
||||
|
||||
// A self-owned object that will destroy itself after ScreenCapturerMac and
|
||||
@ -395,8 +346,6 @@ ScreenCapturerMac::~ScreenCapturerMac() {
|
||||
ReleaseBuffers();
|
||||
UnregisterRefreshAndMoveHandlers();
|
||||
display_stream_manager_->PrepareForSelfDestruction();
|
||||
dlclose(app_services_library_);
|
||||
dlclose(opengl_library_);
|
||||
}
|
||||
|
||||
bool ScreenCapturerMac::Init() {
|
||||
@ -411,11 +360,6 @@ bool ScreenCapturerMac::Init() {
|
||||
}
|
||||
|
||||
void ScreenCapturerMac::ReleaseBuffers() {
|
||||
if (cgl_context_) {
|
||||
pixel_buffer_object_.Release();
|
||||
CGLDestroyContext(cgl_context_);
|
||||
cgl_context_ = nullptr;
|
||||
}
|
||||
// The buffers might be in use by the encoder, so don't delete them here.
|
||||
// Instead, mark them as "needs update"; next time the buffers are used by
|
||||
// the capturer, they will be recreated if necessary.
|
||||
@ -459,28 +403,11 @@ void ScreenCapturerMac::CaptureFrame() {
|
||||
|
||||
DesktopFrame* current_frame = queue_.current_frame();
|
||||
|
||||
bool flip = false; // GL capturers need flipping.
|
||||
if (rtc::GetOSVersionName() >= rtc::kMacOSLion) {
|
||||
// Lion requires us to use their new APIs for doing screen capture. These
|
||||
// APIS currently crash on 10.6.8 if there is no monitor attached.
|
||||
if (!CgBlitPostLion(*current_frame, region)) {
|
||||
desktop_config_monitor_->Unlock();
|
||||
callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
|
||||
return;
|
||||
}
|
||||
} else if (cgl_context_) {
|
||||
flip = true;
|
||||
if (pixel_buffer_object_.get() != 0) {
|
||||
GlBlitFast(*current_frame, region);
|
||||
} else {
|
||||
// See comment in ScopedPixelBufferObject::Init about why the slow
|
||||
// path is always used on 10.5.
|
||||
GlBlitSlow(*current_frame);
|
||||
}
|
||||
} else {
|
||||
CgBlitPreLion(*current_frame, region);
|
||||
if (!CgBlit(*current_frame, region)) {
|
||||
desktop_config_monitor_->Unlock();
|
||||
callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<DesktopFrame> new_frame = queue_.current_frame()->Share();
|
||||
if (detect_updated_region_) {
|
||||
*new_frame->mutable_updated_region() = region;
|
||||
@ -489,9 +416,6 @@ void ScreenCapturerMac::CaptureFrame() {
|
||||
DesktopRect::MakeSize(new_frame->size()));
|
||||
}
|
||||
|
||||
if (flip)
|
||||
new_frame.reset(new InvertedDesktopFrame(std::move(new_frame)));
|
||||
|
||||
if (current_display_) {
|
||||
const MacDisplayConfiguration* config =
|
||||
desktop_config_.FindDisplayConfigurationById(current_display_);
|
||||
@ -518,11 +442,6 @@ void ScreenCapturerMac::SetExcludedWindow(WindowId window) {
|
||||
|
||||
bool ScreenCapturerMac::GetSourceList(SourceList* screens) {
|
||||
assert(screens->size() == 0);
|
||||
if (rtc::GetOSVersionName() < rtc::kMacOSLion) {
|
||||
// Single monitor cast is not supported on pre OS X 10.7.
|
||||
screens->push_back({kFullDesktopScreenId});
|
||||
return true;
|
||||
}
|
||||
|
||||
for (MacDisplayConfigurations::iterator it = desktop_config_.displays.begin();
|
||||
it != desktop_config_.displays.end(); ++it) {
|
||||
@ -532,12 +451,6 @@ bool ScreenCapturerMac::GetSourceList(SourceList* screens) {
|
||||
}
|
||||
|
||||
bool ScreenCapturerMac::SelectSource(SourceId id) {
|
||||
if (rtc::GetOSVersionName() < rtc::kMacOSLion) {
|
||||
// Ignore the screen selection on unsupported OS.
|
||||
assert(!current_display_);
|
||||
return id == kFullDesktopScreenId;
|
||||
}
|
||||
|
||||
if (id == kFullDesktopScreenId) {
|
||||
current_display_ = 0;
|
||||
} else {
|
||||
@ -553,146 +466,7 @@ bool ScreenCapturerMac::SelectSource(SourceId id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenCapturerMac::GlBlitFast(const DesktopFrame& frame,
|
||||
const DesktopRegion& region) {
|
||||
// Clip to the size of our current screen.
|
||||
DesktopRect clip_rect = DesktopRect::MakeSize(frame.size());
|
||||
if (queue_.previous_frame()) {
|
||||
// We are doing double buffer for the capture data so we just need to copy
|
||||
// the invalid region from the previous capture in the current buffer.
|
||||
// TODO(hclam): We can reduce the amount of copying here by subtracting
|
||||
// |capturer_helper_|s region from |last_invalid_region_|.
|
||||
// http://crbug.com/92354
|
||||
|
||||
// Since the image obtained from OpenGL is upside-down, need to do some
|
||||
// magic here to copy the correct rectangle.
|
||||
const int y_offset = (frame.size().height() - 1) * frame.stride();
|
||||
for (DesktopRegion::Iterator i(last_invalid_region_);
|
||||
!i.IsAtEnd(); i.Advance()) {
|
||||
DesktopRect copy_rect = i.rect();
|
||||
copy_rect.IntersectWith(clip_rect);
|
||||
if (!copy_rect.is_empty()) {
|
||||
CopyRect(queue_.previous_frame()->data() + y_offset,
|
||||
-frame.stride(),
|
||||
frame.data() + y_offset,
|
||||
-frame.stride(),
|
||||
DesktopFrame::kBytesPerPixel,
|
||||
copy_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
last_invalid_region_ = region;
|
||||
|
||||
CGLContextObj CGL_MACRO_CONTEXT = cgl_context_;
|
||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get());
|
||||
glReadPixels(0, 0, frame.size().width(), frame.size().height(), GL_BGRA,
|
||||
GL_UNSIGNED_BYTE, 0);
|
||||
GLubyte* ptr = static_cast<GLubyte*>(
|
||||
glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB));
|
||||
if (!ptr) {
|
||||
// If the buffer can't be mapped, assume that it's no longer valid and
|
||||
// release it.
|
||||
pixel_buffer_object_.Release();
|
||||
} else {
|
||||
// Copy only from the dirty rects. Since the image obtained from OpenGL is
|
||||
// upside-down we need to do some magic here to copy the correct rectangle.
|
||||
const int y_offset = (frame.size().height() - 1) * frame.stride();
|
||||
for (DesktopRegion::Iterator i(region);
|
||||
!i.IsAtEnd(); i.Advance()) {
|
||||
DesktopRect copy_rect = i.rect();
|
||||
copy_rect.IntersectWith(clip_rect);
|
||||
if (!copy_rect.is_empty()) {
|
||||
CopyRect(ptr + y_offset,
|
||||
-frame.stride(),
|
||||
frame.data() + y_offset,
|
||||
-frame.stride(),
|
||||
DesktopFrame::kBytesPerPixel,
|
||||
copy_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) {
|
||||
// If glUnmapBuffer returns false, then the contents of the data store are
|
||||
// undefined. This might be because the screen mode has changed, in which
|
||||
// case it will be recreated in ScreenConfigurationChanged, but releasing
|
||||
// the object here is the best option. Capturing will fall back on
|
||||
// GlBlitSlow until such time as the pixel buffer object is recreated.
|
||||
pixel_buffer_object_.Release();
|
||||
}
|
||||
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
|
||||
}
|
||||
|
||||
void ScreenCapturerMac::GlBlitSlow(const DesktopFrame& frame) {
|
||||
CGLContextObj CGL_MACRO_CONTEXT = cgl_context_;
|
||||
glReadBuffer(GL_FRONT);
|
||||
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment.
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
// Read a block of pixels from the frame buffer.
|
||||
glReadPixels(0, 0, frame.size().width(), frame.size().height(),
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, frame.data());
|
||||
glPopClientAttrib();
|
||||
}
|
||||
|
||||
void ScreenCapturerMac::CgBlitPreLion(const DesktopFrame& frame,
|
||||
const DesktopRegion& region) {
|
||||
// Copy the entire contents of the previous capture buffer, to capture over.
|
||||
// TODO(wez): Get rid of this as per crbug.com/145064, or implement
|
||||
// crbug.com/92354.
|
||||
if (queue_.previous_frame()) {
|
||||
memcpy(frame.data(),
|
||||
queue_.previous_frame()->data(),
|
||||
frame.stride() * frame.size().height());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < desktop_config_.displays.size(); ++i) {
|
||||
const MacDisplayConfiguration& display_config = desktop_config_.displays[i];
|
||||
|
||||
// Use deprecated APIs to determine the display buffer layout.
|
||||
assert(cg_display_base_address_ && cg_display_bytes_per_row_ &&
|
||||
cg_display_bits_per_pixel_);
|
||||
uint8_t* display_base_address = reinterpret_cast<uint8_t*>(
|
||||
(*cg_display_base_address_)(display_config.id));
|
||||
assert(display_base_address);
|
||||
int src_bytes_per_row = (*cg_display_bytes_per_row_)(display_config.id);
|
||||
int src_bytes_per_pixel =
|
||||
(*cg_display_bits_per_pixel_)(display_config.id) / 8;
|
||||
|
||||
// Determine the display's position relative to the desktop, in pixels.
|
||||
DesktopRect display_bounds = display_config.pixel_bounds;
|
||||
display_bounds.Translate(-desktop_config_.pixel_bounds.left(),
|
||||
-desktop_config_.pixel_bounds.top());
|
||||
|
||||
// Determine which parts of the blit region, if any, lay within the monitor.
|
||||
DesktopRegion copy_region = region;
|
||||
copy_region.IntersectWith(display_bounds);
|
||||
if (copy_region.is_empty())
|
||||
continue;
|
||||
|
||||
// Translate the region to be copied into display-relative coordinates.
|
||||
copy_region.Translate(-display_bounds.left(), -display_bounds.top());
|
||||
|
||||
// Calculate where in the output buffer the display's origin is.
|
||||
uint8_t* out_ptr = frame.data() +
|
||||
(display_bounds.left() * src_bytes_per_pixel) +
|
||||
(display_bounds.top() * frame.stride());
|
||||
|
||||
// Copy the dirty region from the display buffer into our desktop buffer.
|
||||
for (DesktopRegion::Iterator i(copy_region); !i.IsAtEnd(); i.Advance()) {
|
||||
CopyRect(display_base_address,
|
||||
src_bytes_per_row,
|
||||
out_ptr,
|
||||
frame.stride(),
|
||||
src_bytes_per_pixel,
|
||||
i.rect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenCapturerMac::CgBlitPostLion(const DesktopFrame& frame,
|
||||
const DesktopRegion& region) {
|
||||
bool ScreenCapturerMac::CgBlit(const DesktopFrame& frame, const DesktopRegion& region) {
|
||||
// Copy the entire contents of the previous capture buffer, to capture over.
|
||||
// TODO(wez): Get rid of this as per crbug.com/145064, or implement
|
||||
// crbug.com/92354.
|
||||
@ -862,88 +636,6 @@ void ScreenCapturerMac::ScreenConfigurationChanged() {
|
||||
|
||||
// Make sure the frame buffers will be reallocated.
|
||||
queue_.Reset();
|
||||
|
||||
// CgBlitPostLion uses CGDisplayCreateImage() to snapshot each display's
|
||||
// contents. Although the API exists in OS 10.6, it crashes the caller if
|
||||
// the machine has no monitor connected, so we fall back to depcreated APIs
|
||||
// when running on 10.6.
|
||||
if (rtc::GetOSVersionName() >= rtc::kMacOSLion) {
|
||||
LOG(LS_INFO) << "Using CgBlitPostLion.";
|
||||
// No need for any OpenGL support on Lion
|
||||
return;
|
||||
}
|
||||
|
||||
// Dynamically link to the deprecated pre-Lion capture APIs.
|
||||
app_services_library_ = dlopen(kApplicationServicesLibraryName,
|
||||
RTLD_LAZY);
|
||||
if (!app_services_library_) {
|
||||
LOG_F(LS_ERROR) << "Failed to open " << kApplicationServicesLibraryName;
|
||||
abort();
|
||||
}
|
||||
|
||||
opengl_library_ = dlopen(kOpenGlLibraryName, RTLD_LAZY);
|
||||
if (!opengl_library_) {
|
||||
LOG_F(LS_ERROR) << "Failed to open " << kOpenGlLibraryName;
|
||||
abort();
|
||||
}
|
||||
|
||||
cg_display_base_address_ = reinterpret_cast<CGDisplayBaseAddressFunc>(
|
||||
dlsym(app_services_library_, "CGDisplayBaseAddress"));
|
||||
cg_display_bytes_per_row_ = reinterpret_cast<CGDisplayBytesPerRowFunc>(
|
||||
dlsym(app_services_library_, "CGDisplayBytesPerRow"));
|
||||
cg_display_bits_per_pixel_ = reinterpret_cast<CGDisplayBitsPerPixelFunc>(
|
||||
dlsym(app_services_library_, "CGDisplayBitsPerPixel"));
|
||||
cgl_set_full_screen_ = reinterpret_cast<CGLSetFullScreenFunc>(
|
||||
dlsym(opengl_library_, "CGLSetFullScreen"));
|
||||
if (!(cg_display_base_address_ && cg_display_bytes_per_row_ &&
|
||||
cg_display_bits_per_pixel_ && cgl_set_full_screen_)) {
|
||||
LOG_F(LS_ERROR);
|
||||
abort();
|
||||
}
|
||||
|
||||
if (desktop_config_.displays.size() > 1) {
|
||||
LOG(LS_INFO) << "Using CgBlitPreLion (Multi-monitor).";
|
||||
return;
|
||||
}
|
||||
|
||||
CGDirectDisplayID mainDevice = CGMainDisplayID();
|
||||
if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) {
|
||||
LOG(LS_INFO) << "Using CgBlitPreLion (OpenGL unavailable).";
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(LS_INFO) << "Using GlBlit";
|
||||
|
||||
CGLPixelFormatAttribute attributes[] = {
|
||||
// This function does an early return if GetOSVersionName() >= kMacOSLion,
|
||||
// this code only runs on 10.6 and can be deleted once 10.6 support is
|
||||
// dropped. So just keep using kCGLPFAFullScreen even though it was
|
||||
// deprecated in 10.6 -- it's still functional there, and it's not used on
|
||||
// newer OS X versions.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
kCGLPFAFullScreen,
|
||||
#pragma clang diagnostic pop
|
||||
kCGLPFADisplayMask,
|
||||
(CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice),
|
||||
(CGLPixelFormatAttribute)0
|
||||
};
|
||||
CGLPixelFormatObj pixel_format = nullptr;
|
||||
GLint matching_pixel_format_count = 0;
|
||||
CGLError err = CGLChoosePixelFormat(attributes,
|
||||
&pixel_format,
|
||||
&matching_pixel_format_count);
|
||||
assert(err == kCGLNoError);
|
||||
err = CGLCreateContext(pixel_format, nullptr, &cgl_context_);
|
||||
assert(err == kCGLNoError);
|
||||
CGLDestroyPixelFormat(pixel_format);
|
||||
(*cgl_set_full_screen_)(cgl_context_);
|
||||
CGLSetCurrentContext(cgl_context_);
|
||||
|
||||
size_t buffer_size = screen_pixel_bounds_.width() *
|
||||
screen_pixel_bounds_.height() *
|
||||
sizeof(uint32_t);
|
||||
pixel_buffer_object_.Init(cgl_context_, buffer_size);
|
||||
}
|
||||
|
||||
bool ScreenCapturerMac::RegisterRefreshAndMoveHandlers() {
|
||||
|
@ -1075,9 +1075,6 @@ if (rtc_include_tests) {
|
||||
"win32window_unittest.cc",
|
||||
]
|
||||
}
|
||||
if (is_mac) {
|
||||
sources += [ "macutils_unittest.cc" ]
|
||||
}
|
||||
if (is_posix) {
|
||||
sources += [
|
||||
"openssladapter_unittest.cc",
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
namespace rtc {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ToUtf8(const CFStringRef str16, std::string* str8) {
|
||||
if ((nullptr == str16) || (nullptr == str8)) {
|
||||
return false;
|
||||
@ -48,80 +46,4 @@ bool ToUtf16(const std::string& str8, CFStringRef* str16) {
|
||||
false);
|
||||
return nullptr != *str16;
|
||||
}
|
||||
|
||||
void DecodeFourChar(UInt32 fc, std::string* out) {
|
||||
std::stringstream ss;
|
||||
ss << '\'';
|
||||
bool printable = true;
|
||||
for (int i = 3; i >= 0; --i) {
|
||||
char ch = (fc >> (8 * i)) & 0xFF;
|
||||
if (isprint(static_cast<unsigned char>(ch))) {
|
||||
ss << ch;
|
||||
} else {
|
||||
printable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (printable) {
|
||||
ss << '\'';
|
||||
} else {
|
||||
ss.str("");
|
||||
ss << "0x" << std::hex << fc;
|
||||
}
|
||||
out->append(ss.str());
|
||||
}
|
||||
|
||||
static bool GetOSVersion(int* major, int* minor, int* bugfix) {
|
||||
RTC_DCHECK(major);
|
||||
RTC_DCHECK(minor);
|
||||
RTC_DCHECK(bugfix);
|
||||
struct utsname uname_info;
|
||||
if (uname(&uname_info) != 0)
|
||||
return false;
|
||||
|
||||
if (strcmp(uname_info.sysname, "Darwin") != 0)
|
||||
return false;
|
||||
*major = 10;
|
||||
|
||||
// The market version of macOS is always 4 lower than the internal version.
|
||||
int minor_version = atoi(uname_info.release);
|
||||
RTC_CHECK(minor_version >= 6);
|
||||
*minor = minor_version - 4;
|
||||
|
||||
const char* dot = ::strchr(uname_info.release, '.');
|
||||
if (!dot)
|
||||
return false;
|
||||
*bugfix = atoi(dot + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
MacOSVersionName GetOSVersionName() {
|
||||
int major = 0, minor = 0, bugfix = 0;
|
||||
if (!GetOSVersion(&major, &minor, &bugfix)) {
|
||||
return kMacOSUnknown;
|
||||
}
|
||||
if (major > 10) {
|
||||
return kMacOSNewer;
|
||||
}
|
||||
if ((major < 10) || (minor < 3)) {
|
||||
return kMacOSOlder;
|
||||
}
|
||||
switch (minor) {
|
||||
case 3:
|
||||
return kMacOSPanther;
|
||||
case 4:
|
||||
return kMacOSTiger;
|
||||
case 5:
|
||||
return kMacOSLeopard;
|
||||
case 6:
|
||||
return kMacOSSnowLeopard;
|
||||
case 7:
|
||||
return kMacOSLion;
|
||||
case 8:
|
||||
return kMacOSMountainLion;
|
||||
case 9:
|
||||
return kMacOSMavericks;
|
||||
}
|
||||
return kMacOSNewer;
|
||||
}
|
||||
} // namespace rtc
|
||||
|
@ -15,36 +15,8 @@
|
||||
#include <string>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Note that some of these functions work for both iOS and Mac OS X. The ones
|
||||
// that are specific to Mac are #ifdef'ed as such.
|
||||
|
||||
bool ToUtf8(const CFStringRef str16, std::string* str8);
|
||||
bool ToUtf16(const std::string& str8, CFStringRef* str16);
|
||||
|
||||
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
||||
void DecodeFourChar(UInt32 fc, std::string* out);
|
||||
|
||||
enum MacOSVersionName {
|
||||
kMacOSUnknown, // ???
|
||||
kMacOSOlder, // 10.2-
|
||||
kMacOSPanther, // 10.3
|
||||
kMacOSTiger, // 10.4
|
||||
kMacOSLeopard, // 10.5
|
||||
kMacOSSnowLeopard, // 10.6
|
||||
kMacOSLion, // 10.7
|
||||
kMacOSMountainLion, // 10.8
|
||||
kMacOSMavericks, // 10.9
|
||||
kMacOSNewer, // 10.10+
|
||||
};
|
||||
|
||||
MacOSVersionName GetOSVersionName();
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_MACUTILS_H_
|
||||
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 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 "rtc_base/macutils.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
|
||||
TEST(MacUtilsTest, GetOsVersionName) {
|
||||
rtc::MacOSVersionName ver = rtc::GetOSVersionName();
|
||||
LOG(LS_INFO) << "GetOsVersionName " << ver;
|
||||
EXPECT_NE(rtc::kMacOSUnknown, ver);
|
||||
}
|
Reference in New Issue
Block a user