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.h" | |
12 | |
13 #include "webrtc/media/engine/webrtcvideoframe.h" | |
14 | |
15 #import "webrtc/api/objc/RTCVideoFrame+Private.h" | |
16 #import "webrtc/api/objc/RTCVideoRendererAdapter+Private.h" | |
17 | |
18 namespace webrtc { | |
19 | |
20 class VideoRendererAdapter | |
21 : public rtc::VideoSinkInterface<cricket::VideoFrame> { | |
22 public: | |
23 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { | |
24 adapter_ = adapter; | |
25 size_ = CGSizeZero; | |
26 } | |
27 | |
28 void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override { | |
29 RTCVideoFrame *videoFrame = nil; | |
30 // Rotation of native handles is unsupported right now. Convert to CPU | |
31 // I420 buffer for rotation before calling the rotation method otherwise | |
32 // it will hit a DCHECK. | |
33 if (nativeVideoFrame.rotation() != webrtc::kVideoRotation_0 && | |
34 nativeVideoFrame.GetNativeHandle()) { | |
35 rtc::scoped_refptr<webrtc::VideoFrameBuffer> i420Buffer = | |
36 nativeVideoFrame.video_frame_buffer()->NativeToI420Buffer(); | |
37 std::unique_ptr<cricket::VideoFrame> cpuFrame( | |
38 new cricket::WebRtcVideoFrame(i420Buffer, | |
39 nativeVideoFrame.rotation(), | |
40 nativeVideoFrame.timestamp_us())); | |
41 const cricket::VideoFrame *rotatedFrame = | |
42 cpuFrame->GetCopyWithRotationApplied(); | |
43 videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; | |
44 } else { | |
45 const cricket::VideoFrame *rotatedFrame = | |
46 nativeVideoFrame.GetCopyWithRotationApplied(); | |
47 videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; | |
48 } | |
49 CGSize current_size = CGSizeMake(videoFrame.width, videoFrame.height); | |
50 if (!CGSizeEqualToSize(size_, current_size)) { | |
51 size_ = current_size; | |
52 [adapter_.videoRenderer setSize:size_]; | |
53 } | |
54 [adapter_.videoRenderer renderFrame:videoFrame]; | |
55 } | |
56 | |
57 private: | |
58 __weak RTCVideoRendererAdapter *adapter_; | |
59 CGSize size_; | |
60 }; | |
61 } | |
62 | |
63 @implementation RTCVideoRendererAdapter { | |
64 rtc::scoped_ptr<webrtc::VideoRendererAdapter> _adapter; | |
65 } | |
66 | |
67 @synthesize videoRenderer = _videoRenderer; | |
68 | |
69 - (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer { | |
70 NSParameterAssert(videoRenderer); | |
71 if (self = [super init]) { | |
72 _videoRenderer = videoRenderer; | |
73 _adapter.reset(new webrtc::VideoRendererAdapter(self)); | |
74 } | |
75 return self; | |
76 } | |
77 | |
78 - (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer { | |
79 return _adapter.get(); | |
80 } | |
81 | |
82 @end | |
OLD | NEW |