blob: a4eaefb85398ffe64958072783ce47c49873fca7 [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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCVideoFrame+Private.h"
Jon Hjelle78234952016-01-11 09:47:07 -080012
magjedc3c46242017-02-21 05:28:48 -080013#include "webrtc/common_video/include/corevideo_frame_buffer.h"
14
Jon Hjelle78234952016-01-11 09:47:07 -080015@implementation RTCVideoFrame {
magjedfb372f02016-08-10 07:58:29 -070016 rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer;
magjed7ee51252017-02-21 04:19:46 -080017 RTCVideoRotation _rotation;
magjedfb372f02016-08-10 07:58:29 -070018 int64_t _timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -080019}
20
magjed7ee51252017-02-21 04:19:46 -080021- (int)width {
magjedfb372f02016-08-10 07:58:29 -070022 return _videoBuffer->width();
Jon Hjelle78234952016-01-11 09:47:07 -080023}
24
magjed7ee51252017-02-21 04:19:46 -080025- (int)height {
magjedfb372f02016-08-10 07:58:29 -070026 return _videoBuffer->height();
27}
28
magjed7ee51252017-02-21 04:19:46 -080029- (RTCVideoRotation)rotation {
30 return _rotation;
Jon Hjelle78234952016-01-11 09:47:07 -080031}
32
magjed7ee51252017-02-21 04:19:46 -080033- (const uint8_t *)dataY {
34 return _videoBuffer->DataY();
Jon Hjelle78234952016-01-11 09:47:07 -080035}
36
magjed7ee51252017-02-21 04:19:46 -080037- (const uint8_t *)dataU {
38 return _videoBuffer->DataU();
Jon Hjelle78234952016-01-11 09:47:07 -080039}
40
magjed7ee51252017-02-21 04:19:46 -080041- (const uint8_t *)dataV {
42 return _videoBuffer->DataV();
Jon Hjelle78234952016-01-11 09:47:07 -080043}
44
magjed7ee51252017-02-21 04:19:46 -080045- (int)strideY {
46 return _videoBuffer->StrideY();
Jon Hjelle78234952016-01-11 09:47:07 -080047}
48
magjed7ee51252017-02-21 04:19:46 -080049- (int)strideU {
50 return _videoBuffer->StrideU();
Jon Hjelle78234952016-01-11 09:47:07 -080051}
52
magjed7ee51252017-02-21 04:19:46 -080053- (int)strideV {
54 return _videoBuffer->StrideV();
tkchin7d06a8c2016-04-04 14:10:43 -070055}
56
magjedfb372f02016-08-10 07:58:29 -070057- (int64_t)timeStampNs {
58 return _timeStampNs;
tkchin7d06a8c2016-04-04 14:10:43 -070059}
60
61- (CVPixelBufferRef)nativeHandle {
magjedfb372f02016-08-10 07:58:29 -070062 return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle());
tkchin7d06a8c2016-04-04 14:10:43 -070063}
64
magjed7ee51252017-02-21 04:19:46 -080065- (RTCVideoFrame *)newI420VideoFrame {
66 return [[RTCVideoFrame alloc]
67 initWithVideoBuffer:_videoBuffer->NativeToI420Buffer()
68 rotation:_rotation
69 timeStampNs:_timeStampNs];
Jon Hjelle78234952016-01-11 09:47:07 -080070}
71
magjedc3c46242017-02-21 05:28:48 -080072- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
73 rotation:(RTCVideoRotation)rotation
74 timeStampNs:(int64_t)timeStampNs {
75 rtc::scoped_refptr<webrtc::VideoFrameBuffer> videoBuffer(
76 new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(pixelBuffer));
77 return [self initWithVideoBuffer:videoBuffer
78 rotation:rotation
79 timeStampNs:timeStampNs];
80}
81
82- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
83 scaledWidth:(int)scaledWidth
84 scaledHeight:(int)scaledHeight
85 cropWidth:(int)cropWidth
86 cropHeight:(int)cropHeight
87 cropX:(int)cropX
88 cropY:(int)cropY
89 rotation:(RTCVideoRotation)rotation
90 timeStampNs:(int64_t)timeStampNs {
91 rtc::scoped_refptr<webrtc::VideoFrameBuffer> videoBuffer(
92 new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(
93 pixelBuffer,
94 scaledWidth, scaledHeight,
95 cropWidth, cropHeight,
96 cropX, cropY));
97 return [self initWithVideoBuffer:videoBuffer
98 rotation:rotation
99 timeStampNs:timeStampNs];
100}
101
Jon Hjelle78234952016-01-11 09:47:07 -0800102#pragma mark - Private
103
magjedfb372f02016-08-10 07:58:29 -0700104- (instancetype)initWithVideoBuffer:
105 (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer
magjed7ee51252017-02-21 04:19:46 -0800106 rotation:(RTCVideoRotation)rotation
magjedfb372f02016-08-10 07:58:29 -0700107 timeStampNs:(int64_t)timeStampNs {
Jon Hjelle78234952016-01-11 09:47:07 -0800108 if (self = [super init]) {
magjedfb372f02016-08-10 07:58:29 -0700109 _videoBuffer = videoBuffer;
110 _rotation = rotation;
111 _timeStampNs = timeStampNs;
Jon Hjelle78234952016-01-11 09:47:07 -0800112 }
113 return self;
114}
115
magjedabb84b82017-03-28 01:56:41 -0700116- (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer {
117 return _videoBuffer;
118}
119
Jon Hjelle78234952016-01-11 09:47:07 -0800120@end