OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "media/base/container_names.h" | 6 #include "media/base/container_names.h" |
7 #include "media/base/test_data_util.h" | 7 #include "media/base/test_data_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 namespace container_names { | 12 namespace container_names { |
13 | 13 |
14 // Using a macros to simplify tests. Since EXPECT_EQ outputs the second argument | 14 // Using a macros to simplify tests. Since EXPECT_EQ outputs the second argument |
15 // as a string when it fails, this lets the output identify what item actually | 15 // as a string when it fails, this lets the output identify what item actually |
16 // failed. | 16 // failed. |
17 #define VERIFY(buffer, name) \ | 17 #define VERIFY(buffer, name) \ |
18 EXPECT_EQ(name, \ | 18 EXPECT_EQ(name, DetermineContainer(reinterpret_cast<const uint8_t*>(buffer), \ |
19 DetermineContainer(reinterpret_cast<const uint8*>(buffer), \ | 19 sizeof(buffer))) |
20 sizeof(buffer))) | |
21 | 20 |
22 // Test that small buffers are handled correctly. | 21 // Test that small buffers are handled correctly. |
23 TEST(ContainerNamesTest, CheckSmallBuffer) { | 22 TEST(ContainerNamesTest, CheckSmallBuffer) { |
24 // Empty buffer. | 23 // Empty buffer. |
25 char buffer[1]; // ([0] not allowed on win) | 24 char buffer[1]; // ([0] not allowed on win) |
26 VERIFY(buffer, CONTAINER_UNKNOWN); | 25 VERIFY(buffer, CONTAINER_UNKNOWN); |
27 | 26 |
28 // Try a simple SRT file. | 27 // Try a simple SRT file. |
29 char buffer1[] = | 28 char buffer1[] = |
30 "1\n" | 29 "1\n" |
(...skipping 19 matching lines...) Expand all Loading... |
50 // Reuse buffer, but all \n this time. | 49 // Reuse buffer, but all \n this time. |
51 memset(buffer3, '\n', sizeof(buffer3)); | 50 memset(buffer3, '\n', sizeof(buffer3)); |
52 VERIFY(buffer3, CONTAINER_UNKNOWN); | 51 VERIFY(buffer3, CONTAINER_UNKNOWN); |
53 } | 52 } |
54 | 53 |
55 #define BYTE_ORDER_MARK "\xef\xbb\xbf" | 54 #define BYTE_ORDER_MARK "\xef\xbb\xbf" |
56 | 55 |
57 // Note that the comparisons need at least 12 bytes, so make sure the buffer is | 56 // Note that the comparisons need at least 12 bytes, so make sure the buffer is |
58 // at least that size. | 57 // at least that size. |
59 const char kAmrBuffer[12] = "#!AMR"; | 58 const char kAmrBuffer[12] = "#!AMR"; |
60 uint8 kAsfBuffer[] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, | 59 uint8_t kAsfBuffer[] = {0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, |
61 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }; | 60 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}; |
62 const char kAss1Buffer[] = "[Script Info]"; | 61 const char kAss1Buffer[] = "[Script Info]"; |
63 const char kAss2Buffer[] = BYTE_ORDER_MARK "[Script Info]"; | 62 const char kAss2Buffer[] = BYTE_ORDER_MARK "[Script Info]"; |
64 uint8 kCafBuffer[] = { 'c', 'a', 'f', 'f', 0, 1, 0, 0, 'd', 'e', 's', 'c', 0, 0, | 63 uint8_t kCafBuffer[] = { |
65 0, 0, 0, 0, 0, 32, 64, 229, 136, 128, 0, 0, 0, 0, 'a', | 64 'c', 'a', 'f', 'f', 0, 1, 0, 0, 'd', 'e', 's', 'c', 0, 0, 0, 0, 0, 0, 0, |
66 'a', 'c', ' ', 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, | 65 32, 64, 229, 136, 128, 0, 0, 0, 0, 'a', 'a', 'c', ' ', 0, 0, 0, 2, 0, 0, |
67 0, 2, 0, 0, 0, 0 }; | 66 0, 0, 0, 0, 4, 0, 0, 0, 0, 2, 0, 0, 0, 0}; |
68 const char kDtshdBuffer[12] = "DTSHDHDR"; | 67 const char kDtshdBuffer[12] = "DTSHDHDR"; |
69 const char kDxaBuffer[16] = "DEXA"; | 68 const char kDxaBuffer[16] = "DEXA"; |
70 const char kFlacBuffer[12] = "fLaC"; | 69 const char kFlacBuffer[12] = "fLaC"; |
71 uint8 kFlvBuffer[12] = { 'F', 'L', 'V', 0, 0, 0, 0, 1, 0, 0, 0, 0 }; | 70 uint8_t kFlvBuffer[12] = {'F', 'L', 'V', 0, 0, 0, 0, 1, 0, 0, 0, 0}; |
72 uint8 kIrcamBuffer[] = { 0x64, 0xa3, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 }; | 71 uint8_t kIrcamBuffer[] = {0x64, 0xa3, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1}; |
73 const char kRm1Buffer[12] = ".RMF\0\0"; | 72 const char kRm1Buffer[12] = ".RMF\0\0"; |
74 const char kRm2Buffer[12] = ".ra\xfd"; | 73 const char kRm2Buffer[12] = ".ra\xfd"; |
75 uint8 kWtvBuffer[] = { 0xb7, 0xd8, 0x00, 0x20, 0x37, 0x49, 0xda, 0x11, 0xa6, | 74 uint8_t kWtvBuffer[] = {0xb7, 0xd8, 0x00, 0x20, 0x37, 0x49, 0xda, 0x11, |
76 0x4e, 0x00, 0x07, 0xe9, 0x5e, 0xad, 0x8d }; | 75 0xa6, 0x4e, 0x00, 0x07, 0xe9, 0x5e, 0xad, 0x8d}; |
77 uint8 kBug263073Buffer[] = { | 76 uint8_t kBug263073Buffer[] = { |
78 0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x6d, 0x70, 0x34, 0x32, | 77 0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x6d, 0x70, 0x34, |
79 0x00, 0x00, 0x00, 0x00, 0x69, 0x73, 0x6f, 0x6d, 0x6d, 0x70, 0x34, 0x32, | 78 0x32, 0x00, 0x00, 0x00, 0x00, 0x69, 0x73, 0x6f, 0x6d, 0x6d, 0x70, |
80 0x00, 0x00, 0x00, 0x01, 0x6d, 0x64, 0x61, 0x74, 0x00, 0x00, 0x00, 0x00, | 79 0x34, 0x32, 0x00, 0x00, 0x00, 0x01, 0x6d, 0x64, 0x61, 0x74, 0x00, |
81 0xaa, 0x2e, 0x22, 0xcf, 0x00, 0x00, 0x00, 0x37, 0x67, 0x64, 0x00, 0x28, | 80 0x00, 0x00, 0x00, 0xaa, 0x2e, 0x22, 0xcf, 0x00, 0x00, 0x00, 0x37, |
82 0xac, 0x2c, 0xa4, 0x01, 0xe0, 0x08, 0x9f, 0x97, 0x01, 0x52, 0x02, 0x02, | 81 0x67, 0x64, 0x00, 0x28, 0xac, 0x2c, 0xa4, 0x01, 0xe0, 0x08, 0x9f, |
83 0x02, 0x80, 0x00, 0x01}; | 82 0x97, 0x01, 0x52, 0x02, 0x02, 0x02, 0x80, 0x00, 0x01}; |
84 | 83 |
85 // Test that containers that start with fixed strings are handled correctly. | 84 // Test that containers that start with fixed strings are handled correctly. |
86 // This is to verify that the TAG matches the first 4 characters of the string. | 85 // This is to verify that the TAG matches the first 4 characters of the string. |
87 TEST(ContainerNamesTest, CheckFixedStrings) { | 86 TEST(ContainerNamesTest, CheckFixedStrings) { |
88 VERIFY(kAmrBuffer, CONTAINER_AMR); | 87 VERIFY(kAmrBuffer, CONTAINER_AMR); |
89 VERIFY(kAsfBuffer, CONTAINER_ASF); | 88 VERIFY(kAsfBuffer, CONTAINER_ASF); |
90 VERIFY(kAss1Buffer, CONTAINER_ASS); | 89 VERIFY(kAss1Buffer, CONTAINER_ASS); |
91 VERIFY(kAss2Buffer, CONTAINER_ASS); | 90 VERIFY(kAss2Buffer, CONTAINER_ASS); |
92 VERIFY(kCafBuffer, CONTAINER_CAF); | 91 VERIFY(kCafBuffer, CONTAINER_CAF); |
93 VERIFY(kDtshdBuffer, CONTAINER_DTSHD); | 92 VERIFY(kDtshdBuffer, CONTAINER_DTSHD); |
94 VERIFY(kDxaBuffer, CONTAINER_DXA); | 93 VERIFY(kDxaBuffer, CONTAINER_DXA); |
95 VERIFY(kFlacBuffer, CONTAINER_FLAC); | 94 VERIFY(kFlacBuffer, CONTAINER_FLAC); |
96 VERIFY(kFlvBuffer, CONTAINER_FLV); | 95 VERIFY(kFlvBuffer, CONTAINER_FLV); |
97 VERIFY(kIrcamBuffer, CONTAINER_IRCAM); | 96 VERIFY(kIrcamBuffer, CONTAINER_IRCAM); |
98 VERIFY(kRm1Buffer, CONTAINER_RM); | 97 VERIFY(kRm1Buffer, CONTAINER_RM); |
99 VERIFY(kRm2Buffer, CONTAINER_RM); | 98 VERIFY(kRm2Buffer, CONTAINER_RM); |
100 VERIFY(kWtvBuffer, CONTAINER_WTV); | 99 VERIFY(kWtvBuffer, CONTAINER_WTV); |
101 VERIFY(kBug263073Buffer, CONTAINER_MOV); | 100 VERIFY(kBug263073Buffer, CONTAINER_MOV); |
102 } | 101 } |
103 | 102 |
104 // Determine the container type of a specified file. | 103 // Determine the container type of a specified file. |
105 void TestFile(MediaContainerName expected, const base::FilePath& filename) { | 104 void TestFile(MediaContainerName expected, const base::FilePath& filename) { |
106 char buffer[8192]; | 105 char buffer[8192]; |
107 | 106 |
108 // Windows implementation of ReadFile fails if file smaller than desired size, | 107 // Windows implementation of ReadFile fails if file smaller than desired size, |
109 // so use file length if file less than 8192 bytes (http://crbug.com/243885). | 108 // so use file length if file less than 8192 bytes (http://crbug.com/243885). |
110 int read_size = sizeof(buffer); | 109 int read_size = sizeof(buffer); |
111 int64 actual_size; | 110 int64_t actual_size; |
112 if (base::GetFileSize(filename, &actual_size) && actual_size < read_size) | 111 if (base::GetFileSize(filename, &actual_size) && actual_size < read_size) |
113 read_size = actual_size; | 112 read_size = actual_size; |
114 int read = base::ReadFile(filename, buffer, read_size); | 113 int read = base::ReadFile(filename, buffer, read_size); |
115 | 114 |
116 // Now verify the type. | 115 // Now verify the type. |
117 EXPECT_EQ(expected, | 116 EXPECT_EQ(expected, |
118 DetermineContainer(reinterpret_cast<const uint8*>(buffer), read)) | 117 DetermineContainer(reinterpret_cast<const uint8_t*>(buffer), read)) |
119 << "Failure with file " << filename.value(); | 118 << "Failure with file " << filename.value(); |
120 } | 119 } |
121 | 120 |
122 TEST(ContainerNamesTest, FileCheckOGG) { | 121 TEST(ContainerNamesTest, FileCheckOGG) { |
123 TestFile(CONTAINER_OGG, GetTestDataFilePath("bear.ogv")); | 122 TestFile(CONTAINER_OGG, GetTestDataFilePath("bear.ogv")); |
124 TestFile(CONTAINER_OGG, GetTestDataFilePath("9ch.ogg")); | 123 TestFile(CONTAINER_OGG, GetTestDataFilePath("9ch.ogg")); |
125 } | 124 } |
126 | 125 |
127 TEST(ContainerNamesTest, FileCheckWAV) { | 126 TEST(ContainerNamesTest, FileCheckWAV) { |
128 TestFile(CONTAINER_WAV, GetTestDataFilePath("4ch.wav")); | 127 TestFile(CONTAINER_WAV, GetTestDataFilePath("4ch.wav")); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("ten_byte_file")); | 210 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("ten_byte_file")); |
212 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("README")); | 211 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("README")); |
213 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_P422.yuv")); | 212 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_P422.yuv")); |
214 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_RGB24.rgb")); | 213 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_RGB24.rgb")); |
215 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("webm_vp8_track_entry")); | 214 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("webm_vp8_track_entry")); |
216 } | 215 } |
217 | 216 |
218 } // namespace container_names | 217 } // namespace container_names |
219 | 218 |
220 } // namespace media | 219 } // namespace media |
OLD | NEW |