Chromium Code Reviews| Index: webrtc/api/objc/RTCVideoRendererAdapter.mm |
| diff --git a/webrtc/api/objc/RTCVideoRendererAdapter.mm b/webrtc/api/objc/RTCVideoRendererAdapter.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d874216a1fe6529e5200c00ee77da6b549e24c3b |
| --- /dev/null |
| +++ b/webrtc/api/objc/RTCVideoRendererAdapter.mm |
| @@ -0,0 +1,63 @@ |
| +/* |
| + * Copyright 2015 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. |
| + */ |
| + |
| +#import "RTCVideoRendererAdapter.h" |
| + |
| +#import "webrtc/api/objc/RTCVideoRendererAdapter+Private.h" |
| +#import "webrtc/api/objc/RTCVideoFrame+Private.h" |
| + |
| +namespace webrtc { |
| + |
| +class RTCVideoRendererNativeAdapter : public VideoRendererInterface { |
|
tkchin_webrtc
2016/01/14 01:43:32
nit: already namespaced in webrtc.
class VideoRen
hjon
2016/01/14 18:48:52
Done.
|
| + public: |
| + RTCVideoRendererNativeAdapter(RTCVideoRendererAdapter *adapter) { |
| + _adapter = adapter; |
| + _size = CGSizeZero; |
| + } |
| + |
| + void RenderFrame(const cricket::VideoFrame *nativeVideoFrame) override { |
| + const cricket::VideoFrame *frame = |
| + nativeVideoFrame->GetCopyWithRotationApplied(); |
| + CGSize currentSize = CGSizeMake(frame->GetWidth(), frame->GetHeight()); |
| + if (!CGSizeEqualToSize(_size, currentSize)) { |
| + _size = currentSize; |
| + [_adapter.videoRenderer setSize:_size]; |
| + } |
| + RTCVideoFrame *videoFrame = |
| + [[RTCVideoFrame alloc] initWithNativeFrame:frame]; |
| + [_adapter.videoRenderer renderFrame:videoFrame]; |
| + } |
| + |
| + private: |
| + __weak RTCVideoRendererAdapter *_adapter; |
| + CGSize _size; |
| +}; |
| +} |
| + |
| +@implementation RTCVideoRendererAdapter { |
| + rtc::scoped_ptr<webrtc::RTCVideoRendererNativeAdapter> _adapter; |
| +} |
| + |
| +@synthesize videoRenderer = _videoRenderer; |
| + |
| +- (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer { |
| + NSParameterAssert(videoRenderer); |
| + if (self = [super init]) { |
| + _videoRenderer = videoRenderer; |
| + _adapter.reset(new webrtc::RTCVideoRendererNativeAdapter(self)); |
| + } |
| + return self; |
| +} |
| + |
| +- (webrtc::VideoRendererInterface *)nativeVideoRenderer { |
| + return _adapter.get(); |
| +} |
| + |
| +@end |