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:
parent
048eb7cda6
commit
1f992807eb
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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> _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> 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_
|
||||
|
Loading…
Reference in New Issue
Block a user