| Index: webrtc/media/engine/webrtcvideoframefactory.cc
|
| diff --git a/webrtc/media/engine/webrtcvideoframefactory.cc b/webrtc/media/engine/webrtcvideoframefactory.cc
|
| index 2c08c63129c6c28303a743d5122bf69d6e0f57d3..ad478d68bd005fe6661f62a056998b96bb5f5abf 100644
|
| --- a/webrtc/media/engine/webrtcvideoframefactory.cc
|
| +++ b/webrtc/media/engine/webrtcvideoframefactory.cc
|
| @@ -10,12 +10,77 @@
|
|
|
| #include <memory>
|
|
|
| +#include "libyuv/convert.h"
|
| +#include "libyuv/scale.h"
|
| +
|
| #include "webrtc/base/logging.h"
|
| #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::CreateCroppedAndScaledFrame(
|
| + const CapturedFrame* input_frame,
|
| + int crop_x,
|
| + int crop_y,
|
| + int crop_width,
|
| + int crop_height,
|
| + int dst_width,
|
| + int dst_height) const {
|
| + webrtc::VideoRotation rotation = input_frame->rotation;
|
| + // The size of the input frame, after cropping and rotation.
|
| + int src_width = crop_width;
|
| + int src_height = crop_height;
|
| + if (apply_rotation_ && (rotation == webrtc::kVideoRotation_90 ||
|
| + rotation == webrtc::kVideoRotation_270)) {
|
| + std::swap(dst_width, dst_height);
|
| + std::swap(src_width, src_height);
|
| + }
|
| +
|
| + rtc::scoped_refptr<webrtc::I420Buffer> buffer(
|
| + new rtc::RefCountedObject<webrtc::I420Buffer>(src_width, src_height));
|
| +
|
| + // Color space conversion, cropping, and rotation.
|
| + uint32_t format = CanonicalFourCC(input_frame->fourcc);
|
| + 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(),
|
| + // Cropping coordinates, width and height, are all pre-rotation values.
|
| + crop_x, crop_y,
|
| + input_frame->width, input_frame->height,
|
| + crop_width, crop_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.
|
| + if (src_width != dst_width || src_height != dst_height) {
|
| + buffer = webrtc::I420Buffer::Scale(buffer, dst_width, dst_height);
|
| + if (!buffer) {
|
| + LOG(LS_ERROR) << "I420Scale failed: src size "
|
| + << src_width << " x " << src_height
|
| + << ", dst size: "
|
| + << dst_width << " x " << dst_height;
|
| + return nullptr;
|
| + }
|
| + }
|
| + 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());
|
|
|