Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 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 "RTCVideoFrame.h" |
| 12 | |
| 13 | #include "webrtc/base/scoped_ptr.h" |
| 14 | |
| 15 | #import "webrtc/api/objc/RTCVideoFrame+Private.h" |
| 16 | |
| 17 | @implementation RTCVideoFrame { |
| 18 | rtc::scoped_ptr<cricket::VideoFrame> _videoFrame; |
| 19 | } |
| 20 | |
| 21 | - (size_t)width { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 22 | return _videoFrame->width(); |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | - (size_t)height { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 26 | return _videoFrame->height(); |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 27 | } |
| 28 | |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 29 | // TODO(nisse): chromaWidth and chromaHeight are used only in |
| 30 | // RTCOpenGLVideoRenderer.mm. Update, and then delete these |
| 31 | // properties. |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 32 | - (size_t)chromaWidth { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 33 | return (self.width + 1) / 2; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | - (size_t)chromaHeight { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 37 | return (self.height + 1) / 2; |
Jon Hjelle | 7823495 | 2016-01-11 09:47:07 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | - (const uint8_t *)yPlane { |
| 41 | const cricket::VideoFrame *const_frame = _videoFrame.get(); |
| 42 | return const_frame->GetYPlane(); |
| 43 | } |
| 44 | |
| 45 | - (const uint8_t *)uPlane { |
| 46 | const cricket::VideoFrame *const_frame = _videoFrame.get(); |
| 47 | return const_frame->GetUPlane(); |
| 48 | } |
| 49 | |
| 50 | - (const uint8_t *)vPlane { |
| 51 | const cricket::VideoFrame *const_frame = _videoFrame.get(); |
| 52 | return const_frame->GetVPlane(); |
| 53 | } |
| 54 | |
| 55 | - (int32_t)yPitch { |
| 56 | return _videoFrame->GetYPitch(); |
| 57 | } |
| 58 | |
| 59 | - (int32_t)uPitch { |
| 60 | return _videoFrame->GetUPitch(); |
| 61 | } |
| 62 | |
| 63 | - (int32_t)vPitch { |
| 64 | return _videoFrame->GetVPitch(); |
| 65 | } |
| 66 | |
| 67 | #pragma mark - Private |
| 68 | |
| 69 | - (instancetype)initWithNativeFrame:(const cricket::VideoFrame *)nativeFrame { |
| 70 | if (self = [super init]) { |
| 71 | // Keep a shallow copy of the video frame. The underlying frame buffer is |
| 72 | // not copied. |
| 73 | _videoFrame.reset(nativeFrame->Copy()); |
| 74 | } |
| 75 | return self; |
| 76 | } |
| 77 | |
| 78 | @end |