From 5b383c0ebd586b973d6bf14624cece61d2fc590c Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Tue, 13 Jun 2017 09:14:36 +0000 Subject: [PATCH] Revert "Update webrtc/sdk/objc to new VideoFrameBuffer interface" This reverts commit b008b45f1e609556a04c1aabb4e8ed6a894265af. Reason for revert: Breaks external clients. Original change's description: > 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 > Commit-Queue: Magnus Jedvert > Cr-Commit-Position: refs/heads/master@{#18553} TBR=magjed@webrtc.org,andersc@webrtc.org No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:7632,webrtc:7785 Change-Id: Ib5c6fcb939175c67c3ac7b3df7cea0f7c2bb0af0 Reviewed-on: https://chromium-review.googlesource.com/533013 Reviewed-by: Magnus Jedvert Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#18557} --- .../Classes/PeerConnection/RTCVideoFrame.mm | 18 ++++---- .../Classes/Video/corevideo_frame_buffer.cc | 42 ++++++------------- .../Classes/Video/corevideo_frame_buffer.h | 19 +++------ .../Framework/Classes/VideoToolbox/encoder.mm | 14 ++++--- 4 files changed, 35 insertions(+), 58 deletions(-) diff --git a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm index 20e8f927e2..bad3dc8473 100644 --- a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm +++ b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm @@ -31,27 +31,27 @@ } - (const uint8_t *)dataY { - return _videoBuffer->GetI420()->DataY(); + return _videoBuffer->DataY(); } - (const uint8_t *)dataU { - return _videoBuffer->GetI420()->DataU(); + return _videoBuffer->DataU(); } - (const uint8_t *)dataV { - return _videoBuffer->GetI420()->DataV(); + return _videoBuffer->DataV(); } - (int)strideY { - return _videoBuffer->GetI420()->StrideY(); + return _videoBuffer->StrideY(); } - (int)strideU { - return _videoBuffer->GetI420()->StrideU(); + return _videoBuffer->StrideU(); } - (int)strideV { - return _videoBuffer->GetI420()->StrideV(); + return _videoBuffer->StrideV(); } - (int64_t)timeStampNs { @@ -59,14 +59,12 @@ } - (CVPixelBufferRef)nativeHandle { - return (_videoBuffer->type() == webrtc::VideoFrameBuffer::Type::kNative) ? - static_cast(_videoBuffer.get())->pixel_buffer() : - nil; + return static_cast(_videoBuffer->native_handle()); } - (RTCVideoFrame *)newI420VideoFrame { return [[RTCVideoFrame alloc] - initWithVideoBuffer:_videoBuffer->ToI420() + initWithVideoBuffer:_videoBuffer->NativeToI420Buffer() rotation:_rotation timeStampNs:_timeStampNs]; } diff --git a/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.cc b/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.cc index 660b2aab9e..9593d13b34 100644 --- a/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.cc +++ b/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.cc @@ -25,29 +25,24 @@ CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer, int crop_height, int crop_x, int crop_y) - : pixel_buffer_(pixel_buffer), - width_(adapted_width), - height_(adapted_height), + : NativeHandleBuffer(pixel_buffer, adapted_width, adapted_height), + pixel_buffer_(pixel_buffer), buffer_width_(CVPixelBufferGetWidth(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. - crop_x_(crop_x & ~1), - crop_y_(crop_y & ~1) { + crop_x_(crop_x & ~1), crop_y_(crop_y & ~1) { CVBufferRetain(pixel_buffer_); } CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer) - : pixel_buffer_(pixel_buffer), - width_(CVPixelBufferGetWidth(pixel_buffer)), - height_(CVPixelBufferGetHeight(pixel_buffer)), - buffer_width_(width_), - buffer_height_(height_), - crop_width_(width_), - crop_height_(height_), - crop_x_(0), - crop_y_(0) { + : NativeHandleBuffer(pixel_buffer, + CVPixelBufferGetWidth(pixel_buffer), + CVPixelBufferGetHeight(pixel_buffer)), + pixel_buffer_(pixel_buffer), + buffer_width_(width_), buffer_height_(height_), + crop_width_(width_), crop_height_(height_), + crop_x_(0), crop_y_(0) { CVBufferRetain(pixel_buffer_); } @@ -55,19 +50,8 @@ CoreVideoFrameBuffer::~CoreVideoFrameBuffer() { CVBufferRelease(pixel_buffer_); } -VideoFrameBuffer::Type CoreVideoFrameBuffer::type() const { - return Type::kNative; -} - -int CoreVideoFrameBuffer::width() const { - return width_; -} - -int CoreVideoFrameBuffer::height() const { - return height_; -} - -rtc::scoped_refptr CoreVideoFrameBuffer::ToI420() { +rtc::scoped_refptr +CoreVideoFrameBuffer::NativeToI420Buffer() { const OSType pixel_format = CVPixelBufferGetPixelFormatType(pixel_buffer_); RTC_DCHECK(pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange || pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange); diff --git a/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h b/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h index 603cbc01c4..fc8c171a0b 100644 --- a/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h +++ b/webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h @@ -19,7 +19,7 @@ namespace webrtc { -class CoreVideoFrameBuffer : public VideoFrameBuffer { +class CoreVideoFrameBuffer : public NativeHandleBuffer { public: explicit CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer); CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer, @@ -31,8 +31,7 @@ class CoreVideoFrameBuffer : public VideoFrameBuffer { int crop_y); ~CoreVideoFrameBuffer() override; - CVPixelBufferRef pixel_buffer() { return pixel_buffer_; } - + rtc::scoped_refptr NativeToI420Buffer() override; // Returns true if the internal pixel buffer needs to be cropped. bool RequiresCropping() const; // Crop and scales the internal pixel buffer to the output pixel buffer. The @@ -42,17 +41,11 @@ class CoreVideoFrameBuffer : public VideoFrameBuffer { CVPixelBufferRef output_pixel_buffer) const; private: - Type type() const override; - int width() const override; - int height() const override; - rtc::scoped_refptr ToI420() override; - CVPixelBufferRef pixel_buffer_; - // buffer_width/height is the actual pixel buffer resolution. The - // width_/height_ is the resolution we will scale to in ToI420(). Cropping - // happens before scaling, so: buffer_width >= crop_width >= width(). - const int width_; - const int height_; + // buffer_width/height is the actual pixel buffer resolution. The width/height + // in NativeHandleBuffer, i.e. width()/height(), is the resolution we will + // scale to in NativeToI420Buffer(). Cropping happens before scaling, so: + // buffer_width >= crop_width >= width(). const int buffer_width_; const int buffer_height_; const int crop_width_; diff --git a/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm b/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm index bc6672b9ac..8ff27f8d3a 100644 --- a/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm +++ b/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm @@ -155,8 +155,9 @@ struct FrameEncodeParams { // We receive I420Frames as input, but we need to feed CVPixelBuffers into the // encoder. This performs the copy and format conversion. // TODO(tkchin): See if encoder will accept i420 frames and compare performance. -bool CopyVideoFrameToPixelBuffer(const rtc::scoped_refptr& frame, - CVPixelBufferRef pixel_buffer) { +bool CopyVideoFrameToPixelBuffer( + const rtc::scoped_refptr& frame, + CVPixelBufferRef pixel_buffer) { RTC_DCHECK(pixel_buffer); RTC_DCHECK_EQ(CVPixelBufferGetPixelFormatType(pixel_buffer), kCVPixelFormatType_420YpCbCr8BiPlanarFullRange); @@ -411,12 +412,13 @@ int H264VideoToolboxEncoder::Encode( } #endif - CVPixelBufferRef pixel_buffer; - if (frame.video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative) { + CVPixelBufferRef pixel_buffer = static_cast( + frame.video_frame_buffer()->native_handle()); + if (pixel_buffer) { + // Native frame. rtc::scoped_refptr core_video_frame_buffer( static_cast(frame.video_frame_buffer().get())); 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 // compression session is configured to. The compression session can // handle that and will output encoded frames in the configured @@ -439,7 +441,7 @@ int H264VideoToolboxEncoder::Encode( return WEBRTC_VIDEO_CODEC_ERROR; } RTC_DCHECK(pixel_buffer); - if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer()->ToI420(), + if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer(), pixel_buffer)) { LOG(LS_ERROR) << "Failed to copy frame data."; CVBufferRelease(pixel_buffer);