Update webrtc/sdk/objc to new VideoFrameBuffer interface
More thorough refactoring work is planned for RTCVideoFrame (see webrtc:7785), and this CL just unblocks removing the old interface from webrtc::VideoFrameBuffer. Bug: webrtc:7632,webrtc:7785 Change-Id: I351536c5ca454c2acd8944bbc2ebb1d1439dc50c Reviewed-on: https://chromium-review.googlesource.com/530231 Reviewed-by: Anders Carlsson <andersc@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18553}
This commit is contained in:
parent
687bc3e27b
commit
b008b45f1e
@ -31,27 +31,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (const uint8_t *)dataY {
|
- (const uint8_t *)dataY {
|
||||||
return _videoBuffer->DataY();
|
return _videoBuffer->GetI420()->DataY();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (const uint8_t *)dataU {
|
- (const uint8_t *)dataU {
|
||||||
return _videoBuffer->DataU();
|
return _videoBuffer->GetI420()->DataU();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (const uint8_t *)dataV {
|
- (const uint8_t *)dataV {
|
||||||
return _videoBuffer->DataV();
|
return _videoBuffer->GetI420()->DataV();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)strideY {
|
- (int)strideY {
|
||||||
return _videoBuffer->StrideY();
|
return _videoBuffer->GetI420()->StrideY();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)strideU {
|
- (int)strideU {
|
||||||
return _videoBuffer->StrideU();
|
return _videoBuffer->GetI420()->StrideU();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)strideV {
|
- (int)strideV {
|
||||||
return _videoBuffer->StrideV();
|
return _videoBuffer->GetI420()->StrideV();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int64_t)timeStampNs {
|
- (int64_t)timeStampNs {
|
||||||
@ -59,12 +59,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (CVPixelBufferRef)nativeHandle {
|
- (CVPixelBufferRef)nativeHandle {
|
||||||
return static_cast<CVPixelBufferRef>(_videoBuffer->native_handle());
|
return (_videoBuffer->type() == webrtc::VideoFrameBuffer::Type::kNative) ?
|
||||||
|
static_cast<webrtc::CoreVideoFrameBuffer *>(_videoBuffer.get())->pixel_buffer() :
|
||||||
|
nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RTCVideoFrame *)newI420VideoFrame {
|
- (RTCVideoFrame *)newI420VideoFrame {
|
||||||
return [[RTCVideoFrame alloc]
|
return [[RTCVideoFrame alloc]
|
||||||
initWithVideoBuffer:_videoBuffer->NativeToI420Buffer()
|
initWithVideoBuffer:_videoBuffer->ToI420()
|
||||||
rotation:_rotation
|
rotation:_rotation
|
||||||
timeStampNs:_timeStampNs];
|
timeStampNs:_timeStampNs];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,24 +25,29 @@ CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer,
|
|||||||
int crop_height,
|
int crop_height,
|
||||||
int crop_x,
|
int crop_x,
|
||||||
int crop_y)
|
int crop_y)
|
||||||
: NativeHandleBuffer(pixel_buffer, adapted_width, adapted_height),
|
: pixel_buffer_(pixel_buffer),
|
||||||
pixel_buffer_(pixel_buffer),
|
width_(adapted_width),
|
||||||
|
height_(adapted_height),
|
||||||
buffer_width_(CVPixelBufferGetWidth(pixel_buffer)),
|
buffer_width_(CVPixelBufferGetWidth(pixel_buffer)),
|
||||||
buffer_height_(CVPixelBufferGetHeight(pixel_buffer)),
|
buffer_height_(CVPixelBufferGetHeight(pixel_buffer)),
|
||||||
crop_width_(crop_width), crop_height_(crop_height),
|
crop_width_(crop_width),
|
||||||
|
crop_height_(crop_height),
|
||||||
// Can only crop at even pixels.
|
// Can only crop at even pixels.
|
||||||
crop_x_(crop_x & ~1), crop_y_(crop_y & ~1) {
|
crop_x_(crop_x & ~1),
|
||||||
|
crop_y_(crop_y & ~1) {
|
||||||
CVBufferRetain(pixel_buffer_);
|
CVBufferRetain(pixel_buffer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer)
|
CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer)
|
||||||
: NativeHandleBuffer(pixel_buffer,
|
: pixel_buffer_(pixel_buffer),
|
||||||
CVPixelBufferGetWidth(pixel_buffer),
|
width_(CVPixelBufferGetWidth(pixel_buffer)),
|
||||||
CVPixelBufferGetHeight(pixel_buffer)),
|
height_(CVPixelBufferGetHeight(pixel_buffer)),
|
||||||
pixel_buffer_(pixel_buffer),
|
buffer_width_(width_),
|
||||||
buffer_width_(width_), buffer_height_(height_),
|
buffer_height_(height_),
|
||||||
crop_width_(width_), crop_height_(height_),
|
crop_width_(width_),
|
||||||
crop_x_(0), crop_y_(0) {
|
crop_height_(height_),
|
||||||
|
crop_x_(0),
|
||||||
|
crop_y_(0) {
|
||||||
CVBufferRetain(pixel_buffer_);
|
CVBufferRetain(pixel_buffer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +55,19 @@ CoreVideoFrameBuffer::~CoreVideoFrameBuffer() {
|
|||||||
CVBufferRelease(pixel_buffer_);
|
CVBufferRelease(pixel_buffer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoFrameBuffer>
|
VideoFrameBuffer::Type CoreVideoFrameBuffer::type() const {
|
||||||
CoreVideoFrameBuffer::NativeToI420Buffer() {
|
return Type::kNative;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CoreVideoFrameBuffer::width() const {
|
||||||
|
return width_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CoreVideoFrameBuffer::height() const {
|
||||||
|
return height_;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc::scoped_refptr<I420BufferInterface> CoreVideoFrameBuffer::ToI420() {
|
||||||
const OSType pixel_format = CVPixelBufferGetPixelFormatType(pixel_buffer_);
|
const OSType pixel_format = CVPixelBufferGetPixelFormatType(pixel_buffer_);
|
||||||
RTC_DCHECK(pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange ||
|
RTC_DCHECK(pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange ||
|
||||||
pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
|
pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class CoreVideoFrameBuffer : public NativeHandleBuffer {
|
class CoreVideoFrameBuffer : public VideoFrameBuffer {
|
||||||
public:
|
public:
|
||||||
explicit CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer);
|
explicit CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer);
|
||||||
CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer,
|
CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer,
|
||||||
@ -31,7 +31,8 @@ class CoreVideoFrameBuffer : public NativeHandleBuffer {
|
|||||||
int crop_y);
|
int crop_y);
|
||||||
~CoreVideoFrameBuffer() override;
|
~CoreVideoFrameBuffer() override;
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override;
|
CVPixelBufferRef pixel_buffer() { return pixel_buffer_; }
|
||||||
|
|
||||||
// Returns true if the internal pixel buffer needs to be cropped.
|
// Returns true if the internal pixel buffer needs to be cropped.
|
||||||
bool RequiresCropping() const;
|
bool RequiresCropping() const;
|
||||||
// Crop and scales the internal pixel buffer to the output pixel buffer. The
|
// Crop and scales the internal pixel buffer to the output pixel buffer. The
|
||||||
@ -41,11 +42,17 @@ class CoreVideoFrameBuffer : public NativeHandleBuffer {
|
|||||||
CVPixelBufferRef output_pixel_buffer) const;
|
CVPixelBufferRef output_pixel_buffer) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Type type() const override;
|
||||||
|
int width() const override;
|
||||||
|
int height() const override;
|
||||||
|
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
||||||
|
|
||||||
CVPixelBufferRef pixel_buffer_;
|
CVPixelBufferRef pixel_buffer_;
|
||||||
// buffer_width/height is the actual pixel buffer resolution. The width/height
|
// buffer_width/height is the actual pixel buffer resolution. The
|
||||||
// in NativeHandleBuffer, i.e. width()/height(), is the resolution we will
|
// width_/height_ is the resolution we will scale to in ToI420(). Cropping
|
||||||
// scale to in NativeToI420Buffer(). Cropping happens before scaling, so:
|
// happens before scaling, so: buffer_width >= crop_width >= width().
|
||||||
// buffer_width >= crop_width >= width().
|
const int width_;
|
||||||
|
const int height_;
|
||||||
const int buffer_width_;
|
const int buffer_width_;
|
||||||
const int buffer_height_;
|
const int buffer_height_;
|
||||||
const int crop_width_;
|
const int crop_width_;
|
||||||
|
|||||||
@ -155,9 +155,8 @@ struct FrameEncodeParams {
|
|||||||
// We receive I420Frames as input, but we need to feed CVPixelBuffers into the
|
// We receive I420Frames as input, but we need to feed CVPixelBuffers into the
|
||||||
// encoder. This performs the copy and format conversion.
|
// encoder. This performs the copy and format conversion.
|
||||||
// TODO(tkchin): See if encoder will accept i420 frames and compare performance.
|
// TODO(tkchin): See if encoder will accept i420 frames and compare performance.
|
||||||
bool CopyVideoFrameToPixelBuffer(
|
bool CopyVideoFrameToPixelBuffer(const rtc::scoped_refptr<webrtc::I420BufferInterface>& frame,
|
||||||
const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& frame,
|
CVPixelBufferRef pixel_buffer) {
|
||||||
CVPixelBufferRef pixel_buffer) {
|
|
||||||
RTC_DCHECK(pixel_buffer);
|
RTC_DCHECK(pixel_buffer);
|
||||||
RTC_DCHECK_EQ(CVPixelBufferGetPixelFormatType(pixel_buffer),
|
RTC_DCHECK_EQ(CVPixelBufferGetPixelFormatType(pixel_buffer),
|
||||||
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
|
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
|
||||||
@ -412,13 +411,12 @@ int H264VideoToolboxEncoder::Encode(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CVPixelBufferRef pixel_buffer = static_cast<CVPixelBufferRef>(
|
CVPixelBufferRef pixel_buffer;
|
||||||
frame.video_frame_buffer()->native_handle());
|
if (frame.video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative) {
|
||||||
if (pixel_buffer) {
|
|
||||||
// Native frame.
|
|
||||||
rtc::scoped_refptr<CoreVideoFrameBuffer> core_video_frame_buffer(
|
rtc::scoped_refptr<CoreVideoFrameBuffer> core_video_frame_buffer(
|
||||||
static_cast<CoreVideoFrameBuffer*>(frame.video_frame_buffer().get()));
|
static_cast<CoreVideoFrameBuffer*>(frame.video_frame_buffer().get()));
|
||||||
if (!core_video_frame_buffer->RequiresCropping()) {
|
if (!core_video_frame_buffer->RequiresCropping()) {
|
||||||
|
pixel_buffer = core_video_frame_buffer->pixel_buffer();
|
||||||
// This pixel buffer might have a higher resolution than what the
|
// This pixel buffer might have a higher resolution than what the
|
||||||
// compression session is configured to. The compression session can
|
// compression session is configured to. The compression session can
|
||||||
// handle that and will output encoded frames in the configured
|
// handle that and will output encoded frames in the configured
|
||||||
@ -441,7 +439,7 @@ int H264VideoToolboxEncoder::Encode(
|
|||||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||||
}
|
}
|
||||||
RTC_DCHECK(pixel_buffer);
|
RTC_DCHECK(pixel_buffer);
|
||||||
if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer(),
|
if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer()->ToI420(),
|
||||||
pixel_buffer)) {
|
pixel_buffer)) {
|
||||||
LOG(LS_ERROR) << "Failed to copy frame data.";
|
LOG(LS_ERROR) << "Failed to copy frame data.";
|
||||||
CVBufferRelease(pixel_buffer);
|
CVBufferRelease(pixel_buffer);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user