diff options
-rw-r--r-- | dom/media/fmp4/MP4Stream.cpp | 3 | ||||
-rw-r--r-- | dom/media/gtest/Cargo.toml | 7 | ||||
-rw-r--r-- | dom/media/gtest/TestMP4Reader.cpp | 217 | ||||
-rw-r--r-- | dom/media/gtest/TestRust.cpp | 9 | ||||
-rw-r--r-- | dom/media/gtest/hello.rs | 6 | ||||
-rw-r--r-- | dom/media/gtest/moz.build | 1 | ||||
-rw-r--r-- | dom/media/platforms/wmf/WMFMediaDataDecoder.h | 2 | ||||
-rw-r--r-- | media/libstagefright/gtest/TestMP4Rust.cpp | 142 |
8 files changed, 1 insertions, 386 deletions
diff --git a/dom/media/fmp4/MP4Stream.cpp b/dom/media/fmp4/MP4Stream.cpp index 615a7dc01..9a79cac7a 100644 --- a/dom/media/fmp4/MP4Stream.cpp +++ b/dom/media/fmp4/MP4Stream.cpp @@ -48,9 +48,6 @@ MP4Stream::BlockingReadIntoCache(int64_t aOffset, size_t aCount, Monitor* aToUnl return true; } -// We surreptitiously reimplement the supposedly-blocking ReadAt as a non- -// blocking CachedReadAt, and record when it fails. This allows MP4Reader -// to retry the read as an actual blocking read without holding the lock. bool MP4Stream::ReadAt(int64_t aOffset, void* aBuffer, size_t aCount, size_t* aBytesRead) diff --git a/dom/media/gtest/Cargo.toml b/dom/media/gtest/Cargo.toml deleted file mode 100644 index a55f8fb68..000000000 --- a/dom/media/gtest/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "mp4parse-gtest" -version = "0.1.0" -authors = ["nobody@mozilla.org"] - -[lib] -path = "hello.rs" diff --git a/dom/media/gtest/TestMP4Reader.cpp b/dom/media/gtest/TestMP4Reader.cpp deleted file mode 100644 index f08f7a40d..000000000 --- a/dom/media/gtest/TestMP4Reader.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* -*- 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 "MP4Reader.h" -#include "MP4Decoder.h" -#include "mozilla/SharedThreadPool.h" -#include "MockMediaResource.h" -#include "MockMediaDecoderOwner.h" -#include "mozilla/Preferences.h" -#include "TimeUnits.h" - -using namespace mozilla; -using namespace mozilla::dom; - -class TestBinding -{ -public: - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestBinding); - - RefPtr<MP4Decoder> decoder; - RefPtr<MockMediaResource> resource; - RefPtr<MP4Reader> reader; - - explicit TestBinding(const char* aFileName = "gizmo.mp4") - : decoder(new MP4Decoder()) - , resource(new MockMediaResource(aFileName)) - , reader(new MP4Reader(decoder)) - { - EXPECT_EQ(NS_OK, Preferences::SetBool( - "media.use-blank-decoder", true)); - - EXPECT_EQ(NS_OK, resource->Open(nullptr)); - decoder->SetResource(resource); - - reader->Init(nullptr); - // This needs to be done before invoking GetBuffered. This is normally - // done by MediaDecoderStateMachine. - reader->DispatchSetStartTime(0); - } - - void Init() { - nsCOMPtr<nsIThread> thread; - nsCOMPtr<nsIRunnable> r = NewRunnableMethod(this, &TestBinding::ReadMetadata); - nsresult rv = NS_NewThread(getter_AddRefs(thread), r); - EXPECT_EQ(NS_OK, rv); - thread->Shutdown(); - } - -private: - virtual ~TestBinding() - { - { - RefPtr<TaskQueue> queue = reader->OwnerThread(); - nsCOMPtr<nsIRunnable> task = NewRunnableMethod(reader, &MP4Reader::Shutdown); - // Hackily bypass the tail dispatcher so that we can AwaitShutdownAndIdle. - // In production code we'd use BeginShutdown + promises. - queue->Dispatch(task.forget(), AbstractThread::AssertDispatchSuccess, - AbstractThread::TailDispatch); - queue->AwaitShutdownAndIdle(); - } - decoder = nullptr; - resource = nullptr; - reader = nullptr; - SharedThreadPool::SpinUntilEmpty(); - } - - void ReadMetadata() - { - MediaInfo info; - MetadataTags* tags; - EXPECT_EQ(NS_OK, reader->ReadMetadata(&info, &tags)); - } -}; - -TEST(MP4Reader, BufferedRange) -{ - RefPtr<TestBinding> b = new TestBinding(); - b->Init(); - - // Video 3-4 sec, audio 2.986666-4.010666 sec - b->resource->MockAddBufferedRange(248400, 327455); - - media::TimeIntervals ranges = b->reader->GetBuffered(); - EXPECT_EQ(1U, ranges.Length()); - EXPECT_NEAR(270000 / 90000.0, ranges.Start(0).ToSeconds(), 0.000001); - EXPECT_NEAR(360000 / 90000.0, ranges.End(0).ToSeconds(), 0.000001); -} - -TEST(MP4Reader, BufferedRangeMissingLastByte) -{ - RefPtr<TestBinding> b = new TestBinding(); - b->Init(); - - // Dropping the last byte of the video - b->resource->MockClearBufferedRanges(); - b->resource->MockAddBufferedRange(248400, 324912); - b->resource->MockAddBufferedRange(324913, 327455); - - media::TimeIntervals ranges = b->reader->GetBuffered(); - EXPECT_EQ(1U, ranges.Length()); - EXPECT_NEAR(270000.0 / 90000.0, ranges.Start(0).ToSeconds(), 0.000001); - EXPECT_NEAR(357000 / 90000.0, ranges.End(0).ToSeconds(), 0.000001); -} - -TEST(MP4Reader, BufferedRangeSyncFrame) -{ - RefPtr<TestBinding> b = new TestBinding(); - b->Init(); - - // Check that missing the first byte at 2 seconds skips right through to 3 - // seconds because of a missing sync frame - b->resource->MockClearBufferedRanges(); - b->resource->MockAddBufferedRange(146336, 327455); - - media::TimeIntervals ranges = b->reader->GetBuffered(); - EXPECT_EQ(1U, ranges.Length()); - EXPECT_NEAR(270000.0 / 90000.0, ranges.Start(0).ToSeconds(), 0.000001); - EXPECT_NEAR(360000 / 90000.0, ranges.End(0).ToSeconds(), 0.000001); -} - -TEST(MP4Reader, CompositionOrder) -{ - RefPtr<TestBinding> b = new TestBinding("mediasource_test.mp4"); - b->Init(); - - // The first 5 video samples of this file are: - // Video timescale=2500 - // Frame Start Size Time Duration Sync - // 1 48 5455 166 83 Yes - // 2 5503 145 249 83 - // 3 6228 575 581 83 - // 4 7383 235 415 83 - // 5 8779 183 332 83 - // 6 9543 191 498 83 - // - // Audio timescale=44100 - // 1 5648 580 0 1024 Yes - // 2 6803 580 1024 1058 Yes - // 3 7618 581 2082 1014 Yes - // 4 8199 580 3096 1015 Yes - // 5 8962 581 4111 1014 Yes - // 6 9734 580 5125 1014 Yes - // 7 10314 581 6139 1059 Yes - // 8 11207 580 7198 1014 Yes - // 9 12035 581 8212 1014 Yes - // 10 12616 580 9226 1015 Yes - // 11 13220 581 10241 1014 Yes - - b->resource->MockClearBufferedRanges(); - // First two frames in decoding + first audio frame - b->resource->MockAddBufferedRange(48, 5503); // Video 1 - b->resource->MockAddBufferedRange(5503, 5648); // Video 2 - b->resource->MockAddBufferedRange(6228, 6803); // Video 3 - - // Audio - 5 frames; 0 - 139206 us - b->resource->MockAddBufferedRange(5648, 6228); - b->resource->MockAddBufferedRange(6803, 7383); - b->resource->MockAddBufferedRange(7618, 8199); - b->resource->MockAddBufferedRange(8199, 8779); - b->resource->MockAddBufferedRange(8962, 9563); - b->resource->MockAddBufferedRange(9734, 10314); - b->resource->MockAddBufferedRange(10314, 10895); - b->resource->MockAddBufferedRange(11207, 11787); - b->resource->MockAddBufferedRange(12035, 12616); - b->resource->MockAddBufferedRange(12616, 13196); - b->resource->MockAddBufferedRange(13220, 13901); - - media::TimeIntervals ranges = b->reader->GetBuffered(); - EXPECT_EQ(2U, ranges.Length()); - - EXPECT_NEAR(166.0 / 2500.0, ranges.Start(0).ToSeconds(), 0.000001); - EXPECT_NEAR(332.0 / 2500.0, ranges.End(0).ToSeconds(), 0.000001); - - EXPECT_NEAR(581.0 / 2500.0, ranges.Start(1).ToSeconds(), 0.000001); - EXPECT_NEAR(11255.0 / 44100.0, ranges.End(1).ToSeconds(), 0.000001); -} - -TEST(MP4Reader, Normalised) -{ - RefPtr<TestBinding> b = new TestBinding("mediasource_test.mp4"); - b->Init(); - - // The first 5 video samples of this file are: - // Video timescale=2500 - // Frame Start Size Time Duration Sync - // 1 48 5455 166 83 Yes - // 2 5503 145 249 83 - // 3 6228 575 581 83 - // 4 7383 235 415 83 - // 5 8779 183 332 83 - // 6 9543 191 498 83 - // - // Audio timescale=44100 - // 1 5648 580 0 1024 Yes - // 2 6803 580 1024 1058 Yes - // 3 7618 581 2082 1014 Yes - // 4 8199 580 3096 1015 Yes - // 5 8962 581 4111 1014 Yes - // 6 9734 580 5125 1014 Yes - // 7 10314 581 6139 1059 Yes - // 8 11207 580 7198 1014 Yes - // 9 12035 581 8212 1014 Yes - // 10 12616 580 9226 1015 Yes - // 11 13220 581 10241 1014 Yes - - b->resource->MockClearBufferedRanges(); - b->resource->MockAddBufferedRange(48, 13901); - - media::TimeIntervals ranges = b->reader->GetBuffered(); - EXPECT_EQ(1U, ranges.Length()); - - EXPECT_NEAR(166.0 / 2500.0, ranges.Start(0).ToSeconds(), 0.000001); - EXPECT_NEAR(11255.0 / 44100.0, ranges.End(0).ToSeconds(), 0.000001); -} diff --git a/dom/media/gtest/TestRust.cpp b/dom/media/gtest/TestRust.cpp deleted file mode 100644 index 86d0e99b8..000000000 --- a/dom/media/gtest/TestRust.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdint.h> -#include "gtest/gtest.h" - -extern "C" uint8_t* test_rust(); - -TEST(rust, CallFromCpp) { - auto greeting = test_rust(); - EXPECT_STREQ(reinterpret_cast<char*>(greeting), "hello from rust."); -} diff --git a/dom/media/gtest/hello.rs b/dom/media/gtest/hello.rs deleted file mode 100644 index cd111882a..000000000 --- a/dom/media/gtest/hello.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[no_mangle] -pub extern fn test_rust() -> *const u8 { - // NB: rust &str aren't null terminated. - let greeting = "hello from rust.\0"; - greeting.as_ptr() -} diff --git a/dom/media/gtest/moz.build b/dom/media/gtest/moz.build index d5d02bced..a7ea73807 100644 --- a/dom/media/gtest/moz.build +++ b/dom/media/gtest/moz.build @@ -21,7 +21,6 @@ UNIFIED_SOURCES += [ 'TestMozPromise.cpp', 'TestMP3Demuxer.cpp', 'TestMP4Demuxer.cpp', - # 'TestMP4Reader.cpp', disabled so we can turn check tests back on (bug 1175752) 'TestTrackEncoder.cpp', 'TestVideoSegment.cpp', 'TestVideoUtils.cpp', diff --git a/dom/media/platforms/wmf/WMFMediaDataDecoder.h b/dom/media/platforms/wmf/WMFMediaDataDecoder.h index a4dd49f56..75571d61e 100644 --- a/dom/media/platforms/wmf/WMFMediaDataDecoder.h +++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.h @@ -33,7 +33,7 @@ public: // Returns S_OK on success, or MF_E_TRANSFORM_NEED_MORE_INPUT if there's not // enough data to produce more output. If this returns a failure code other // than MF_E_TRANSFORM_NEED_MORE_INPUT, an error will be reported to the - // MP4Reader. + // MP4Demuxer. virtual HRESULT Output(int64_t aStreamOffset, RefPtr<MediaData>& aOutput) = 0; diff --git a/media/libstagefright/gtest/TestMP4Rust.cpp b/media/libstagefright/gtest/TestMP4Rust.cpp deleted file mode 100644 index a338b5386..000000000 --- a/media/libstagefright/gtest/TestMP4Rust.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- 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 "mp4parse.h" - -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <algorithm> -#include <vector> - -static intptr_t -error_reader(uint8_t* buffer, uintptr_t size, void* userdata) -{ - return -1; -} - -struct read_vector { - explicit read_vector(FILE* file, size_t length); - explicit read_vector(size_t length); - - size_t location; - std::vector<uint8_t> buffer; -}; - -read_vector::read_vector(FILE* file, size_t length) - : location(0) -{ - buffer.resize(length); - size_t read = fread(buffer.data(), sizeof(decltype(buffer)::value_type), - buffer.size(), file); - buffer.resize(read); -} - -read_vector::read_vector(size_t length) - : location(0) -{ - buffer.resize(length, 0); -} - -static intptr_t -vector_reader(uint8_t* buffer, uintptr_t size, void* userdata) -{ - if (!buffer || !userdata) { - return -1; - } - - auto source = reinterpret_cast<read_vector*>(userdata); - if (source->location > source->buffer.size()) { - return -1; - } - uintptr_t available = source->buffer.size() - source->location; - uintptr_t length = std::min(available, size); - memcpy(buffer, source->buffer.data() + source->location, length); - source->location += length; - return length; -} - -TEST(rust, MP4MetadataEmpty) -{ - mp4parse_error rv; - mp4parse_io io; - - // Shouldn't be able to read with no context. - rv = mp4parse_read(nullptr); - EXPECT_EQ(rv, MP4PARSE_ERROR_BADARG); - - // Shouldn't be able to wrap an mp4parse_io with null members. - io = { nullptr, nullptr }; - mp4parse_parser* context = mp4parse_new(&io); - EXPECT_EQ(context, nullptr); - - io = { nullptr, &io }; - context = mp4parse_new(&io); - EXPECT_EQ(context, nullptr); - - // FIXME: this should probably be accepted. - io = { error_reader, nullptr }; - context = mp4parse_new(&io); - EXPECT_EQ(context, nullptr); - - // Read method errors should propagate. - io = { error_reader, &io }; - context = mp4parse_new(&io); - ASSERT_NE(context, nullptr); - rv = mp4parse_read(context); - EXPECT_EQ(rv, MP4PARSE_ERROR_IO); - mp4parse_free(context); - - // Short buffers should fail. - read_vector buf(0); - io = { vector_reader, &buf }; - context = mp4parse_new(&io); - ASSERT_NE(context, nullptr); - rv = mp4parse_read(context); - EXPECT_EQ(rv, MP4PARSE_ERROR_INVALID); - mp4parse_free(context); - - buf.buffer.reserve(4097); - context = mp4parse_new(&io); - ASSERT_NE(context, nullptr); - rv = mp4parse_read(context); - EXPECT_EQ(rv, MP4PARSE_ERROR_INVALID); - mp4parse_free(context); - - // Empty buffers should fail. - buf.buffer.resize(4097, 0); - context = mp4parse_new(&io); - rv = mp4parse_read(context); - EXPECT_EQ(rv, MP4PARSE_ERROR_UNSUPPORTED); - mp4parse_free(context); -} - -TEST(rust, MP4Metadata) -{ - FILE* f = fopen("street.mp4", "rb"); - ASSERT_TRUE(f != nullptr); - // Read just the moov header to work around the parser - // treating mid-box eof as an error. - //read_vector reader = read_vector(f, 1061); - struct stat s; - ASSERT_EQ(0, fstat(fileno(f), &s)); - read_vector reader = read_vector(f, s.st_size); - fclose(f); - - mp4parse_io io = { vector_reader, &reader }; - mp4parse_parser* context = mp4parse_new(&io); - ASSERT_NE(nullptr, context); - - mp4parse_error rv = mp4parse_read(context); - EXPECT_EQ(MP4PARSE_OK, rv); - - uint32_t tracks = 0; - rv = mp4parse_get_track_count(context, &tracks); - EXPECT_EQ(MP4PARSE_OK, rv); - EXPECT_EQ(2U, tracks); - - mp4parse_free(context); -} |