Bug 1320895 - Test ADTS frame size calculation. r=gerald
authorRalph Giles <giles@mozilla.com>
Wed, 30 Nov 2016 14:38:52 -0800
changeset 324881 928ed9aab0b9a46c728758fd1f7959fa975f9350
parent 324880 ff6eea6062d469834591bc94a4c01ecdb76c0f8e
child 324882 a183d5c5a8f79b09be159329992ef958a55f23ed
child 324889 5245a7806885597b14805c900f41dc87dac990d7
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersgerald
bugs1320895
milestone53.0a1
Bug 1320895 - Test ADTS frame size calculation. r=gerald We don't generate timestamps for ADTS but we can verify the Init Segment Range and Media Segment Range returned by the parser match the frame size declared in the Init Segment header. MozReview-Commit-ID: FCZfxn9b69R
dom/media/mediasource/gtest/TestContainerParser.cpp
--- a/dom/media/mediasource/gtest/TestContainerParser.cpp
+++ b/dom/media/mediasource/gtest/TestContainerParser.cpp
@@ -66,16 +66,24 @@ TEST(ContainerParser, ADTSHeader) {
 
   // Test a short header.
   header->SetLength(6);
   EXPECT_FALSE(NS_SUCCEEDED(parser->IsInitSegmentPresent(header)))
     << "Accepted too-short header.";
   EXPECT_FALSE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(header)))
     << "Found media segment when there was just a partial header.";
 
+  // Test a header with short data.
+  header = make_adts_header();
+  header->AppendElements(1);
+  EXPECT_TRUE(NS_SUCCEEDED(parser->IsInitSegmentPresent(header)))
+    << "Rejected a valid header.";
+  EXPECT_TRUE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(header)))
+    << "Rejected a one-byte media segment.";
+
   // Test parse results.
   header = make_adts_header();
   EXPECT_FALSE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(header)))
     << "Found media segment when there was just a header.";
   int64_t start = 0;
   int64_t end = 0;
   EXPECT_TRUE(NS_FAILED(parser->ParseStartAndEndTimestamps(header, start, end)));
 
@@ -85,8 +93,52 @@ TEST(ContainerParser, ADTSHeader) {
   ASSERT_NE(init, nullptr);
   EXPECT_EQ(init->Length(), header->Length());
 
   EXPECT_EQ(parser->InitSegmentRange(), MediaByteRange(0, int64_t(header->Length())));
   // Media segment range should be empty here.
   EXPECT_EQ(parser->MediaHeaderRange(), MediaByteRange());
   EXPECT_EQ(parser->MediaSegmentRange(), MediaByteRange());
 }
+
+TEST(ContainerParser, ADTSBlankMedia) {
+  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 the header only.
+  RefPtr<MediaByteBuffer> header = make_adts_header();
+  EXPECT_TRUE(NS_SUCCEEDED(parser->IsInitSegmentPresent(header)));
+
+  // Test with the correct length of (invalid) frame data.
+  size_t header_length = header->Length();
+  size_t data_length = 24;
+  size_t frame_length = header_length + data_length;
+  header->AppendElements(data_length);
+  EXPECT_TRUE(NS_SUCCEEDED(parser->IsInitSegmentPresent(header)))
+    << "Rejected a valid header.";
+  EXPECT_TRUE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(header)))
+    << "Rejected a full (but zeroed) media segment.";
+  int64_t start = 0;
+  int64_t end = 0;
+  // We don't report timestamps from ADTS.
+  EXPECT_TRUE(NS_FAILED(parser->ParseStartAndEndTimestamps(header, start, end)));
+  EXPECT_EQ(start, 0);
+  EXPECT_EQ(end, 0);
+
+  // Verify the parser calculated header and packet data boundaries.
+  EXPECT_TRUE(parser->HasInitData());
+  EXPECT_TRUE(parser->HasCompleteInitData());
+  MediaByteBuffer* init = parser->InitData();
+  ASSERT_NE(init, nullptr);
+  EXPECT_EQ(init->Length(), header_length)
+    << "Found incorrect init segment length.";
+  EXPECT_EQ(parser->InitSegmentRange(),
+      MediaByteRange(0, int64_t(header_length)));
+  // In ADTS the Media Header is the same as the Media Segment.
+  MediaByteRange expected_media =
+    MediaByteRange(int64_t(header_length), int64_t(frame_length));
+  EXPECT_EQ(parser->MediaHeaderRange(), expected_media);
+  EXPECT_EQ(parser->MediaSegmentRange(), expected_media);
+}