blob: 06689471dae46dfd0513c2bcc8a11d4c84352596 [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
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000011#include "modules/utility/source/frame_scaler.h"
12
niklase@google.com470e71d2011-07-07 08:21:25 +000013#ifdef WEBRTC_MODULE_UTILITY_VIDEO
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000014
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000015#include "common_video/libyuv/include/scaler.h"
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000016#include "system_wrappers/interface/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000019
niklase@google.com470e71d2011-07-07 08:21:25 +000020FrameScaler::FrameScaler()
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000021 : scaler_(new Scaler()),
22 scaled_frame_() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000024FrameScaler::~FrameScaler() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000026int FrameScaler::ResizeFrameIfNeeded(I420VideoFrame* video_frame,
27 int out_width,
28 int out_height) {
29 if (video_frame->IsZeroSize()) {
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000030 return -1;
31 }
niklase@google.com470e71d2011-07-07 08:21:25 +000032
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000033 if ((video_frame->width() != out_width) ||
34 (video_frame->height() != out_height)) {
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000035 // Set correct scale settings and scale |video_frame| into |scaled_frame_|.
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000036 scaler_->Set(video_frame->width(), video_frame->height(), out_width,
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000037 out_height, kI420, kI420, kScaleBox);
mikhal@webrtc.org2a476e92012-09-28 19:47:23 +000038 int ret = scaler_->Scale(*video_frame, &scaled_frame_);
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000039 if (ret < 0) {
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000040 return ret;
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000041 }
42
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000043 scaled_frame_.set_render_time_ms(video_frame->render_time_ms());
44 scaled_frame_.set_timestamp(video_frame->timestamp());
45 video_frame->SwapFrame(&scaled_frame_);
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000046 }
47 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000048}
mflodman@webrtc.org1f992802012-01-27 13:42:53 +000049
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000050} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000051
mikhal@webrtc.org2ab104e2011-12-09 02:46:22 +000052#endif // WEBRTC_MODULE_UTILITY_VIDEO