Chromium Code Reviews| Index: webrtc/media/engine/webrtcvideoframefactory.cc |
| diff --git a/webrtc/media/engine/webrtcvideoframefactory.cc b/webrtc/media/engine/webrtcvideoframefactory.cc |
| index 2c08c63129c6c28303a743d5122bf69d6e0f57d3..e2a0c04f4ba11640d725bd7d2c6ec346f56805e6 100644 |
| --- a/webrtc/media/engine/webrtcvideoframefactory.cc |
| +++ b/webrtc/media/engine/webrtcvideoframefactory.cc |
| @@ -10,12 +10,89 @@ |
| #include <memory> |
| +#include "libyuv/convert.h" |
| +#include "libyuv/scale.h" |
| + |
| #include "webrtc/base/logging.h" |
| +// #include "webrtc/common_video/include/video_frame_buffer.h" |
|
magjed_webrtc
2016/05/09 10:58:08
remove if not used
nisse-webrtc
2016/05/09 11:06:01
Done.
|
| #include "webrtc/media/engine/webrtcvideoframe.h" |
| #include "webrtc/media/engine/webrtcvideoframefactory.h" |
| +// TODO(nisse): Needed for the struct CapturedFrame. Move declaration |
| +// to videoframefactory.h instead? |
| +#include "webrtc/media/base/videocapturer.h" |
| + |
| namespace cricket { |
| +std::unique_ptr<VideoFrame> WebRtcVideoFrameFactory::CreateScaledFrame( |
| + const CapturedFrame* input_frame, |
| + int width, |
| + int height) const { |
| + webrtc::VideoRotation rotation = input_frame->rotation; |
| + int rotated_width; |
| + int rotated_height; |
| + if (apply_rotation_ && (rotation == webrtc::kVideoRotation_90 || |
| + rotation == webrtc::kVideoRotation_270)) { |
| + rotated_width = input_frame->height; |
| + rotated_height = input_frame->width; |
| + } else { |
| + rotated_width = input_frame->width; |
| + rotated_height = input_frame->height; |
| + } |
| + uint32_t format = CanonicalFourCC(input_frame->fourcc); |
|
magjed_webrtc
2016/05/09 10:58:08
Move this to the line above libyuv::ConvertToI420.
nisse-webrtc
2016/05/09 11:06:01
Done.
|
| + rtc::scoped_refptr<webrtc::I420Buffer> buffer( |
| + new rtc::RefCountedObject<webrtc::I420Buffer>(rotated_width, |
| + rotated_height)); |
| + |
| + // TODO(nisse): Do center crop if needed to preserve aspect ratio. |
|
magjed_webrtc
2016/05/09 10:58:08
I would like if you implemented this immediately.
nisse-webrtc
2016/05/09 11:06:01
Ok, I'll give it a try.
|
| + // Old code carried a comment saying that MJPG can only be cropped |
| + // vertically, and disabled cropping in this case. |
| + |
| + // Color space conversion, and rotation. |
| + int r = libyuv::ConvertToI420( |
| + static_cast<const uint8_t*>(input_frame->data), input_frame->data_size, |
| + buffer->MutableDataY(), buffer->StrideY(), |
| + buffer->MutableDataU(), buffer->StrideU(), |
| + buffer->MutableDataV(), buffer->StrideV(), |
| + 0, 0, /* No cropping. */ |
| + buffer->width(), buffer->height(), |
| + rotated_width, rotated_height, |
| + static_cast<libyuv::RotationMode>( |
| + apply_rotation_ ? rotation : webrtc::kVideoRotation_0), |
| + format); |
| + if (r) { |
| + LOG(LS_ERROR) << "Error parsing format: " << GetFourccName(format) |
| + << " return code : " << r; |
| + return nullptr; |
| + } |
| + |
| + // Scaling, if needed. Currently doesn't respect aspect ratio. |
| + if (rotated_width != width || rotated_height != height) { |
| + rtc::scoped_refptr<webrtc::I420Buffer> scaled( |
| + new rtc::RefCountedObject<webrtc::I420Buffer>(width, height)); |
| + |
| + if (libyuv::I420Scale(buffer->DataY(), buffer->StrideY(), |
| + buffer->DataU(), buffer->StrideU(), |
| + buffer->DataV(), buffer->StrideV(), |
| + buffer->width(), buffer->height(), |
| + scaled->MutableDataY(), scaled->StrideY(), |
| + scaled->MutableDataU(), scaled->StrideU(), |
| + scaled->MutableDataV(), scaled->StrideV(), |
| + scaled->width(), scaled->height(), |
| + libyuv::kFilterBox) < 0) { |
| + LOG(LS_ERROR) << "I420Scale failed: src size " |
| + << buffer->width() << " x " << buffer->height() |
| + << ", dst size: " |
| + << scaled->width() << " x " << scaled->height(); |
| + return nullptr; |
| + } |
| + buffer = scaled; |
| + } |
| + return std::unique_ptr<VideoFrame>(new WebRtcVideoFrame( |
| + buffer, apply_rotation_ ? webrtc::kVideoRotation_0 : rotation, |
| + input_frame->time_stamp / rtc::kNumNanosecsPerMicrosec)); |
| +} |
| + |
| VideoFrame* WebRtcVideoFrameFactory::CreateAliasedFrame( |
| const CapturedFrame* aliased_frame, int width, int height) const { |
| std::unique_ptr<WebRtcVideoFrame> frame(new WebRtcVideoFrame()); |