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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-27 14:12:16 +00:00
|
|
|
#include "webrtc/modules/video_processing/main/source/spatial_resampler.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
2013-10-03 16:42:41 +00:00
|
|
|
: resampling_mode_(kFastRescaling),
|
|
|
|
|
target_width_(0),
|
|
|
|
|
target_height_(0),
|
|
|
|
|
scaler_() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width,
|
|
|
|
|
int32_t height) {
|
|
|
|
|
if (resampling_mode_ == kNoRescaling) return VPM_OK;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
if (width < 1 || height < 1) return VPM_PARAMETER_ERROR;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
target_width_ = width;
|
|
|
|
|
target_height_ = 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
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
void VPMSimpleSpatialResampler::SetInputFrameResampleMode(
|
|
|
|
|
VideoFrameResampling resampling_mode) {
|
|
|
|
|
resampling_mode_ = resampling_mode;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
void VPMSimpleSpatialResampler::Reset() {
|
|
|
|
|
resampling_mode_ = kFastRescaling;
|
|
|
|
|
target_width_ = 0;
|
|
|
|
|
target_height_ = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame,
|
|
|
|
|
VideoFrame* outFrame) {
|
2012-12-13 18:25:36 +00:00
|
|
|
// Don't copy if frame remains as is.
|
2013-10-03 16:42:41 +00:00
|
|
|
if (resampling_mode_ == kNoRescaling)
|
2012-12-13 18:25:36 +00:00
|
|
|
return VPM_OK;
|
2011-12-09 02:46:22 +00:00
|
|
|
// Check if re-sampling is needed
|
2013-10-03 16:42:41 +00:00
|
|
|
else if ((inFrame.width() == target_width_) &&
|
|
|
|
|
(inFrame.height() == target_height_)) {
|
2012-12-13 18:25:36 +00:00
|
|
|
return VPM_OK;
|
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
|
2013-10-03 16:42:41 +00:00
|
|
|
// _scale.Set() with |resampling_mode_|?
|
|
|
|
|
int ret_val = 0;
|
|
|
|
|
ret_val = scaler_.Set(inFrame.width(), inFrame.height(),
|
|
|
|
|
target_width_, target_height_, kI420, kI420, kScaleBox);
|
|
|
|
|
if (ret_val < 0)
|
|
|
|
|
return ret_val;
|
2011-12-09 02:46:22 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
ret_val = scaler_.Scale(inFrame, outFrame);
|
2012-11-07 23:37:41 +00:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
if (ret_val == 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
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int32_t VPMSimpleSpatialResampler::TargetHeight() {
|
|
|
|
|
return target_height_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int32_t VPMSimpleSpatialResampler::TargetWidth() {
|
|
|
|
|
return target_width_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
bool VPMSimpleSpatialResampler::ApplyResample(int32_t width,
|
|
|
|
|
int32_t height) {
|
|
|
|
|
if ((width == target_width_ && height == target_height_) ||
|
|
|
|
|
resampling_mode_ == kNoRescaling)
|
2011-12-09 02:46:22 +00:00
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2011-11-01 16:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
} // namespace webrtc
|