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:
@ -115,6 +115,26 @@ void VideoFrame::CopyToFrame(VideoFrame* dst) const {
|
|||||||
dst->GetYPitch(), dst->GetUPitch(), dst->GetVPitch());
|
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.
|
// TODO(fbarchard): Handle odd width/height with rounding.
|
||||||
void VideoFrame::StretchToPlanes(
|
void VideoFrame::StretchToPlanes(
|
||||||
uint8* dst_y, uint8* dst_u, uint8* dst_v,
|
uint8* dst_y, uint8* dst_u, uint8* dst_v,
|
||||||
|
@ -137,7 +137,7 @@ class VideoFrame {
|
|||||||
// not (like snprintf). Parameters size and stride_rgb are in units of bytes.
|
// not (like snprintf). Parameters size and stride_rgb are in units of bytes.
|
||||||
// If there is insufficient space, nothing is written.
|
// If there is insufficient space, nothing is written.
|
||||||
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer,
|
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
|
// Writes the frame into the given planes, stretched to the given width and
|
||||||
// height. The parameter "interpolate" controls whether to interpolate or just
|
// height. The parameter "interpolate" controls whether to interpolate or just
|
||||||
|
@ -665,36 +665,6 @@ class WebRtcVideoRenderFrame : public VideoFrame {
|
|||||||
return 0;
|
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:
|
protected:
|
||||||
virtual VideoFrame* CreateEmptyFrame(int w,
|
virtual VideoFrame* CreateEmptyFrame(int w,
|
||||||
int h,
|
int h,
|
||||||
|
@ -246,30 +246,12 @@ size_t WebRtcVideoFrame::CopyToBuffer(uint8* buffer, size_t size) const {
|
|||||||
return needed;
|
return needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(fbarchard): Refactor into base class and share with lmi
|
|
||||||
size_t WebRtcVideoFrame::ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
size_t WebRtcVideoFrame::ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
||||||
size_t size, int stride_rgb) const {
|
size_t size, int stride_rgb) const {
|
||||||
if (!frame()->Buffer()) {
|
if (!frame()->Buffer()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t width = frame()->Width();
|
return VideoFrame::ConvertToRgbBuffer(to_fourcc, buffer, size, stride_rgb);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcVideoFrame::Attach(
|
void WebRtcVideoFrame::Attach(
|
||||||
|
Reference in New Issue
Block a user