From 1f992807eb2969bd9368cae3bead2de019679a14 Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Fri, 27 Jan 2012 13:42:53 +0000 Subject: [PATCH] Fixed frame scaler bugs. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/367018 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1562 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../utility/source/file_player_impl.cc | 4 +- .../utility/source/file_recorder_impl.cc | 4 +- src/modules/utility/source/frame_scaler.cc | 61 ++++++++++--------- src/modules/utility/source/frame_scaler.h | 45 +++++++------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/modules/utility/source/file_player_impl.cc b/src/modules/utility/source/file_player_impl.cc index fb673cb95..c080e6c7b 100644 --- a/src/modules/utility/source/file_player_impl.cc +++ b/src/modules/utility/source/file_player_impl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 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 @@ -540,7 +540,7 @@ WebRtc_Word32 VideoFilePlayerImpl::GetVideoFromFile(VideoFrame& videoFrame, } if( videoFrame.Length() > 0) { - retVal = _frameScaler.ResizeFrameIfNeeded(videoFrame, outWidth, + retVal = _frameScaler.ResizeFrameIfNeeded(&videoFrame, outWidth, outHeight); } return retVal; diff --git a/src/modules/utility/source/file_recorder_impl.cc b/src/modules/utility/source/file_recorder_impl.cc index 192244297..a31d47d5c 100644 --- a/src/modules/utility/source/file_recorder_impl.cc +++ b/src/modules/utility/source/file_recorder_impl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 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 @@ -672,7 +672,7 @@ WebRtc_Word32 AviRecorder::EncodeAndWriteVideoToFile(VideoFrame& videoFrame) return -1; } - if(_frameScaler->ResizeFrameIfNeeded(videoFrame, _videoCodecInst.width, + if(_frameScaler->ResizeFrameIfNeeded(&videoFrame, _videoCodecInst.width, _videoCodecInst.height) != 0) { return -1; diff --git a/src/modules/utility/source/frame_scaler.cc b/src/modules/utility/source/frame_scaler.cc index 96a12fbca..c012e892e 100644 --- a/src/modules/utility/source/frame_scaler.cc +++ b/src/modules/utility/source/frame_scaler.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 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 @@ -8,50 +8,51 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "modules/utility/source/frame_scaler.h" + #ifdef WEBRTC_MODULE_UTILITY_VIDEO -#include "frame_scaler.h" - #include "common_video/libyuv/include/scaler.h" -#include "trace.h" +#include "system_wrappers/interface/trace.h" namespace webrtc { + FrameScaler::FrameScaler() - : _scaler(new Scaler()), - _scalerBuffer(), - _outWidth(0), - _outHeight(0), - _inWidth(0), - _inHeight(0) {} + : scaler_(new Scaler()), + scaled_frame_() {} -FrameScaler::~FrameScaler( ) {} +FrameScaler::~FrameScaler() {} -WebRtc_Word32 FrameScaler::ResizeFrameIfNeeded(VideoFrame& videoFrame, - WebRtc_UWord32 outWidth, - WebRtc_UWord32 outHeight) { - if ( videoFrame.Length( ) == 0) { +int FrameScaler::ResizeFrameIfNeeded(VideoFrame* video_frame, + WebRtc_UWord32 out_width, + WebRtc_UWord32 out_height) { + if (video_frame->Length() == 0) { return -1; } - if ((videoFrame.Width() != outWidth) || (videoFrame.Height() != outHeight)) { - _scaler->Set(videoFrame.Width(), videoFrame.Height(), - outWidth, outHeight, - kI420, kI420, kScaleBox); - - int reqSize = CalcBufferSize(kI420, _outWidth, _outHeight); - _scalerBuffer.VerifyAndAllocate(reqSize); - int ret = _scaler->Scale(videoFrame.Buffer(), - _scalerBuffer.Buffer(), - reqSize); - if (ret < 0) + if ((video_frame->Width() != out_width) || + (video_frame->Height() != out_height)) { + // Set correct scale settings and scale |video_frame| into |scaled_frame_|. + scaler_->Set(video_frame->Width(), video_frame->Height(), out_width, + out_height, kI420, kI420, kScaleBox); + int out_length = CalcBufferSize(kI420, out_width, out_height); + scaled_frame_.VerifyAndAllocate(out_length); + int ret = scaler_->Scale(video_frame->Buffer(), scaled_frame_.Buffer(), + out_length); + if (ret < 0) { return ret; - videoFrame.VerifyAndAllocate(reqSize); - videoFrame.CopyFrame(videoFrame.Length(), _scalerBuffer.Buffer()); - videoFrame.SetWidth(_outWidth); - videoFrame.SetHeight(_outHeight); + } + + scaled_frame_.SetWidth(out_width); + scaled_frame_.SetHeight(out_height); + scaled_frame_.SetLength(out_length); + scaled_frame_.SetRenderTime(video_frame->RenderTimeMs()); + scaled_frame_.SetTimeStamp(video_frame->TimeStamp()); + video_frame->SwapFrame(scaled_frame_); } return 0; } + } // namespace webrtc #endif // WEBRTC_MODULE_UTILITY_VIDEO diff --git a/src/modules/utility/source/frame_scaler.h b/src/modules/utility/source/frame_scaler.h index 4dc3d2aec..f86a93382 100644 --- a/src/modules/utility/source/frame_scaler.h +++ b/src/modules/utility/source/frame_scaler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 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 @@ -9,40 +9,39 @@ */ // This file implements a class that can be used for scaling frames. + #ifndef WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ #define WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ #ifdef WEBRTC_MODULE_UTILITY_VIDEO #include "engine_configurations.h" -#include "module_common_types.h" +#include "modules/interface/module_common_types.h" #include "system_wrappers/interface/scoped_ptr.h" -#include "typedefs.h" -namespace webrtc -{ +namespace webrtc { + class Scaler; class VideoFrame; -class FrameScaler -{ -public: + +class FrameScaler { + public: FrameScaler(); ~FrameScaler(); - // Re-size videoFrame so that it has the width outWidth and height - // outHeight. - WebRtc_Word32 ResizeFrameIfNeeded(VideoFrame& videoFrame, - WebRtc_UWord32 outWidth, - WebRtc_UWord32 outHeight); -private: - scoped_ptr _scaler; - VideoFrame _scalerBuffer; - WebRtc_UWord32 _outWidth; - WebRtc_UWord32 _outHeight; - WebRtc_UWord32 _inWidth; - WebRtc_UWord32 _inHeight; + // Re-sizes |video_frame| so that it has the width |out_width| and height + // |out_height|. + int ResizeFrameIfNeeded(VideoFrame* video_frame, + WebRtc_UWord32 out_width, + WebRtc_UWord32 out_height); + private: + scoped_ptr scaler_; + VideoFrame scaled_frame_; }; -#endif // WEBRTC_MODULE_UTILITY_VIDEO -} // namespace webrtc -#endif // WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ + +} // namespace webrtc + +#endif // WEBRTC_MODULE_UTILITY_VIDEO + +#endif // WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_