| 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 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 40 | 40 | 
| 41   src_width_ = src_width; | 41   src_width_ = src_width; | 
| 42   src_height_ = src_height; | 42   src_height_ = src_height; | 
| 43   dst_width_ = dst_width; | 43   dst_width_ = dst_width; | 
| 44   dst_height_ = dst_height; | 44   dst_height_ = dst_height; | 
| 45   method_ = method; | 45   method_ = method; | 
| 46   set_ = true; | 46   set_ = true; | 
| 47   return 0; | 47   return 0; | 
| 48 } | 48 } | 
| 49 | 49 | 
|  | 50 // TODO(nisse): Should work with VideoFrameBuffer instead. | 
| 50 int Scaler::Scale(const VideoFrame& src_frame, VideoFrame* dst_frame) { | 51 int Scaler::Scale(const VideoFrame& src_frame, VideoFrame* dst_frame) { | 
| 51   assert(dst_frame); | 52   assert(dst_frame); | 
| 52   if (src_frame.IsZeroSize()) | 53   if (src_frame.IsZeroSize()) | 
| 53     return -1; | 54     return -1; | 
| 54   if (!set_) | 55   if (!set_) | 
| 55     return -2; | 56     return -2; | 
| 56 | 57 | 
| 57   // Making sure that destination frame is of sufficient size. | 58   // Making sure that destination frame is of sufficient size. | 
| 58   dst_frame->set_video_frame_buffer( | 59   dst_frame->set_video_frame_buffer( | 
| 59       buffer_pool_.CreateBuffer(dst_width_, dst_height_)); | 60       buffer_pool_.CreateBuffer(dst_width_, dst_height_)); | 
| 60 | 61 | 
| 61   // We want to preserve aspect ratio instead of stretching the frame. | 62   // We want to preserve aspect ratio instead of stretching the frame. | 
| 62   // Therefore, we need to crop the source frame. Calculate the largest center | 63   // Therefore, we need to crop the source frame. Calculate the largest center | 
| 63   // aligned region of the source frame that can be used. | 64   // aligned region of the source frame that can be used. | 
| 64   const int cropped_src_width = | 65   const int cropped_src_width = | 
| 65       std::min(src_width_, dst_width_ * src_height_ / dst_height_); | 66       std::min(src_width_, dst_width_ * src_height_ / dst_height_); | 
| 66   const int cropped_src_height = | 67   const int cropped_src_height = | 
| 67       std::min(src_height_, dst_height_ * src_width_ / dst_width_); | 68       std::min(src_height_, dst_height_ * src_width_ / dst_width_); | 
| 68   // Make sure the offsets are even to avoid rounding errors for the U/V planes. | 69   // Make sure the offsets are even to avoid rounding errors for the U/V planes. | 
| 69   const int src_offset_x = ((src_width_ - cropped_src_width) / 2) & ~1; | 70   const int src_offset_x = ((src_width_ - cropped_src_width) / 2) & ~1; | 
| 70   const int src_offset_y = ((src_height_ - cropped_src_height) / 2) & ~1; | 71   const int src_offset_y = ((src_height_ - cropped_src_height) / 2) & ~1; | 
| 71 | 72 | 
| 72   const uint8_t* y_ptr = src_frame.buffer(kYPlane) + | 73   const uint8_t* y_ptr = | 
| 73                          src_offset_y * src_frame.stride(kYPlane) + | 74       src_frame.video_frame_buffer()->DataY() + | 
| 74                          src_offset_x; | 75       src_offset_y * src_frame.video_frame_buffer()->StrideY() + | 
| 75   const uint8_t* u_ptr = src_frame.buffer(kUPlane) + | 76       src_offset_x; | 
| 76                          src_offset_y / 2 * src_frame.stride(kUPlane) + | 77   const uint8_t* u_ptr = | 
| 77                          src_offset_x / 2; | 78       src_frame.video_frame_buffer()->DataU() + | 
| 78   const uint8_t* v_ptr = src_frame.buffer(kVPlane) + | 79       src_offset_y / 2 * src_frame.video_frame_buffer()->StrideU() + | 
| 79                          src_offset_y / 2 * src_frame.stride(kVPlane) + | 80       src_offset_x / 2; | 
| 80                          src_offset_x / 2; | 81   const uint8_t* v_ptr = | 
|  | 82       src_frame.video_frame_buffer()->DataV() + | 
|  | 83       src_offset_y / 2 * src_frame.video_frame_buffer()->StrideV() + | 
|  | 84       src_offset_x / 2; | 
| 81 | 85 | 
| 82   return libyuv::I420Scale(y_ptr, | 86   return libyuv::I420Scale( | 
| 83                            src_frame.stride(kYPlane), | 87       y_ptr, | 
| 84                            u_ptr, | 88       src_frame.video_frame_buffer()->StrideY(), | 
| 85                            src_frame.stride(kUPlane), | 89       u_ptr, | 
| 86                            v_ptr, | 90       src_frame.video_frame_buffer()->StrideU(), | 
| 87                            src_frame.stride(kVPlane), | 91       v_ptr, | 
| 88                            cropped_src_width, cropped_src_height, | 92       src_frame.video_frame_buffer()->StrideV(), | 
| 89                            dst_frame->buffer(kYPlane), | 93       cropped_src_width, cropped_src_height, | 
| 90                            dst_frame->stride(kYPlane), | 94       dst_frame->video_frame_buffer()->MutableDataY(), | 
| 91                            dst_frame->buffer(kUPlane), | 95       dst_frame->video_frame_buffer()->StrideY(), | 
| 92                            dst_frame->stride(kUPlane), | 96       dst_frame->video_frame_buffer()->MutableDataU(), | 
| 93                            dst_frame->buffer(kVPlane), | 97       dst_frame->video_frame_buffer()->StrideU(), | 
| 94                            dst_frame->stride(kVPlane), | 98       dst_frame->video_frame_buffer()->MutableDataV(), | 
| 95                            dst_width_, dst_height_, | 99       dst_frame->video_frame_buffer()->StrideV(), | 
| 96                            libyuv::FilterMode(method_)); | 100       dst_width_, dst_height_, | 
|  | 101       libyuv::FilterMode(method_)); | 
| 97 } | 102 } | 
| 98 | 103 | 
| 99 bool Scaler::SupportedVideoType(VideoType src_video_type, | 104 bool Scaler::SupportedVideoType(VideoType src_video_type, | 
| 100                                 VideoType dst_video_type) { | 105                                 VideoType dst_video_type) { | 
| 101   if (src_video_type != dst_video_type) | 106   if (src_video_type != dst_video_type) | 
| 102     return false; | 107     return false; | 
| 103 | 108 | 
| 104   if ((src_video_type == kI420) || (src_video_type == kIYUV) || | 109   if ((src_video_type == kI420) || (src_video_type == kIYUV) || | 
| 105       (src_video_type == kYV12)) | 110       (src_video_type == kYV12)) | 
| 106     return true; | 111     return true; | 
| 107 | 112 | 
| 108   return false; | 113   return false; | 
| 109 } | 114 } | 
| 110 | 115 | 
| 111 }  // namespace webrtc | 116 }  // namespace webrtc | 
| OLD | NEW | 
|---|