Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1137)

Unified Diff: webrtc/common_video/video_frame_buffer.cc

Issue 2528153002: Add I420Buffer::Copy method taking plane pointers as input. (Closed)
Patch Set: Reordered methods. Use RTC_CHECK_EQ. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_video/include/video_frame_buffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_video/video_frame_buffer.cc
diff --git a/webrtc/common_video/video_frame_buffer.cc b/webrtc/common_video/video_frame_buffer.cc
index 1ee97531b07aac91a9b169a08ddbba3c9b5e1477..d23b4c5d45417e2d738cf226235479ceae06a8aa 100644
--- a/webrtc/common_video/video_frame_buffer.cc
+++ b/webrtc/common_video/video_frame_buffer.cc
@@ -61,10 +61,12 @@ I420Buffer::I420Buffer(int width,
I420Buffer::~I420Buffer() {
}
+// static
rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, int height) {
return new rtc::RefCountedObject<I420Buffer>(width, height);
}
+// static
rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width,
int height,
int stride_y,
@@ -74,6 +76,67 @@ rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width,
width, height, stride_y, stride_u, stride_v);
}
+// static
+rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(
+ const VideoFrameBuffer& source) {
+ return Copy(source.width(), source.height(),
+ source.DataY(), source.StrideY(),
+ source.DataU(), source.StrideU(),
+ source.DataV(), source.StrideV());
+}
+
+// static
+rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(
+ int width, int height,
+ const uint8_t* data_y, int stride_y,
+ const uint8_t* data_u, int stride_u,
+ const uint8_t* data_v, int stride_v) {
+ // Note: May use different strides than the input data.
+ rtc::scoped_refptr<I420Buffer> buffer = Create(width, height);
+ RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y,
+ data_u, stride_u,
+ data_v, stride_v,
+ buffer->MutableDataY(), buffer->StrideY(),
+ buffer->MutableDataU(), buffer->StrideU(),
+ buffer->MutableDataV(), buffer->StrideV(),
+ width, height));
+ return buffer;
+}
+
+// static
+rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate(
+ rtc::scoped_refptr<VideoFrameBuffer> src,
+ VideoRotation rotation) {
+ RTC_CHECK(src->DataY());
nisse-webrtc 2016/11/28 09:44:54 I also changed these from DCHECK to CHECK. I think
+ RTC_CHECK(src->DataU());
+ RTC_CHECK(src->DataV());
+
+ if (rotation == webrtc::kVideoRotation_0) {
+ return src;
+ }
+
+ int rotated_width = src->width();
+ int rotated_height = src->height();
+ if (rotation == webrtc::kVideoRotation_90 ||
+ rotation == webrtc::kVideoRotation_270) {
+ std::swap(rotated_width, rotated_height);
+ }
+
+ rtc::scoped_refptr<webrtc::I420Buffer> buffer =
+ I420Buffer::Create(rotated_width, rotated_height);
+
+ RTC_CHECK_EQ(0, libyuv::I420Rotate(
nisse-webrtc 2016/11/28 09:44:54 And this is changed from res = ...; RTC_DCHECK_EQ(
+ src->DataY(), src->StrideY(),
+ src->DataU(), src->StrideU(),
+ src->DataV(), src->StrideV(),
+ buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(),
+ buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(),
+ src->width(), src->height(),
+ static_cast<libyuv::RotationMode>(rotation)));
+
+ return buffer;
+}
+
void I420Buffer::InitializeData() {
memset(data_.get(), 0,
I420DataSize(height_, stride_y_, stride_u_, stride_v_));
@@ -126,23 +189,6 @@ rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() {
return nullptr;
}
-// static
-rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(
- const VideoFrameBuffer& source) {
- int width = source.width();
- int height = source.height();
- rtc::scoped_refptr<I420Buffer> target = I420Buffer::Create(width, height);
- RTC_CHECK(libyuv::I420Copy(source.DataY(), source.StrideY(),
- source.DataU(), source.StrideU(),
- source.DataV(), source.StrideV(),
- target->MutableDataY(), target->StrideY(),
- target->MutableDataU(), target->StrideU(),
- target->MutableDataV(), target->StrideV(),
- width, height) == 0);
-
- return target;
-}
-
void I420Buffer::SetToBlack() {
RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(),
MutableDataU(), StrideU(),
@@ -205,41 +251,6 @@ void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) {
CropAndScaleFrom(src, 0, 0, src.width(), src.height());
}
-// static
-rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate(
- rtc::scoped_refptr<VideoFrameBuffer> src,
- VideoRotation rotation) {
- RTC_DCHECK(src->DataY());
- RTC_DCHECK(src->DataU());
- RTC_DCHECK(src->DataV());
-
- if (rotation == webrtc::kVideoRotation_0) {
- return src;
- }
-
- int rotated_width = src->width();
- int rotated_height = src->height();
- if (rotation == webrtc::kVideoRotation_90 ||
- rotation == webrtc::kVideoRotation_270) {
- std::swap(rotated_width, rotated_height);
- }
-
- rtc::scoped_refptr<webrtc::I420Buffer> buffer =
- I420Buffer::Create(rotated_width, rotated_height);
-
- int res = libyuv::I420Rotate(
- src->DataY(), src->StrideY(),
- src->DataU(), src->StrideU(),
- src->DataV(), src->StrideV(),
- buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(),
- buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(),
- src->width(), src->height(),
- static_cast<libyuv::RotationMode>(rotation));
- RTC_DCHECK_EQ(res, 0);
-
- return buffer;
-}
-
NativeHandleBuffer::NativeHandleBuffer(void* native_handle,
int width,
int height)
« no previous file with comments | « webrtc/common_video/include/video_frame_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698