From 58849fd1ecf489074ef02fb575bdb5a8a75e0b38 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 11 Oct 2012 15:33:05 +0000 Subject: [PATCH] Adding Scale for I420VideoFrame Review URL: https://webrtc-codereview.appspot.com/857012 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2910 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/common_video/libyuv/include/scaler.h | 5 ++++ src/common_video/libyuv/scaler.cc | 29 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/common_video/libyuv/include/scaler.h b/src/common_video/libyuv/include/scaler.h index 8838844b65..8851194a79 100644 --- a/src/common_video/libyuv/include/scaler.h +++ b/src/common_video/libyuv/include/scaler.h @@ -16,6 +16,7 @@ #define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_SCALER_H_ #include "common_video/libyuv/include/webrtc_libyuv.h" +#include "common_video/interface/i420_video_frame.h" #include "typedefs.h" namespace webrtc { @@ -47,9 +48,13 @@ class Scaler { // Return value: 0 - OK, // -1 - parameter error // -2 - scaler not set + // TODO(mikhal): Remove legacy implementation of old VideoFrame. int Scale(const VideoFrame& src_frame, VideoFrame* dst_frame); + int Scale(const I420VideoFrame& src_frame, + I420VideoFrame* dst_frame); + private: // Determine if the VideoTypes are currently supported. bool SupportedVideoType(VideoType src_video_type, diff --git a/src/common_video/libyuv/scaler.cc b/src/common_video/libyuv/scaler.cc index 1304e0dfa4..5851b2a824 100644 --- a/src/common_video/libyuv/scaler.cc +++ b/src/common_video/libyuv/scaler.cc @@ -84,6 +84,35 @@ int Scaler::Scale(const VideoFrame& src_frame, libyuv::FilterMode(method_)); } + +// TODO(mikhal): Add test to new function. Currently not used. +int Scaler::Scale(const I420VideoFrame& src_frame, + I420VideoFrame* dst_frame) { + assert(dst_frame); + // TODO(mikhal): Add isEmpty + // if (src_frame.Buffer() == NULL || src_frame.Length() == 0) + // return -1; + if (!set_) + return -2; + + // TODO(mikhal): Setting stride equal to width - should align. + dst_frame->CreateEmptyFrame(dst_width_, dst_height_, dst_width_ , + (dst_width_ + 1) / 2, (dst_width_ + 1) / 2); + + return libyuv::I420Scale(src_frame.buffer(kYPlane), src_frame.stride(kYPlane), + src_frame.buffer(kUPlane), src_frame.stride(kYPlane), + src_frame.buffer(kVPlane), src_frame.stride(kYPlane), + src_width_, src_height_, + dst_frame->buffer(kYPlane), + dst_frame->stride(kYPlane), + dst_frame->buffer(kYPlane), + dst_frame->stride(kYPlane), + dst_frame->buffer(kYPlane), + dst_frame->stride(kYPlane), + dst_width_, dst_height_, + libyuv::FilterMode(method_)); +} + // TODO(mikhal): Add support for more types. bool Scaler::SupportedVideoType(VideoType src_video_type, VideoType dst_video_type) {