Bug 1188150 - ADTSContainerParser gtest. r=jya
authorRalph Giles <giles@mozilla.com>
Thu, 23 Jul 2015 11:23:39 -0700
changeset 287199 0edf0a39a23cab4c080b8b88e964a495f7078082
parent 287198 032bfd7a5e7508876be2b7441fba291af99a1653
child 287200 6b0074c4133d860b5a878fd1043c248a9b0ebf65
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1188150
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1188150 - ADTSContainerParser gtest. r=jya Ran an m4a file from magnatune through ffmpeg -acopy foo.aac to convert to adts, and pulled the first header out of the hexdump. - Test rejection of non-zero layer fields. - Test rejecting explicit frequency in headers. - Test rejection of plain headers as media segments.
dom/media/mediasource/gtest/TestContainerParser.cpp
dom/media/mediasource/gtest/moz.build
dom/media/mediasource/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/gtest/TestContainerParser.cpp
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <gtest/gtest.h>
+#include <stdint.h>
+
+#include "ContainerParser.h"
+#include "mozilla/ArrayUtils.h"
+#include "nsAutoPtr.h"
+
+using namespace mozilla;
+
+TEST(ContainerParser, MIMETypes) {
+  const char* content_types[] = {
+    "video/webm",
+    "audio/webm",
+    "video/mp4",
+    "audio/mp4",
+    "audio/aac"
+  };
+  nsAutoPtr<ContainerParser> parser;
+  for (size_t i = 0; i < ArrayLength(content_types); ++i) {
+    nsAutoCString content_type(content_types[i]);
+    parser = ContainerParser::CreateForMIMEType(content_type);
+    ASSERT_NE(parser, nullptr);
+  }
+}
+
+
+already_AddRefed<MediaByteBuffer> make_adts_header()
+{
+  const uint8_t test[] = { 0xff, 0xf1, 0x50, 0x80, 0x03, 0x1f, 0xfc };
+  nsRefPtr<MediaByteBuffer> buffer(new MediaByteBuffer);
+  buffer->AppendElements(test, ArrayLength(test));
+  return buffer.forget();
+}
+
+TEST(ContainerParser, ADTSHeader) {
+  nsAutoPtr<ContainerParser> parser;
+  parser = ContainerParser::CreateForMIMEType(NS_LITERAL_CSTRING("audio/aac"));
+  ASSERT_NE(parser, nullptr);
+
+  // Audio data should have no gaps.
+  EXPECT_EQ(parser->GetRoundingError(), 0);
+
+  // Test a valid header.
+  nsRefPtr<MediaByteBuffer> header = make_adts_header();
+  EXPECT_TRUE(parser->IsInitSegmentPresent(header));
+
+  // Test variations.
+  uint8_t save = header->ElementAt(1);
+  for (uint8_t i = 1; i < 3; ++i) {
+    // Set non-zero layer.
+    header->ReplaceElementAt(1, (header->ElementAt(1) & 0xf9) | (i << 1));
+    EXPECT_FALSE(parser->IsInitSegmentPresent(header))
+      << "Accepted non-zero layer in header.";
+  }
+  header->ReplaceElementAt(1, save);
+  save = header->ElementAt(2);
+  header->ReplaceElementAt(2, (header->ElementAt(2) & 0x3b) | (15 << 2));
+  EXPECT_FALSE(parser->IsInitSegmentPresent(header))
+    << "Accepted explicit frequency in header.";
+  header->ReplaceElementAt(2, save);
+
+  // Test a short header.
+  header->SetLength(6);
+  EXPECT_FALSE(parser->IsInitSegmentPresent(header))
+    << "Accepted too-short header.";
+  EXPECT_FALSE(parser->IsMediaSegmentPresent(header))
+    << "Found media segment when there was just a partial header.";
+
+  // Test parse results.
+  header = make_adts_header();
+  EXPECT_FALSE(parser->IsMediaSegmentPresent(header))
+    << "Found media segment when there was just a header.";
+  int64_t start = 0;
+  int64_t end = 0;
+  EXPECT_FALSE(parser->ParseStartAndEndTimestamps(header, start, end));
+
+  EXPECT_TRUE(parser->HasInitData());
+  EXPECT_TRUE(parser->HasCompleteInitData());
+  MediaByteBuffer* init = parser->InitData();
+  ASSERT_NE(init, nullptr);
+  EXPECT_EQ(init->Length(), header->Length());
+
+  EXPECT_EQ(parser->InitSegmentRange(), MediaByteRange(0, header->Length()));
+  // Media segment range should be empty here.
+  EXPECT_EQ(parser->MediaHeaderRange(), MediaByteRange());
+  EXPECT_EQ(parser->MediaSegmentRange(), MediaByteRange());
+}
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/gtest/moz.build
@@ -0,0 +1,18 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+UNIFIED_SOURCES += [
+    'TestContainerParser.cpp',
+]
+
+LOCAL_INCLUDES += [
+    '/dom/media',
+    '/dom/media/mediasource',
+]
+
+FINAL_LIBRARY = 'xul-gtest'
+
+FAIL_ON_WARNINGS = True
--- a/dom/media/mediasource/moz.build
+++ b/dom/media/mediasource/moz.build
@@ -31,11 +31,15 @@ UNIFIED_SOURCES += [
     'SourceBufferContentManager.cpp',
     'SourceBufferDecoder.cpp',
     'SourceBufferList.cpp',
     'SourceBufferResource.cpp',
     'TrackBuffer.cpp',
     'TrackBuffersManager.cpp',
 ]
 
+TEST_DIRS += [
+    'gtest',
+]
+
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'