Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/media/base/videoframefactory.h" | 11 #include "webrtc/media/base/videoframefactory.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include "webrtc/media/base/videocapturer.h" | 14 #include "webrtc/media/base/videocapturer.h" |
| 15 | 15 |
| 16 namespace cricket { | 16 namespace cricket { |
| 17 | 17 |
| 18 // For backwards compatiblity, default implementation in terms of old methods. | |
| 19 // TODO(nisse): Delete when Chrome's subclass is updated. | |
|
perkj_webrtc
2016/05/11 10:05:17
Is this really the method you should delete?
nisse-webrtc
2016/05/12 12:23:06
It's not. Good catch.
| |
| 20 std::unique_ptr<VideoFrame> VideoFrameFactory::CreateScaledFrame( | |
| 21 const CapturedFrame* input_frame, | |
| 22 int dst_width, | |
| 23 int dst_height) const { | |
| 24 // Size of the used portion of the input frame. | |
| 25 int crop_width = input_frame->width; | |
| 26 int crop_height = input_frame->height; | |
| 27 | |
| 28 // Cropp the input frame, if needed to preserve aspect ratio. | |
| 29 long aspect_diff = static_cast<long>(crop_width) * dst_height - | |
| 30 static_cast<long>(crop_height) * dst_width; | |
| 31 if (aspect_diff > 0) { | |
| 32 // Horizontal crop. | |
| 33 | |
| 34 // TODO(nisse): Old code carried a comment saying that MJPG can | |
| 35 // only be cropped vertically, and disabled horizontal cropping in | |
| 36 // that case. Still needed? | |
| 37 crop_width -= aspect_diff / dst_height; | |
| 38 RTC_DCHECK(crop_width > 0); | |
| 39 } else if (aspect_diff < 0) { | |
| 40 // Vertical crop. | |
| 41 crop_height -= (-aspect_diff) / dst_width; | |
| 42 RTC_DCHECK(crop_height > 0); | |
| 43 } | |
| 44 return CreateScaledCroppedFrame( | |
| 45 input_frame, | |
| 46 (input_frame->width - crop_width) / 2, | |
| 47 (input_frame->height - crop_height) / 2, | |
| 48 crop_width, crop_height, | |
| 49 dst_width, dst_height); | |
| 50 } | |
| 51 | |
| 52 // For backwards compatibility, default implementation in terms of old | |
| 53 // methods. Ignores the position of the cropping window, and leaves it | |
| 54 // up to CreateAliasedFrame. | |
| 55 // TODO(nisse): Delete when Chrome's subclass is updated. | |
| 56 std::unique_ptr<VideoFrame> VideoFrameFactory::CreateScaledCroppedFrame( | |
| 57 const CapturedFrame* input_frame, | |
| 58 int crop_x, | |
| 59 int crop_y, | |
| 60 int crop_width, | |
| 61 int crop_height, | |
| 62 int dst_width, | |
| 63 int dst_height) const { | |
| 64 return std::unique_ptr<VideoFrame>(CreateAliasedFrame( | |
| 65 input_frame, crop_width, crop_height, dst_width, dst_height)); | |
| 66 } | |
| 67 | |
| 18 VideoFrame* VideoFrameFactory::CreateAliasedFrame( | 68 VideoFrame* VideoFrameFactory::CreateAliasedFrame( |
| 19 const CapturedFrame* input_frame, | 69 const CapturedFrame* input_frame, |
| 20 int cropped_input_width, | 70 int cropped_input_width, |
| 21 int cropped_input_height, | 71 int cropped_input_height, |
| 22 int output_width, | 72 int output_width, |
| 23 int output_height) const { | 73 int output_height) const { |
| 24 std::unique_ptr<VideoFrame> cropped_input_frame(CreateAliasedFrame( | 74 std::unique_ptr<VideoFrame> cropped_input_frame(CreateAliasedFrame( |
| 25 input_frame, cropped_input_width, cropped_input_height)); | 75 input_frame, cropped_input_width, cropped_input_height)); |
| 26 if (!cropped_input_frame) | 76 if (!cropped_input_frame) |
| 27 return nullptr; | 77 return nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 52 return NULL; | 102 return NULL; |
| 53 } | 103 } |
| 54 } else { | 104 } else { |
| 55 cropped_input_frame->StretchToFrame(output_frame_.get(), true, true); | 105 cropped_input_frame->StretchToFrame(output_frame_.get(), true, true); |
| 56 output_frame_->SetTimeStamp(cropped_input_frame->GetTimeStamp()); | 106 output_frame_->SetTimeStamp(cropped_input_frame->GetTimeStamp()); |
| 57 } | 107 } |
| 58 return output_frame_->Copy(); | 108 return output_frame_->Copy(); |
| 59 } | 109 } |
| 60 | 110 |
| 61 } // namespace cricket | 111 } // namespace cricket |
| OLD | NEW |