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
This commit is contained in:
mflodman@webrtc.org 2012-01-27 13:42:53 +00:00
parent 048eb7cda6
commit 1f992807eb
4 changed files with 57 additions and 57 deletions

View File

@ -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 * 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 * 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) if( videoFrame.Length() > 0)
{ {
retVal = _frameScaler.ResizeFrameIfNeeded(videoFrame, outWidth, retVal = _frameScaler.ResizeFrameIfNeeded(&videoFrame, outWidth,
outHeight); outHeight);
} }
return retVal; return retVal;

View File

@ -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 * 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 * 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; return -1;
} }
if(_frameScaler->ResizeFrameIfNeeded(videoFrame, _videoCodecInst.width, if(_frameScaler->ResizeFrameIfNeeded(&videoFrame, _videoCodecInst.width,
_videoCodecInst.height) != 0) _videoCodecInst.height) != 0)
{ {
return -1; return -1;

View File

@ -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 * 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 * 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. * 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 #ifdef WEBRTC_MODULE_UTILITY_VIDEO
#include "frame_scaler.h"
#include "common_video/libyuv/include/scaler.h" #include "common_video/libyuv/include/scaler.h"
#include "trace.h" #include "system_wrappers/interface/trace.h"
namespace webrtc { namespace webrtc {
FrameScaler::FrameScaler() FrameScaler::FrameScaler()
: _scaler(new Scaler()), : scaler_(new Scaler()),
_scalerBuffer(), scaled_frame_() {}
_outWidth(0),
_outHeight(0),
_inWidth(0),
_inHeight(0) {}
FrameScaler::~FrameScaler( ) {} FrameScaler::~FrameScaler() {}
WebRtc_Word32 FrameScaler::ResizeFrameIfNeeded(VideoFrame& videoFrame, int FrameScaler::ResizeFrameIfNeeded(VideoFrame* video_frame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 out_width,
WebRtc_UWord32 outHeight) { WebRtc_UWord32 out_height) {
if ( videoFrame.Length( ) == 0) { if (video_frame->Length() == 0) {
return -1; return -1;
} }
if ((videoFrame.Width() != outWidth) || (videoFrame.Height() != outHeight)) { if ((video_frame->Width() != out_width) ||
_scaler->Set(videoFrame.Width(), videoFrame.Height(), (video_frame->Height() != out_height)) {
outWidth, outHeight, // Set correct scale settings and scale |video_frame| into |scaled_frame_|.
kI420, kI420, kScaleBox); scaler_->Set(video_frame->Width(), video_frame->Height(), out_width,
out_height, kI420, kI420, kScaleBox);
int reqSize = CalcBufferSize(kI420, _outWidth, _outHeight); int out_length = CalcBufferSize(kI420, out_width, out_height);
_scalerBuffer.VerifyAndAllocate(reqSize); scaled_frame_.VerifyAndAllocate(out_length);
int ret = _scaler->Scale(videoFrame.Buffer(), int ret = scaler_->Scale(video_frame->Buffer(), scaled_frame_.Buffer(),
_scalerBuffer.Buffer(), out_length);
reqSize); if (ret < 0) {
if (ret < 0)
return ret; return ret;
videoFrame.VerifyAndAllocate(reqSize); }
videoFrame.CopyFrame(videoFrame.Length(), _scalerBuffer.Buffer());
videoFrame.SetWidth(_outWidth); scaled_frame_.SetWidth(out_width);
videoFrame.SetHeight(_outHeight); 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; return 0;
} }
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULE_UTILITY_VIDEO #endif // WEBRTC_MODULE_UTILITY_VIDEO

View File

@ -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 * 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 * 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. // This file implements a class that can be used for scaling frames.
#ifndef WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ #ifndef WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_
#define WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ #define WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_
#ifdef WEBRTC_MODULE_UTILITY_VIDEO #ifdef WEBRTC_MODULE_UTILITY_VIDEO
#include "engine_configurations.h" #include "engine_configurations.h"
#include "module_common_types.h" #include "modules/interface/module_common_types.h"
#include "system_wrappers/interface/scoped_ptr.h" #include "system_wrappers/interface/scoped_ptr.h"
#include "typedefs.h"
namespace webrtc namespace webrtc {
{
class Scaler; class Scaler;
class VideoFrame; class VideoFrame;
class FrameScaler
{ class FrameScaler {
public: public:
FrameScaler(); FrameScaler();
~FrameScaler(); ~FrameScaler();
// Re-size videoFrame so that it has the width outWidth and height // Re-sizes |video_frame| so that it has the width |out_width| and height
// outHeight. // |out_height|.
WebRtc_Word32 ResizeFrameIfNeeded(VideoFrame& videoFrame, int ResizeFrameIfNeeded(VideoFrame* video_frame,
WebRtc_UWord32 outWidth, WebRtc_UWord32 out_width,
WebRtc_UWord32 outHeight); WebRtc_UWord32 out_height);
private:
scoped_ptr<Scaler> _scaler;
VideoFrame _scalerBuffer;
WebRtc_UWord32 _outWidth;
WebRtc_UWord32 _outHeight;
WebRtc_UWord32 _inWidth;
WebRtc_UWord32 _inHeight;
private:
scoped_ptr<Scaler> scaler_;
VideoFrame scaled_frame_;
}; };
#endif // WEBRTC_MODULE_UTILITY_VIDEO
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULE_UTILITY_VIDEO
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_ #endif // WEBRTC_MODULES_UTILITY_SOURCE_FRAME_SCALER_H_