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 <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "libyuv/convert.h" | |
| 14 #include "libyuv/scale.h" | |
| 15 | |
| 13 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/media/engine/webrtcvideoframe.h" | 17 #include "webrtc/media/engine/webrtcvideoframe.h" |
| 15 #include "webrtc/media/engine/webrtcvideoframefactory.h" | 18 #include "webrtc/media/engine/webrtcvideoframefactory.h" |
| 16 | 19 |
| 20 // TODO(nisse): Needed for the struct CapturedFrame. Move declaration | |
| 21 // to videoframefactory.h instead? | |
| 22 #include "webrtc/media/base/videocapturer.h" | |
| 23 | |
| 17 namespace cricket { | 24 namespace cricket { |
| 18 | 25 |
| 26 std::unique_ptr<VideoFrame> WebRtcVideoFrameFactory::CreateScaledCroppedFrame( | |
| 27 const CapturedFrame* input_frame, | |
| 28 int crop_x, | |
| 29 int crop_y, | |
| 30 int crop_width, | |
| 31 int crop_height, | |
| 32 int dst_width, | |
| 33 int dst_height) const { | |
| 34 webrtc::VideoRotation rotation = input_frame->rotation; | |
| 35 // The size of the input frame, after cropping and rotation. | |
| 36 int src_width = crop_width; | |
| 37 int src_height = crop_height; | |
| 38 if (apply_rotation_ && (rotation == webrtc::kVideoRotation_90 || | |
| 39 rotation == webrtc::kVideoRotation_270)) { | |
| 40 std::swap(dst_width, dst_height); | |
| 41 std::swap(src_width, src_height); | |
| 42 } | |
| 43 | |
| 44 rtc::scoped_refptr<webrtc::I420Buffer> buffer( | |
| 45 new rtc::RefCountedObject<webrtc::I420Buffer>(src_width, src_height)); | |
| 46 | |
| 47 // Color space conversion, cropping, and rotation. | |
| 48 uint32_t format = CanonicalFourCC(input_frame->fourcc); | |
|
nisse-webrtc
2016/05/12 12:23:06
But calling CanonicalFourCC seems unnecessary, tha
| |
| 49 int r = libyuv::ConvertToI420( | |
| 50 static_cast<const uint8_t*>(input_frame->data), input_frame->data_size, | |
| 51 buffer->MutableDataY(), buffer->StrideY(), | |
| 52 buffer->MutableDataU(), buffer->StrideU(), | |
| 53 buffer->MutableDataV(), buffer->StrideV(), | |
| 54 // Cropping coordinates, width and height, are all pre-rotation values. | |
| 55 crop_x, crop_y, | |
| 56 input_frame->width, input_frame->height, | |
| 57 crop_width, crop_height, | |
| 58 static_cast<libyuv::RotationMode>( | |
| 59 apply_rotation_ ? rotation : webrtc::kVideoRotation_0), | |
| 60 format); | |
| 61 if (r) { | |
| 62 LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) | |
| 63 << " return code : " << r; | |
| 64 return nullptr; | |
| 65 } | |
| 66 | |
| 67 // Scaling, if needed. | |
| 68 if (src_width != dst_width || src_height != dst_height) { | |
| 69 buffer = webrtc::I420Buffer::Scale(buffer, dst_width, dst_height); | |
| 70 if (!buffer) { | |
| 71 LOG(LS_ERROR) << "I420Scale failed: src size " | |
| 72 << src_width << " x " << src_height | |
| 73 << ", dst size: " | |
| 74 << dst_width << " x " << dst_height; | |
| 75 return nullptr; | |
| 76 } | |
| 77 } | |
| 78 return std::unique_ptr<VideoFrame>(new WebRtcVideoFrame( | |
| 79 buffer, apply_rotation_ ? webrtc::kVideoRotation_0 : rotation, | |
| 80 input_frame->time_stamp / rtc::kNumNanosecsPerMicrosec)); | |
| 81 } | |
| 82 | |
| 19 VideoFrame* WebRtcVideoFrameFactory::CreateAliasedFrame( | 83 VideoFrame* WebRtcVideoFrameFactory::CreateAliasedFrame( |
| 20 const CapturedFrame* aliased_frame, int width, int height) const { | 84 const CapturedFrame* aliased_frame, int width, int height) const { |
| 21 std::unique_ptr<WebRtcVideoFrame> frame(new WebRtcVideoFrame()); | 85 std::unique_ptr<WebRtcVideoFrame> frame(new WebRtcVideoFrame()); |
| 22 if (!frame->Init(aliased_frame, width, height, apply_rotation_)) { | 86 if (!frame->Init(aliased_frame, width, height, apply_rotation_)) { |
|
perkj_webrtc
2016/05/11 10:05:17
It looks like |aliased_frame| always is I420? No n
nisse-webrtc
2016/05/12 12:23:06
In the (common) case that the CapturedFrame holds
| |
| 23 LOG(LS_ERROR) << | 87 LOG(LS_ERROR) << |
| 24 "Failed to create WebRtcVideoFrame in CreateAliasedFrame."; | 88 "Failed to create WebRtcVideoFrame in CreateAliasedFrame."; |
| 25 return NULL; | 89 return NULL; |
| 26 } | 90 } |
| 27 return frame.release(); | 91 return frame.release(); |
| 28 } | 92 } |
| 29 | 93 |
| 30 } // namespace cricket | 94 } // namespace cricket |
| OLD | NEW |