2014-09-25 22:25:13 -07:00
|
|
|
/* 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"
|
2014-10-16 08:39:00 -07:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2014-10-09 19:56:07 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsTArray.h"
|
2014-09-25 22:25:13 -07:00
|
|
|
#include "WebMBufferedParser.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-10-09 19:56:07 -07:00
|
|
|
// "test.webm" contains 8 SimpleBlocks in a single Cluster with the following attributes
|
2014-09-25 22:25:13 -07:00
|
|
|
static const uint64_t gTimecodes[] = { 66000000, 160000000, 100000000, 133000000,
|
|
|
|
166000000, 200000000, 233000000, 320000000 };
|
|
|
|
static const int64_t gEndOffsets[] = { 501, 772, 930, 1085, 1244, 1380, 1543, 2015 };
|
|
|
|
|
|
|
|
TEST(WebMBuffered, BasicTests)
|
|
|
|
{
|
|
|
|
ReentrantMonitor dummy("dummy");
|
|
|
|
WebMBufferedParser parser(0);
|
|
|
|
|
|
|
|
nsTArray<WebMTimeDataOffset> mapping;
|
|
|
|
parser.Append(nullptr, 0, mapping, dummy);
|
|
|
|
EXPECT_TRUE(mapping.IsEmpty());
|
|
|
|
EXPECT_EQ(parser.mStartOffset, 0);
|
|
|
|
EXPECT_EQ(parser.mCurrentOffset, 0);
|
|
|
|
|
|
|
|
unsigned char buf[] = { 0x1a, 0x45, 0xdf, 0xa3 };
|
|
|
|
parser.Append(buf, ArrayLength(buf), mapping, dummy);
|
|
|
|
EXPECT_TRUE(mapping.IsEmpty());
|
|
|
|
EXPECT_EQ(parser.mStartOffset, 0);
|
|
|
|
EXPECT_EQ(parser.mCurrentOffset, 4);
|
|
|
|
}
|
|
|
|
|
2014-10-09 19:56:07 -07:00
|
|
|
static void
|
|
|
|
ReadFile(const char* aPath, nsTArray<uint8_t>& aBuffer)
|
|
|
|
{
|
|
|
|
FILE* f = fopen(aPath, "rb");
|
|
|
|
ASSERT_NE(f, (FILE *) nullptr);
|
|
|
|
|
|
|
|
int r = fseek(f, 0, SEEK_END);
|
|
|
|
ASSERT_EQ(r, 0);
|
|
|
|
|
|
|
|
long size = ftell(f);
|
|
|
|
ASSERT_NE(size, -1);
|
|
|
|
aBuffer.SetLength(size);
|
|
|
|
|
|
|
|
r = fseek(f, 0, SEEK_SET);
|
|
|
|
ASSERT_EQ(r, 0);
|
|
|
|
|
|
|
|
size_t got = fread(aBuffer.Elements(), 1, size, f);
|
|
|
|
ASSERT_EQ(got, size_t(size));
|
|
|
|
|
|
|
|
r = fclose(f);
|
|
|
|
ASSERT_EQ(r, 0);
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:25:13 -07:00
|
|
|
TEST(WebMBuffered, RealData)
|
|
|
|
{
|
|
|
|
ReentrantMonitor dummy("dummy");
|
|
|
|
WebMBufferedParser parser(0);
|
|
|
|
|
2014-10-09 19:56:07 -07:00
|
|
|
nsTArray<uint8_t> webmData;
|
|
|
|
ReadFile("test.webm", webmData);
|
|
|
|
|
2014-09-25 22:25:13 -07:00
|
|
|
nsTArray<WebMTimeDataOffset> mapping;
|
2014-10-09 19:56:07 -07:00
|
|
|
parser.Append(webmData.Elements(), webmData.Length(), mapping, dummy);
|
2014-09-25 22:25:13 -07:00
|
|
|
EXPECT_EQ(mapping.Length(), 8u);
|
|
|
|
EXPECT_EQ(parser.mStartOffset, 0);
|
2014-10-09 19:56:07 -07:00
|
|
|
EXPECT_EQ(parser.mCurrentOffset, int64_t(webmData.Length()));
|
2014-09-25 22:25:13 -07:00
|
|
|
EXPECT_EQ(parser.GetTimecodeScale(), 500000u);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mapping.Length(); ++i) {
|
|
|
|
EXPECT_EQ(mapping[i].mEndOffset, gEndOffsets[i]);
|
|
|
|
EXPECT_EQ(mapping[i].mSyncOffset, 361);
|
|
|
|
EXPECT_EQ(mapping[i].mTimecode, gTimecodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(WebMBuffered, RealDataAppend)
|
|
|
|
{
|
|
|
|
ReentrantMonitor dummy("dummy");
|
|
|
|
WebMBufferedParser parser(0);
|
|
|
|
nsTArray<WebMTimeDataOffset> mapping;
|
|
|
|
|
2014-10-09 19:56:07 -07:00
|
|
|
nsTArray<uint8_t> webmData;
|
|
|
|
ReadFile("test.webm", webmData);
|
|
|
|
|
2014-09-25 22:25:13 -07:00
|
|
|
uint32_t arrayEntries = mapping.Length();
|
|
|
|
size_t offset = 0;
|
2014-10-09 19:56:07 -07:00
|
|
|
while (offset < webmData.Length()) {
|
|
|
|
parser.Append(webmData.Elements() + offset, 1, mapping, dummy);
|
2014-09-25 22:25:13 -07:00
|
|
|
offset += 1;
|
|
|
|
EXPECT_EQ(parser.mCurrentOffset, int64_t(offset));
|
|
|
|
if (mapping.Length() != arrayEntries) {
|
|
|
|
arrayEntries = mapping.Length();
|
|
|
|
ASSERT_LE(arrayEntries, 8u);
|
|
|
|
uint32_t i = arrayEntries - 1;
|
|
|
|
EXPECT_EQ(mapping[i].mEndOffset, gEndOffsets[i]);
|
|
|
|
EXPECT_EQ(mapping[i].mSyncOffset, 361);
|
|
|
|
EXPECT_EQ(mapping[i].mTimecode, gTimecodes[i]);
|
|
|
|
EXPECT_EQ(parser.GetTimecodeScale(), 500000u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_EQ(mapping.Length(), 8u);
|
|
|
|
EXPECT_EQ(parser.mStartOffset, 0);
|
2014-10-09 19:56:07 -07:00
|
|
|
EXPECT_EQ(parser.mCurrentOffset, int64_t(webmData.Length()));
|
2014-09-25 22:25:13 -07:00
|
|
|
EXPECT_EQ(parser.GetTimecodeScale(), 500000u);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mapping.Length(); ++i) {
|
|
|
|
EXPECT_EQ(mapping[i].mEndOffset, gEndOffsets[i]);
|
|
|
|
EXPECT_EQ(mapping[i].mSyncOffset, 361);
|
|
|
|
EXPECT_EQ(mapping[i].mTimecode, gTimecodes[i]);
|
|
|
|
}
|
|
|
|
}
|