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

Side by Side Diff: webrtc/api/objc/RTCVideoRendererAdapter.mm

Issue 1894873002: Fix crash when receiving a texture frame with rotation bit set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 11 #import "RTCVideoRendererAdapter.h"
12 12
13 #include "webrtc/media/engine/webrtcvideoframe.h"
14
13 #import "webrtc/api/objc/RTCVideoFrame+Private.h" 15 #import "webrtc/api/objc/RTCVideoFrame+Private.h"
14 #import "webrtc/api/objc/RTCVideoRendererAdapter+Private.h" 16 #import "webrtc/api/objc/RTCVideoRendererAdapter+Private.h"
15 17
16 namespace webrtc { 18 namespace webrtc {
17 19
18 class VideoRendererAdapter 20 class VideoRendererAdapter
19 : public rtc::VideoSinkInterface<cricket::VideoFrame> { 21 : public rtc::VideoSinkInterface<cricket::VideoFrame> {
20 public: 22 public:
21 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) { 23 VideoRendererAdapter(RTCVideoRendererAdapter* adapter) {
22 adapter_ = adapter; 24 adapter_ = adapter;
23 size_ = CGSizeZero; 25 size_ = CGSizeZero;
24 } 26 }
25 27
26 void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override { 28 void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override {
27 const cricket::VideoFrame *frame = 29 RTCVideoFrame *videoFrame = nil;
28 nativeVideoFrame.GetCopyWithRotationApplied(); 30 // Rotation of native handles is unsupported right now. Convert to CPU
29 CGSize current_size = CGSizeMake(frame->width(), frame->height()); 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);
30 if (!CGSizeEqualToSize(size_, current_size)) { 50 if (!CGSizeEqualToSize(size_, current_size)) {
31 size_ = current_size; 51 size_ = current_size;
32 [adapter_.videoRenderer setSize:size_]; 52 [adapter_.videoRenderer setSize:size_];
33 } 53 }
34 RTCVideoFrame *videoFrame =
35 [[RTCVideoFrame alloc] initWithNativeFrame:frame];
36 [adapter_.videoRenderer renderFrame:videoFrame]; 54 [adapter_.videoRenderer renderFrame:videoFrame];
37 } 55 }
38 56
39 private: 57 private:
40 __weak RTCVideoRendererAdapter *adapter_; 58 __weak RTCVideoRendererAdapter *adapter_;
41 CGSize size_; 59 CGSize size_;
42 }; 60 };
43 } 61 }
44 62
45 @implementation RTCVideoRendererAdapter { 63 @implementation RTCVideoRendererAdapter {
46 rtc::scoped_ptr<webrtc::VideoRendererAdapter> _adapter; 64 rtc::scoped_ptr<webrtc::VideoRendererAdapter> _adapter;
47 } 65 }
48 66
49 @synthesize videoRenderer = _videoRenderer; 67 @synthesize videoRenderer = _videoRenderer;
50 68
51 - (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer { 69 - (instancetype)initWithNativeRenderer:(id<RTCVideoRenderer>)videoRenderer {
52 NSParameterAssert(videoRenderer); 70 NSParameterAssert(videoRenderer);
53 if (self = [super init]) { 71 if (self = [super init]) {
54 _videoRenderer = videoRenderer; 72 _videoRenderer = videoRenderer;
55 _adapter.reset(new webrtc::VideoRendererAdapter(self)); 73 _adapter.reset(new webrtc::VideoRendererAdapter(self));
56 } 74 }
57 return self; 75 return self;
58 } 76 }
59 77
60 - (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer { 78 - (rtc::VideoSinkInterface<cricket::VideoFrame> *)nativeVideoRenderer {
61 return _adapter.get(); 79 return _adapter.get();
62 } 80 }
63 81
64 @end 82 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698