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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-18 22:31:24 +01:00
|
|
|
#include "webrtc/modules/video_processing/spatial_resampler.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
VPMSimpleSpatialResampler::VPMSimpleSpatialResampler()
|
2016-06-13 13:06:01 +02:00
|
|
|
: resampling_mode_(kFastRescaling), target_width_(0), target_height_(0) {}
|
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) {
|
2015-12-07 22:54:50 -08:00
|
|
|
if (resampling_mode_ == kNoRescaling)
|
|
|
|
|
return VPM_OK;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-07 22:54:50 -08: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.
|
2015-12-07 22:54:50 -08:00
|
|
|
if (resampling_mode_ == kNoRescaling) {
|
|
|
|
|
return VPM_OK;
|
2011-12-09 02:46:22 +00:00
|
|
|
// Check if re-sampling is needed
|
2015-12-07 22:54:50 -08: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
|
|
|
}
|
|
|
|
|
|
2016-06-13 13:06:01 +02:00
|
|
|
rtc::scoped_refptr<I420Buffer> scaled_buffer(
|
|
|
|
|
buffer_pool_.CreateBuffer(target_width_, target_height_));
|
2011-12-09 02:46:22 +00:00
|
|
|
|
2016-06-13 13:06:01 +02:00
|
|
|
scaled_buffer->CropAndScaleFrom(inFrame.video_frame_buffer());
|
2012-11-07 23:37:41 +00:00
|
|
|
|
2016-06-17 02:55:14 -07:00
|
|
|
outFrame->set_video_frame_buffer(scaled_buffer);
|
|
|
|
|
// Setting time parameters to the output frame.
|
|
|
|
|
outFrame->set_timestamp(inFrame.timestamp());
|
|
|
|
|
outFrame->set_render_time_ms(inFrame.render_time_ms());
|
2011-12-09 02:46:22 +00:00
|
|
|
|
2016-06-13 13:06:01 +02:00
|
|
|
return VPM_OK;
|
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
|
|
|
}
|
|
|
|
|
|
2015-12-07 22:54:50 -08:00
|
|
|
bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) {
|
2013-10-03 16:42:41 +00:00
|
|
|
if ((width == target_width_ && height == target_height_) ||
|
2015-12-07 22:54:50 -08:00
|
|
|
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
|