
This is unfortunately causing build problems in Chrome on Windows. > Unify underlying frame buffer in I420VideoFrame and WebRtcVideoFrame > > Currently, I420VideoFrame uses three webrtc::Plane to store pixel data, and WebRtcVideoFrame uses WebRtcVideoFrame::FrameBuffer/webrtc::VideoFrame. The two subclasses WebRtcTextureVideoFrame and TextureVideoFrame use a NativeHandle to store pixel data, and there is also a class WebRtcVideoRenderFrame that wraps an I420VideoFrame. > > This CL replaces these classes with a new interface VideoFrameBuffer that provides the common functionality. This makes it possible to remove deep frame copies between cricket::VideoFrame and I420VideoFrame. > > Some additional minor changes are: > * Disallow creation of 0x0 texture frames. > * Remove the half-implemented ref count functions in I420VideoFrame. > * Remove the Alias functionality in WebRtcVideoFrame > > The final goal is to eliminate all frame copies, but to limit the scope of this CL, some planned changes are postponed to follow-up CL:s (see planned changes in https://webrtc-codereview.appspot.com/38879004, or https://docs.google.com/document/d/1bxoJZNmlo-Z9GnQwIaWpEG6hDlL_W-bzka8Zb_K2NbA/preview). Specifically, this CL: > * Keeps empty subclasses WebRtcTextureVideoFrame and TextureVideoFrame, and just delegates the construction to the superclass. > * Keeps the deep copies from cricket::VideoFrame to I420VideoFrame. > > BUG=1128 > R=mflodman@webrtc.org, pbos@webrtc.org, perkj@webrtc.org, tommi@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/42469004 TBR=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42199005 Cr-Commit-Position: refs/heads/master@{#8599} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8599 4adac7df-926f-26a2-2b94-8c16560cd09d
199 lines
6.1 KiB
C++
199 lines
6.1 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/common_video/interface/i420_video_frame.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <algorithm> // swap
|
|
|
|
namespace webrtc {
|
|
|
|
I420VideoFrame::I420VideoFrame()
|
|
: width_(0),
|
|
height_(0),
|
|
timestamp_(0),
|
|
ntp_time_ms_(0),
|
|
render_time_ms_(0),
|
|
rotation_(kVideoRotation_0) {
|
|
}
|
|
|
|
I420VideoFrame::~I420VideoFrame() {}
|
|
|
|
int I420VideoFrame::CreateEmptyFrame(int width, int height,
|
|
int stride_y, int stride_u, int stride_v) {
|
|
if (CheckDimensions(width, height, stride_y, stride_u, stride_v) < 0)
|
|
return -1;
|
|
int size_y = stride_y * height;
|
|
int half_height = (height + 1) / 2;
|
|
int size_u = stride_u * half_height;
|
|
int size_v = stride_v * half_height;
|
|
width_ = width;
|
|
height_ = height;
|
|
y_plane_.CreateEmptyPlane(size_y, stride_y, size_y);
|
|
u_plane_.CreateEmptyPlane(size_u, stride_u, size_u);
|
|
v_plane_.CreateEmptyPlane(size_v, stride_v, size_v);
|
|
// Creating empty frame - reset all values.
|
|
timestamp_ = 0;
|
|
ntp_time_ms_ = 0;
|
|
render_time_ms_ = 0;
|
|
rotation_ = kVideoRotation_0;
|
|
return 0;
|
|
}
|
|
|
|
int I420VideoFrame::CreateFrame(int size_y, const uint8_t* buffer_y,
|
|
int size_u, const uint8_t* buffer_u,
|
|
int size_v, const uint8_t* buffer_v,
|
|
int width, int height,
|
|
int stride_y, int stride_u, int stride_v) {
|
|
return CreateFrame(size_y, buffer_y, size_u, buffer_u, size_v, buffer_v,
|
|
width, height, stride_y, stride_u, stride_v,
|
|
kVideoRotation_0);
|
|
}
|
|
|
|
int I420VideoFrame::CreateFrame(int size_y,
|
|
const uint8_t* buffer_y,
|
|
int size_u,
|
|
const uint8_t* buffer_u,
|
|
int size_v,
|
|
const uint8_t* buffer_v,
|
|
int width,
|
|
int height,
|
|
int stride_y,
|
|
int stride_u,
|
|
int stride_v,
|
|
VideoRotation rotation) {
|
|
if (size_y < 1 || size_u < 1 || size_v < 1)
|
|
return -1;
|
|
if (CheckDimensions(width, height, stride_y, stride_u, stride_v) < 0)
|
|
return -1;
|
|
y_plane_.Copy(size_y, stride_y, buffer_y);
|
|
u_plane_.Copy(size_u, stride_u, buffer_u);
|
|
v_plane_.Copy(size_v, stride_v, buffer_v);
|
|
width_ = width;
|
|
height_ = height;
|
|
rotation_ = rotation;
|
|
return 0;
|
|
}
|
|
|
|
int I420VideoFrame::CopyFrame(const I420VideoFrame& videoFrame) {
|
|
int ret = CreateFrame(videoFrame.allocated_size(kYPlane),
|
|
videoFrame.buffer(kYPlane),
|
|
videoFrame.allocated_size(kUPlane),
|
|
videoFrame.buffer(kUPlane),
|
|
videoFrame.allocated_size(kVPlane),
|
|
videoFrame.buffer(kVPlane),
|
|
videoFrame.width_, videoFrame.height_,
|
|
videoFrame.stride(kYPlane), videoFrame.stride(kUPlane),
|
|
videoFrame.stride(kVPlane));
|
|
if (ret < 0)
|
|
return ret;
|
|
timestamp_ = videoFrame.timestamp_;
|
|
ntp_time_ms_ = videoFrame.ntp_time_ms_;
|
|
render_time_ms_ = videoFrame.render_time_ms_;
|
|
rotation_ = videoFrame.rotation_;
|
|
return 0;
|
|
}
|
|
|
|
I420VideoFrame* I420VideoFrame::CloneFrame() const {
|
|
rtc::scoped_ptr<I420VideoFrame> new_frame(new I420VideoFrame());
|
|
if (new_frame->CopyFrame(*this) == -1) {
|
|
// CopyFrame failed.
|
|
return NULL;
|
|
}
|
|
return new_frame.release();
|
|
}
|
|
|
|
void I420VideoFrame::SwapFrame(I420VideoFrame* videoFrame) {
|
|
y_plane_.Swap(videoFrame->y_plane_);
|
|
u_plane_.Swap(videoFrame->u_plane_);
|
|
v_plane_.Swap(videoFrame->v_plane_);
|
|
std::swap(width_, videoFrame->width_);
|
|
std::swap(height_, videoFrame->height_);
|
|
std::swap(timestamp_, videoFrame->timestamp_);
|
|
std::swap(ntp_time_ms_, videoFrame->ntp_time_ms_);
|
|
std::swap(render_time_ms_, videoFrame->render_time_ms_);
|
|
std::swap(rotation_, videoFrame->rotation_);
|
|
}
|
|
|
|
uint8_t* I420VideoFrame::buffer(PlaneType type) {
|
|
Plane* plane_ptr = GetPlane(type);
|
|
if (plane_ptr)
|
|
return plane_ptr->buffer();
|
|
return NULL;
|
|
}
|
|
|
|
const uint8_t* I420VideoFrame::buffer(PlaneType type) const {
|
|
const Plane* plane_ptr = GetPlane(type);
|
|
if (plane_ptr)
|
|
return plane_ptr->buffer();
|
|
return NULL;
|
|
}
|
|
|
|
int I420VideoFrame::allocated_size(PlaneType type) const {
|
|
const Plane* plane_ptr = GetPlane(type);
|
|
if (plane_ptr)
|
|
return plane_ptr->allocated_size();
|
|
return -1;
|
|
}
|
|
|
|
int I420VideoFrame::stride(PlaneType type) const {
|
|
const Plane* plane_ptr = GetPlane(type);
|
|
if (plane_ptr)
|
|
return plane_ptr->stride();
|
|
return -1;
|
|
}
|
|
|
|
bool I420VideoFrame::IsZeroSize() const {
|
|
return (y_plane_.IsZeroSize() && u_plane_.IsZeroSize() &&
|
|
v_plane_.IsZeroSize());
|
|
}
|
|
|
|
void* I420VideoFrame::native_handle() const { return NULL; }
|
|
|
|
int I420VideoFrame::CheckDimensions(int width, int height,
|
|
int stride_y, int stride_u, int stride_v) {
|
|
int half_width = (width + 1) / 2;
|
|
if (width < 1 || height < 1 ||
|
|
stride_y < width || stride_u < half_width || stride_v < half_width)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
const Plane* I420VideoFrame::GetPlane(PlaneType type) const {
|
|
switch (type) {
|
|
case kYPlane :
|
|
return &y_plane_;
|
|
case kUPlane :
|
|
return &u_plane_;
|
|
case kVPlane :
|
|
return &v_plane_;
|
|
default:
|
|
assert(false);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
Plane* I420VideoFrame::GetPlane(PlaneType type) {
|
|
switch (type) {
|
|
case kYPlane :
|
|
return &y_plane_;
|
|
case kUPlane :
|
|
return &u_plane_;
|
|
case kVPlane :
|
|
return &v_plane_;
|
|
default:
|
|
assert(false);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
} // namespace webrtc
|