cricket::VideoFrame: Refactor CopyToBuffer into base class
It’s possible to implement cricket::VideoFrame::CopyToBuffer using the virtual interface. This removes the need for subclasses to implement their own versions. This CL also fixes a bug in cricket::VideoFrame::CopyToPlanes which currently assumes that GetUPitch() == GetVPitch(), otherwise it may segfault. I think this CL should land regardless, but the main purpose is to pave the way for for planned changes to I420VideoFrame. See https://review.webrtc.org/38879004. R=fbarchard@google.com, perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39889004 Cr-Commit-Position: refs/heads/master@{#8403} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8403 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
dd4a8da68a
commit
3864363e2c
@ -80,9 +80,25 @@ rtc::StreamResult VideoFrame::Write(rtc::StreamInterface* stream,
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t VideoFrame::CopyToBuffer(uint8* buffer, size_t size) const {
|
||||
const size_t y_size = GetHeight() * GetYPitch();
|
||||
const size_t u_size = GetUPitch() * GetChromaHeight();
|
||||
const size_t v_size = GetVPitch() * GetChromaHeight();
|
||||
const size_t needed = y_size + u_size + v_size;
|
||||
if (size < needed)
|
||||
return needed;
|
||||
CopyToPlanes(buffer, buffer + y_size, buffer + y_size + u_size,
|
||||
GetYPitch(), GetUPitch(), GetVPitch());
|
||||
return needed;
|
||||
}
|
||||
|
||||
bool VideoFrame::CopyToPlanes(
|
||||
uint8* dst_y, uint8* dst_u, uint8* dst_v,
|
||||
int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const {
|
||||
if (!GetYPlane() || !GetUPlane() || !GetVPlane()) {
|
||||
LOG(LS_ERROR) << "NULL plane pointer.";
|
||||
return false;
|
||||
}
|
||||
int32 src_width = static_cast<int>(GetWidth());
|
||||
int32 src_height = static_cast<int>(GetHeight());
|
||||
return libyuv::I420Copy(GetYPlane(), GetYPitch(),
|
||||
|
@ -142,7 +142,7 @@ class VideoFrame {
|
||||
// sufficient size. Returns the frame's actual size, regardless of whether
|
||||
// it was written or not (like snprintf). If there is insufficient space,
|
||||
// nothing is written.
|
||||
virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const = 0;
|
||||
virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const;
|
||||
|
||||
// Writes the frame into the given planes, stretched to the given width and
|
||||
// height. The parameter "interpolate" controls whether to interpolate or just
|
||||
|
@ -250,18 +250,6 @@ bool WebRtcVideoFrame::MakeExclusive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t WebRtcVideoFrame::CopyToBuffer(uint8* buffer, size_t size) const {
|
||||
if (!frame()->Buffer()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t needed = frame()->Length();
|
||||
if (needed <= size) {
|
||||
memcpy(buffer, frame()->Buffer(), needed);
|
||||
}
|
||||
return needed;
|
||||
}
|
||||
|
||||
size_t WebRtcVideoFrame::ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
||||
size_t size, int stride_rgb) const {
|
||||
if (!frame()->Buffer()) {
|
||||
|
@ -138,7 +138,6 @@ class WebRtcVideoFrame : public VideoFrame {
|
||||
|
||||
virtual VideoFrame* Copy() const;
|
||||
virtual bool MakeExclusive();
|
||||
virtual size_t CopyToBuffer(uint8* buffer, size_t size) const;
|
||||
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
||||
size_t size, int stride_rgb) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user