blob: 6c6c5645823d283975835d4f462722851e595062 [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 {
nisse05654512016-04-29 02:56:00 -070058 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
59 _videoFrame->video_frame_buffer();
60 return buffer ? buffer->DataY() : nullptr;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000061}
62
63- (const uint8_t*)uPlane {
nisse05654512016-04-29 02:56:00 -070064 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
65 _videoFrame->video_frame_buffer();
66 return buffer ? buffer->DataU() : nullptr;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000067}
68
69- (const uint8_t*)vPlane {
nisse05654512016-04-29 02:56:00 -070070 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
71 _videoFrame->video_frame_buffer();
72 return buffer ? buffer->DataV() : nullptr;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000073}
74
75- (NSInteger)yPitch {
nisse05654512016-04-29 02:56:00 -070076 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
77 _videoFrame->video_frame_buffer();
78 return buffer ? buffer->StrideY() : 0;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000079}
80
81- (NSInteger)uPitch {
nisse05654512016-04-29 02:56:00 -070082 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
83 _videoFrame->video_frame_buffer();
84 return buffer ? buffer->StrideU() : 0;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000085}
86
87- (NSInteger)vPitch {
nisse05654512016-04-29 02:56:00 -070088 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer =
89 _videoFrame->video_frame_buffer();
90 return buffer ? buffer->StrideV() : 0;
tkchin@webrtc.org1732a592014-05-19 23:26:01 +000091}
92
93@end
94
95@implementation RTCI420Frame (Internal)
96
97- (instancetype)initWithVideoFrame:(cricket::VideoFrame*)videoFrame {
98 if (self = [super init]) {
99 // Keep a shallow copy of the video frame. The underlying frame buffer is
100 // not copied.
101 _videoFrame.reset(videoFrame->Copy());
102 }
103 return self;
104}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
106@end