| 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 "RTCVideoFrame+Private.h" | 11 #import "RTCVideoFrame+Private.h" |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "webrtc/common_video/rotation.h" |
| 16 |
| 15 @implementation RTCVideoFrame { | 17 @implementation RTCVideoFrame { |
| 16 std::unique_ptr<cricket::VideoFrame> _videoFrame; | 18 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer; |
| 19 webrtc::VideoRotation _rotation; |
| 20 int64_t _timeStampNs; |
| 17 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer; | 21 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer; |
| 18 } | 22 } |
| 19 | 23 |
| 20 - (size_t)width { | 24 - (size_t)width { |
| 21 return _videoFrame->width(); | 25 return _videoBuffer->width(); |
| 22 } | 26 } |
| 23 | 27 |
| 24 - (size_t)height { | 28 - (size_t)height { |
| 25 return _videoFrame->height(); | 29 return _videoBuffer->height(); |
| 30 } |
| 31 |
| 32 - (int)rotation { |
| 33 return static_cast<int>(_rotation); |
| 26 } | 34 } |
| 27 | 35 |
| 28 // TODO(nisse): chromaWidth and chromaHeight are used only in | 36 // TODO(nisse): chromaWidth and chromaHeight are used only in |
| 29 // RTCOpenGLVideoRenderer.mm. Update, and then delete these | 37 // RTCOpenGLVideoRenderer.mm. Update, and then delete these |
| 30 // properties. | 38 // properties. |
| 31 - (size_t)chromaWidth { | 39 - (size_t)chromaWidth { |
| 32 return (self.width + 1) / 2; | 40 return (self.width + 1) / 2; |
| 33 } | 41 } |
| 34 | 42 |
| 35 - (size_t)chromaHeight { | 43 - (size_t)chromaHeight { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return self.i420Buffer->StrideU(); | 79 return self.i420Buffer->StrideU(); |
| 72 } | 80 } |
| 73 | 81 |
| 74 - (int32_t)vPitch { | 82 - (int32_t)vPitch { |
| 75 if (!self.i420Buffer) { | 83 if (!self.i420Buffer) { |
| 76 return 0; | 84 return 0; |
| 77 } | 85 } |
| 78 return self.i420Buffer->StrideV(); | 86 return self.i420Buffer->StrideV(); |
| 79 } | 87 } |
| 80 | 88 |
| 81 - (int64_t)timeStamp { | 89 - (int64_t)timeStampNs { |
| 82 return _videoFrame->GetTimeStamp(); | 90 return _timeStampNs; |
| 83 } | 91 } |
| 84 | 92 |
| 85 - (CVPixelBufferRef)nativeHandle { | 93 - (CVPixelBufferRef)nativeHandle { |
| 86 return static_cast<CVPixelBufferRef>( | 94 return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle()); |
| 87 _videoFrame->video_frame_buffer()->native_handle()); | |
| 88 } | 95 } |
| 89 | 96 |
| 90 - (void)convertBufferIfNeeded { | 97 - (void)convertBufferIfNeeded { |
| 91 if (!_i420Buffer) { | 98 if (!_i420Buffer) { |
| 92 if (_videoFrame->video_frame_buffer()->native_handle()) { | 99 _i420Buffer = _videoBuffer->native_handle() |
| 93 // Convert to I420. | 100 ? _videoBuffer->NativeToI420Buffer() |
| 94 _i420Buffer = _videoFrame->video_frame_buffer()->NativeToI420Buffer(); | 101 : _videoBuffer; |
| 95 } else { | |
| 96 // Should already be I420. | |
| 97 _i420Buffer = _videoFrame->video_frame_buffer(); | |
| 98 } | |
| 99 } | 102 } |
| 100 } | 103 } |
| 101 | 104 |
| 102 #pragma mark - Private | 105 #pragma mark - Private |
| 103 | 106 |
| 104 - (instancetype)initWithNativeFrame:(const cricket::VideoFrame *)nativeFrame { | 107 - (instancetype)initWithVideoBuffer: |
| 108 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer |
| 109 rotation:(webrtc::VideoRotation)rotation |
| 110 timeStampNs:(int64_t)timeStampNs { |
| 105 if (self = [super init]) { | 111 if (self = [super init]) { |
| 106 // Keep a shallow copy of the video frame. The underlying frame buffer is | 112 _videoBuffer = videoBuffer; |
| 107 // not copied. | 113 _rotation = rotation; |
| 108 _videoFrame.reset(nativeFrame->Copy()); | 114 _timeStampNs = timeStampNs; |
| 109 } | 115 } |
| 110 return self; | 116 return self; |
| 111 } | 117 } |
| 112 | 118 |
| 113 - (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer { | 119 - (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer { |
| 114 [self convertBufferIfNeeded]; | 120 [self convertBufferIfNeeded]; |
| 115 return _i420Buffer; | 121 return _i420Buffer; |
| 116 } | 122 } |
| 117 | 123 |
| 118 @end | 124 @end |
| OLD | NEW |