OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_processing/spatial_resampler.h" | 11 #include "webrtc/modules/video_processing/spatial_resampler.h" |
12 | 12 |
13 | |
14 namespace webrtc { | 13 namespace webrtc { |
15 | 14 |
16 VPMSimpleSpatialResampler::VPMSimpleSpatialResampler() | 15 VPMSimpleSpatialResampler::VPMSimpleSpatialResampler() |
17 : resampling_mode_(kFastRescaling), | 16 : resampling_mode_(kFastRescaling), |
18 target_width_(0), | 17 target_width_(0), |
19 target_height_(0), | 18 target_height_(0), |
20 scaler_() {} | 19 scaler_() {} |
21 | 20 |
22 VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {} | 21 VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {} |
23 | 22 |
24 | |
25 int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width, | 23 int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width, |
26 int32_t height) { | 24 int32_t height) { |
27 if (resampling_mode_ == kNoRescaling) return VPM_OK; | 25 if (resampling_mode_ == kNoRescaling) |
| 26 return VPM_OK; |
28 | 27 |
29 if (width < 1 || height < 1) return VPM_PARAMETER_ERROR; | 28 if (width < 1 || height < 1) |
| 29 return VPM_PARAMETER_ERROR; |
30 | 30 |
31 target_width_ = width; | 31 target_width_ = width; |
32 target_height_ = height; | 32 target_height_ = height; |
33 | 33 |
34 return VPM_OK; | 34 return VPM_OK; |
35 } | 35 } |
36 | 36 |
37 void VPMSimpleSpatialResampler::SetInputFrameResampleMode( | 37 void VPMSimpleSpatialResampler::SetInputFrameResampleMode( |
38 VideoFrameResampling resampling_mode) { | 38 VideoFrameResampling resampling_mode) { |
39 resampling_mode_ = resampling_mode; | 39 resampling_mode_ = resampling_mode; |
40 } | 40 } |
41 | 41 |
42 void VPMSimpleSpatialResampler::Reset() { | 42 void VPMSimpleSpatialResampler::Reset() { |
43 resampling_mode_ = kFastRescaling; | 43 resampling_mode_ = kFastRescaling; |
44 target_width_ = 0; | 44 target_width_ = 0; |
45 target_height_ = 0; | 45 target_height_ = 0; |
46 } | 46 } |
47 | 47 |
48 int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame, | 48 int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame, |
49 VideoFrame* outFrame) { | 49 VideoFrame* outFrame) { |
50 // Don't copy if frame remains as is. | 50 // Don't copy if frame remains as is. |
51 if (resampling_mode_ == kNoRescaling) | 51 if (resampling_mode_ == kNoRescaling) |
52 return VPM_OK; | 52 return VPM_OK; |
53 // Check if re-sampling is needed | 53 // Check if re-sampling is needed |
54 else if ((inFrame.width() == target_width_) && | 54 else if ((inFrame.width() == target_width_) && |
55 (inFrame.height() == target_height_)) { | 55 (inFrame.height() == target_height_)) { |
56 return VPM_OK; | 56 return VPM_OK; |
57 } | 57 } |
58 | 58 |
59 // Setting scaler | 59 // Setting scaler |
60 // TODO(mikhal/marpan): Should we allow for setting the filter mode in | 60 // TODO(mikhal/marpan): Should we allow for setting the filter mode in |
61 // _scale.Set() with |resampling_mode_|? | 61 // _scale.Set() with |resampling_mode_|? |
62 int ret_val = 0; | 62 int ret_val = 0; |
63 ret_val = scaler_.Set(inFrame.width(), inFrame.height(), | 63 ret_val = scaler_.Set(inFrame.width(), inFrame.height(), target_width_, |
64 target_width_, target_height_, kI420, kI420, kScaleBox); | 64 target_height_, kI420, kI420, kScaleBox); |
65 if (ret_val < 0) | 65 if (ret_val < 0) |
66 return ret_val; | 66 return ret_val; |
67 | 67 |
68 ret_val = scaler_.Scale(inFrame, outFrame); | 68 ret_val = scaler_.Scale(inFrame, outFrame); |
69 | 69 |
70 // Setting time parameters to the output frame. | 70 // Setting time parameters to the output frame. |
71 // Timestamp will be reset in Scale call above, so we should set it after. | 71 // Timestamp will be reset in Scale call above, so we should set it after. |
72 outFrame->set_timestamp(inFrame.timestamp()); | 72 outFrame->set_timestamp(inFrame.timestamp()); |
73 outFrame->set_render_time_ms(inFrame.render_time_ms()); | 73 outFrame->set_render_time_ms(inFrame.render_time_ms()); |
74 | 74 |
75 if (ret_val == 0) | 75 if (ret_val == 0) |
76 return VPM_OK; | 76 return VPM_OK; |
77 else | 77 else |
78 return VPM_SCALE_ERROR; | 78 return VPM_SCALE_ERROR; |
79 } | 79 } |
80 | 80 |
81 int32_t VPMSimpleSpatialResampler::TargetHeight() { | 81 int32_t VPMSimpleSpatialResampler::TargetHeight() { |
82 return target_height_; | 82 return target_height_; |
83 } | 83 } |
84 | 84 |
85 int32_t VPMSimpleSpatialResampler::TargetWidth() { | 85 int32_t VPMSimpleSpatialResampler::TargetWidth() { |
86 return target_width_; | 86 return target_width_; |
87 } | 87 } |
88 | 88 |
89 bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, | 89 bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) { |
90 int32_t height) { | |
91 if ((width == target_width_ && height == target_height_) || | 90 if ((width == target_width_ && height == target_height_) || |
92 resampling_mode_ == kNoRescaling) | 91 resampling_mode_ == kNoRescaling) |
93 return false; | 92 return false; |
94 else | 93 else |
95 return true; | 94 return true; |
96 } | 95 } |
97 | 96 |
98 } // namespace webrtc | 97 } // namespace webrtc |
OLD | NEW |