blob: aacdfe33b22fb387a659425c7208d8a2b78c3191 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2013 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#import "RTCI420Frame.h"
29
kwiberg84cc9182016-03-11 22:12:57 -080030#include <memory>
31
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/videoframe.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000034@implementation RTCI420Frame {
kwiberg84cc9182016-03-11 22:12:57 -080035 std::unique_ptr<cricket::VideoFrame> _videoFrame;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000036}
37
38- (NSUInteger)width {
nisse71a0c2f2016-04-04 00:57:29 -070039 return _videoFrame->width();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000040}
41
42- (NSUInteger)height {
nisse71a0c2f2016-04-04 00:57:29 -070043 return _videoFrame->height();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000044}
45
nisse71a0c2f2016-04-04 00:57:29 -070046// TODO(nisse): chromaWidth and chromaHeight are used only in
47// RTCOpenGLVideoRenderer.mm. Update, and then delete these
48// properties.
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000049- (NSUInteger)chromaWidth {
nisse71a0c2f2016-04-04 00:57:29 -070050 return (self.width + 1) / 2;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000051}
52
53- (NSUInteger)chromaHeight {
nisse71a0c2f2016-04-04 00:57:29 -070054 return (self.height + 1) / 2;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000055}
56
57- (const uint8_t*)yPlane {
tereliusb05f9942016-04-25 11:41:47 -070058 const cricket::VideoFrame* const_frame = _videoFrame.get();
59 return const_frame->GetYPlane();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000060}
61
62- (const uint8_t*)uPlane {
tereliusb05f9942016-04-25 11:41:47 -070063 const cricket::VideoFrame* const_frame = _videoFrame.get();
64 return const_frame->GetUPlane();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000065}
66
67- (const uint8_t*)vPlane {
tereliusb05f9942016-04-25 11:41:47 -070068 const cricket::VideoFrame* const_frame = _videoFrame.get();
69 return const_frame->GetVPlane();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000070}
71
72- (NSInteger)yPitch {
tereliusb05f9942016-04-25 11:41:47 -070073 return _videoFrame->GetYPitch();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000074}
75
76- (NSInteger)uPitch {
tereliusb05f9942016-04-25 11:41:47 -070077 return _videoFrame->GetUPitch();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000078}
79
80- (NSInteger)vPitch {
tereliusb05f9942016-04-25 11:41:47 -070081 return _videoFrame->GetVPitch();
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000082}
83
84@end
85
86@implementation RTCI420Frame (Internal)
87
88- (instancetype)initWithVideoFrame:(cricket::VideoFrame*)videoFrame {
89 if (self = [super init]) {
90 // Keep a shallow copy of the video frame. The underlying frame buffer is
91 // not copied.
92 _videoFrame.reset(videoFrame->Copy());
93 }
94 return self;
95}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97@end