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

Side by Side Diff: media/base/container_names_unittest.cc

Issue 14495010: Add UMA stats for audio/video containers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 unified diff | Download patch
« no previous file with comments | « media/base/container_names.cc ('k') | media/filters/ffmpeg_glue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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[1]; // ([0] not allowed on win)
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(MediaContainerName expected, const base::FilePath& filename) {
98 char buffer[8192];
99
100 // Windows implementation of ReadFile fails if file smaller than desired size,
101 // so use file length if file less than 8192 bytes (http://crbug.com/243885).
102 int read_size = sizeof(buffer);
103 int64 actual_size;
104 if (file_util::GetFileSize(filename, &actual_size) && actual_size < read_size)
105 read_size = actual_size;
106 int read = file_util::ReadFile(filename, buffer, read_size);
107
108 // Now verify the type.
109 EXPECT_EQ(expected,
110 DetermineContainer(reinterpret_cast<const uint8*>(buffer), read))
111 << "Failure with file " << filename.value();
112 }
113
114 // Test several OGG files to ensure that the container is detected properly.
115 TEST(ContainerNamesTest, FileCheckOGG) {
116 TestFile(CONTAINER_OGG, GetTestDataFilePath("bear.ogv"));
117 TestFile(CONTAINER_OGG, GetTestDataFilePath("9ch.ogg"));
118 }
119
120 // Test several WAV files to ensure that the container is detected properly.
121 TEST(ContainerNamesTest, FileCheckWAV) {
122 TestFile(CONTAINER_WAV, GetTestDataFilePath("4ch.wav"));
123 TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_f32le.wav"));
124 TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_s16le.wav"));
125 }
126
127 // Test several MOV files to ensure that the container is detected properly.
128 TEST(ContainerNamesTest, FileCheckMOV) {
129 TestFile(CONTAINER_MOV, GetTestDataFilePath("bear-1280x720.mp4"));
130 TestFile(CONTAINER_MOV, GetTestDataFilePath("sfx.m4a"));
131 }
132
133 // Test several WEBM files to ensure that the container is detected properly.
134 TEST(ContainerNamesTest, FileCheckWEBM) {
135 TestFile(CONTAINER_WEBM, GetTestDataFilePath("bear-320x240.webm"));
136 TestFile(CONTAINER_WEBM, GetTestDataFilePath("no_streams.webm"));
137 TestFile(CONTAINER_WEBM, GetTestDataFilePath("webm_ebml_element"));
138 }
139
140 // Test several MP3 files to ensure that the container is detected properly.
141 TEST(ContainerNamesTest, FileCheckMP3) {
142 TestFile(CONTAINER_MP3, GetTestDataFilePath("id3_test.mp3"));
143 TestFile(CONTAINER_MP3, GetTestDataFilePath("sfx.mp3"));
144 }
145
146 // Try a few non containers.
147 TEST(ContainerNamesTest, FileCheckUNKNOWN) {
148 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("ten_byte_file"));
149 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("README"));
150 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_P422.yuv"));
151 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_RGB24.rgb"));
152 TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("webm_vp8_track_entry"));
153 }
154
155 } // namespace container_names
156
157 } // namespace media
OLDNEW
« no previous file with comments | « media/base/container_names.cc ('k') | media/filters/ffmpeg_glue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698