blob: 50ccf8adc6739b07f3aef47110eb32b78c3950c4 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org1f992802012-01-27 13:42:53 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
pbos@webrtc.org8b062002013-07-12 08:28:10 +000011#include "webrtc/modules/utility/source/frame_scaler.h"
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000012
niklase@google.com470e71d2011-07-07 08:21:25 +000013#ifdef WEBRTC_MODULE_UTILITY_VIDEO
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000014
pbos@webrtc.org8b062002013-07-12 08:28:10 +000015#include "webrtc/common_video/libyuv/include/scaler.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000018
niklase@google.com470e71d2011-07-07 08:21:25 +000019FrameScaler::FrameScaler()
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000020 : scaler_(new Scaler()),
21 scaled_frame_() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000022
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000023FrameScaler::~FrameScaler() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000024
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000025int FrameScaler::ResizeFrameIfNeeded(I420VideoFrame* video_frame,
26 int out_width,
27 int out_height) {
28 if (video_frame->IsZeroSize()) {
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000029 return -1;
30 }
niklase@google.com470e71d2011-07-07 08:21:25 +000031
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000032 if ((video_frame->width() != out_width) ||
33 (video_frame->height() != out_height)) {
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000034 // Set correct scale settings and scale |video_frame| into |scaled_frame_|.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000035 scaler_->Set(video_frame->width(), video_frame->height(), out_width,
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000036 out_height, kI420, kI420, kScaleBox);
mikhal@webrtc.org2a476e92012-09-28 19:47:23 +000037 int ret = scaler_->Scale(*video_frame, &scaled_frame_);
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000038 if (ret < 0) {
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000039 return ret;
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000040 }
41
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000042 scaled_frame_.set_render_time_ms(video_frame->render_time_ms());
43 scaled_frame_.set_timestamp(video_frame->timestamp());
44 video_frame->SwapFrame(&scaled_frame_);
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000045 }
46 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000047}
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000048
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000049} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000050
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000051#endif // WEBRTC_MODULE_UTILITY_VIDEO