blob: d70ab372ac86ea8fd2a7efb48fb862d6ffee7b0d [file] [log] [blame]
Jon Hjelle78234952016-01-11 09:47:07 -08001/*
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 {
nisse71a0c2f2016-04-04 00:57:29 -070022 return _videoFrame->width();
Jon Hjelle78234952016-01-11 09:47:07 -080023}
24
25- (size_t)height {
nisse71a0c2f2016-04-04 00:57:29 -070026 return _videoFrame->height();
Jon Hjelle78234952016-01-11 09:47:07 -080027}
28
nisse71a0c2f2016-04-04 00:57:29 -070029// TODO(nisse): chromaWidth and chromaHeight are used only in
30// RTCOpenGLVideoRenderer.mm. Update, and then delete these
31// properties.
Jon Hjelle78234952016-01-11 09:47:07 -080032- (size_t)chromaWidth {
nisse71a0c2f2016-04-04 00:57:29 -070033 return (self.width + 1) / 2;
Jon Hjelle78234952016-01-11 09:47:07 -080034}
35
36- (size_t)chromaHeight {
nisse71a0c2f2016-04-04 00:57:29 -070037 return (self.height + 1) / 2;
Jon Hjelle78234952016-01-11 09:47:07 -080038}
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