1/* 2 * Copyright 2017 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 11#include "sdk/objc/native/src/objc_frame_buffer.h" 12 13#import "base/RTCVideoFrameBuffer.h" 14#import "sdk/objc/api/video_frame_buffer/RTCNativeI420Buffer+Private.h" 15 16namespace webrtc { 17 18namespace { 19 20/** ObjCFrameBuffer that conforms to I420BufferInterface by wrapping RTC_OBJC_TYPE(RTCI420Buffer) */ 21class ObjCI420FrameBuffer : public I420BufferInterface { 22 public: 23 explicit ObjCI420FrameBuffer(id<RTC_OBJC_TYPE(RTCI420Buffer)> frame_buffer) 24 : frame_buffer_(frame_buffer), width_(frame_buffer.width), height_(frame_buffer.height) {} 25 ~ObjCI420FrameBuffer() override {} 26 27 int width() const override { return width_; } 28 29 int height() const override { return height_; } 30 31 const uint8_t* DataY() const override { return frame_buffer_.dataY; } 32 33 const uint8_t* DataU() const override { return frame_buffer_.dataU; } 34 35 const uint8_t* DataV() const override { return frame_buffer_.dataV; } 36 37 int StrideY() const override { return frame_buffer_.strideY; } 38 39 int StrideU() const override { return frame_buffer_.strideU; } 40 41 int StrideV() const override { return frame_buffer_.strideV; } 42 43 private: 44 id<RTC_OBJC_TYPE(RTCI420Buffer)> frame_buffer_; 45 int width_; 46 int height_; 47}; 48 49} // namespace 50 51ObjCFrameBuffer::ObjCFrameBuffer(id<RTC_OBJC_TYPE(RTCVideoFrameBuffer)> frame_buffer) 52 : frame_buffer_(frame_buffer), width_(frame_buffer.width), height_(frame_buffer.height) {} 53 54ObjCFrameBuffer::~ObjCFrameBuffer() {} 55 56VideoFrameBuffer::Type ObjCFrameBuffer::type() const { 57 return Type::kNative; 58} 59 60int ObjCFrameBuffer::width() const { 61 return width_; 62} 63 64int ObjCFrameBuffer::height() const { 65 return height_; 66} 67 68rtc::scoped_refptr<I420BufferInterface> ObjCFrameBuffer::ToI420() { 69 rtc::scoped_refptr<I420BufferInterface> buffer = 70 new rtc::RefCountedObject<ObjCI420FrameBuffer>([frame_buffer_ toI420]); 71 72 return buffer; 73} 74 75id<RTC_OBJC_TYPE(RTCVideoFrameBuffer)> ObjCFrameBuffer::wrapped_frame_buffer() const { 76 return frame_buffer_; 77} 78 79id<RTC_OBJC_TYPE(RTCVideoFrameBuffer)> ToObjCVideoFrameBuffer( 80 const rtc::scoped_refptr<VideoFrameBuffer>& buffer) { 81 if (buffer->type() == VideoFrameBuffer::Type::kNative) { 82 return static_cast<ObjCFrameBuffer*>(buffer.get())->wrapped_frame_buffer(); 83 } else { 84 return [[RTC_OBJC_TYPE(RTCI420Buffer) alloc] initWithFrameBuffer:buffer->ToI420()]; 85 } 86} 87 88} // namespace webrtc 89