Revert "Add concept of whether video renderer supports rotation."

This reverts commit 31d16467aceac56c3cb87a84564ea5e45a49ffe4.

TBR=guoweis@webrtc.org

BUG=

Review URL: https://webrtc-codereview.appspot.com/47489004

Cr-Commit-Position: refs/heads/master@{#8662}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8662 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
guoweis@webrtc.org 2015-03-10 06:19:55 +00:00
parent 31d16467ac
commit 60a2aa0652
4 changed files with 52 additions and 54 deletions

View File

@ -122,6 +122,51 @@ void VideoFrame::CopyToFrame(VideoFrame* dst) const {
dst->GetYPitch(), dst->GetUPitch(), dst->GetVPitch());
}
const VideoFrame* VideoFrame::GetCopyWithRotationApplied() const {
// If the frame is not rotated, the caller should reuse this frame instead of
// making a redundant copy.
if (GetVideoRotation() == webrtc::kVideoRotation_0) {
return this;
}
// If the video frame is backed up by a native handle, it resides in the GPU
// memory which we can't rotate here. The assumption is that the renderers
// which uses GPU to render should be able to rotate themselves.
DCHECK(!GetNativeHandle());
if (rotated_frame_) {
return rotated_frame_.get();
}
int width = static_cast<int>(GetWidth());
int height = static_cast<int>(GetHeight());
int rotated_width = width;
int rotated_height = height;
if (GetVideoRotation() == webrtc::kVideoRotation_90 ||
GetVideoRotation() == webrtc::kVideoRotation_270) {
rotated_width = height;
rotated_height = width;
}
rotated_frame_.reset(CreateEmptyFrame(rotated_width, rotated_height,
GetPixelWidth(), GetPixelHeight(),
GetElapsedTime(), GetTimeStamp()));
// TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from
// VideoRotation to libyuv::RotationMode.
int ret = libyuv::I420Rotate(
GetYPlane(), GetYPitch(), GetUPlane(), GetUPitch(), GetVPlane(),
GetVPitch(), rotated_frame_->GetYPlane(), rotated_frame_->GetYPitch(),
rotated_frame_->GetUPlane(), rotated_frame_->GetUPitch(),
rotated_frame_->GetVPlane(), rotated_frame_->GetVPitch(), width, height,
static_cast<libyuv::RotationMode>(GetVideoRotation()));
if (ret == 0) {
return rotated_frame_.get();
}
return nullptr;
}
size_t VideoFrame::ConvertToRgbBuffer(uint32 to_fourcc,
uint8* buffer,
size_t size,

View File

@ -29,6 +29,7 @@
#define TALK_MEDIA_BASE_VIDEOFRAME_H_
#include "webrtc/base/basictypes.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/stream.h"
#include "webrtc/common_video/rotation.h"
@ -161,9 +162,7 @@ class VideoFrame {
// Return a copy of frame which has its pending rotation applied. The
// ownership of the returned frame is held by this frame.
virtual const VideoFrame* GetCopyWithRotationApplied() const {
return nullptr;
}
virtual const VideoFrame* GetCopyWithRotationApplied() const;
// Writes the frame into the given stream and returns the StreamResult.
// See webrtc/base/stream.h for a description of StreamResult and error.
@ -229,6 +228,11 @@ class VideoFrame {
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) const = 0;
private:
// This is mutable as the calculation is expensive but once calculated, it
// remains const.
mutable rtc::scoped_ptr<VideoFrame> rotated_frame_;
};
} // namespace cricket

View File

@ -288,49 +288,4 @@ void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h, size_t pixel_width,
rotation_ = webrtc::kVideoRotation_0;
}
const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const {
// If the frame is not rotated, the caller should reuse this frame instead of
// making a redundant copy.
if (GetVideoRotation() == webrtc::kVideoRotation_0) {
return this;
}
// If the video frame is backed up by a native handle, it resides in the GPU
// memory which we can't rotate here. The assumption is that the renderers
// which uses GPU to render should be able to rotate themselves.
DCHECK(!GetNativeHandle());
if (rotated_frame_) {
return rotated_frame_.get();
}
int width = static_cast<int>(GetWidth());
int height = static_cast<int>(GetHeight());
int rotated_width = width;
int rotated_height = height;
if (GetVideoRotation() == webrtc::kVideoRotation_90 ||
GetVideoRotation() == webrtc::kVideoRotation_270) {
rotated_width = height;
rotated_height = width;
}
rotated_frame_.reset(CreateEmptyFrame(rotated_width, rotated_height,
GetPixelWidth(), GetPixelHeight(),
GetElapsedTime(), GetTimeStamp()));
// TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from
// VideoRotation to libyuv::RotationMode.
int ret = libyuv::I420Rotate(
GetYPlane(), GetYPitch(), GetUPlane(), GetUPitch(), GetVPlane(),
GetVPitch(), rotated_frame_->GetYPlane(), rotated_frame_->GetYPitch(),
rotated_frame_->GetUPlane(), rotated_frame_->GetUPitch(),
rotated_frame_->GetVPlane(), rotated_frame_->GetVPitch(), width, height,
static_cast<libyuv::RotationMode>(GetVideoRotation()));
if (ret == 0) {
return rotated_frame_.get();
}
return nullptr;
}
} // namespace cricket

View File

@ -124,8 +124,6 @@ class WebRtcVideoFrame : public VideoFrame {
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
size_t size, int stride_rgb) const;
const VideoFrame* GetCopyWithRotationApplied() const override;
protected:
void SetRotation(webrtc::VideoRotation rotation) { rotation_ = rotation; }
@ -142,10 +140,6 @@ class WebRtcVideoFrame : public VideoFrame {
int64_t elapsed_time_ns_;
int64_t time_stamp_ns_;
webrtc::VideoRotation rotation_;
// This is mutable as the calculation is expensive but once calculated, it
// remains const.
mutable rtc::scoped_ptr<VideoFrame> rotated_frame_;
};
} // namespace cricket