henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 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 | |
kwiberg | 84cc918 | 2016-03-11 22:12:57 -0800 | [diff] [blame] | 30 | #include <memory> |
| 31 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 32 | #include "webrtc/media/base/videoframe.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 34 | @implementation RTCI420Frame { |
kwiberg | 84cc918 | 2016-03-11 22:12:57 -0800 | [diff] [blame] | 35 | std::unique_ptr<cricket::VideoFrame> _videoFrame; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | - (NSUInteger)width { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 39 | return _videoFrame->width(); |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | - (NSUInteger)height { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 43 | return _videoFrame->height(); |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 44 | } |
| 45 | |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 46 | // TODO(nisse): chromaWidth and chromaHeight are used only in |
| 47 | // RTCOpenGLVideoRenderer.mm. Update, and then delete these |
| 48 | // properties. |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 49 | - (NSUInteger)chromaWidth { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 50 | return (self.width + 1) / 2; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | - (NSUInteger)chromaHeight { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 54 | return (self.height + 1) / 2; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | - (const uint8_t*)yPlane { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 58 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 59 | _videoFrame->video_frame_buffer(); |
| 60 | return buffer ? buffer->DataY() : nullptr; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | - (const uint8_t*)uPlane { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 64 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 65 | _videoFrame->video_frame_buffer(); |
| 66 | return buffer ? buffer->DataU() : nullptr; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | - (const uint8_t*)vPlane { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 70 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 71 | _videoFrame->video_frame_buffer(); |
| 72 | return buffer ? buffer->DataV() : nullptr; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | - (NSInteger)yPitch { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 76 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 77 | _videoFrame->video_frame_buffer(); |
| 78 | return buffer ? buffer->StrideY() : 0; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | - (NSInteger)uPitch { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 82 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 83 | _videoFrame->video_frame_buffer(); |
| 84 | return buffer ? buffer->StrideU() : 0; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | - (NSInteger)vPitch { |
nisse | 0565451 | 2016-04-29 02:56:00 -0700 | [diff] [blame^] | 88 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer = |
| 89 | _videoFrame->video_frame_buffer(); |
| 90 | return buffer ? buffer->StrideV() : 0; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame] | 91 | } |
| 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | |
| 106 | @end |