Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / utility / source / frame_scaler.cc
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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
11 #include "webrtc/modules/utility/source/frame_scaler.h"
12
13 #ifdef WEBRTC_MODULE_UTILITY_VIDEO
14
15 #include "webrtc/common_video/libyuv/include/scaler.h"
16
17 namespace webrtc {
18
19 FrameScaler::FrameScaler()
20     : scaler_(new Scaler()),
21       scaled_frame_() {}
22
23 FrameScaler::~FrameScaler() {}
24
25 int FrameScaler::ResizeFrameIfNeeded(I420VideoFrame* video_frame,
26                                      int out_width,
27                                      int out_height) {
28   if (video_frame->IsZeroSize()) {
29     return -1;
30   }
31
32   if ((video_frame->width() != out_width) ||
33       (video_frame->height() != out_height)) {
34     // Set correct scale settings and scale |video_frame| into |scaled_frame_|.
35     scaler_->Set(video_frame->width(), video_frame->height(), out_width,
36                  out_height, kI420, kI420, kScaleBox);
37     int ret = scaler_->Scale(*video_frame, &scaled_frame_);
38     if (ret < 0) {
39       return ret;
40     }
41
42     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_);
45   }
46   return 0;
47 }
48
49 }  // namespace webrtc
50
51 #endif  // WEBRTC_MODULE_UTILITY_VIDEO