Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm

Issue 2176623002: iOS render: Handle frame rotation in OpenGL (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@nv21_texture_render
Patch Set: Keep RTCVideoFrame.h pure ObjC Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« no previous file with comments | « webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h ('k') | webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698