Revert 8580 "Unify underlying frame buffer in I420VideoFrame and..."

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
This commit is contained in:
tommi@webrtc.org
2015-03-04 17:33:55 +00:00
parent c86bbbaa93
commit 1f94407319
22 changed files with 1384 additions and 534 deletions

View File

@ -394,6 +394,232 @@ struct VideoContentMetrics {
float spatial_pred_err_v;
};
/*************************************************
*
* VideoFrame class
*
* The VideoFrame class allows storing and
* handling of video frames.
*
*
*************************************************/
class VideoFrame {
public:
VideoFrame();
~VideoFrame();
/**
* Verifies that current allocated buffer size is larger than or equal to the
* input size.
* If the current buffer size is smaller, a new allocation is made and the old
* buffer data
* is copied to the new buffer.
* Buffer size is updated to minimumSize.
*/
int32_t VerifyAndAllocate(const size_t minimumSize);
/**
* Update length of data buffer in frame. Function verifies that new length
* is less or
* equal to allocated size.
*/
int32_t SetLength(const size_t newLength);
/*
* Swap buffer and size data
*/
int32_t Swap(uint8_t*& newMemory, size_t& newLength, size_t& newSize);
/*
* Swap buffer and size data
*/
int32_t SwapFrame(VideoFrame& videoFrame);
/**
* Copy buffer: If newLength is bigger than allocated size, a new buffer of
* size length
* is allocated.
*/
int32_t CopyFrame(const VideoFrame& videoFrame);
/**
* Copy buffer: If newLength is bigger than allocated size, a new buffer of
* size length
* is allocated.
*/
int32_t CopyFrame(size_t length, const uint8_t* sourceBuffer);
/**
* Delete VideoFrame and resets members to zero
*/
void Free();
/**
* Set frame timestamp (90kHz)
*/
void SetTimeStamp(const uint32_t timeStamp) { _timeStamp = timeStamp; }
/**
* Get pointer to frame buffer
*/
uint8_t* Buffer() const { return _buffer; }
uint8_t*& Buffer() { return _buffer; }
/**
* Get allocated buffer size
*/
size_t Size() const { return _bufferSize; }
/**
* Get frame length
*/
size_t Length() const { return _bufferLength; }
/**
* Get frame timestamp (90kHz)
*/
uint32_t TimeStamp() const { return _timeStamp; }
/**
* Get frame width
*/
uint32_t Width() const { return _width; }
/**
* Get frame height
*/
uint32_t Height() const { return _height; }
/**
* Set frame width
*/
void SetWidth(const uint32_t width) { _width = width; }
/**
* Set frame height
*/
void SetHeight(const uint32_t height) { _height = height; }
/**
* Set render time in miliseconds
*/
void SetRenderTime(const int64_t renderTimeMs) {
_renderTimeMs = renderTimeMs;
}
/**
* Get render time in miliseconds
*/
int64_t RenderTimeMs() const { return _renderTimeMs; }
private:
void Set(uint8_t* buffer, uint32_t size, uint32_t length, uint32_t timeStamp);
uint8_t* _buffer; // Pointer to frame buffer
size_t _bufferSize; // Allocated buffer size
size_t _bufferLength; // Length (in bytes) of buffer
uint32_t _timeStamp; // Timestamp of frame (90kHz)
uint32_t _width;
uint32_t _height;
int64_t _renderTimeMs;
}; // end of VideoFrame class declaration
// inline implementation of VideoFrame class:
inline VideoFrame::VideoFrame()
: _buffer(0),
_bufferSize(0),
_bufferLength(0),
_timeStamp(0),
_width(0),
_height(0),
_renderTimeMs(0) {
//
}
inline VideoFrame::~VideoFrame() {
if (_buffer) {
delete[] _buffer;
_buffer = NULL;
}
}
inline int32_t VideoFrame::VerifyAndAllocate(const size_t minimumSize) {
if (minimumSize < 1) {
return -1;
}
if (minimumSize > _bufferSize) {
// create buffer of sufficient size
uint8_t* newBufferBuffer = new uint8_t[minimumSize];
if (_buffer) {
// copy old data
memcpy(newBufferBuffer, _buffer, _bufferSize);
delete[] _buffer;
} else {
memset(newBufferBuffer, 0, minimumSize * sizeof(uint8_t));
}
_buffer = newBufferBuffer;
_bufferSize = minimumSize;
}
return 0;
}
inline int32_t VideoFrame::SetLength(const size_t newLength) {
if (newLength > _bufferSize) { // can't accomodate new value
return -1;
}
_bufferLength = newLength;
return 0;
}
inline int32_t VideoFrame::SwapFrame(VideoFrame& videoFrame) {
uint32_t tmpTimeStamp = _timeStamp;
uint32_t tmpWidth = _width;
uint32_t tmpHeight = _height;
int64_t tmpRenderTime = _renderTimeMs;
_timeStamp = videoFrame._timeStamp;
_width = videoFrame._width;
_height = videoFrame._height;
_renderTimeMs = videoFrame._renderTimeMs;
videoFrame._timeStamp = tmpTimeStamp;
videoFrame._width = tmpWidth;
videoFrame._height = tmpHeight;
videoFrame._renderTimeMs = tmpRenderTime;
return Swap(videoFrame._buffer, videoFrame._bufferLength,
videoFrame._bufferSize);
}
inline int32_t VideoFrame::Swap(uint8_t*& newMemory, size_t& newLength,
size_t& newSize) {
std::swap(_buffer, newMemory);
std::swap(_bufferLength, newLength);
std::swap(_bufferSize, newSize);
return 0;
}
inline int32_t VideoFrame::CopyFrame(size_t length,
const uint8_t* sourceBuffer) {
if (length > _bufferSize) {
int32_t ret = VerifyAndAllocate(length);
if (ret < 0) {
return ret;
}
}
memcpy(_buffer, sourceBuffer, length);
_bufferLength = length;
return 0;
}
inline int32_t VideoFrame::CopyFrame(const VideoFrame& videoFrame) {
if (CopyFrame(videoFrame.Length(), videoFrame.Buffer()) != 0) {
return -1;
}
_timeStamp = videoFrame._timeStamp;
_width = videoFrame._width;
_height = videoFrame._height;
_renderTimeMs = videoFrame._renderTimeMs;
return 0;
}
inline void VideoFrame::Free() {
_timeStamp = 0;
_bufferLength = 0;
_bufferSize = 0;
_height = 0;
_width = 0;
_renderTimeMs = 0;
if (_buffer) {
delete[] _buffer;
_buffer = NULL;
}
}
/* This class holds up to 60 ms of super-wideband (32 kHz) stereo audio. It
* allows for adding and subtracting frames while keeping track of the resulting
* states.