OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/media/h264_bit_reader.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 using content::H264BitReader; |
| 10 |
| 11 TEST(BitReaderTest, H264StreamTest) { |
| 12 // This stream contains an escape sequence. Its last byte only has 4 bits. |
| 13 // 0001 0010 0011 0100 0000 0000 0000 0000 0000 0011 0101 0110 0111 0000 |
| 14 uint8 buffer[] = {0x12, 0x34, 0x00, 0x00, 0x03, 0x56, 0x70}; |
| 15 H264BitReader reader; |
| 16 uint8 value8; |
| 17 uint32 value32; |
| 18 |
| 19 reader.Initialize(buffer, sizeof(buffer)); |
| 20 EXPECT_EQ(reader.Tell(), 0); |
| 21 EXPECT_TRUE(reader.ReadBits(4, &value8)); |
| 22 EXPECT_EQ(value8, 1u); |
| 23 EXPECT_EQ(reader.Tell(), 4); |
| 24 EXPECT_TRUE(reader.HasMoreData()); |
| 25 |
| 26 EXPECT_TRUE(reader.ReadBits(8, &value8)); |
| 27 EXPECT_EQ(value8, 0x23u); |
| 28 EXPECT_EQ(reader.Tell(), 12); |
| 29 EXPECT_TRUE(reader.HasMoreData()); |
| 30 |
| 31 EXPECT_TRUE(reader.ReadBits(24, &value32)); |
| 32 EXPECT_EQ(value32, 0x400005u); |
| 33 EXPECT_EQ(reader.Tell(), 44); // Include the skipped escape byte |
| 34 EXPECT_TRUE(reader.HasMoreData()); |
| 35 |
| 36 EXPECT_TRUE(reader.ReadBits(8, &value8)); |
| 37 EXPECT_EQ(value8, 0x67u); |
| 38 EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte |
| 39 EXPECT_FALSE(reader.HasMoreData()); |
| 40 |
| 41 EXPECT_TRUE(reader.ReadBits(0, &value8)); |
| 42 EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte |
| 43 EXPECT_FALSE(reader.ReadBits(1, &value8)); |
| 44 EXPECT_FALSE(reader.HasMoreData()); |
| 45 |
| 46 // Do it again using SkipBits |
| 47 reader.Initialize(buffer, sizeof(buffer)); |
| 48 EXPECT_EQ(reader.Tell(), 0); |
| 49 EXPECT_TRUE(reader.SkipBits(4)); |
| 50 EXPECT_EQ(reader.Tell(), 4); |
| 51 EXPECT_TRUE(reader.HasMoreData()); |
| 52 |
| 53 EXPECT_TRUE(reader.SkipBits(8)); |
| 54 EXPECT_EQ(reader.Tell(), 12); |
| 55 EXPECT_TRUE(reader.HasMoreData()); |
| 56 |
| 57 EXPECT_TRUE(reader.SkipBits(24)); |
| 58 EXPECT_EQ(reader.Tell(), 44); // Include the skipped escape byte |
| 59 EXPECT_TRUE(reader.HasMoreData()); |
| 60 |
| 61 EXPECT_TRUE(reader.SkipBits(8)); |
| 62 EXPECT_EQ(reader.Tell(), 52); // Include the skipped escape byte |
| 63 EXPECT_FALSE(reader.HasMoreData()); |
| 64 |
| 65 EXPECT_TRUE(reader.SkipBits(0)); |
| 66 EXPECT_FALSE(reader.SkipBits(1)); |
| 67 EXPECT_FALSE(reader.HasMoreData()); |
| 68 } |
OLD | NEW |