cricket::VideoFrame: Refactor ConvertToRgbBuffer into base class

There is also an implementation in Chromium that can be removed if/when this lands:
content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc

R=fbarchard@google.com, pbos@webrtc.org, perkj@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7728 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
magjed@webrtc.org 2014-11-21 10:53:00 +00:00
parent ad0e71c9a3
commit bdcf38c894
4 changed files with 22 additions and 50 deletions

View File

@ -115,6 +115,26 @@ void VideoFrame::CopyToFrame(VideoFrame* dst) const {
dst->GetYPitch(), dst->GetUPitch(), dst->GetVPitch());
}
size_t VideoFrame::ConvertToRgbBuffer(uint32 to_fourcc,
uint8* buffer,
size_t size,
int stride_rgb) const {
const size_t needed = std::abs(stride_rgb) * GetHeight();
if (size < needed) {
LOG(LS_WARNING) << "RGB buffer is not large enough";
return needed;
}
if (libyuv::ConvertFromI420(GetYPlane(), GetYPitch(), GetUPlane(),
GetUPitch(), GetVPlane(), GetVPitch(), buffer,
stride_rgb, static_cast<int>(GetWidth()),
static_cast<int>(GetHeight()), to_fourcc)) {
LOG(LS_ERROR) << "RGB type not supported: " << to_fourcc;
return 0; // 0 indicates error
}
return needed;
}
// TODO(fbarchard): Handle odd width/height with rounding.
void VideoFrame::StretchToPlanes(
uint8* dst_y, uint8* dst_u, uint8* dst_v,

View File

@ -137,7 +137,7 @@ class VideoFrame {
// not (like snprintf). Parameters size and stride_rgb are in units of bytes.
// If there is insufficient space, nothing is written.
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer,
size_t size, int stride_rgb) const = 0;
size_t size, int stride_rgb) const;
// Writes the frame into the given planes, stretched to the given width and
// height. The parameter "interpolate" controls whether to interpolate or just

View File

@ -665,36 +665,6 @@ class WebRtcVideoRenderFrame : public VideoFrame {
return 0;
}
// TODO(fbarchard): Refactor into base class and share with LMI
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc,
uint8* buffer,
size_t size,
int stride_rgb) const OVERRIDE {
size_t width = GetWidth();
size_t height = GetHeight();
size_t needed = (stride_rgb >= 0 ? stride_rgb : -stride_rgb) * height;
if (size < needed) {
LOG(LS_WARNING) << "RGB buffer is not large enough";
return needed;
}
if (libyuv::ConvertFromI420(GetYPlane(),
GetYPitch(),
GetUPlane(),
GetUPitch(),
GetVPlane(),
GetVPitch(),
buffer,
stride_rgb,
static_cast<int>(width),
static_cast<int>(height),
to_fourcc)) {
LOG(LS_ERROR) << "RGB type not supported: " << to_fourcc;
return 0; // 0 indicates error
}
return needed;
}
protected:
virtual VideoFrame* CreateEmptyFrame(int w,
int h,

View File

@ -246,30 +246,12 @@ size_t WebRtcVideoFrame::CopyToBuffer(uint8* buffer, size_t size) const {
return needed;
}
// TODO(fbarchard): Refactor into base class and share with lmi
size_t WebRtcVideoFrame::ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
size_t size, int stride_rgb) const {
if (!frame()->Buffer()) {
return 0;
}
size_t width = frame()->Width();
size_t height = frame()->Height();
size_t needed = (stride_rgb >= 0 ? stride_rgb : -stride_rgb) * height;
if (size < needed) {
LOG(LS_WARNING) << "RGB buffer is not large enough";
return needed;
}
if (libyuv::ConvertFromI420(GetYPlane(), GetYPitch(), GetUPlane(),
GetUPitch(), GetVPlane(), GetVPitch(), buffer,
stride_rgb,
static_cast<int>(width),
static_cast<int>(height),
to_fourcc)) {
LOG(LS_WARNING) << "RGB type not supported: " << to_fourcc;
return 0; // 0 indicates error
}
return needed;
return VideoFrame::ConvertToRgbBuffer(to_fourcc, buffer, size, stride_rgb);
}
void WebRtcVideoFrame::Attach(