OLD | NEW |
| (Empty) |
1 /* | |
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+Private.h" | |
12 | |
13 #import "RTCVideoFrame+Private.h" | |
14 | |
15 #include <memory> | |
16 | |
17 namespace webrtc { | |
18 | |
19 class VideoRendererAdapter | |
20 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | |
21 public: | |
22 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { | |
23 adapter_ = adapter; | |
24 size_ = CGSizeZero; | |
25 } | |
26 | |
27 void OnFrame(const webrtc::VideoFrame& nativeVideoFrame) override { | |
28 RTCVideoFrame* videoFrame = [[RTCVideoFrame alloc] | |
29 initWithVideoBuffer:nativeVideoFrame.video_frame_buffer() | |
30 rotation:static_cast<RTCVideoRotation>( | |
31 nativeVideoFrame.rotation()) | |
32 timeStampNs:nativeVideoFrame.timestamp_us() * | |
33 rtc::kNumNanosecsPerMicrosec]; | |
34 CGSize current_size = (videoFrame.rotation % 180 == 0) | |
35 ? CGSizeMake(videoFrame.width, videoFrame.height) | |
36 : CGSizeMake(videoFrame.height, videoFrame.width); | |
37 | |
38 if (!CGSizeEqualToSize(size_, current_size)) { | |
39 size_ = current_size; | |
40 [adapter_.videoRenderer setSize:size_]; | |
41 } | |
42 [adapter_.videoRenderer renderFrame:videoFrame]; | |
43 } | |
44 | |
45 private: | |
46 __weak RTCVideoRendererAdapter *adapter_; | |
47 CGSize size_; | |
48 }; | |
49 } | |
50 | |
51 @implementation RTCVideoRendererAdapter { | |
52 std::unique_ptr<webrtc::VideoRendererAdapter> _adapter; | |
53 } | |
54 | |
55 @synthesize videoRenderer = _videoRenderer; | |
56 | |
57 - (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer { | |
58 NSParameterAssert(videoRenderer); | |
59 if (self = [super init]) { | |
60 _videoRenderer = videoRenderer; | |
61 _adapter.reset(new webrtc::VideoRendererAdapter(self)); | |
62 } | |
63 return self; | |
64 } | |
65 | |
66 - (rtc::VideoSinkInterface<webrtc::VideoFrame> *)nativeVideoRenderer { | |
67 return _adapter.get(); | |
68 } | |
69 | |
70 @end | |
OLD | NEW |