2016-01-11 09:47:07 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-06-22 15:26:30 +02:00
|
|
|
#import "webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrame.h"
|
|
|
|
|
#import "webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoFrameBuffer.h"
|
2017-02-21 05:28:48 -08:00
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@implementation RTCVideoFrame {
|
2017-02-21 04:19:46 -08:00
|
|
|
RTCVideoRotation _rotation;
|
2016-08-10 07:58:29 -07:00
|
|
|
int64_t _timeStampNs;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-06-22 15:26:30 +02:00
|
|
|
@synthesize buffer = _buffer;
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)width {
|
2017-06-22 15:26:30 +02:00
|
|
|
return _buffer.width;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)height {
|
2017-06-22 15:26:30 +02:00
|
|
|
return _buffer.height;
|
2016-08-10 07:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (RTCVideoRotation)rotation {
|
|
|
|
|
return _rotation;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (const uint8_t *)dataY {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).dataY;
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (const uint8_t *)dataU {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).dataU;
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (const uint8_t *)dataV {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).dataV;
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideY {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).strideY;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideU {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).strideU;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideV {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer conformsToProtocol:@protocol(RTCI420Buffer)]) {
|
|
|
|
|
return ((id<RTCI420Buffer>)_buffer).strideV;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-10 07:58:29 -07:00
|
|
|
- (int64_t)timeStampNs {
|
|
|
|
|
return _timeStampNs;
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CVPixelBufferRef)nativeHandle {
|
2017-06-22 15:26:30 +02:00
|
|
|
if ([_buffer isKindOfClass:[RTCCVPixelBuffer class]]) {
|
|
|
|
|
return ((RTCCVPixelBuffer *)_buffer).pixelBuffer;
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (RTCVideoFrame *)newI420VideoFrame {
|
2017-06-22 15:26:30 +02:00
|
|
|
return [[RTCVideoFrame alloc] initWithBuffer:[_buffer toI420]
|
|
|
|
|
rotation:_rotation
|
|
|
|
|
timeStampNs:_timeStampNs];
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 05:28:48 -08:00
|
|
|
- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
|
|
|
|
|
rotation:(RTCVideoRotation)rotation
|
|
|
|
|
timeStampNs:(int64_t)timeStampNs {
|
2017-06-22 15:26:30 +02:00
|
|
|
return [self initWithBuffer:[[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer]
|
|
|
|
|
rotation:rotation
|
|
|
|
|
timeStampNs:timeStampNs];
|
2017-02-21 05:28:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
|
|
|
|
|
scaledWidth:(int)scaledWidth
|
|
|
|
|
scaledHeight:(int)scaledHeight
|
|
|
|
|
cropWidth:(int)cropWidth
|
|
|
|
|
cropHeight:(int)cropHeight
|
|
|
|
|
cropX:(int)cropX
|
|
|
|
|
cropY:(int)cropY
|
|
|
|
|
rotation:(RTCVideoRotation)rotation
|
|
|
|
|
timeStampNs:(int64_t)timeStampNs {
|
2017-06-22 15:26:30 +02:00
|
|
|
RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer
|
|
|
|
|
adaptedWidth:scaledWidth
|
|
|
|
|
adaptedHeight:scaledHeight
|
|
|
|
|
cropWidth:cropWidth
|
|
|
|
|
cropHeight:cropHeight
|
|
|
|
|
cropX:cropX
|
|
|
|
|
cropY:cropY];
|
|
|
|
|
return [self initWithBuffer:rtcPixelBuffer rotation:rotation timeStampNs:timeStampNs];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithBuffer:(id<RTCVideoFrameBuffer>)buffer
|
|
|
|
|
rotation:(RTCVideoRotation)rotation
|
|
|
|
|
timeStampNs:(int64_t)timeStampNs {
|
2016-01-11 09:47:07 -08:00
|
|
|
if (self = [super init]) {
|
2017-06-22 15:26:30 +02:00
|
|
|
_buffer = buffer;
|
2016-08-10 07:58:29 -07:00
|
|
|
_rotation = rotation;
|
|
|
|
|
_timeStampNs = timeStampNs;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
2017-06-21 08:41:26 +00:00
|
|
|
|
2017-06-22 15:26:30 +02:00
|
|
|
return self;
|
2017-06-22 13:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@end
|