OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCVideoRendererAdapter+Private.h" | 11 #import "RTCVideoRendererAdapter+Private.h" |
12 | 12 |
13 #import "RTCVideoFrame+Private.h" | 13 #import "RTCVideoFrame+Private.h" |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/media/engine/webrtcvideoframe.h" | 17 #include "webrtc/media/engine/webrtcvideoframe.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 class VideoRendererAdapter | 21 class VideoRendererAdapter |
22 : public rtc::VideoSinkInterface<cricket::VideoFrame> { | 22 : public rtc::VideoSinkInterface<cricket::VideoFrame> { |
23 public: | 23 public: |
24 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { | 24 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { |
25 adapter_ = adapter; | 25 adapter_ = adapter; |
26 size_ = CGSizeZero; | 26 size_ = CGSizeZero; |
27 } | 27 } |
28 | 28 |
29 void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override { | 29 void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override { |
30 RTCVideoFrame *videoFrame = nil; | 30 RTCVideoFrame* videoFrame = [[RTCVideoFrame alloc] |
31 // Rotation of native handles is unsupported right now. Convert to CPU | 31 initWithVideoBuffer:nativeVideoFrame.video_frame_buffer() |
32 // I420 buffer for rotation before calling the rotation method otherwise | 32 rotation:nativeVideoFrame.rotation() |
33 // it will hit a DCHECK. | 33 timeStampNs:nativeVideoFrame.GetTimeStamp()]; |
34 if (nativeVideoFrame.rotation() != webrtc::kVideoRotation_0 && | 34 CGSize current_size = (videoFrame.rotation % 180 == 0) |
35 nativeVideoFrame.video_frame_buffer()->native_handle()) { | 35 ? CGSizeMake(videoFrame.width, videoFrame.height) |
36 rtc::scoped_refptr<webrtc::VideoFrameBuffer> i420Buffer = | 36 : CGSizeMake(videoFrame.height, videoFrame.width); |
37 nativeVideoFrame.video_frame_buffer()->NativeToI420Buffer(); | 37 |
38 std::unique_ptr<cricket::VideoFrame> cpuFrame( | |
39 new cricket::WebRtcVideoFrame(i420Buffer, nativeVideoFrame.rotation(), | |
40 nativeVideoFrame.timestamp_us(), | |
41 nativeVideoFrame.transport_frame_id())); | |
42 const cricket::VideoFrame *rotatedFrame = | |
43 cpuFrame->GetCopyWithRotationApplied(); | |
44 videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; | |
45 } else { | |
46 const cricket::VideoFrame *rotatedFrame = | |
47 nativeVideoFrame.GetCopyWithRotationApplied(); | |
48 videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame]; | |
49 } | |
50 CGSize current_size = CGSizeMake(videoFrame.width, videoFrame.height); | |
51 if (!CGSizeEqualToSize(size_, current_size)) { | 38 if (!CGSizeEqualToSize(size_, current_size)) { |
52 size_ = current_size; | 39 size_ = current_size; |
53 [adapter_.videoRenderer setSize:size_]; | 40 [adapter_.videoRenderer setSize:size_]; |
54 } | 41 } |
55 [adapter_.videoRenderer renderFrame:videoFrame]; | 42 [adapter_.videoRenderer renderFrame:videoFrame]; |
56 } | 43 } |
57 | 44 |
58 private: | 45 private: |
59 __weak RTCVideoRendererAdapter *adapter_; | 46 __weak RTCVideoRendererAdapter *adapter_; |
60 CGSize size_; | 47 CGSize size_; |
(...skipping 13 matching lines...) Expand all Loading... |
74 _adapter.reset(new webrtc::VideoRendererAdapter(self)); | 61 _adapter.reset(new webrtc::VideoRendererAdapter(self)); |
75 } | 62 } |
76 return self; | 63 return self; |
77 } | 64 } |
78 | 65 |
79 - (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer { | 66 - (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer { |
80 return _adapter.get(); | 67 return _adapter.get(); |
81 } | 68 } |
82 | 69 |
83 @end | 70 @end |
OLD | NEW |