2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-07-03 13:21:22 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "spatial_resampler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
|
|
|
|
:
|
|
|
|
|
_resamplingMode(kFastRescaling),
|
|
|
|
|
_targetWidth(0),
|
|
|
|
|
_targetHeight(0),
|
2011-12-09 02:46:22 +00:00
|
|
|
_scaler()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler()
|
|
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
//
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
2011-12-09 02:46:22 +00:00
|
|
|
VPMSimpleSpatialResampler::SetTargetFrameSize(WebRtc_Word32 width,
|
|
|
|
|
WebRtc_Word32 height)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
if (_resamplingMode == kNoRescaling) {
|
|
|
|
|
return VPM_OK;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
if (width < 1 || height < 1) {
|
|
|
|
|
return VPM_PARAMETER_ERROR;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
_targetWidth = width;
|
|
|
|
|
_targetHeight = height;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
return VPM_OK;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
VPMSimpleSpatialResampler::SetInputFrameResampleMode(VideoFrameResampling
|
|
|
|
|
resamplingMode)
|
|
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
_resamplingMode = resamplingMode;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
VPMSimpleSpatialResampler::Reset()
|
|
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
_resamplingMode = kFastRescaling;
|
|
|
|
|
_targetWidth = 0;
|
|
|
|
|
_targetHeight = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
2012-10-24 18:33:04 +00:00
|
|
|
VPMSimpleSpatialResampler::ResampleFrame(const I420VideoFrame& inFrame,
|
|
|
|
|
I420VideoFrame* outFrame)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
if (_resamplingMode == kNoRescaling)
|
2012-10-24 18:33:04 +00:00
|
|
|
return outFrame->CopyFrame(inFrame);
|
2011-12-09 02:46:22 +00:00
|
|
|
// Check if re-sampling is needed
|
2012-10-24 18:33:04 +00:00
|
|
|
if ((inFrame.width() == _targetWidth) &&
|
|
|
|
|
(inFrame.height() == _targetHeight)) {
|
|
|
|
|
return outFrame->CopyFrame(inFrame);
|
2011-12-09 02:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Setting scaler
|
2012-06-26 16:47:36 +00:00
|
|
|
// TODO(mikhal/marpan): Should we allow for setting the filter mode in
|
|
|
|
|
// _scale.Set() with |_resamplingMode|?
|
2011-12-09 02:46:22 +00:00
|
|
|
int retVal = 0;
|
2012-10-24 18:33:04 +00:00
|
|
|
retVal = _scaler.Set(inFrame.width(), inFrame.height(),
|
2011-12-09 02:46:22 +00:00
|
|
|
_targetWidth, _targetHeight, kI420, kI420, kScaleBox);
|
|
|
|
|
if (retVal < 0)
|
|
|
|
|
return retVal;
|
|
|
|
|
|
2012-11-07 23:37:41 +00:00
|
|
|
retVal = _scaler.Scale(inFrame, outFrame);
|
|
|
|
|
|
|
|
|
|
// Setting time parameters to the output frame.
|
|
|
|
|
// Timestamp will be reset in Scale call above, so we should set it after.
|
2012-10-24 18:33:04 +00:00
|
|
|
outFrame->set_timestamp(inFrame.timestamp());
|
|
|
|
|
outFrame->set_render_time_ms(inFrame.render_time_ms());
|
2011-12-09 02:46:22 +00:00
|
|
|
|
|
|
|
|
if (retVal == 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
return VPM_OK;
|
2011-12-09 02:46:22 +00:00
|
|
|
else
|
|
|
|
|
return VPM_SCALE_ERROR;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32
|
|
|
|
|
VPMSimpleSpatialResampler::TargetHeight()
|
|
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
return _targetHeight;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
WebRtc_Word32
|
2011-07-07 08:21:25 +00:00
|
|
|
VPMSimpleSpatialResampler::TargetWidth()
|
|
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
return _targetWidth;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-01 16:44:24 +00:00
|
|
|
bool
|
2011-12-09 02:46:22 +00:00
|
|
|
VPMSimpleSpatialResampler::ApplyResample(WebRtc_Word32 width,
|
|
|
|
|
WebRtc_Word32 height)
|
2011-11-01 16:44:24 +00:00
|
|
|
{
|
2011-12-09 02:46:22 +00:00
|
|
|
if ((width == _targetWidth && height == _targetHeight) ||
|
|
|
|
|
_resamplingMode == kNoRescaling)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2011-11-01 16:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} //namespace
|