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

Unified Diff: media/base/video_frame_unittest.cc

Issue 9766007: Fix incorrect VideoFrame::row_bytes() for RGB. Add tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typos. Created 8 years, 9 months 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
Index: media/base/video_frame_unittest.cc
diff --git a/media/base/video_frame_unittest.cc b/media/base/video_frame_unittest.cc
index d90469bac3d43da2d2010b5fd870f60c7a17f9a3..16f25204889b4b568b85cf711fefcbac96d0ddf8 100644
--- a/media/base/video_frame_unittest.cc
+++ b/media/base/video_frame_unittest.cc
@@ -5,6 +5,7 @@
#include "media/base/video_frame.h"
#include "base/format_macros.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/stringprintf.h"
#include "media/base/buffers.h"
@@ -123,6 +124,12 @@ TEST(VideoFrame, CreateFrame) {
EXPECT_TRUE(frame->IsEndOfStream());
}
+static inline size_t RoundUp(size_t value, size_t alignment) {
Ami GONE FROM CHROMIUM 2012/03/21 04:33:44 If inline was extraneous this could easily become
DaleCurtis 2012/03/22 01:24:43 Aside from the DCHECK it's just a simple return me
Ami GONE FROM CHROMIUM 2012/03/22 10:53:25 Yes.
+ // Check that |alignment| is a power of 2.
+ DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
Ami GONE FROM CHROMIUM 2012/03/21 04:33:44 s/DCHECK/ASSERT_TRUE/ (this is something I'm guil
+ return ((value + (alignment - 1)) & ~(alignment-1));
+}
+
TEST(VideoFrame, CreateBlackFrame) {
const size_t kWidth = 2;
const size_t kHeight = 2;
@@ -160,4 +167,72 @@ TEST(VideoFrame, CreateBlackFrame) {
}
}
+TEST(VideoFrame, CheckRowSizes) {
DaleCurtis 2012/03/20 22:54:06 A bit lengthy, but the generic version proved just
+ const size_t kWidth = 61;
+ const size_t kHeight = 31;
+ const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337);
+ const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667);
+
+ // Ensure each frame format yields the correct number of rows and row_bytes.
Ami GONE FROM CHROMIUM 2012/03/21 04:33:44 This comment belongs at the top of the TEST(). But
DaleCurtis 2012/03/22 01:24:43 I think it sounds great and was similar to what I
+ scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame(
+ VideoFrame::RGB555, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 2);
+ EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 2, 8));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::RGB565, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 2);
+ EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 2, 8));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::RGB24, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 3);
+ EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 3, 8));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::RGB32, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 4);
+ EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 4, 8));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::RGBA, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 4);
+ EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 4, 8));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::YV12, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kYPlane), kHeight);
+ EXPECT_EQ(frame->rows(VideoFrame::kUPlane), RoundUp(kHeight, 2) / 2);
+ EXPECT_EQ(frame->rows(VideoFrame::kVPlane), RoundUp(kHeight, 2) / 2);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kYPlane), kWidth);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kUPlane), RoundUp(kWidth, 2) / 2);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kVPlane), RoundUp(kWidth, 2) / 2);
+ EXPECT_EQ(frame->stride(VideoFrame::kYPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kYPlane), 4));
+ EXPECT_EQ(frame->stride(VideoFrame::kUPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kUPlane), 4));
+ EXPECT_EQ(frame->stride(VideoFrame::kVPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kVPlane), 4));
+
+ frame = VideoFrame::CreateFrame(
+ VideoFrame::YV16, kWidth, kHeight, kTimestampA, kDurationA);
+ EXPECT_EQ(frame->rows(VideoFrame::kYPlane), kHeight);
+ EXPECT_EQ(frame->rows(VideoFrame::kUPlane), kHeight);
+ EXPECT_EQ(frame->rows(VideoFrame::kVPlane), kHeight);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kYPlane), kWidth);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kUPlane), RoundUp(kWidth, 2) / 2);
+ EXPECT_EQ(frame->row_bytes(VideoFrame::kVPlane), RoundUp(kWidth, 2) / 2);
+ EXPECT_EQ(frame->stride(VideoFrame::kYPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kYPlane), 4));
+ EXPECT_EQ(frame->stride(VideoFrame::kUPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kUPlane), 4));
+ EXPECT_EQ(frame->stride(VideoFrame::kVPlane), RoundUp(frame->row_bytes(
+ VideoFrame::kVPlane), 4));
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698