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 13:06:39 +00:00
|
|
|
#import "RTCVideoFrame+Private.h"
|
|
|
|
|
|
|
|
|
|
#include "webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h"
|
2017-02-21 05:28:48 -08:00
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@implementation RTCVideoFrame {
|
2017-06-22 13:06:39 +00:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer;
|
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-02-21 04:19:46 -08:00
|
|
|
- (int)width {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->width();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)height {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->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 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->DataY();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (const uint8_t *)dataU {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->DataU();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (const uint8_t *)dataV {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->DataV();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideY {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->StrideY();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideU {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->StrideU();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (int)strideV {
|
2017-06-22 13:06:39 +00:00
|
|
|
return _videoBuffer->GetI420()->StrideV();
|
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 13:06:39 +00:00
|
|
|
return (_videoBuffer->type() == webrtc::VideoFrameBuffer::Type::kNative) ?
|
|
|
|
|
static_cast<webrtc::CoreVideoFrameBuffer *>(_videoBuffer.get())->pixel_buffer() :
|
|
|
|
|
nil;
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 04:19:46 -08:00
|
|
|
- (RTCVideoFrame *)newI420VideoFrame {
|
2017-06-22 13:06:39 +00:00
|
|
|
return [[RTCVideoFrame alloc]
|
|
|
|
|
initWithVideoBuffer:_videoBuffer->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 13:06:39 +00:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> videoBuffer(
|
|
|
|
|
new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(pixelBuffer));
|
|
|
|
|
return [self initWithVideoBuffer:videoBuffer
|
|
|
|
|
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 13:06:39 +00:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> videoBuffer(
|
|
|
|
|
new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(
|
|
|
|
|
pixelBuffer,
|
|
|
|
|
scaledWidth, scaledHeight,
|
|
|
|
|
cropWidth, cropHeight,
|
|
|
|
|
cropX, cropY));
|
|
|
|
|
return [self initWithVideoBuffer:videoBuffer
|
|
|
|
|
rotation:rotation
|
|
|
|
|
timeStampNs:timeStampNs];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithVideoBuffer:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer
|
|
|
|
|
rotation:(RTCVideoRotation)rotation
|
|
|
|
|
timeStampNs:(int64_t)timeStampNs {
|
2016-01-11 09:47:07 -08:00
|
|
|
if (self = [super init]) {
|
2017-06-22 13:06:39 +00:00
|
|
|
_videoBuffer = videoBuffer;
|
2016-08-10 07:58:29 -07:00
|
|
|
_rotation = rotation;
|
|
|
|
|
_timeStampNs = timeStampNs;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
2017-06-21 10:53:19 +02:00
|
|
|
return self;
|
2017-06-21 08:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-06-22 13:06:39 +00:00
|
|
|
- (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer {
|
|
|
|
|
return _videoBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@end
|