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 namespace webrtc { | 13 namespace webrtc { |
14 | 14 |
15 VPMSimpleSpatialResampler::VPMSimpleSpatialResampler() | 15 VPMSimpleSpatialResampler::VPMSimpleSpatialResampler() |
16 : resampling_mode_(kFastRescaling), | 16 : resampling_mode_(kFastRescaling), target_width_(0), target_height_(0) {} |
17 target_width_(0), | |
18 target_height_(0), | |
19 scaler_() {} | |
20 | 17 |
21 VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {} | 18 VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {} |
22 | 19 |
23 int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width, | 20 int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width, |
24 int32_t height) { | 21 int32_t height) { |
25 if (resampling_mode_ == kNoRescaling) | 22 if (resampling_mode_ == kNoRescaling) |
26 return VPM_OK; | 23 return VPM_OK; |
27 | 24 |
28 if (width < 1 || height < 1) | 25 if (width < 1 || height < 1) |
29 return VPM_PARAMETER_ERROR; | 26 return VPM_PARAMETER_ERROR; |
(...skipping 19 matching lines...) Expand all Loading... |
49 VideoFrame* outFrame) { | 46 VideoFrame* outFrame) { |
50 // Don't copy if frame remains as is. | 47 // Don't copy if frame remains as is. |
51 if (resampling_mode_ == kNoRescaling) { | 48 if (resampling_mode_ == kNoRescaling) { |
52 return VPM_OK; | 49 return VPM_OK; |
53 // Check if re-sampling is needed | 50 // Check if re-sampling is needed |
54 } else if ((inFrame.width() == target_width_) && | 51 } else if ((inFrame.width() == target_width_) && |
55 (inFrame.height() == target_height_)) { | 52 (inFrame.height() == target_height_)) { |
56 return VPM_OK; | 53 return VPM_OK; |
57 } | 54 } |
58 | 55 |
59 // Setting scaler | 56 rtc::scoped_refptr<I420Buffer> scaled_buffer( |
60 // TODO(mikhal/marpan): Should we allow for setting the filter mode in | 57 buffer_pool_.CreateBuffer(target_width_, target_height_)); |
61 // _scale.Set() with |resampling_mode_|? | |
62 int ret_val = 0; | |
63 ret_val = scaler_.Set(inFrame.width(), inFrame.height(), target_width_, | |
64 target_height_, kI420, kI420, kScaleBox); | |
65 if (ret_val < 0) | |
66 return ret_val; | |
67 | 58 |
68 ret_val = scaler_.Scale(inFrame, outFrame); | 59 scaled_buffer->CropAndScaleFrom(inFrame.video_frame_buffer()); |
69 | 60 |
| 61 outFrame->set_video_frame_buffer(scaled_buffer); |
70 // Setting time parameters to the output frame. | 62 // Setting time parameters to the output frame. |
71 // Timestamp will be reset in Scale call above, so we should set it after. | |
72 outFrame->set_timestamp(inFrame.timestamp()); | 63 outFrame->set_timestamp(inFrame.timestamp()); |
73 outFrame->set_render_time_ms(inFrame.render_time_ms()); | 64 outFrame->set_render_time_ms(inFrame.render_time_ms()); |
74 | 65 |
75 if (ret_val == 0) | 66 return VPM_OK; |
76 return VPM_OK; | |
77 else | |
78 return VPM_SCALE_ERROR; | |
79 } | 67 } |
80 | 68 |
81 int32_t VPMSimpleSpatialResampler::TargetHeight() { | 69 int32_t VPMSimpleSpatialResampler::TargetHeight() { |
82 return target_height_; | 70 return target_height_; |
83 } | 71 } |
84 | 72 |
85 int32_t VPMSimpleSpatialResampler::TargetWidth() { | 73 int32_t VPMSimpleSpatialResampler::TargetWidth() { |
86 return target_width_; | 74 return target_width_; |
87 } | 75 } |
88 | 76 |
89 bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) { | 77 bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) { |
90 if ((width == target_width_ && height == target_height_) || | 78 if ((width == target_width_ && height == target_height_) || |
91 resampling_mode_ == kNoRescaling) | 79 resampling_mode_ == kNoRescaling) |
92 return false; | 80 return false; |
93 else | 81 else |
94 return true; | 82 return true; |
95 } | 83 } |
96 | 84 |
97 } // namespace webrtc | 85 } // namespace webrtc |
OLD | NEW |