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

Unified Diff: content/common/gpu/media/h264_bit_reader_unittest.cc

Issue 10753005: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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: content/common/gpu/media/h264_bit_reader_unittest.cc
diff --git a/content/common/gpu/media/h264_bit_reader_unittest.cc b/content/common/gpu/media/h264_bit_reader_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf90e02036b9b530a64824a8e5c79776a8a27226
--- /dev/null
+++ b/content/common/gpu/media/h264_bit_reader_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/media/h264_bit_reader.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using content::H264BitReader;
+
+TEST(BitReaderTest, H264StreamTest) {
+ // This stream contains an escape sequence. Its last byte only has 4 bits.
+ // 0001 0010 0011 0100 0000 0000 0000 0000 0000 0011 0101 0110 0111 0000
+ uint8 buffer[] = {0x12, 0x34, 0x00, 0x00, 0x03, 0x56, 0x70};
+ H264BitReader reader;
+ uint8 value8;
+ uint32 value32;
+
+ reader.Initialize(buffer, sizeof(buffer));
+ EXPECT_EQ(reader.Tell(), 0);
+ EXPECT_TRUE(reader.ReadBits(4, &value8));
+ EXPECT_EQ(value8, 1u);
+ EXPECT_EQ(reader.Tell(), 4);
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.ReadBits(8, &value8));
+ EXPECT_EQ(value8, 0x23u);
+ EXPECT_EQ(reader.Tell(), 12);
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.ReadBits(24, &value32));
+ EXPECT_EQ(value32, 0x400005u);
+ EXPECT_EQ(reader.Tell(), 44); // Include the skipped escape byte
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.ReadBits(8, &value8));
+ EXPECT_EQ(value8, 0x67u);
+ EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte
+ EXPECT_FALSE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.ReadBits(0, &value8));
+ EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte
+ EXPECT_FALSE(reader.ReadBits(1, &value8));
+ EXPECT_FALSE(reader.HasMoreData());
+
+ // Do it again using SkipBits
+ reader.Initialize(buffer, sizeof(buffer));
+ EXPECT_EQ(reader.Tell(), 0);
+ EXPECT_TRUE(reader.SkipBits(4));
+ EXPECT_EQ(reader.Tell(), 4);
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.SkipBits(8));
+ EXPECT_EQ(reader.Tell(), 12);
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.SkipBits(24));
+ EXPECT_EQ(reader.Tell(), 44); // Include the skipped escape byte
+ EXPECT_TRUE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.SkipBits(8));
+ EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte
+ EXPECT_FALSE(reader.HasMoreData());
+
+ EXPECT_TRUE(reader.SkipBits(0));
+ EXPECT_FALSE(reader.SkipBits(1));
+ EXPECT_FALSE(reader.HasMoreData());
+}

Powered by Google App Engine
This is Rietveld 408576698