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/avc_config_record_builder.h" | |
6 | |
7 #include "content/common/gpu/media/h264_parser.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace { | |
11 | |
12 const uint8 kSPSData[] = { | |
13 0x67, 0x64, 0x00, 0x1f, 0xac, 0x34, 0xec, 0x05, | |
14 0x00, 0x5b, 0xa1, 0x00, 0x00, 0x03, 0x00, 0x01, | |
15 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, | |
16 0x38, | |
17 }; | |
18 | |
19 const uint8 kPPSData[] = { | |
20 0x68, 0xef, 0xb2, 0xc8, 0xb0, | |
21 }; | |
22 | |
23 const uint8 kNALUHeader[] = { | |
24 0x00, 0x00, 0x00, 0x01 | |
25 }; | |
26 | |
27 } // namespace | |
28 | |
29 TEST(AVCConfigRecordBuilderTest, BuildConfig) { | |
30 std::vector<uint8> stream; | |
31 stream.insert(stream.end(), kNALUHeader, | |
32 kNALUHeader + arraysize(kNALUHeader)); | |
33 stream.insert(stream.end(), kSPSData, kSPSData + arraysize(kSPSData)); | |
34 stream.insert(stream.end(), kNALUHeader, | |
35 kNALUHeader + arraysize(kNALUHeader)); | |
36 stream.insert(stream.end(), kPPSData, kPPSData + arraysize(kPPSData)); | |
37 | |
38 content::H264Parser parser; | |
39 parser.SetStream(&stream[0], stream.size()); | |
40 content::H264NALU nalu; | |
41 ASSERT_EQ(parser.AdvanceToNextNALU(&nalu), content::H264Parser::kOk); | |
42 | |
43 content::AVCConfigRecordBuilder config; | |
44 std::vector<uint8> config_data; | |
45 EXPECT_TRUE(config.ProcessNALU(&parser, nalu, &config_data)); | |
46 EXPECT_TRUE(config_data.empty()); | |
47 | |
48 ASSERT_EQ(parser.AdvanceToNextNALU(&nalu), content::H264Parser::kOk); | |
49 | |
50 EXPECT_TRUE(config.ProcessNALU(&parser, nalu, &config_data)); | |
51 EXPECT_TRUE(config_data.empty()); | |
52 | |
53 nalu.nal_unit_type = content::H264NALU::kIDRSlice; | |
54 EXPECT_TRUE(config.ProcessNALU(&parser, nalu, &config_data)); | |
55 EXPECT_FALSE(config_data.empty()); | |
56 EXPECT_EQ(config.coded_width(), 1280); | |
57 EXPECT_EQ(config.coded_height(), 720); | |
58 | |
59 const uint8 kExpectedData[] = { | |
60 0x01, 0x64, 0x00, 0x1f, 0xff, 0xe1, 0x00, 0x19, | |
61 0x67, 0x64, 0x00, 0x1f, 0xac, 0x34, 0xec, 0x05, | |
62 0x00, 0x5b, 0xa1, 0x00, 0x00, 0x03, 0x00, 0x01, | |
63 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, | |
64 0x38, 0x01, 0x00, 0x05, 0x68, 0xef, 0xb2, 0xc8, | |
65 0xb0, | |
66 }; | |
67 std::vector<uint8> expected_config_data( | |
68 kExpectedData, kExpectedData + arraysize(kExpectedData)); | |
69 EXPECT_EQ(config_data, expected_config_data); | |
70 } | |
71 | |
72 // Test building a config record with zero SPS and PPS data. | |
73 TEST(AVCConfigRecordBuilderTest, EmptyConfig) { | |
74 content::AVCConfigRecordBuilder config; | |
75 content::H264Parser parser; | |
76 std::vector<uint8> config_data; | |
77 | |
78 // Feed the builder a slice right away. | |
79 content::H264NALU nalu; | |
80 nalu.nal_unit_type = content::H264NALU::kIDRSlice; | |
81 EXPECT_TRUE(config.ProcessNALU(&parser, nalu, &config_data)); | |
82 EXPECT_FALSE(config_data.empty()); | |
83 EXPECT_EQ(config.coded_width(), 0); | |
84 EXPECT_EQ(config.coded_height(), 0); | |
85 | |
86 const uint8 kExpectedData[] = { | |
87 0x01, 0x0, 0x00, 0x0, 0xff, 0xe0, 0x00, | |
88 }; | |
89 std::vector<uint8> expected_config_data( | |
90 kExpectedData, kExpectedData + arraysize(kExpectedData)); | |
91 EXPECT_EQ(config_data, expected_config_data); | |
92 } | |
OLD | NEW |