Reland of move all reference to carbon api (patchset #1 id:1 of https://codereview.webrtc.org/2316563002/ )
Reason for revert: Chromium build issues have been resolved. Original issue's description: > Revert of Remove all reference to carbon api (patchset #2 id:20001 of https://codereview.webrtc.org/2299633002/ ) > > Reason for revert: > Breaks chromium build > > Original issue's description: > > Remove all reference to carbon api > > > > BUG=webrtc:6282 > > > > Committed: https://crrev.com/dbd8b6bec4143c940b2f2ca8cd85c25d17327964 > > Cr-Commit-Position: refs/heads/master@{#14080} > > TBR=magjed@webrtc.org,mflodman@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:6282 > > Committed: https://crrev.com/b096aa7fd375a980daab3a986596548ca5de2a1c > Cr-Commit-Position: refs/heads/master@{#14081} TBR=magjed@webrtc.org,mflodman@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6282 Review-Url: https://codereview.webrtc.org/2321493002 Cr-Commit-Position: refs/heads/master@{#14125}
This commit is contained in:
@ -186,17 +186,6 @@ rtc_source_set("rtc_media") {
|
||||
"strmiids.lib",
|
||||
]
|
||||
}
|
||||
if (is_mac && current_cpu == "x86") {
|
||||
sources += [
|
||||
"devices/carbonvideorenderer.cc",
|
||||
"devices/carbonvideorenderer.h",
|
||||
]
|
||||
libs += [ "Carbon.framework" ]
|
||||
}
|
||||
if (is_ios || (is_mac && current_cpu != "x86")) {
|
||||
defines += [ "CARBON_DEPRECATED=YES" ]
|
||||
}
|
||||
|
||||
deps += [
|
||||
"..:webrtc_common",
|
||||
"../api:call_api",
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 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.
|
||||
*/
|
||||
|
||||
// Implementation of CarbonVideoRenderer
|
||||
|
||||
#include "webrtc/media/devices/carbonvideorenderer.h"
|
||||
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/media/base/videocommon.h"
|
||||
#include "webrtc/media/base/videoframe.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
CarbonVideoRenderer::CarbonVideoRenderer(int x, int y)
|
||||
: image_width_(0),
|
||||
image_height_(0),
|
||||
x_(x),
|
||||
y_(y),
|
||||
window_ref_(NULL) {
|
||||
}
|
||||
|
||||
CarbonVideoRenderer::~CarbonVideoRenderer() {
|
||||
if (window_ref_) {
|
||||
DisposeWindow(window_ref_);
|
||||
}
|
||||
}
|
||||
|
||||
// Called from the main event loop. All renderering needs to happen on
|
||||
// the main thread.
|
||||
OSStatus CarbonVideoRenderer::DrawEventHandler(EventHandlerCallRef handler,
|
||||
EventRef event,
|
||||
void* data) {
|
||||
OSStatus status = noErr;
|
||||
CarbonVideoRenderer* renderer = static_cast<CarbonVideoRenderer*>(data);
|
||||
if (renderer != NULL) {
|
||||
if (!renderer->DrawFrame()) {
|
||||
LOG(LS_ERROR) << "Failed to draw frame.";
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
bool CarbonVideoRenderer::DrawFrame() {
|
||||
// Grab the image lock to make sure it is not changed why we'll draw it.
|
||||
rtc::CritScope cs(&image_crit_);
|
||||
|
||||
if (image_.get() == NULL) {
|
||||
// Nothing to draw, just return.
|
||||
return true;
|
||||
}
|
||||
int width = image_width_;
|
||||
int height = image_height_;
|
||||
CGDataProviderRef provider =
|
||||
CGDataProviderCreateWithData(NULL, image_.get(), width * height * 4,
|
||||
NULL);
|
||||
CGColorSpaceRef color_space_ref = CGColorSpaceCreateDeviceRGB();
|
||||
CGBitmapInfo bitmap_info = kCGBitmapByteOrderDefault;
|
||||
CGColorRenderingIntent rendering_intent = kCGRenderingIntentDefault;
|
||||
CGImageRef image_ref = CGImageCreate(width, height, 8, 32, width * 4,
|
||||
color_space_ref, bitmap_info, provider,
|
||||
NULL, false, rendering_intent);
|
||||
CGDataProviderRelease(provider);
|
||||
|
||||
if (image_ref == NULL) {
|
||||
return false;
|
||||
}
|
||||
CGContextRef context;
|
||||
SetPortWindowPort(window_ref_);
|
||||
if (QDBeginCGContext(GetWindowPort(window_ref_), &context) != noErr) {
|
||||
CGImageRelease(image_ref);
|
||||
return false;
|
||||
}
|
||||
Rect window_bounds;
|
||||
GetWindowPortBounds(window_ref_, &window_bounds);
|
||||
|
||||
// Anchor the image to the top left corner.
|
||||
int x = 0;
|
||||
int y = window_bounds.bottom - CGImageGetHeight(image_ref);
|
||||
CGRect dst_rect = CGRectMake(x, y, CGImageGetWidth(image_ref),
|
||||
CGImageGetHeight(image_ref));
|
||||
CGContextDrawImage(context, dst_rect, image_ref);
|
||||
CGContextFlush(context);
|
||||
QDEndCGContext(GetWindowPort(window_ref_), &context);
|
||||
CGImageRelease(image_ref);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CarbonVideoRenderer::SetSize(int width, int height) {
|
||||
if (width != image_width_ || height != image_height_) {
|
||||
// Grab the image lock while changing its size.
|
||||
rtc::CritScope cs(&image_crit_);
|
||||
image_width_ = width;
|
||||
image_height_ = height;
|
||||
image_.reset(new uint8_t[width * height * 4]);
|
||||
memset(image_.get(), 255, width * height * 4);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CarbonVideoRenderer::OnFrame(const VideoFrame& video_frame) {
|
||||
{
|
||||
const cricket::WebRtcVideoFrame frame(
|
||||
webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(),
|
||||
video_frame.rotation()),
|
||||
webrtc::kVideoRotation_0, video_frame.timestamp_us());
|
||||
|
||||
if (!SetSize(frame.width(), frame.height())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the image lock so we are not trashing up the image being drawn.
|
||||
rtc::CritScope cs(&image_crit_);
|
||||
frame.ConvertToRgbBuffer(cricket::FOURCC_ABGR,
|
||||
image_.get(),
|
||||
static_cast<size_t>(frame.width()) *
|
||||
frame.height() * 4,
|
||||
frame.width() * 4);
|
||||
}
|
||||
|
||||
// Trigger a repaint event for the whole window.
|
||||
Rect bounds;
|
||||
InvalWindowRect(window_ref_, GetWindowPortBounds(window_ref_, &bounds));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CarbonVideoRenderer::Initialize() {
|
||||
OSStatus err;
|
||||
WindowAttributes attributes =
|
||||
kWindowStandardDocumentAttributes |
|
||||
kWindowLiveResizeAttribute |
|
||||
kWindowFrameworkScaledAttribute |
|
||||
kWindowStandardHandlerAttribute;
|
||||
|
||||
struct Rect bounds;
|
||||
bounds.top = y_;
|
||||
bounds.bottom = 480;
|
||||
bounds.left = x_;
|
||||
bounds.right = 640;
|
||||
err = CreateNewWindow(kDocumentWindowClass, attributes,
|
||||
&bounds, &window_ref_);
|
||||
if (!window_ref_ || err != noErr) {
|
||||
LOG(LS_ERROR) << "CreateNewWindow failed, error code: " << err;
|
||||
return false;
|
||||
}
|
||||
static const EventTypeSpec event_spec = {
|
||||
kEventClassWindow,
|
||||
kEventWindowDrawContent
|
||||
};
|
||||
|
||||
err = InstallWindowEventHandler(
|
||||
window_ref_,
|
||||
NewEventHandlerUPP(CarbonVideoRenderer::DrawEventHandler),
|
||||
GetEventTypeCount(event_spec),
|
||||
&event_spec,
|
||||
this,
|
||||
NULL);
|
||||
if (err != noErr) {
|
||||
LOG(LS_ERROR) << "Failed to install event handler, error code: " << err;
|
||||
return false;
|
||||
}
|
||||
SelectWindow(window_ref_);
|
||||
ShowWindow(window_ref_);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 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.
|
||||
*/
|
||||
|
||||
// Definition of class CarbonVideoRenderer that implements the abstract class
|
||||
// cricket::VideoRenderer via Carbon.
|
||||
|
||||
#ifndef WEBRTC_MEDIA_DEVICES_CARBONVIDEORENDERER_H_
|
||||
#define WEBRTC_MEDIA_DEVICES_CARBONVIDEORENDERER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#include "webrtc/base/criticalsection.h"
|
||||
#include "webrtc/media/base/videosinkinterface.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class CarbonVideoRenderer
|
||||
: public rtc::VideoSinkInterface<cricket::VideoFrame> {
|
||||
public:
|
||||
CarbonVideoRenderer(int x, int y);
|
||||
virtual ~CarbonVideoRenderer();
|
||||
|
||||
// Implementation of VideoSinkInterface.
|
||||
void OnFrame(const VideoFrame& frame) override;
|
||||
|
||||
// Needs to be called on the main thread.
|
||||
bool Initialize();
|
||||
|
||||
private:
|
||||
bool SetSize(int width, int height);
|
||||
bool DrawFrame();
|
||||
|
||||
static OSStatus DrawEventHandler(EventHandlerCallRef handler,
|
||||
EventRef event,
|
||||
void* data);
|
||||
std::unique_ptr<uint8_t[]> image_;
|
||||
rtc::CriticalSection image_crit_;
|
||||
int image_width_;
|
||||
int image_height_;
|
||||
int x_;
|
||||
int y_;
|
||||
WindowRef window_ref_;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
#endif // WEBRTC_MEDIA_DEVICES_CARBONVIDEORENDERER_H_
|
||||
@ -17,8 +17,6 @@
|
||||
#include "webrtc/media/base/videosinkinterface.h"
|
||||
#if defined(WEBRTC_LINUX) && defined(HAVE_GTK)
|
||||
#include "webrtc/media/devices/gtkvideorenderer.h"
|
||||
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && !defined(CARBON_DEPRECATED)
|
||||
#include "webrtc/media/devices/carbonvideorenderer.h"
|
||||
#elif defined(WIN32)
|
||||
#include "webrtc/media/devices/gdivideorenderer.h"
|
||||
#endif
|
||||
@ -32,16 +30,6 @@ class VideoRendererFactory {
|
||||
int y) {
|
||||
#if defined(WEBRTC_LINUX) && defined(HAVE_GTK)
|
||||
return new GtkVideoRenderer(x, y);
|
||||
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && \
|
||||
!defined(CARBON_DEPRECATED)
|
||||
CarbonVideoRenderer* renderer = new CarbonVideoRenderer(x, y);
|
||||
// Needs to be initialized on the main thread.
|
||||
if (renderer->Initialize()) {
|
||||
return renderer;
|
||||
} else {
|
||||
delete renderer;
|
||||
return NULL;
|
||||
}
|
||||
#elif defined(WIN32)
|
||||
return new GdiVideoRenderer(x, y);
|
||||
#else
|
||||
|
||||
@ -173,24 +173,6 @@
|
||||
},
|
||||
},
|
||||
}],
|
||||
['OS=="mac" and target_arch=="ia32"', {
|
||||
'sources': [
|
||||
'devices/carbonvideorenderer.cc',
|
||||
'devices/carbonvideorenderer.h',
|
||||
],
|
||||
'link_settings': {
|
||||
'xcode_settings': {
|
||||
'OTHER_LDFLAGS': [
|
||||
'-framework Carbon',
|
||||
],
|
||||
},
|
||||
},
|
||||
}],
|
||||
['OS=="ios" or (OS=="mac" and target_arch!="ia32")', {
|
||||
'defines': [
|
||||
'CARBON_DEPRECATED=YES',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}, # target rtc_media
|
||||
], # targets.
|
||||
|
||||
Reference in New Issue
Block a user