blob: fdaba68b9dd31e65b198a669fc3c35dcae48e073 [file] [log] [blame]
Jon Hjelle891a4462016-01-21 11:42:05 -08001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#import "RTCVideoRendererAdapter.h"
12
13#import "webrtc/api/objc/RTCVideoFrame+Private.h"
14#import "webrtc/api/objc/RTCVideoRendererAdapter+Private.h"
15
16namespace webrtc {
17
18class VideoRendererAdapter : public VideoRendererInterface {
19 public:
20 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) {
21 adapter_ = adapter;
22 size_ = CGSizeZero;
23 }
24
25 void RenderFrame(const cricket::VideoFrame *nativeVideoFrame) override {
26 const cricket::VideoFrame *frame =
27 nativeVideoFrame->GetCopyWithRotationApplied();
28 CGSize current_size = CGSizeMake(frame->GetWidth(), frame->GetHeight());
29 if (!CGSizeEqualToSize(size_, current_size)) {
30 size_ = current_size;
31 [adapter_.videoRenderer setSize:size_];
32 }
33 RTCVideoFrame *videoFrame =
34 [[RTCVideoFrame alloc] initWithNativeFrame:frame];
35 [adapter_.videoRenderer renderFrame:videoFrame];
36 }
37
38 private:
39 __weak RTCVideoRendererAdapter *adapter_;
40 CGSize size_;
41};
42}
43
44@implementation RTCVideoRendererAdapter {
45 rtc::scoped_ptr<webrtc::VideoRendererAdapter> _adapter;
46}
47
48@synthesize videoRenderer = _videoRenderer;
49
50- (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer {
51 NSParameterAssert(videoRenderer);
52 if (self = [super init]) {
53 _videoRenderer = videoRenderer;
54 _adapter.reset(new webrtc::VideoRendererAdapter(self));
55 }
56 return self;
57}
58
59- (webrtc::VideoRendererInterface *)nativeVideoRenderer {
60 return _adapter.get();
61}
62
63@end