2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-27 13:42:53 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-01-27 13:42:53 +00:00
|
|
|
#include "modules/utility/source/frame_scaler.h"
|
2011-12-09 02:46:22 +00:00
|
|
|
|
2012-01-27 13:42:53 +00:00
|
|
|
#ifdef WEBRTC_MODULE_UTILITY_VIDEO
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
#include "common_video/libyuv/include/scaler.h"
|
2012-01-27 13:42:53 +00:00
|
|
|
#include "system_wrappers/interface/trace.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2012-01-27 13:42:53 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
FrameScaler::FrameScaler()
|
2012-01-27 13:42:53 +00:00
|
|
|
: scaler_(new Scaler()),
|
|
|
|
|
scaled_frame_() {}
|
|
|
|
|
|
|
|
|
|
FrameScaler::~FrameScaler() {}
|
|
|
|
|
|
|
|
|
|
int FrameScaler::ResizeFrameIfNeeded(VideoFrame* video_frame,
|
|
|
|
|
WebRtc_UWord32 out_width,
|
|
|
|
|
WebRtc_UWord32 out_height) {
|
|
|
|
|
if (video_frame->Length() == 0) {
|
2011-12-09 02:46:22 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 13:42:53 +00:00
|
|
|
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) {
|
2011-12-09 02:46:22 +00:00
|
|
|
return ret;
|
2012-01-27 13:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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_);
|
2011-12-09 02:46:22 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-27 13:42:53 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-09 02:46:22 +00:00
|
|
|
#endif // WEBRTC_MODULE_UTILITY_VIDEO
|