OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/file_util.h" |
| 6 #include "media/base/container_names.h" |
| 7 #include "media/base/test_data_util.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 namespace container_names { |
| 13 |
| 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 |
| 16 // failed. |
| 17 #define VERIFY(buffer, name) \ |
| 18 EXPECT_EQ(name, \ |
| 19 DetermineContainer(reinterpret_cast<const uint8*>(buffer), \ |
| 20 sizeof(buffer))) |
| 21 |
| 22 // Test that small buffers are handled correctly. |
| 23 TEST(ContainerNamesTest, CheckSmallBuffer) { |
| 24 // Empty buffer. |
| 25 char buffer[0]; |
| 26 VERIFY(buffer, CONTAINER_UNKNOWN); |
| 27 |
| 28 // Try a simple SRT file. |
| 29 char buffer1[] = |
| 30 "1\n" |
| 31 "00:03:23,550 --> 00:03:24,375\n" |
| 32 "You always had a hard time finding your place in this world.\n" |
| 33 "\n" |
| 34 "2\n" |
| 35 "00:03:24,476 --> 00:03:25,175\n" |
| 36 "What are you talking about?\n"; |
| 37 VERIFY(buffer1, CONTAINER_SRT); |
| 38 |
| 39 // HLS has it's own loop. |
| 40 char buffer2[] = "#EXTM3U" |
| 41 "some other random stuff" |
| 42 "#EXT-X-MEDIA-SEQUENCE:"; |
| 43 VERIFY(buffer2, CONTAINER_HLS); |
| 44 |
| 45 // Try a large buffer all zeros. |
| 46 char buffer3[4096]; |
| 47 memset(buffer3, 0, sizeof(buffer3)); |
| 48 VERIFY(buffer3, CONTAINER_UNKNOWN); |
| 49 |
| 50 // Reuse buffer, but all \n this time. |
| 51 memset(buffer3, '\n', sizeof(buffer3)); |
| 52 VERIFY(buffer3, CONTAINER_UNKNOWN); |
| 53 } |
| 54 |
| 55 #define BYTE_ORDER_MARK "\xef\xbb\xbf" |
| 56 |
| 57 // Note that the comparisons need at least 12 bytes, so make sure the buffer is |
| 58 // at least that size. |
| 59 const char kAmrBuffer[12] = "#!AMR"; |
| 60 uint8 kAsfBuffer[] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, |
| 61 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }; |
| 62 const char kAss1Buffer[] = "[Script Info]"; |
| 63 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, |
| 65 0, 0, 0, 0, 0, 32, 64, 229, 136, 128, 0, 0, 0, 0, 'a', |
| 66 'a', 'c', ' ', 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, |
| 67 0, 2, 0, 0, 0, 0 }; |
| 68 const char kDtshdBuffer[12] = "DTSHDHDR"; |
| 69 const char kDxaBuffer[16] = "DEXA"; |
| 70 const char kFlacBuffer[12] = "fLaC"; |
| 71 uint8 kFlvBuffer[12] = { 'F', 'L', 'V', 0, 0, 0, 0, 1, 0, 0, 0, 0 }; |
| 72 uint8 kIrcamBuffer[] = { '\x64', '\xa3', 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 }; |
| 73 const char kRm1Buffer[12] = ".RMF\0\0"; |
| 74 const char kRm2Buffer[12] = ".ra\xfd"; |
| 75 uint8 kWtvBuffer[] = { 0xb7, 0xd8, 0x00, 0x20, 0x37, 0x49, 0xda, 0x11, 0xa6, |
| 76 0x4e, 0x00, 0x07, 0xe9, 0x5e, 0xad, 0x8d }; |
| 77 |
| 78 // Test that containers that start with fixed strings are handled correctly. |
| 79 // This is to verify that the TAG matches the first 4 characters of the string. |
| 80 TEST(ContainerNamesTest, CheckFixedStrings) { |
| 81 VERIFY(kAmrBuffer, CONTAINER_AMR); |
| 82 VERIFY(kAsfBuffer, CONTAINER_ASF); |
| 83 VERIFY(kAss1Buffer, CONTAINER_ASS); |
| 84 VERIFY(kAss2Buffer, CONTAINER_ASS); |
| 85 VERIFY(kCafBuffer, CONTAINER_CAF); |
| 86 VERIFY(kDtshdBuffer, CONTAINER_DTSHD); |
| 87 VERIFY(kDxaBuffer, CONTAINER_DXA); |
| 88 VERIFY(kFlacBuffer, CONTAINER_FLAC); |
| 89 VERIFY(kFlvBuffer, CONTAINER_FLV); |
| 90 VERIFY(kIrcamBuffer, CONTAINER_IRCAM); |
| 91 VERIFY(kRm1Buffer, CONTAINER_RM); |
| 92 VERIFY(kRm2Buffer, CONTAINER_RM); |
| 93 VERIFY(kWtvBuffer, CONTAINER_WTV); |
| 94 } |
| 95 |
| 96 // Determine the container type of a specified file. |
| 97 void TestFile(FFmpegContainerName expected, const base::FilePath& filename) { |
| 98 char buffer[8192]; |
| 99 size_t read = file_util::ReadFile(filename, buffer, sizeof(buffer)); |
| 100 |
| 101 // Now verify the type. |
| 102 EXPECT_EQ(expected, |
| 103 DetermineContainer(reinterpret_cast<const uint8*>(buffer), read)) |
| 104 << "Failure with file " << filename.value(); |
| 105 } |
| 106 |
| 107 // Test several OGG files to ensure that the container is detected properly. |
| 108 TEST(ContainerNamesTest, FileCheckOGG) { |
| 109 TestFile(CONTAINER_OGG, GetTestDataFilePath("bear.ogv")); |
| 110 TestFile(CONTAINER_OGG, GetTestDataFilePath("9ch.ogg")); |
| 111 } |
| 112 |
| 113 // Test several WAV files to ensure that the container is detected properly. |
| 114 TEST(ContainerNamesTest, FileCheckWAV) { |
| 115 TestFile(CONTAINER_WAV, GetTestDataFilePath("4ch.wav")); |
| 116 TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_f32le.wav")); |
| 117 TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_s16le.wav")); |
| 118 } |
| 119 |
| 120 // Test several MOV files to ensure that the container is detected properly. |
| 121 TEST(ContainerNamesTest, FileCheckMOV) { |
| 122 TestFile(CONTAINER_MOV, GetTestDataFilePath("bear-1280x720.mp4")); |
| 123 TestFile(CONTAINER_MOV, GetTestDataFilePath("sfx.m4a")); |
| 124 } |
| 125 |
| 126 // Test several WEBM files to ensure that the container is detected properly. |
| 127 TEST(ContainerNamesTest, FileCheckWEBM) { |
| 128 TestFile(CONTAINER_WEBM, GetTestDataFilePath("bear-320x240.webm")); |
| 129 TestFile(CONTAINER_WEBM, GetTestDataFilePath("no_streams.webm")); |
| 130 TestFile(CONTAINER_WEBM, GetTestDataFilePath("webm_ebml_element")); |
| 131 } |
| 132 |
| 133 // Test several MP3 files to ensure that the container is detected properly. |
| 134 TEST(ContainerNamesTest, FileCheckMP3) { |
| 135 TestFile(CONTAINER_MP3, GetTestDataFilePath("id3_test.mp3")); |
| 136 TestFile(CONTAINER_MP3, GetTestDataFilePath("sfx.mp3")); |
| 137 } |
| 138 |
| 139 // Try a few non containers. |
| 140 TEST(ContainerNamesTest, FileCheckUNKNOWN) { |
| 141 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("ten_byte_file")); |
| 142 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("README")); |
| 143 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_P422.yuv")); |
| 144 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_RGB24.rgb")); |
| 145 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("webm_vp8_track_entry")); |
| 146 } |
| 147 |
| 148 } // namespace container_names |
| 149 |
| 150 } // namespace media |
OLD | NEW |