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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: media/base/container_names_unittest.cc
diff --git a/media/base/container_names_unittest.cc b/media/base/container_names_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e9e50729f73cb507f1ab7e1d30ce036552ba396
--- /dev/null
+++ b/media/base/container_names_unittest.cc
@@ -0,0 +1,234 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/stringprintf.h"
+#include "media/base/container_names.h"
+#include "media/base/test_data_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+// Friend class to get access to internals of ContainerNames.
+class ContainerTest : public testing::Test {
+ public:
+ // Returns the number of elements in container_name_mapping.
+ static int MappingSize() {
+ int size = ContainerNames::ContainerNameMappingSize();
+ EXPECT_GT(size, 0);
+ return size;
+ }
+
+ // Returns the mapping at the specified index.
+ static ContainerNameMapping Mapping(int index) {
+ EXPECT_GE(index, 0);
+ EXPECT_LE(index, MappingSize());
+ return ContainerNames::container_name_mapping[index];
+ }
+
+ // Determine the container based on a name.
+ static FFmpegContainerName Lookup(const char* name) {
+ return ContainerNames::LookupContainer(name);
+ }
+
+ // Verify the container name matches the result based
+ // on the contents of a buffer.
+ static void Verify(FFmpegContainerName name,
xhwang 2013/05/03 19:59:06 Verify seems too generic. How about ExpectContaine
jrummell 2013/05/03 23:56:21 Done.
+ char* buffer,
+ size_t buffer_size) {
+ EXPECT_EQ(name,
+ ContainerNames::DetermineContainer(
+ reinterpret_cast<uint8_t*>(buffer), buffer_size));
+ }
+};
+
+// Test that the names are in the correct sorted order.
+TEST(ContainerNamesTest, CheckSortOrder) {
+ for (int i = 1; i < ContainerTest::MappingSize(); ++i) {
+ EXPECT_LT(strcasecmp(ContainerTest::Mapping(i - 1).name,
+ ContainerTest::Mapping(i).name),
+ 0)
+ << ContainerTest::Mapping(i - 1).name << " and "
+ << ContainerTest::Mapping(i).name << " are in the wrong order.";
+ }
+}
+
+// Test that string lookup works for all names in the list.
+TEST(ContainerNamesTest, NameLookup) {
+ // Search for all strings.
+ for (int i = 0; i < ContainerTest::MappingSize(); ++i) {
+ const char* name = ContainerTest::Mapping(i).name;
+ EXPECT_EQ(ContainerTest::Mapping(i).id, ContainerTest::Lookup(name))
+ << "Unable to lookup " << name;
+ }
+
+ // Check that some name not in the list fails.
+ EXPECT_EQ(CONTAINER_UNKNOWN, ContainerTest::Lookup("foo"));
+ // A name before the first one in the list.
+ EXPECT_EQ(CONTAINER_UNKNOWN, ContainerTest::Lookup(" "));
+ // A name after the last one in the list.
+ EXPECT_EQ(CONTAINER_UNKNOWN, ContainerTest::Lookup("ZZZ"));
+}
+
+#define BYTE_ORDER_MARK "\xef\xbb\xbf"
+
+// Test that small buffers are handled correctly.
+TEST(ContainerNamesTest, CheckSmallBufferSize) {
+ // Empty buffer.
+ char buffer[0];
+ ContainerTest::Verify(CONTAINER_UNKNOWN, buffer, 0);
+
+ // Try a simple string
+ char buffer1[] = "******** START SCRIPT ********";
+ ContainerTest::Verify(CONTAINER_SUBVIEWER1, buffer1, strlen(buffer1));
+
+ // Try adding byte order mark at beginning.
+ char buffer2[] = BYTE_ORDER_MARK "Interplay MVE File\x1A\x00\x1A";
+ ContainerTest::Verify(CONTAINER_IPMOVIE, buffer2, 24);
+ // Repeat but leave out a character (so it won't match)
+ ContainerTest::Verify(CONTAINER_UNKNOWN, buffer2, 23);
+
+ // Try a simple SRT file.
+ char buffer3[] =
+ "1\n"
+ "00:03:23,550 --> 00:03:24,375\n"
+ "You always had a hard time finding your place in this world.\n"
+ "\n"
+ "2\n"
+ "00:03:24,476 --> 00:03:25,175\n"
+ "What are you talking about?\n";
+ ContainerTest::Verify(CONTAINER_SRT, buffer3, strlen(buffer3));
+
+ // Try a simple tag. Note that the tag checking requires
+ // at least 128 characters.
+ char buffer4[256] = ".snd";
xhwang 2013/05/03 19:59:06 will 128 work?
jrummell 2013/05/03 23:56:21 Done.
+ ContainerTest::Verify(CONTAINER_AU, buffer4, sizeof(buffer4));
+
+ // HLS has it's own loop, so try it
xhwang 2013/05/03 19:59:06 Here and below, comments should be complete senten
jrummell 2013/05/03 23:56:21 Done.
+ char buffer5[256] = "#EXTM3U"
+ "some other random stuff"
xhwang 2013/05/03 19:59:06 indent
jrummell 2013/05/03 23:56:21 Done.
+ "#EXT-X-MEDIA-SEQUENCE:";
+ ContainerTest::Verify(CONTAINER_HLS, buffer5, sizeof(buffer5));
+
+ // PJS has several loops, so try it
+ char buffer6[256] = "1234567890,123456,0\n"
+ "some filler\n"
xhwang 2013/05/03 19:59:06 indent
jrummell 2013/05/03 23:56:21 Done.
+ "\"quoted string\"\n";
+ ContainerTest::Verify(CONTAINER_PJS, buffer6, sizeof(buffer6));
+
+ // try a large buffer all 0
+ char buffer7[4096];
+ memset(buffer7, 0, sizeof(buffer7));
+ ContainerTest::Verify(CONTAINER_UNKNOWN, buffer7, sizeof(buffer7));
+
+ // reuse buffer, but all \n this time
+ memset(buffer7, '\n', sizeof(buffer7));
+ ContainerTest::Verify(CONTAINER_UNKNOWN, buffer7, sizeof(buffer7));
+}
+
+struct Mapping {
xhwang 2013/05/03 19:59:06 Document what this is.
jrummell 2013/05/03 23:56:21 Done.
+ FFmpegContainerName id;
+ int length;
xhwang 2013/05/03 19:59:06 Comment about what this length is. Why you have 0
jrummell 2013/05/03 23:56:21 Done.
+ const char* name;
+};
+
+// The following are the fixed strings compared in ContainerNames.
+// Since the first 4 characters are used as a TAG, this checks that the
+// TAG is defined correctly.
+const Mapping fixed_strings[] = {
xhwang 2013/05/03 19:59:06 Use kCamelCase for consts.
jrummell 2013/05/03 23:56:21 Done.
+ { CONTAINER_AMR, 0, "#!AMR" },
+ { CONTAINER_APC, 0, "CRYO_APC" },
+ { CONTAINER_AQTITLE, 0, "-->> 23" },
+ { CONTAINER_ASF, 16, "\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00"
+ "\xaa\x00\x62\xce\x6c" },
+ { CONTAINER_ASS, 0, "[Script Info]" },
+ { CONTAINER_ASS, 0, BYTE_ORDER_MARK "[Script Info]" },
+ { CONTAINER_CONCAT, 0, "ffconcat version 1.0" },
+ { CONTAINER_DNXHD, 43, "\x00\x00\x02\x80\x01 789*123456789*123456789"
+ "*123456789*\x04\xd3" },
+ { CONTAINER_FFMETADATA, 0, ";FFMETADATA" },
+ { CONTAINER_IDF, 12, "\x04\x31\x2e\x34\x00\x00\x00\x00\x4f\x00\x15"
+ "\x00" },
+ { CONTAINER_ILBC, 0, "#!iLBC" },
+ { CONTAINER_ISS, 0, "IMA_ADPCM_Sound" },
+ { CONTAINER_IV8, 0, "\x01\x01\x03\xb8\x80\x60" },
+ { CONTAINER_JV, 0, "JVxx Compression by John M Phillips Copyright "
+ "(C) 1995 The Bitmap Brothers Ltd." },
+ { CONTAINER_LIBNUT, 0, "nut/multimedia container" },
+ { CONTAINER_LXF, 8, "LEITCH\x00\x00" },
+ { CONTAINER_NUV, 0, "NuppelVideo" },
+ { CONTAINER_NUV, 0, "MythTVVideo" },
+ { CONTAINER_PAF, 0, "Packed Animation File V1.0\n(c) 1992-96 "
+ "Amazing Studio\x0a\x1a" },
+ { CONTAINER_REALTEXT, 0, "<window" },
+ { CONTAINER_REALTEXT, 0, BYTE_ORDER_MARK "<window" },
+ { CONTAINER_RPL, 0, "ARMovie\x0A" },
+ { CONTAINER_SAMI, 0, "<SAMI>" },
+ { CONTAINER_SAMI, 0, BYTE_ORDER_MARK "<SAMI>" },
+ { CONTAINER_SMJPEG, 8, "\x00\x0aSMJPEG" },
+ { CONTAINER_VPLAYER, 0, "12:34:56.789=" },
+ { CONTAINER_VOBSUB, 0, "# VobSub index file," },
+ { CONTAINER_VOC, 0, "Creative Voice File\x1A" },
+ { CONTAINER_W64, 42, "riff\x2e\x91\xcf\x11\xa5\xd6\x28\xdb\x04\xc1"
+ "\x00\x00 89*1234wave\xf3\xac\xd3\x11\x8c\xd1"
+ "\x00\xc0\x4f\x8e\xdb\x8a" },
+ { CONTAINER_WEBVTT, 0, "WEBVTT" },
+ { CONTAINER_WEBVTT, 0, BYTE_ORDER_MARK "WEBVTT" },
+ { CONTAINER_WTV, 16, "\xb7\xd8\x00\x20\x37\x49\xda\x11\xa6\x4e\x00"
+ "\x07\xe9\x5e\xad\x8d" },
+ { CONTAINER_YUV4MPEGPIPE, 0, "YUV4MPEG2" }
+};
+
+// Test that containers that start with fixed strings are handled correctly.
+// This is to verify that the TAG matches the first 4 characters of the string.
+TEST(ContainerNamesTest, CheckFixedStrings) {
+ for (int i = 0; i < static_cast<int>(arraysize(fixed_strings)); ++i) {
+ char buffer[256];
+ int length = fixed_strings[i].length;
+ if (length == 0)
+ length = strlen(fixed_strings[i].name);
+ memcpy(buffer, fixed_strings[i].name, length);
+ // Put some random characters after the string.
+ buffer[length] = 'a';
+ buffer[length + 1] = 'b';
+ ContainerTest::Verify(
+ fixed_strings[i].id, buffer, sizeof(buffer));
+ }
+}
+
+// Determine the container type of a specified file.
+void TestFile(FFmpegContainerName expected, const base::FilePath& filename) {
+ // Open the file.
+ FILE* f = fopen(filename.value().c_str(), "r");
+ EXPECT_NE(f, (FILE*)NULL);
+
+ // Read the first few bytes.
+ char buffer[8192];
+ size_t read = fread(buffer, sizeof(char), sizeof(buffer), f);
xhwang 2013/05/03 19:59:06 copy from other comment: Use file_util::ReadFile()
jrummell 2013/05/03 23:56:21 Done.
+
+ // Now verify the type.
+ ContainerTest::Verify(expected, buffer, read);
+}
+
+// Test several files to ensure that the container is detected properly.
+TEST(ContainerNamesTest, FileCheck) {
+ TestFile(CONTAINER_OGG, GetTestDataFilePath("bear.ogv"));
+ TestFile(CONTAINER_OGG, GetTestDataFilePath("9ch.ogg"));
+ TestFile(CONTAINER_WAV, GetTestDataFilePath("4ch.wav"));
+ TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_f32le.wav"));
+ TestFile(CONTAINER_WAV, GetTestDataFilePath("sfx_s16le.wav"));
+ TestFile(CONTAINER_MOV, GetTestDataFilePath("bear-1280x720.mp4"));
+ TestFile(CONTAINER_MOV, GetTestDataFilePath("sfx.m4a"));
+ TestFile(CONTAINER_WEBM, GetTestDataFilePath("bear-320x240.webm"));
+ TestFile(CONTAINER_MP3, GetTestDataFilePath("id3_test.mp3"));
+ TestFile(CONTAINER_MP3, GetTestDataFilePath("sfx.mp3"));
+
+ // now try a few non containers
+ TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("ten_byte_file"));
+ TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("README"));
+ TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_P422.yuv"));
+ TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("bali_640x360_RGB24.rgb"));
+ TestFile(CONTAINER_UNKNOWN, GetTestDataFilePath("webm_vp8_track_entry"));
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698