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

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
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 "base/stringprintf.h"
7 #include "media/base/container_names.h"
8 #include "media/base/test_data_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace container_names {
12
13 // Verify the container name matches the result
xhwang 2013/05/06 23:51:27 nit: wrapping too early?
jrummell 2013/05/16 23:48:01 Done.
14 // based on the contents of a buffer.
15 void ExpectContainer(FFmpegContainerName name,
xhwang 2013/05/06 23:51:27 nit: make this function static.
jrummell 2013/05/16 23:48:01 Done.
16 char* buffer,
17 size_t buffer_size) {
18 EXPECT_EQ(
19 name,
20 DetermineContainer(reinterpret_cast<uint8_t*>(buffer), buffer_size));
21 }
22
23 // Test that the names are in the correct sorted order.
24 TEST(ContainerNamesTest, CheckSortOrder) {
25 EXPECT_GT(container_names::ContainerNameMappingSize(), 0);
26 for (int i = 1; i < ContainerNameMappingSize(); ++i) {
27 EXPECT_LT(strcasecmp(ContainerNameMappingItem(i - 1).name,
28 ContainerNameMappingItem(i).name),
29 0)
30 << ContainerNameMappingItem(i - 1).name << " and "
31 << ContainerNameMappingItem(i).name << " are in the wrong order.";
32 }
33 }
34
35 // Test that string lookup works for all names in the list.
36 TEST(ContainerNamesTest, NameLookup) {
37 // Search for all strings.
38 for (int i = 0; i < ContainerNameMappingSize(); ++i) {
39 const char* name = ContainerNameMappingItem(i).name;
40 EXPECT_EQ(ContainerNameMappingItem(i).id, LookupContainer(name))
41 << "Unable to lookup " << name;
42 }
43
44 // Check that some name not in the list fails.
45 EXPECT_EQ(CONTAINER_UNKNOWN, LookupContainer("foo"));
46 // A name before the first one in the list.
47 EXPECT_EQ(CONTAINER_UNKNOWN, LookupContainer(" "));
48 // A name after the last one in the list.
49 EXPECT_EQ(CONTAINER_UNKNOWN, LookupContainer("ZZZ"));
50 }
51
52 #define BYTE_ORDER_MARK "\xef\xbb\xbf"
53
54 // Test that small buffers are handled correctly.
55 TEST(ContainerNamesTest, CheckSmallBufferSize) {
56 // Empty buffer.
57 char buffer[0];
58 ExpectContainer(CONTAINER_UNKNOWN, buffer, 0);
59
60 // Try a simple string
61 char buffer1[] = "******** START SCRIPT ********";
62 ExpectContainer(CONTAINER_SUBVIEWER1, buffer1, strlen(buffer1));
63
64 // Try adding byte order mark at beginning.
65 char buffer2[] = BYTE_ORDER_MARK "Interplay MVE File\x1A\x00\x1A";
66 ExpectContainer(CONTAINER_IPMOVIE, buffer2, 24);
67 // Repeat but leave out a character (so it won't match)
68 ExpectContainer(CONTAINER_UNKNOWN, buffer2, 23);
69
70 // Try a simple SRT file.
71 char buffer3[] =
72 "1\n"
73 "00:03:23,550 --> 00:03:24,375\n"
74 "You always had a hard time finding your place in this world.\n"
75 "\n"
76 "2\n"
77 "00:03:24,476 --> 00:03:25,175\n"
78 "What are you talking about?\n";
79 ExpectContainer(CONTAINER_SRT, buffer3, strlen(buffer3));
80
81 // Try a simple tag. Note that the tag checking requires
82 // at least 12 characters.
83 char buffer4[12] = ".snd";
84 ExpectContainer(CONTAINER_AU, buffer4, sizeof(buffer4));
85
86 // HLS has it's own loop.
87 char buffer5[] = "#EXTM3U"
88 "some other random stuff"
89 "#EXT-X-MEDIA-SEQUENCE:";
90 ExpectContainer(CONTAINER_HLS, buffer5, sizeof(buffer5));
91
92 // PJS has several loops.
93 char buffer6[] = "1234567890, 123456, \"My subtitle.\"\n";
94 ExpectContainer(CONTAINER_PJS, buffer6, sizeof(buffer6));
95 // Repeat but leave out \n\0 at end.
96 ExpectContainer(CONTAINER_PJS, buffer6, sizeof(buffer6) - 2);
97 // Repeat but leave out \"\n\0 at end.
98 ExpectContainer(CONTAINER_UNKNOWN, buffer6, sizeof(buffer6) - 3);
99
100 // Try a large buffer all zeros.
101 char buffer7[4096];
102 memset(buffer7, 0, sizeof(buffer7));
103 ExpectContainer(CONTAINER_UNKNOWN, buffer7, sizeof(buffer7));
104
105 // Reuse buffer, but all \n this time.
106 memset(buffer7, '\n', sizeof(buffer7));
107 ExpectContainer(CONTAINER_UNKNOWN, buffer7, sizeof(buffer7));
108 }
109
110 // Define the test data as string which should return the specfied
111 // FFmpegContainerName. Length needs to be specified if the string
112 // contains embedded \0 characters.
113 struct Mapping {
114 FFmpegContainerName id;
115 int length;
116 const char* name;
117 };
118
119 // The following are the fixed strings compared in ContainerNames.
120 // Since the first 4 characters are used as a TAG, this checks that the
121 // TAG is defined correctly.
122 const Mapping kFixedStrings[] = {
123 { CONTAINER_AMR, 0, "#!AMR" },
124 { CONTAINER_APC, 0, "CRYO_APC" },
125 { CONTAINER_AQTITLE, 0, "-->> 23" },
126 { CONTAINER_ASF, 16, "\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00"
127 "\xaa\x00\x62\xce\x6c" },
128 { CONTAINER_ASS, 0, "[Script Info]" },
129 { CONTAINER_ASS, 0, BYTE_ORDER_MARK "[Script Info]" },
130 { CONTAINER_CONCAT, 0, "ffconcat version 1.0" },
131 { CONTAINER_DNXHD, 43, "\x00\x00\x02\x80\x01 789*123456789*123456789"
132 "*123456789*\x04\xd3" },
133 { CONTAINER_FFMETADATA, 0, ";FFMETADATA" },
134 { CONTAINER_IDF, 12, "\x04\x31\x2e\x34\x00\x00\x00\x00\x4f\x00\x15"
135 "\x00" },
136 { CONTAINER_ILBC, 0, "#!iLBC" },
137 { CONTAINER_ISS, 0, "IMA_ADPCM_Sound" },
138 { CONTAINER_IV8, 0, "\x01\x01\x03\xb8\x80\x60" },
139 { CONTAINER_JV, 0, "JVxx Compression by John M Phillips Copyright "
140 "(C) 1995 The Bitmap Brothers Ltd." },
141 { CONTAINER_LIBNUT, 0, "nut/multimedia container" },
142 { CONTAINER_LXF, 8, "LEITCH\x00\x00" },
143 { CONTAINER_NUV, 0, "NuppelVideo" },
144 { CONTAINER_NUV, 0, "MythTVVideo" },
145 { CONTAINER_PAF, 0, "Packed Animation File V1.0\n(c) 1992-96 "
146 "Amazing Studio\x0a\x1a" },
147 { CONTAINER_REALTEXT, 0, "<window" },
148 { CONTAINER_REALTEXT, 0, BYTE_ORDER_MARK "<window" },
149 { CONTAINER_RPL, 0, "ARMovie\x0A" },
150 { CONTAINER_SAMI, 0, "<SAMI>" },
151 { CONTAINER_SAMI, 0, BYTE_ORDER_MARK "<SAMI>" },
152 { CONTAINER_SMJPEG, 8, "\x00\x0aSMJPEG" },
153 { CONTAINER_VPLAYER, 0, "12:34:56.789=" },
154 { CONTAINER_VOBSUB, 0, "# VobSub index file," },
155 { CONTAINER_VOC, 0, "Creative Voice File\x1A" },
156 { CONTAINER_W64, 42, "riff\x2e\x91\xcf\x11\xa5\xd6\x28\xdb\x04\xc1"
157 "\x00\x00 89*1234wave\xf3\xac\xd3\x11\x8c\xd1"
158 "\x00\xc0\x4f\x8e\xdb\x8a" },
159 { CONTAINER_WEBVTT, 0, "WEBVTT" },
160 { CONTAINER_WEBVTT, 0, BYTE_ORDER_MARK "WEBVTT" },
161 { CONTAINER_WTV, 16, "\xb7\xd8\x00\x20\x37\x49\xda\x11\xa6\x4e\x00"
162 "\x07\xe9\x5e\xad\x8d" },
163 { CONTAINER_YUV4MPEGPIPE, 0, "YUV4MPEG2" }
164 };
165
166 // Test that containers that start with fixed strings are handled correctly.
167 // This is to verify that the TAG matches the first 4 characters of the string.
168 TEST(ContainerNamesTest, CheckFixedStrings) {
169 for (int i = 0; i < static_cast<int>(arraysize(kFixedStrings)); ++i) {
170 char buffer[256];
171 int length = kFixedStrings[i].length;
172 if (length == 0)
173 length = strlen(kFixedStrings[i].name);
174 memcpy(buffer, kFixedStrings[i].name, length);
175 // Put some random characters after the string.
176 buffer[length] = 'a';
177 buffer[length + 1] = 'b';
178 ExpectContainer(kFixedStrings[i].id, buffer, sizeof(buffer));
179 }
180 }
181
182 // Determine the container type of a specified file.
183 void TestFile(FFmpegContainerName expected, const base::FilePath& filename) {
184 char buffer[8192];
185 size_t read = file_util::ReadFile(filename, buffer, sizeof(buffer));
186
187 // Now verify the type.
188 ExpectContainer(expected, buffer, read);
189 }
190
191 // Test several files to ensure that the container is detected properly.
192 TEST(ContainerNamesTest, FileCheck) {
193 TestFile(CONTAINER_OGG, media::GetTestDataFilePath("bear.ogv"));
194 TestFile(CONTAINER_OGG, media::GetTestDataFilePath("9ch.ogg"));
195 TestFile(CONTAINER_WAV, media::GetTestDataFilePath("4ch.wav"));
196 TestFile(CONTAINER_WAV, media::GetTestDataFilePath("sfx_f32le.wav"));
197 TestFile(CONTAINER_WAV, media::GetTestDataFilePath("sfx_s16le.wav"));
198 TestFile(CONTAINER_MOV, media::GetTestDataFilePath("bear-1280x720.mp4"));
199 TestFile(CONTAINER_MOV, media::GetTestDataFilePath("sfx.m4a"));
200 TestFile(CONTAINER_WEBM, media::GetTestDataFilePath("bear-320x240.webm"));
201 TestFile(CONTAINER_MP3, media::GetTestDataFilePath("id3_test.mp3"));
202 TestFile(CONTAINER_MP3, media::GetTestDataFilePath("sfx.mp3"));
203
204 // now try a few non containers
205 TestFile(CONTAINER_UNKNOWN, media::GetTestDataFilePath("ten_byte_file"));
206 TestFile(CONTAINER_UNKNOWN, media::GetTestDataFilePath("README"));
207 TestFile(CONTAINER_UNKNOWN,
208 media::GetTestDataFilePath("bali_640x360_P422.yuv"));
209 TestFile(CONTAINER_UNKNOWN,
210 media::GetTestDataFilePath("bali_640x360_RGB24.rgb"));
211 TestFile(CONTAINER_UNKNOWN,
212 media::GetTestDataFilePath("webm_vp8_track_entry"));
213 }
214
215 } // namespace container_names
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698