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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCVideoFrame+Private.h"
|
2016-01-11 09:47:07 -08:00
|
|
|
|
2016-05-01 14:53:46 -07:00
|
|
|
#include <memory>
|
2016-01-11 09:47:07 -08:00
|
|
|
|
2017-01-10 07:44:26 -08:00
|
|
|
#include "webrtc/api/video/video_rotation.h"
|
2016-08-10 07:58:29 -07:00
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@implementation RTCVideoFrame {
|
2016-08-10 07:58:29 -07:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> _videoBuffer;
|
|
|
|
|
webrtc::VideoRotation _rotation;
|
|
|
|
|
int64_t _timeStampNs;
|
2016-04-04 14:10:43 -07:00
|
|
|
rtc::scoped_refptr<webrtc::VideoFrameBuffer> _i420Buffer;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (size_t)width {
|
2016-08-10 07:58:29 -07:00
|
|
|
return _videoBuffer->width();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (size_t)height {
|
2016-08-10 07:58:29 -07:00
|
|
|
return _videoBuffer->height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int)rotation {
|
|
|
|
|
return static_cast<int>(_rotation);
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
2016-04-04 00:57:29 -07:00
|
|
|
// TODO(nisse): chromaWidth and chromaHeight are used only in
|
|
|
|
|
// RTCOpenGLVideoRenderer.mm. Update, and then delete these
|
|
|
|
|
// properties.
|
2016-01-11 09:47:07 -08:00
|
|
|
- (size_t)chromaWidth {
|
2016-04-04 00:57:29 -07:00
|
|
|
return (self.width + 1) / 2;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (size_t)chromaHeight {
|
2016-04-04 00:57:29 -07:00
|
|
|
return (self.height + 1) / 2;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const uint8_t *)yPlane {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->DataY();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const uint8_t *)uPlane {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->DataU();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const uint8_t *)vPlane {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->DataV();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int32_t)yPitch {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->StrideY();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int32_t)uPitch {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->StrideU();
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int32_t)vPitch {
|
2016-04-04 14:10:43 -07:00
|
|
|
if (!self.i420Buffer) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-06-17 05:03:04 -07:00
|
|
|
return self.i420Buffer->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 {
|
2016-08-10 07:58:29 -07:00
|
|
|
return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle());
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)convertBufferIfNeeded {
|
|
|
|
|
if (!_i420Buffer) {
|
2016-08-10 07:58:29 -07:00
|
|
|
_i420Buffer = _videoBuffer->native_handle()
|
|
|
|
|
? _videoBuffer->NativeToI420Buffer()
|
|
|
|
|
: _videoBuffer;
|
2016-04-04 14:10:43 -07:00
|
|
|
}
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Private
|
|
|
|
|
|
2016-08-10 07:58:29 -07:00
|
|
|
- (instancetype)initWithVideoBuffer:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::VideoFrameBuffer>)videoBuffer
|
|
|
|
|
rotation:(webrtc::VideoRotation)rotation
|
|
|
|
|
timeStampNs:(int64_t)timeStampNs {
|
2016-01-11 09:47:07 -08:00
|
|
|
if (self = [super init]) {
|
2016-08-10 07:58:29 -07:00
|
|
|
_videoBuffer = videoBuffer;
|
|
|
|
|
_rotation = rotation;
|
|
|
|
|
_timeStampNs = timeStampNs;
|
2016-01-11 09:47:07 -08:00
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-04 14:10:43 -07:00
|
|
|
- (rtc::scoped_refptr<webrtc::VideoFrameBuffer>)i420Buffer {
|
|
|
|
|
[self convertBufferIfNeeded];
|
|
|
|
|
return _i420Buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 09:47:07 -08:00
|
|
|
@end
|