| OLD | NEW |
| (Empty) |
| 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/video_processing/spatial_resampler.h" | |
| 12 | |
| 13 namespace webrtc { | |
| 14 | |
| 15 VPMSimpleSpatialResampler::VPMSimpleSpatialResampler() | |
| 16 : resampling_mode_(kFastRescaling), target_width_(0), target_height_(0) {} | |
| 17 | |
| 18 VPMSimpleSpatialResampler::~VPMSimpleSpatialResampler() {} | |
| 19 | |
| 20 int32_t VPMSimpleSpatialResampler::SetTargetFrameSize(int32_t width, | |
| 21 int32_t height) { | |
| 22 if (resampling_mode_ == kNoRescaling) | |
| 23 return VPM_OK; | |
| 24 | |
| 25 if (width < 1 || height < 1) | |
| 26 return VPM_PARAMETER_ERROR; | |
| 27 | |
| 28 target_width_ = width; | |
| 29 target_height_ = height; | |
| 30 | |
| 31 return VPM_OK; | |
| 32 } | |
| 33 | |
| 34 void VPMSimpleSpatialResampler::SetInputFrameResampleMode( | |
| 35 VideoFrameResampling resampling_mode) { | |
| 36 resampling_mode_ = resampling_mode; | |
| 37 } | |
| 38 | |
| 39 void VPMSimpleSpatialResampler::Reset() { | |
| 40 resampling_mode_ = kFastRescaling; | |
| 41 target_width_ = 0; | |
| 42 target_height_ = 0; | |
| 43 } | |
| 44 | |
| 45 int32_t VPMSimpleSpatialResampler::ResampleFrame(const VideoFrame& inFrame, | |
| 46 VideoFrame* outFrame) { | |
| 47 // Don't copy if frame remains as is. | |
| 48 if (resampling_mode_ == kNoRescaling) { | |
| 49 return VPM_OK; | |
| 50 // Check if re-sampling is needed | |
| 51 } else if ((inFrame.width() == target_width_) && | |
| 52 (inFrame.height() == target_height_)) { | |
| 53 return VPM_OK; | |
| 54 } | |
| 55 | |
| 56 rtc::scoped_refptr<I420Buffer> scaled_buffer( | |
| 57 buffer_pool_.CreateBuffer(target_width_, target_height_)); | |
| 58 | |
| 59 scaled_buffer->CropAndScaleFrom(*inFrame.video_frame_buffer()); | |
| 60 | |
| 61 *outFrame = VideoFrame(scaled_buffer, | |
| 62 inFrame.timestamp(), | |
| 63 inFrame.render_time_ms(), | |
| 64 inFrame.rotation()); | |
| 65 | |
| 66 return VPM_OK; | |
| 67 } | |
| 68 | |
| 69 int32_t VPMSimpleSpatialResampler::TargetHeight() { | |
| 70 return target_height_; | |
| 71 } | |
| 72 | |
| 73 int32_t VPMSimpleSpatialResampler::TargetWidth() { | |
| 74 return target_width_; | |
| 75 } | |
| 76 | |
| 77 bool VPMSimpleSpatialResampler::ApplyResample(int32_t width, int32_t height) { | |
| 78 if ((width == target_width_ && height == target_height_) || | |
| 79 resampling_mode_ == kNoRescaling) | |
| 80 return false; | |
| 81 else | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 } // namespace webrtc | |
| OLD | NEW |