--- a/dom/media/gtest/TestMP4Demuxer.cpp
+++ b/dom/media/gtest/TestMP4Demuxer.cpp
@@ -10,17 +10,16 @@
#include "mozilla/SharedThreadPool.h"
#include "mozilla/TaskQueue.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Unused.h"
#include "MockMediaResource.h"
#include "VideoUtils.h"
using namespace mozilla;
-using namespace mp4_demuxer;
using media::TimeUnit;
class AutoTaskQueue;
#define DO_FAIL [binding]()->void { EXPECT_TRUE(false); binding->mTaskQueue->BeginShutdown(); }
class MP4DemuxerBinding
{
--- a/dom/media/gtest/mp4_demuxer/TestInterval.cpp
+++ b/dom/media/gtest/mp4_demuxer/TestInterval.cpp
@@ -1,88 +1,87 @@
/* -*- 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 "Interval.h"
+#include "MP4Interval.h"
+
+using mozilla::MP4Interval;
-using namespace mp4_demuxer;
-using namespace mozilla;
-
-TEST(Interval, Length)
+TEST(MP4Interval, Length)
{
- Interval<int> i(15, 25);
+ MP4Interval<int> i(15, 25);
EXPECT_EQ(10, i.Length());
}
-TEST(Interval, Intersection)
+TEST(MP4Interval, Intersection)
{
- Interval<int> i0(10, 20);
- Interval<int> i1(15, 25);
- Interval<int> i = i0.Intersection(i1);
+ MP4Interval<int> i0(10, 20);
+ MP4Interval<int> i1(15, 25);
+ MP4Interval<int> i = i0.Intersection(i1);
EXPECT_EQ(15, i.start);
EXPECT_EQ(20, i.end);
}
-TEST(Interval, Equals)
+TEST(MP4Interval, Equals)
{
- Interval<int> i0(10, 20);
- Interval<int> i1(10, 20);
+ MP4Interval<int> i0(10, 20);
+ MP4Interval<int> i1(10, 20);
EXPECT_EQ(i0, i1);
- Interval<int> i2(5, 20);
+ MP4Interval<int> i2(5, 20);
EXPECT_NE(i0, i2);
- Interval<int> i3(10, 15);
+ MP4Interval<int> i3(10, 15);
EXPECT_NE(i0, i2);
}
-TEST(Interval, IntersectionVector)
+TEST(MP4Interval, IntersectionVector)
{
- nsTArray<Interval<int>> i0;
- i0.AppendElement(Interval<int>(5, 10));
- i0.AppendElement(Interval<int>(20, 25));
- i0.AppendElement(Interval<int>(40, 60));
+ nsTArray<MP4Interval<int>> i0;
+ i0.AppendElement(MP4Interval<int>(5, 10));
+ i0.AppendElement(MP4Interval<int>(20, 25));
+ i0.AppendElement(MP4Interval<int>(40, 60));
- nsTArray<Interval<int>> i1;
- i1.AppendElement(Interval<int>(7, 15));
- i1.AppendElement(Interval<int>(16, 27));
- i1.AppendElement(Interval<int>(45, 50));
- i1.AppendElement(Interval<int>(53, 57));
+ nsTArray<MP4Interval<int>> i1;
+ i1.AppendElement(MP4Interval<int>(7, 15));
+ i1.AppendElement(MP4Interval<int>(16, 27));
+ i1.AppendElement(MP4Interval<int>(45, 50));
+ i1.AppendElement(MP4Interval<int>(53, 57));
- nsTArray<Interval<int>> i;
- Interval<int>::Intersection(i0, i1, &i);
+ nsTArray<MP4Interval<int>> i;
+ MP4Interval<int>::Intersection(i0, i1, &i);
EXPECT_EQ(4u, i.Length());
EXPECT_EQ(7, i[0].start);
EXPECT_EQ(10, i[0].end);
EXPECT_EQ(20, i[1].start);
EXPECT_EQ(25, i[1].end);
EXPECT_EQ(45, i[2].start);
EXPECT_EQ(50, i[2].end);
EXPECT_EQ(53, i[3].start);
EXPECT_EQ(57, i[3].end);
}
-TEST(Interval, Normalize)
+TEST(MP4Interval, Normalize)
{
- nsTArray<Interval<int>> i;
- i.AppendElement(Interval<int>(20, 30));
- i.AppendElement(Interval<int>(1, 8));
- i.AppendElement(Interval<int>(5, 10));
- i.AppendElement(Interval<int>(2, 7));
+ nsTArray<MP4Interval<int>> i;
+ i.AppendElement(MP4Interval<int>(20, 30));
+ i.AppendElement(MP4Interval<int>(1, 8));
+ i.AppendElement(MP4Interval<int>(5, 10));
+ i.AppendElement(MP4Interval<int>(2, 7));
- nsTArray<Interval<int>> o;
- Interval<int>::Normalize(i, &o);
+ nsTArray<MP4Interval<int>> o;
+ MP4Interval<int>::Normalize(i, &o);
EXPECT_EQ(2u, o.Length());
EXPECT_EQ(1, o[0].start);
EXPECT_EQ(10, o[0].end);
EXPECT_EQ(20, o[1].start);
EXPECT_EQ(30, o[1].end);
--- a/dom/media/gtest/mp4_demuxer/TestParser.cpp
+++ b/dom/media/gtest/mp4_demuxer/TestParser.cpp
@@ -8,21 +8,20 @@
#include "MediaPrefs.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Preferences.h"
#include "BufferStream.h"
#include "MP4Metadata.h"
#include "MoofParser.h"
using namespace mozilla;
-using namespace mp4_demuxer;
static const uint32_t E = MP4Metadata::NumberTracksError();
-class TestStream : public Stream
+class TestStream : public ByteStream
{
public:
TestStream(const uint8_t* aBuffer, size_t aSize)
: mHighestSuccessfulEndOffset(0)
, mBuffer(aBuffer)
, mSize(aSize)
{
}
@@ -69,17 +68,17 @@ protected:
}
const uint8_t* mBuffer;
size_t mSize;
};
TEST(MP4Metadata, EmptyStream)
{
- RefPtr<Stream> stream = new TestStream(nullptr, 0);
+ RefPtr<ByteStream> stream = new TestStream(nullptr, 0);
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
EXPECT_TRUE(NS_OK != metadataBuffer.Result());
EXPECT_FALSE(static_cast<bool>(metadataBuffer.Ref()));
MP4Metadata metadata(stream);
EXPECT_TRUE(0u == metadata.GetNumberTracks(TrackInfo::kUndefinedTrack).Ref() ||
@@ -95,17 +94,17 @@ TEST(MP4Metadata, EmptyStream)
EXPECT_FALSE(metadata.GetTrackInfo(TrackInfo::kTextTrack, 0).Ref());
// We can seek anywhere in any MPEG4.
EXPECT_TRUE(metadata.CanSeek());
EXPECT_FALSE(metadata.Crypto().Ref()->valid);
}
TEST(MoofParser, EmptyStream)
{
- RefPtr<Stream> stream = new TestStream(nullptr, 0);
+ RefPtr<ByteStream> stream = new TestStream(nullptr, 0);
MoofParser parser(stream, 0, false);
EXPECT_EQ(0u, parser.mOffset);
EXPECT_TRUE(parser.ReachedEnd());
MediaByteRangeSet byteRanges;
EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges));
@@ -239,17 +238,17 @@ TEST(MP4Metadata, test_case_mp4)
size_t length = 0;
tests = testFiles;
length = ArrayLength(testFiles);
for (size_t test = 0; test < length; ++test) {
nsTArray<uint8_t> buffer = ReadTestFile(tests[test].mFilename);
ASSERT_FALSE(buffer.IsEmpty());
- RefPtr<Stream> stream = new TestStream(buffer.Elements(), buffer.Length());
+ RefPtr<ByteStream> stream = new TestStream(buffer.Elements(), buffer.Length());
MP4Metadata::ResultAndByteBuffer metadataBuffer =
MP4Metadata::Metadata(stream);
EXPECT_EQ(NS_OK, metadataBuffer.Result());
EXPECT_TRUE(metadataBuffer.Ref());
MP4Metadata metadata(stream);
nsresult res = metadata.Parse();
@@ -377,17 +376,17 @@ TEST(MoofParser, test_case_mp4)
size_t length = 0;
tests = testFiles;
length = ArrayLength(testFiles);
for (size_t test = 0; test < length; ++test) {
nsTArray<uint8_t> buffer = ReadTestFile(tests[test].mFilename);
ASSERT_FALSE(buffer.IsEmpty());
- RefPtr<Stream> stream = new TestStream(buffer.Elements(), buffer.Length());
+ RefPtr<ByteStream> stream = new TestStream(buffer.Elements(), buffer.Length());
MoofParser parser(stream, 0, false);
EXPECT_EQ(0u, parser.mOffset) << tests[test].mFilename;
EXPECT_FALSE(parser.ReachedEnd()) << tests[test].mFilename;
EXPECT_TRUE(parser.mInitRange.IsEmpty()) << tests[test].mFilename;
EXPECT_TRUE(parser.HasMetadata()) << tests[test].mFilename;
RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
--- a/dom/media/mediasource/ContainerParser.cpp
+++ b/dom/media/mediasource/ContainerParser.cpp
@@ -13,17 +13,19 @@
#include "MoofParser.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "MediaData.h"
#ifdef MOZ_FMP4
#include "AtomType.h"
#include "BufferReader.h"
-#include "Stream.h"
+#include "Index.h"
+#include "MP4Interval.h"
+#include "ByteStream.h"
#endif
#include "nsAutoPtr.h"
#include "SourceBufferResource.h"
#include <algorithm>
extern mozilla::LogModule* GetMediaSourceSamplesLog();
#define STRINGIFY(x) #x
@@ -334,17 +336,17 @@ private:
WebMBufferedParser mParser;
nsTArray<WebMTimeDataOffset> mOverlappedMapping;
int64_t mOffset;
Maybe<WebMTimeDataOffset> mLastMapping;
};
#ifdef MOZ_FMP4
-class MP4Stream : public mp4_demuxer::Stream
+class MP4Stream : public ByteStream
{
public:
explicit MP4Stream(SourceBufferResource* aResource);
virtual ~MP4Stream();
bool ReadAt(int64_t aOffset,
void* aBuffer,
size_t aCount,
size_t* aBytesRead) override;
@@ -461,61 +463,61 @@ private:
mValid = Init(aType, aData, aStop).isOk();
}
Result<Ok, nsresult> Init(const MediaContainerType& aType, const MediaByteBuffer* aData,
StopAt aStop)
{
const MediaContainerType mType(aType); // for logging macro.
BufferReader reader(aData);
- mp4_demuxer::AtomType initAtom("moov");
- mp4_demuxer::AtomType mediaAtom("moof");
- mp4_demuxer::AtomType dataAtom("mdat");
+ AtomType initAtom("moov");
+ AtomType mediaAtom("moof");
+ AtomType dataAtom("mdat");
// Valid top-level boxes defined in ISO/IEC 14496-12 (Table 1)
- static const mp4_demuxer::AtomType validBoxes[] = {
+ static const AtomType validBoxes[] = {
"ftyp", "moov", // init segment
"pdin", "free", "sidx", // optional prior moov box
"styp", "moof", "mdat", // media segment
"mfra", "skip", "meta", "meco", "ssix", "prft", // others.
"pssh", // optional with encrypted EME, though ignored.
"emsg", // ISO23009-1:2014 Section 5.10.3.3
"bloc", "uuid" // boxes accepted by chrome.
};
while (reader.Remaining() >= 8) {
uint32_t tmp;
MOZ_TRY_VAR(tmp, reader.ReadU32());
uint64_t size = tmp;
const uint8_t* typec = reader.Peek(4);
MOZ_TRY_VAR(tmp, reader.ReadU32());
- mp4_demuxer::AtomType type(tmp);
+ AtomType type(tmp);
MSE_DEBUGV(AtomParser ,"Checking atom:'%c%c%c%c' @ %u",
typec[0], typec[1], typec[2], typec[3],
(uint32_t)reader.Offset() - 8);
if (std::find(std::begin(validBoxes), std::end(validBoxes), type)
== std::end(validBoxes)) {
// No valid box found, no point continuing.
mLastInvalidBox[0] = typec[0];
mLastInvalidBox[1] = typec[1];
mLastInvalidBox[2] = typec[2];
mLastInvalidBox[3] = typec[3];
mLastInvalidBox[4] = '\0';
return Err(NS_ERROR_FAILURE);
}
if (mInitOffset.isNothing() &&
- mp4_demuxer::AtomType(type) == initAtom) {
+ AtomType(type) == initAtom) {
mInitOffset = Some(reader.Offset());
}
if (mMediaOffset.isNothing() &&
- mp4_demuxer::AtomType(type) == mediaAtom) {
+ AtomType(type) == mediaAtom) {
mMediaOffset = Some(reader.Offset());
}
if (mDataOffset.isNothing() &&
- mp4_demuxer::AtomType(type) == dataAtom) {
+ AtomType(type) == dataAtom) {
mDataOffset = Some(reader.Offset());
}
if (size == 1) {
// 64 bits size.
MOZ_TRY_VAR(size, reader.ReadU64());
} else if (size == 0) {
// Atom extends to the end of the buffer, it can't have what we're
// looking for.
@@ -573,17 +575,17 @@ public:
bool initSegment = NS_SUCCEEDED(IsInitSegmentPresent(aData));
if (initSegment) {
mResource = new SourceBufferResource();
mStream = new MP4Stream(mResource);
// We use a timestampOffset of 0 for ContainerParser, and require
// consumers of ParseStartAndEndTimestamps to add their timestamp offset
// manually. This allows the ContainerParser to be shared across different
// timestampOffsets.
- mParser = new mp4_demuxer::MoofParser(mStream, 0, /* aIsAudio = */ false);
+ mParser = new MoofParser(mStream, 0, /* aIsAudio = */ false);
mInitData = new MediaByteBuffer();
mCompleteInitSegmentRange = MediaByteRange();
mCompleteMediaHeaderRange = MediaByteRange();
mCompleteMediaSegmentRange = MediaByteRange();
mGlobalOffset = mTotalParsed;
} else if (!mStream || !mParser) {
mTotalParsed += aData->Length();
return NS_ERROR_NOT_AVAILABLE;
@@ -609,17 +611,17 @@ public:
range.Length());
} else {
MSE_DEBUG(MP4ContainerParser, "Incomplete init found.");
}
mHasInitData = true;
}
mTotalParsed += aData->Length();
- mp4_demuxer::Interval<mp4_demuxer::Microseconds> compositionRange =
+ MP4Interval<Microseconds> compositionRange =
mParser->GetCompositionRange(byteRanges);
mCompleteMediaHeaderRange =
mParser->FirstCompleteMediaHeader() + mGlobalOffset;
mCompleteMediaSegmentRange =
mParser->FirstCompleteMediaSegment() + mGlobalOffset;
ErrorResult rv;
@@ -645,17 +647,17 @@ public:
// considered to be sequential frames.
int64_t GetRoundingError() override
{
return 35000;
}
private:
RefPtr<MP4Stream> mStream;
- nsAutoPtr<mp4_demuxer::MoofParser> mParser;
+ nsAutoPtr<MoofParser> mParser;
};
#endif // MOZ_FMP4
#ifdef MOZ_FMP4
class ADTSContainerParser : public ContainerParser
{
public:
explicit ADTSContainerParser(const MediaContainerType& aType)
--- a/dom/media/mp4/AtomType.h
+++ b/dom/media/mp4/AtomType.h
@@ -5,19 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ATOM_TYPE_H_
#define ATOM_TYPE_H_
#include <stdint.h>
#include "mozilla/EndianUtils.h"
-using namespace mozilla;
-
-namespace mp4_demuxer {
+namespace mozilla {
class AtomType
{
public:
AtomType() : mType(0) { }
MOZ_IMPLICIT AtomType(uint32_t aType) : mType(aType) { }
MOZ_IMPLICIT AtomType(const char* aType) : mType(BigEndian::readUint32(aType)) { }
bool operator==(const AtomType& aType) const { return mType == aType.mType; }
--- a/dom/media/mp4/Box.cpp
+++ b/dom/media/mp4/Box.cpp
@@ -1,23 +1,21 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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 "Box.h"
-#include "Stream.h"
+#include "ByteStream.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/Unused.h"
#include <algorithm>
-using namespace mozilla;
-
-namespace mp4_demuxer {
+namespace mozilla {
// Limit reads to 32MiB max.
// static
const uint64_t Box::kMAX_BOX_READ = 32 * 1024 * 1024;
// Returns the offset from the start of the body of a box of type |aType|
// to the start of its first child.
static uint32_t
@@ -164,15 +162,15 @@ Box::Read(nsTArray<uint8_t>* aDest, cons
length = aRange.mEnd - mChildOffset;
}
aDest->SetLength(length);
size_t bytes;
if (!mContext->mSource->CachedReadAt(mChildOffset, aDest->Elements(),
aDest->Length(), &bytes) ||
bytes != aDest->Length()) {
// Byte ranges are being reported incorrectly
- NS_WARNING("Read failed in mp4_demuxer::Box::Read()");
+ NS_WARNING("Read failed in mozilla::Box::Read()");
aDest->Clear();
return false;
}
return true;
}
}
--- a/dom/media/mp4/Box.h
+++ b/dom/media/mp4/Box.h
@@ -9,31 +9,28 @@
#include <stdint.h>
#include "nsTArray.h"
#include "MediaResource.h"
#include "mozilla/EndianUtils.h"
#include "AtomType.h"
#include "BufferReader.h"
-using namespace mozilla;
-
-namespace mp4_demuxer {
-
-class Stream;
+namespace mozilla {
+class ByteStream;
class BoxContext
{
public:
- BoxContext(Stream* aSource, const MediaByteRangeSet& aByteRanges)
+ BoxContext(ByteStream* aSource, const MediaByteRangeSet& aByteRanges)
: mSource(aSource), mByteRanges(aByteRanges)
{
}
- RefPtr<Stream> mSource;
+ RefPtr<ByteStream> mSource;
const MediaByteRangeSet& mByteRanges;
};
class Box
{
public:
Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent = nullptr);
Box();
--- a/dom/media/mp4/BufferStream.cpp
+++ b/dom/media/mp4/BufferStream.cpp
@@ -2,19 +2,17 @@
* 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 "BufferStream.h"
#include "MediaData.h"
#include "MediaResource.h"
#include <algorithm>
-using namespace mozilla;
-
-namespace mp4_demuxer {
+namespace mozilla {
BufferStream::BufferStream()
: mStartOffset(0)
, mData(new mozilla::MediaByteBuffer)
{
}
BufferStream::BufferStream(mozilla::MediaByteBuffer* aBuffer)
--- a/dom/media/mp4/BufferStream.h
+++ b/dom/media/mp4/BufferStream.h
@@ -1,26 +1,23 @@
/* 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/. */
#ifndef BUFFER_STREAM_H_
#define BUFFER_STREAM_H_
-#include "Stream.h"
+#include "ByteStream.h"
#include "nsTArray.h"
#include "MediaResource.h"
namespace mozilla {
class MediaByteBuffer;
-}
-namespace mp4_demuxer {
-
-class BufferStream : public Stream
+class BufferStream : public ByteStream
{
public:
/* BufferStream does not take ownership of aData nor does it make a copy.
* Therefore BufferStream shouldn't get used after aData is destroyed.
*/
BufferStream();
explicit BufferStream(mozilla::MediaByteBuffer* aBuffer);
rename from dom/media/mp4/Stream.h
rename to dom/media/mp4/ByteStream.h
--- a/dom/media/mp4/Stream.h
+++ b/dom/media/mp4/ByteStream.h
@@ -2,31 +2,31 @@
* 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/. */
#ifndef STREAM_H_
#define STREAM_H_
#include "nsISupportsImpl.h"
-namespace mp4_demuxer
+namespace mozilla
{
-class Stream
+class ByteStream
{
public:
- NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Stream);
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ByteStream);
virtual bool ReadAt(int64_t offset, void* data, size_t size,
size_t* bytes_read) = 0;
virtual bool CachedReadAt(int64_t offset, void* data, size_t size,
size_t* bytes_read) = 0;
virtual bool Length(int64_t* size) = 0;
virtual void DiscardBefore(int64_t offset) {}
protected:
- virtual ~Stream() {}
+ virtual ~ByteStream() {}
};
}
#endif
--- a/dom/media/mp4/Index.cpp
+++ b/dom/media/mp4/Index.cpp
@@ -1,27 +1,26 @@
/* 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 "BufferReader.h"
#include "Index.h"
-#include "Interval.h"
+#include "MP4Interval.h"
#include "MP4Metadata.h"
#include "SinfParser.h"
#include "nsAutoPtr.h"
#include "mozilla/RefPtr.h"
#include <algorithm>
#include <limits>
-using namespace mozilla;
using namespace mozilla::media;
-namespace mp4_demuxer
+namespace mozilla
{
class MOZ_STACK_CLASS RangeFinder
{
public:
// Given that we're processing this in order we don't use a binary search
// to find the apropriate time range. Instead we search linearly from the
// last used point.
@@ -319,17 +318,17 @@ SampleIterator::GetNextKeyframeTime()
return sample->mCompositionRange.start;
}
itr.Next();
}
return -1;
}
Index::Index(const IndiceWrapper& aIndices,
- Stream* aSource,
+ ByteStream* aSource,
uint32_t aTrackId,
bool aIsAudio)
: mSource(aSource)
, mIsAudio(aIsAudio)
{
if (!aIndices.Length()) {
mMoofParser = new MoofParser(aSource, aTrackId, aIsAudio);
} else {
@@ -353,18 +352,18 @@ Index::Index(const IndiceWrapper& aIndic
}
if (!haveSync) {
continue;
}
Sample sample;
sample.mByteRange = MediaByteRange(indice.start_offset,
indice.end_offset);
- sample.mCompositionRange = Interval<Microseconds>(indice.start_composition,
- indice.end_composition);
+ sample.mCompositionRange = MP4Interval<Microseconds>(indice.start_composition,
+ indice.end_composition);
sample.mDecodeTime = indice.start_decode;
sample.mSync = indice.sync || mIsAudio;
// FIXME: Make this infallible after bug 968520 is done.
MOZ_ALWAYS_TRUE(mIndex.AppendElement(sample, fallible));
if (indice.start_offset < lastOffset) {
NS_WARNING("Chunks in MP4 out of order, expect slow down");
progressive = false;
}
@@ -395,17 +394,17 @@ Index::Index(const IndiceWrapper& aIndic
if (mDataOffset.Length() && progressive) {
Indice indice;
if (!aIndices.GetIndice(aIndices.Length() - 1, indice)) {
return;
}
auto& last = mDataOffset.LastElement();
last.mEndOffset = indice.end_offset;
- last.mTime = Interval<int64_t>(intervalTime.GetStart(), intervalTime.GetEnd());
+ last.mTime = MP4Interval<int64_t>(intervalTime.GetStart(), intervalTime.GetEnd());
} else {
mDataOffset.Clear();
}
}
}
Index::~Index() {}
@@ -519,29 +518,29 @@ Index::ConvertByteRangesToTimeRanges(con
}
}
}
mLastBufferedRanges = timeRanges;
return timeRanges;
}
RangeFinder rangeFinder(aByteRanges);
- nsTArray<Interval<Microseconds>> timeRanges;
+ nsTArray<MP4Interval<Microseconds>> timeRanges;
nsTArray<FallibleTArray<Sample>*> indexes;
if (mMoofParser) {
// We take the index out of the moof parser and move it into a local
// variable so we don't get concurrency issues. It gets freed when we
// exit this function.
for (int i = 0; i < mMoofParser->Moofs().Length(); i++) {
Moof& moof = mMoofParser->Moofs()[i];
// We need the entire moof in order to play anything
if (rangeFinder.Contains(moof.mRange)) {
if (rangeFinder.Contains(moof.mMdatRange)) {
- Interval<Microseconds>::SemiNormalAppend(timeRanges, moof.mTimeRange);
+ MP4Interval<Microseconds>::SemiNormalAppend(timeRanges, moof.mTimeRange);
} else {
indexes.AppendElement(&moof.mIndex);
}
}
}
} else {
indexes.AppendElement(&mIndex);
}
@@ -558,24 +557,24 @@ Index::ConvertByteRangesToTimeRanges(con
continue;
}
hasSync |= sample.mSync;
if (!hasSync) {
continue;
}
- Interval<Microseconds>::SemiNormalAppend(timeRanges,
+ MP4Interval<Microseconds>::SemiNormalAppend(timeRanges,
sample.mCompositionRange);
}
}
// This fixes up when the compositon order differs from the byte range order
- nsTArray<Interval<Microseconds>> timeRangesNormalized;
- Interval<Microseconds>::Normalize(timeRanges, &timeRangesNormalized);
+ nsTArray<MP4Interval<Microseconds>> timeRangesNormalized;
+ MP4Interval<Microseconds>::Normalize(timeRanges, &timeRangesNormalized);
// convert timeRanges.
media::TimeIntervals ranges;
for (size_t i = 0; i < timeRangesNormalized.Length(); i++) {
ranges +=
media::TimeInterval(media::TimeUnit::FromMicroseconds(timeRangesNormalized[i].start),
media::TimeUnit::FromMicroseconds(timeRangesNormalized[i].end));
}
mLastBufferedRanges = ranges;
--- a/dom/media/mp4/Index.h
+++ b/dom/media/mp4/Index.h
@@ -4,28 +4,27 @@
#ifndef INDEX_H_
#define INDEX_H_
#include "MediaData.h"
#include "MediaResource.h"
#include "TimeUnits.h"
#include "MoofParser.h"
-#include "Interval.h"
-#include "Stream.h"
+#include "MP4Interval.h"
+#include "ByteStream.h"
#include "nsISupportsImpl.h"
template<class T> class nsAutoPtr;
-namespace mozilla {
+namespace mozilla
+{
class IndiceWrapper;
-}
-
-namespace mp4_demuxer
-{
+struct Sample;
+struct CencSampleEncryptionInfoEntry;
class Index;
typedef int64_t Microseconds;
class SampleIterator
{
public:
@@ -89,21 +88,21 @@ public:
bool LessThan(const MP4DataOffset& a, const int64_t& b) const {
return a.mEndOffset < b;
}
};
uint32_t mIndex;
int64_t mStartOffset;
int64_t mEndOffset;
- Interval<Microseconds> mTime;
+ MP4Interval<Microseconds> mTime;
};
Index(const mozilla::IndiceWrapper& aIndices,
- Stream* aSource,
+ ByteStream* aSource,
uint32_t aTrackId,
bool aIsAudio);
void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges,
bool aCanEvict);
void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges);
Microseconds GetEndCompositionIfBuffered(
const mozilla::MediaByteRangeSet& aByteRanges);
@@ -114,17 +113,17 @@ public:
friend class SampleIterator;
private:
~Index();
void RegisterIterator(SampleIterator* aIterator);
void UnregisterIterator(SampleIterator* aIterator);
- Stream* mSource;
+ ByteStream* mSource;
FallibleTArray<Sample> mIndex;
FallibleTArray<MP4DataOffset> mDataOffset;
nsAutoPtr<MoofParser> mMoofParser;
nsTArray<SampleIterator*> mIterators;
// ConvertByteRangesToTimeRanges cache
mozilla::MediaByteRangeSet mLastCachedRanges;
mozilla::media::TimeIntervals mLastBufferedRanges;
--- a/dom/media/mp4/MP4Demuxer.cpp
+++ b/dom/media/mp4/MP4Demuxer.cpp
@@ -61,20 +61,20 @@ public:
private:
friend class MP4Demuxer;
void NotifyDataArrived();
already_AddRefed<MediaRawData> GetNextSample();
void EnsureUpToDateIndex();
void SetNextKeyFrameTime();
RefPtr<MP4Demuxer> mParent;
- RefPtr<mp4_demuxer::ResourceStream> mStream;
+ RefPtr<ResourceStream> mStream;
UniquePtr<TrackInfo> mInfo;
- RefPtr<mp4_demuxer::Index> mIndex;
- UniquePtr<mp4_demuxer::SampleIterator> mIterator;
+ RefPtr<Index> mIndex;
+ UniquePtr<SampleIterator> mIterator;
Maybe<media::TimeUnit> mNextKeyframeTime;
// Queued samples extracted by the demuxer, but not yet returned.
RefPtr<MediaRawData> mQueuedSample;
bool mNeedReIndex;
bool mNeedSPSForTelemetry;
bool mIsH264 = false;
};
@@ -113,24 +113,24 @@ AccumulateSPSTelemetry(const MediaByteBu
return false;
}
return true;
}
MP4Demuxer::MP4Demuxer(MediaResource* aResource)
: mResource(aResource)
- , mStream(new mp4_demuxer::ResourceStream(aResource))
+ , mStream(new ResourceStream(aResource))
{
}
RefPtr<MP4Demuxer::InitPromise>
MP4Demuxer::Init()
{
- AutoPinned<mp4_demuxer::ResourceStream> stream(mStream);
+ AutoPinned<ResourceStream> stream(mStream);
// 'result' will capture the first warning, if any.
MediaResult result{NS_OK};
MP4Metadata::ResultAndByteBuffer initData =
MP4Metadata::Metadata(stream);
if (!initData.Ref()) {
return InitPromise::CreateAndReject(
@@ -138,18 +138,18 @@ MP4Demuxer::Init()
? Move(initData.Result())
: MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
RESULT_DETAIL("Invalid MP4 metadata or OOM")),
__func__);
} else if (NS_FAILED(initData.Result()) && result == NS_OK) {
result = Move(initData.Result());
}
- RefPtr<mp4_demuxer::BufferStream> bufferstream =
- new mp4_demuxer::BufferStream(initData.Ref());
+ RefPtr<BufferStream> bufferstream =
+ new BufferStream(initData.Ref());
MP4Metadata metadata{bufferstream};
nsresult rv = metadata.Parse();
if (NS_FAILED(rv)) {
return InitPromise::CreateAndReject(
MediaResult(rv, RESULT_DETAIL("Parse MP4 metadata failed")), __func__);
}
@@ -346,23 +346,23 @@ MP4Demuxer::GetCrypto()
}
return crypto;
}
MP4TrackDemuxer::MP4TrackDemuxer(MP4Demuxer* aParent,
UniquePtr<TrackInfo>&& aInfo,
const IndiceWrapper& aIndices)
: mParent(aParent)
- , mStream(new mp4_demuxer::ResourceStream(mParent->mResource))
+ , mStream(new ResourceStream(mParent->mResource))
, mInfo(Move(aInfo))
- , mIndex(new mp4_demuxer::Index(aIndices,
- mStream,
- mInfo->mTrackId,
- mInfo->IsAudio()))
- , mIterator(MakeUnique<mp4_demuxer::SampleIterator>(mIndex))
+ , mIndex(new Index(aIndices,
+ mStream,
+ mInfo->mTrackId,
+ mInfo->IsAudio()))
+ , mIterator(MakeUnique<SampleIterator>(mIndex))
, mNeedReIndex(true)
{
EnsureUpToDateIndex(); // Force update of index
VideoInfo* videoInfo = mInfo->GetAsVideoInfo();
// Collect telemetry from h264 AVCC SPS.
if (videoInfo && (mInfo->mMimeType.EqualsLiteral("video/mp4") ||
mInfo->mMimeType.EqualsLiteral("video/avc"))) {
@@ -547,17 +547,17 @@ MP4TrackDemuxer::GetSamples(int32_t aNum
}
return SamplesPromise::CreateAndResolve(samples, __func__);
}
void
MP4TrackDemuxer::SetNextKeyFrameTime()
{
mNextKeyframeTime.reset();
- mp4_demuxer::Microseconds frameTime = mIterator->GetNextKeyframeTime();
+ Microseconds frameTime = mIterator->GetNextKeyframeTime();
if (frameTime != -1) {
mNextKeyframeTime.emplace(
media::TimeUnit::FromMicroseconds(frameTime));
}
}
void
MP4TrackDemuxer::Reset()
--- a/dom/media/mp4/MP4Demuxer.h
+++ b/dom/media/mp4/MP4Demuxer.h
@@ -7,25 +7,19 @@
#if !defined(MP4Demuxer_h_)
#define MP4Demuxer_h_
#include "mozilla/Maybe.h"
#include "mozilla/Monitor.h"
#include "MediaDataDemuxer.h"
#include "MediaResource.h"
-namespace mp4_demuxer {
-class MP4Metadata;
+namespace mozilla {
+class MP4TrackDemuxer;
class ResourceStream;
-class SampleIterator;
-} // namespace mp4_demuxer
-
-namespace mozilla {
-
-class MP4TrackDemuxer;
class MP4Demuxer : public MediaDataDemuxer
{
public:
explicit MP4Demuxer(MediaResource* aResource);
RefPtr<InitPromise> Init() override;
@@ -40,17 +34,17 @@ public:
void NotifyDataArrived() override;
void NotifyDataRemoved() override;
private:
friend class MP4TrackDemuxer;
RefPtr<MediaResource> mResource;
- RefPtr<mp4_demuxer::ResourceStream> mStream;
+ RefPtr<ResourceStream> mStream;
AutoTArray<RefPtr<MP4TrackDemuxer>, 1> mAudioDemuxers;
AutoTArray<RefPtr<MP4TrackDemuxer>, 1> mVideoDemuxers;
nsTArray<uint8_t> mCryptoInitData;
bool mIsSeekable;
};
} // namespace mozilla
rename from dom/media/mp4/Interval.h
rename to dom/media/mp4/MP4Interval.h
--- a/dom/media/mp4/Interval.h
+++ b/dom/media/mp4/MP4Interval.h
@@ -3,145 +3,145 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef INTERVAL_H_
#define INTERVAL_H_
#include "nsTArray.h"
#include <algorithm>
-namespace mp4_demuxer
+namespace mozilla
{
template <typename T>
-struct Interval
+struct MP4Interval
{
- Interval() : start(0), end(0) {}
- Interval(T aStart, T aEnd) : start(aStart), end(aEnd)
+ MP4Interval() : start(0), end(0) {}
+ MP4Interval(T aStart, T aEnd) : start(aStart), end(aEnd)
{
MOZ_ASSERT(aStart <= aEnd);
}
T Length() { return end - start; }
- Interval Intersection(const Interval& aOther) const
+ MP4Interval Intersection(const MP4Interval& aOther) const
{
T s = start > aOther.start ? start : aOther.start;
T e = end < aOther.end ? end : aOther.end;
if (s > e) {
- return Interval();
+ return MP4Interval();
}
- return Interval(s, e);
+ return MP4Interval(s, e);
}
- bool Contains(const Interval& aOther) const
+ bool Contains(const MP4Interval& aOther) const
{
return aOther.start >= start && aOther.end <= end;
}
- bool operator==(const Interval& aOther) const
+ bool operator==(const MP4Interval& aOther) const
{
return start == aOther.start && end == aOther.end;
}
- bool operator!=(const Interval& aOther) const { return !(*this == aOther); }
+ bool operator!=(const MP4Interval& aOther) const { return !(*this == aOther); }
bool IsNull() const
{
return end == start;
}
- Interval Extents(const Interval& aOther) const
+ MP4Interval Extents(const MP4Interval& aOther) const
{
if (IsNull()) {
return aOther;
}
- return Interval(std::min(start, aOther.start),
+ return MP4Interval(std::min(start, aOther.start),
std::max(end, aOther.end));
}
T start;
T end;
- static void SemiNormalAppend(nsTArray<Interval<T>>& aIntervals,
- Interval<T> aInterval)
+ static void SemiNormalAppend(nsTArray<MP4Interval<T>>& aIntervals,
+ MP4Interval<T> aMP4Interval)
{
if (!aIntervals.IsEmpty() &&
- aIntervals.LastElement().end == aInterval.start) {
- aIntervals.LastElement().end = aInterval.end;
+ aIntervals.LastElement().end == aMP4Interval.start) {
+ aIntervals.LastElement().end = aMP4Interval.end;
} else {
- aIntervals.AppendElement(aInterval);
+ aIntervals.AppendElement(aMP4Interval);
}
}
- static void Normalize(const nsTArray<Interval<T>>& aIntervals,
- nsTArray<Interval<T>>* aNormalized)
+ static void Normalize(const nsTArray<MP4Interval<T>>& aIntervals,
+ nsTArray<MP4Interval<T>>* aNormalized)
{
if (!aNormalized || !aIntervals.Length()) {
MOZ_ASSERT(aNormalized);
return;
}
MOZ_ASSERT(aNormalized->IsEmpty());
- nsTArray<Interval<T>> sorted;
+ nsTArray<MP4Interval<T>> sorted;
sorted = aIntervals;
sorted.Sort(Compare());
- Interval<T> current = sorted[0];
+ MP4Interval<T> current = sorted[0];
for (size_t i = 1; i < sorted.Length(); i++) {
MOZ_ASSERT(sorted[i].start <= sorted[i].end);
if (current.Contains(sorted[i])) {
continue;
}
if (current.end >= sorted[i].start) {
current.end = sorted[i].end;
} else {
aNormalized->AppendElement(current);
current = sorted[i];
}
}
aNormalized->AppendElement(current);
}
- static void Intersection(const nsTArray<Interval<T>>& a0,
- const nsTArray<Interval<T>>& a1,
- nsTArray<Interval<T>>* aIntersection)
+ static void Intersection(const nsTArray<MP4Interval<T>>& a0,
+ const nsTArray<MP4Interval<T>>& a1,
+ nsTArray<MP4Interval<T>>* aIntersection)
{
MOZ_ASSERT(IsNormalized(a0));
MOZ_ASSERT(IsNormalized(a1));
size_t i0 = 0;
size_t i1 = 0;
while (i0 < a0.Length() && i1 < a1.Length()) {
- Interval i = a0[i0].Intersection(a1[i1]);
+ MP4Interval i = a0[i0].Intersection(a1[i1]);
if (i.Length()) {
aIntersection->AppendElement(i);
}
if (a0[i0].end < a1[i1].end) {
i0++;
// Assert that the array is sorted
MOZ_ASSERT(i0 == a0.Length() || a0[i0 - 1].start < a0[i0].start);
} else {
i1++;
// Assert that the array is sorted
MOZ_ASSERT(i1 == a1.Length() || a1[i1 - 1].start < a1[i1].start);
}
}
}
- static bool IsNormalized(const nsTArray<Interval<T>>& aIntervals)
+ static bool IsNormalized(const nsTArray<MP4Interval<T>>& aIntervals)
{
for (size_t i = 1; i < aIntervals.Length(); i++) {
if (aIntervals[i - 1].end >= aIntervals[i].start) {
return false;
}
}
return true;
}
struct Compare
{
- bool Equals(const Interval<T>& a0, const Interval<T>& a1) const
+ bool Equals(const MP4Interval<T>& a0, const MP4Interval<T>& a1) const
{
return a0.start == a1.start && a0.end == a1.end;
}
- bool LessThan(const Interval<T>& a0, const Interval<T>& a1) const
+ bool LessThan(const MP4Interval<T>& a0, const MP4Interval<T>& a1) const
{
return a0.start < a1.start;
}
};
};
}
#endif
--- a/dom/media/mp4/MP4Metadata.cpp
+++ b/dom/media/mp4/MP4Metadata.cpp
@@ -7,28 +7,25 @@
#include "mozilla/EndianUtils.h"
#include "mozilla/Logging.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Telemetry.h"
#include "mozilla/UniquePtr.h"
#include "VideoUtils.h"
#include "MoofParser.h"
#include "MP4Metadata.h"
-#include "Stream.h"
+#include "ByteStream.h"
#include "MediaPrefs.h"
#include "mp4parse.h"
#include <limits>
#include <stdint.h>
#include <vector>
using mozilla::media::TimeUnit;
-using mp4_demuxer::Stream;
-using mp4_demuxer::Index;
-using mp4_demuxer::MoofParser;
namespace mozilla {
LazyLogModule gMP4MetadataLog("MP4Metadata");
// the owner of mIndice is rust mp4 paser, so lifetime of this class
// SHOULD NOT longer than rust parser.
class IndiceWrapperRust : public IndiceWrapper
{
@@ -113,17 +110,17 @@ read_source(uint8_t* buffer, uintptr_t s
bool rv = source->Read(buffer, size, &bytes_read);
if (!rv) {
MOZ_LOG(gMP4MetadataLog, LogLevel::Warning, ("Error reading source data"));
return -1;
}
return bytes_read;
}
-MP4Metadata::MP4Metadata(Stream* aSource)
+MP4Metadata::MP4Metadata(ByteStream* aSource)
: mSource(aSource)
, mSourceAdaptor(aSource)
{
mp4parse_io io = { read_source, &mSourceAdaptor };
mParser.reset(mp4parse_new(&io));
MOZ_ASSERT(mParser);
if (MOZ_LOG_TEST(gMP4MetadataLog, LogLevel::Debug)) {
@@ -390,17 +387,17 @@ MP4Metadata::GetTrackIndice(mozilla::Tra
UniquePtr<IndiceWrapper> indice;
indice = mozilla::MakeUnique<IndiceWrapperRust>(indiceRawData);
return {NS_OK, Move(indice)};
}
/*static*/ MP4Metadata::ResultAndByteBuffer
-MP4Metadata::Metadata(Stream* aSource)
+MP4Metadata::Metadata(ByteStream* aSource)
{
auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false);
RefPtr<mozilla::MediaByteBuffer> buffer = parser->Metadata();
if (!buffer) {
return {MediaResult(NS_ERROR_DOM_MEDIA_METADATA_ERR,
RESULT_DETAIL("Cannot parse metadata")),
nullptr};
}
--- a/dom/media/mp4/MP4Metadata.h
+++ b/dom/media/mp4/MP4Metadata.h
@@ -7,56 +7,56 @@
#include "mozilla/TypeTraits.h"
#include "mozilla/UniquePtr.h"
#include "DecoderData.h"
#include "Index.h"
#include "MediaData.h"
#include "MediaInfo.h"
#include "MediaResult.h"
-#include "Stream.h"
+#include "ByteStream.h"
#include "mp4parse.h"
namespace mozilla {
class IndiceWrapper {
public:
virtual size_t Length() const = 0;
// TODO: Index::Indice is from stagefright, we should use another struct once
// stagefrigth is removed.
- virtual bool GetIndice(size_t aIndex, mp4_demuxer::Index::Indice& aIndice) const = 0;
+ virtual bool GetIndice(size_t aIndex, Index::Indice& aIndice) const = 0;
virtual ~IndiceWrapper() {}
};
struct FreeMP4Parser { void operator()(mp4parse_parser* aPtr) { mp4parse_free(aPtr); } };
// Wrap an Stream to remember the read offset.
class StreamAdaptor {
public:
- explicit StreamAdaptor(mp4_demuxer::Stream* aSource)
+ explicit StreamAdaptor(ByteStream* aSource)
: mSource(aSource)
, mOffset(0)
{
}
~StreamAdaptor() {}
bool Read(uint8_t* buffer, uintptr_t size, size_t* bytes_read);
private:
- mp4_demuxer::Stream* mSource;
+ ByteStream* mSource;
CheckedInt<size_t> mOffset;
};
class MP4Metadata
{
public:
- explicit MP4Metadata(mp4_demuxer::Stream* aSource);
+ explicit MP4Metadata(ByteStream* aSource);
~MP4Metadata();
// Simple template class containing a MediaResult and another type.
template <typename T>
class ResultAndType
{
public:
template <typename M2, typename T2>
@@ -73,17 +73,17 @@ public:
T& Ref() { return mT; }
private:
mozilla::MediaResult mResult;
typename mozilla::Decay<T>::Type mT;
};
using ResultAndByteBuffer = ResultAndType<RefPtr<mozilla::MediaByteBuffer>>;
- static ResultAndByteBuffer Metadata(mp4_demuxer::Stream* aSource);
+ static ResultAndByteBuffer Metadata(ByteStream* aSource);
static constexpr uint32_t NumberTracksError() { return UINT32_MAX; }
using ResultAndTrackCount = ResultAndType<uint32_t>;
ResultAndTrackCount GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
using ResultAndTrackInfo =
ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo>>;
ResultAndTrackInfo GetTrackInfo(mozilla::TrackInfo::TrackType aType,
@@ -99,16 +99,16 @@ public:
nsresult Parse();
private:
void UpdateCrypto();
Maybe<uint32_t> TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const;
CryptoFile mCrypto;
- RefPtr<mp4_demuxer::Stream> mSource;
+ RefPtr<ByteStream> mSource;
StreamAdaptor mSourceAdaptor;
mozilla::UniquePtr<mp4parse_parser, FreeMP4Parser> mParser;
};
} // namespace mozilla
#endif // MP4METADATA_H_
--- a/dom/media/mp4/MoofParser.cpp
+++ b/dom/media/mp4/MoofParser.cpp
@@ -1,36 +1,34 @@
/* 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 "MoofParser.h"
#include "Box.h"
#include "SinfParser.h"
#include <limits>
-#include "Intervals.h"
+#include "MP4Interval.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Logging.h"
#if defined(MOZ_FMP4)
extern mozilla::LogModule* GetDemuxerLog();
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define LOG(name, arg, ...) MOZ_LOG(GetDemuxerLog(), mozilla::LogLevel::Debug, (TOSTRING(name) "(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
#else
#define LOG(...)
#endif
-namespace mp4_demuxer
+namespace mozilla
{
-using namespace mozilla;
-
const uint32_t kKeyIdSize = 16;
bool
MoofParser::RebuildFragmentedIndex(const MediaByteRangeSet& aByteRanges)
{
BoxContext context(mSource, aByteRanges);
return RebuildFragmentedIndex(context);
}
@@ -108,19 +106,19 @@ MoofParser::FirstCompleteMediaSegment()
for (uint32_t i = 0 ; i < mMediaRanges.Length(); i++) {
if (mMediaRanges[i].Contains(Moofs()[i].mMdatRange)) {
return mMediaRanges[i];
}
}
return MediaByteRange();
}
-class BlockingStream : public Stream {
+class BlockingStream : public ByteStream {
public:
- explicit BlockingStream(Stream* aStream) : mStream(aStream)
+ explicit BlockingStream(ByteStream* aStream) : mStream(aStream)
{
}
bool ReadAt(int64_t offset, void* data, size_t size, size_t* bytes_read)
override
{
return mStream->ReadAt(offset, data, size, bytes_read);
}
@@ -132,27 +130,27 @@ public:
}
virtual bool Length(int64_t* size) override
{
return mStream->Length(size);
}
private:
- RefPtr<Stream> mStream;
+ RefPtr<ByteStream> mStream;
};
bool
MoofParser::BlockingReadNextMoof()
{
int64_t length = std::numeric_limits<int64_t>::max();
mSource->Length(&length);
MediaByteRangeSet byteRanges;
byteRanges += MediaByteRange(0, length);
- RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
+ RefPtr<BlockingStream> stream = new BlockingStream(mSource);
BoxContext context(stream, byteRanges);
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
if (box.IsType("moof")) {
byteRanges.Clear();
byteRanges += MediaByteRange(mOffset, box.Range().mEnd);
return RebuildFragmentedIndex(context);
}
@@ -163,17 +161,17 @@ MoofParser::BlockingReadNextMoof()
void
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
mozilla::MediaByteRange& aMoov)
{
int64_t length = std::numeric_limits<int64_t>::max();
mSource->Length(&length);
MediaByteRangeSet byteRanges;
byteRanges += MediaByteRange(0, length);
- RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
+ RefPtr<BlockingStream> stream = new BlockingStream(mSource);
BoxContext context(stream, byteRanges);
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
if (box.IsType("ftyp")) {
aFtyp = box.Range();
continue;
}
if (box.IsType("moov")) {
@@ -212,35 +210,35 @@ MoofParser::Metadata()
return nullptr;
}
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
if (!metadata->SetLength(totalLength.value(), fallible)) {
LOG(Moof, "OOM");
return nullptr;
}
- RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
+ RefPtr<BlockingStream> stream = new BlockingStream(mSource);
size_t read;
bool rv =
stream->ReadAt(ftyp.mStart, metadata->Elements(), ftypLength.value(), &read);
if (!rv || read != ftypLength.value()) {
return nullptr;
}
rv =
stream->ReadAt(moov.mStart, metadata->Elements() + ftypLength.value(), moovLength.value(), &read);
if (!rv || read != moovLength.value()) {
return nullptr;
}
return metadata.forget();
}
-Interval<Microseconds>
+MP4Interval<Microseconds>
MoofParser::GetCompositionRange(const MediaByteRangeSet& aByteRanges)
{
- Interval<Microseconds> compositionRange;
+ MP4Interval<Microseconds> compositionRange;
BoxContext context(mSource, aByteRanges);
for (size_t i = 0; i < mMoofs.Length(); i++) {
Moof& moof = mMoofs[i];
Box box(&context, moof.mRange.mStart);
if (box.IsAvailable()) {
compositionRange = compositionRange.Extents(moof.mTimeRange);
}
}
@@ -451,17 +449,17 @@ Moof::Moof(Box& aBox, Trex& aTrex, Mvhd&
int64_t dtsOffset = mIndex[0].mDecodeTime;
int64_t compositionDuration = 0;
// Adjust the dts, ensuring that the new adjusted dts will never be greater
// than decodeTime (the next moof's decode start time).
for (auto& sample : mIndex) {
sample.mDecodeTime = dtsOffset + int64_t(compositionDuration * adjust);
compositionDuration += sample.mCompositionRange.Length();
}
- mTimeRange = Interval<Microseconds>(ctsOrder[0]->mCompositionRange.start,
+ mTimeRange = MP4Interval<Microseconds>(ctsOrder[0]->mCompositionRange.start,
ctsOrder.LastElement()->mCompositionRange.end);
}
ProcessCenc();
}
}
bool
Moof::GetAuxInfo(AtomType aType, FallibleTArray<MediaByteRange>* aByteRanges)
@@ -646,17 +644,17 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd,
MOZ_TRY_VAR(tmp, reader->ReadU32());
offset += tmp;
}
uint32_t firstSampleFlags = aTfhd.mDefaultSampleFlags;
if (flags & 0x04) {
MOZ_TRY_VAR(firstSampleFlags, reader->ReadU32());
}
uint64_t decodeTime = *aDecodeTime;
- nsTArray<Interval<Microseconds>> timeRanges;
+ nsTArray<MP4Interval<Microseconds>> timeRanges;
if (!mIndex.SetCapacity(sampleCount, fallible)) {
LOG(Moof, "Out of Memory");
return Err(NS_ERROR_FAILURE);
}
for (size_t i = 0; i < sampleCount; i++) {
uint32_t sampleDuration = aTfhd.mDefaultSampleDuration;
@@ -682,17 +680,17 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd,
offset += sampleSize;
Microseconds decodeOffset, emptyOffset, startCts, endCts;
MOZ_TRY_VAR(decodeOffset, aMdhd.ToMicroseconds((int64_t)decodeTime - aEdts.mMediaStart));
MOZ_TRY_VAR(emptyOffset, aMvhd.ToMicroseconds(aEdts.mEmptyOffset));
sample.mDecodeTime = decodeOffset + emptyOffset;
MOZ_TRY_VAR(startCts, aMdhd.ToMicroseconds((int64_t)decodeTime + ctsOffset - aEdts.mMediaStart));
MOZ_TRY_VAR(endCts, aMdhd.ToMicroseconds((int64_t)decodeTime + ctsOffset + sampleDuration - aEdts.mMediaStart));
- sample.mCompositionRange = Interval<Microseconds>(startCts + emptyOffset, endCts + emptyOffset);
+ sample.mCompositionRange = MP4Interval<Microseconds>(startCts + emptyOffset, endCts + emptyOffset);
// Sometimes audio streams don't properly mark their samples as keyframes,
// because every audio sample is a keyframe.
sample.mSync = !(sampleFlags & 0x1010000) || aIsAudio;
// FIXME: Make this infallible after bug 968520 is done.
MOZ_ALWAYS_TRUE(mIndex.AppendElement(sample, fallible));
mMdatRange = mMdatRange.Span(sample.mByteRange);
--- a/dom/media/mp4/MoofParser.h
+++ b/dom/media/mp4/MoofParser.h
@@ -4,21 +4,21 @@
#ifndef MOOF_PARSER_H_
#define MOOF_PARSER_H_
#include "mozilla/ResultExtensions.h"
#include "Atom.h"
#include "AtomType.h"
#include "SinfParser.h"
-#include "Stream.h"
-#include "Interval.h"
+#include "ByteStream.h"
+#include "MP4Interval.h"
#include "MediaResource.h"
-namespace mp4_demuxer {
+namespace mozilla {
typedef int64_t Microseconds;
class Box;
class BoxContext;
class BoxReader;
class Moof;
class Mvhd : public Atom
@@ -155,17 +155,17 @@ protected:
Result<Ok, nsresult> Parse(Box& aBox);
};
struct Sample
{
mozilla::MediaByteRange mByteRange;
mozilla::MediaByteRange mCencRange;
Microseconds mDecodeTime;
- Interval<Microseconds> mCompositionRange;
+ MP4Interval<Microseconds> mCompositionRange;
bool mSync;
};
class Saiz final : public Atom
{
public:
Saiz(Box& aBox, AtomType aDefaultType);
@@ -257,17 +257,17 @@ class Moof final : public Atom
{
public:
Moof(Box& aBox, Trex& aTrex, Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, Sinf& aSinf, uint64_t* aDecoderTime, bool aIsAudio);
bool GetAuxInfo(AtomType aType, FallibleTArray<MediaByteRange>* aByteRanges);
void FixRounding(const Moof& aMoof);
mozilla::MediaByteRange mRange;
mozilla::MediaByteRange mMdatRange;
- Interval<Microseconds> mTimeRange;
+ MP4Interval<Microseconds> mTimeRange;
FallibleTArray<Sample> mIndex;
FallibleTArray<CencSampleEncryptionInfoEntry> mFragmentSampleEncryptionInfoEntries;
FallibleTArray<SampleToGroupEntry> mFragmentSampleToGroupEntries;
FallibleTArray<Saiz> mSaizs;
FallibleTArray<Saio> mSaios;
nsTArray<nsTArray<uint8_t>> mPsshes;
@@ -281,17 +281,17 @@ private:
void ParseSaio(Box& aBox);
bool ProcessCenc();
uint64_t mMaxRoundingError;
};
class MoofParser
{
public:
- MoofParser(Stream* aSource, uint32_t aTrackId, bool aIsAudio)
+ MoofParser(ByteStream* aSource, uint32_t aTrackId, bool aIsAudio)
: mSource(aSource)
, mOffset(0)
, mTrex(aTrackId)
, mIsAudio(aIsAudio)
, mLastDecodeTime(0)
{
// Setting the mTrex.mTrackId to 0 is a nasty work around for calculating
// the composition range for MSE. We need an array of tracks.
@@ -299,17 +299,17 @@ public:
bool RebuildFragmentedIndex(
const mozilla::MediaByteRangeSet& aByteRanges);
// If *aCanEvict is set to true. then will remove all moofs already parsed
// from index then rebuild the index. *aCanEvict is set to true upon return if
// some moofs were removed.
bool RebuildFragmentedIndex(
const mozilla::MediaByteRangeSet& aByteRanges, bool* aCanEvict);
bool RebuildFragmentedIndex(BoxContext& aContext);
- Interval<Microseconds> GetCompositionRange(
+ MP4Interval<Microseconds> GetCompositionRange(
const mozilla::MediaByteRangeSet& aByteRanges);
bool ReachedEnd();
void ParseMoov(Box& aBox);
void ParseTrak(Box& aBox);
void ParseMdia(Box& aBox, Tkhd& aTkhd);
void ParseMvex(Box& aBox);
void ParseMinf(Box& aBox);
@@ -320,17 +320,17 @@ public:
bool BlockingReadNextMoof();
bool HasMetadata();
already_AddRefed<mozilla::MediaByteBuffer> Metadata();
MediaByteRange FirstCompleteMediaSegment();
MediaByteRange FirstCompleteMediaHeader();
mozilla::MediaByteRange mInitRange;
- RefPtr<Stream> mSource;
+ RefPtr<ByteStream> mSource;
uint64_t mOffset;
Mvhd mMvhd;
Mdhd mMdhd;
Trex mTrex;
Tfdt mTfdt;
Edts mEdts;
Sinf mSinf;
--- a/dom/media/mp4/ResourceStream.cpp
+++ b/dom/media/mp4/ResourceStream.cpp
@@ -1,17 +1,17 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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 "ResourceStream.h"
-namespace mp4_demuxer {
+namespace mozilla {
ResourceStream::ResourceStream(mozilla::MediaResource* aResource)
: mResource(aResource)
, mPinCount(0)
{
MOZ_ASSERT(aResource);
}
@@ -59,9 +59,9 @@ bool
ResourceStream::Length(int64_t* aSize)
{
if (mResource.GetLength() < 0)
return false;
*aSize = mResource.GetLength();
return true;
}
-} // namespace mp4_demuxer
+} // namespace mozilla
--- a/dom/media/mp4/ResourceStream.h
+++ b/dom/media/mp4/ResourceStream.h
@@ -1,23 +1,23 @@
/* 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/. */
#ifndef RESOURCESTREAM_H_
#define RESOURCESTREAM_H_
#include "MediaResource.h"
-#include "Stream.h"
+#include "ByteStream.h"
#include "mozilla/RefPtr.h"
-namespace mp4_demuxer
+namespace mozilla
{
-class ResourceStream : public Stream
+class ResourceStream : public ByteStream
{
public:
explicit ResourceStream(mozilla::MediaResource* aResource);
virtual bool ReadAt(int64_t offset, void* aBuffer, size_t aCount,
size_t* aBytesRead) override;
virtual bool CachedReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
size_t* aBytesRead) override;
--- a/dom/media/mp4/SinfParser.cpp
+++ b/dom/media/mp4/SinfParser.cpp
@@ -1,19 +1,19 @@
/* 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 "mozilla/Unused.h"
#include "SinfParser.h"
#include "AtomType.h"
#include "Box.h"
-#include "Stream.h"
+#include "ByteStream.h"
-namespace mp4_demuxer {
+namespace mozilla {
Sinf::Sinf(Box& aBox)
: mDefaultIVSize(0)
, mDefaultEncryptionType()
{
SinfParser parser(aBox);
if (parser.GetSinf().IsValid()) {
*this = parser.GetSinf();
--- a/dom/media/mp4/SinfParser.h
+++ b/dom/media/mp4/SinfParser.h
@@ -5,17 +5,17 @@
#ifndef SINF_PARSER_H_
#define SINF_PARSER_H_
#include "mozilla/ResultExtensions.h"
#include "Atom.h"
#include "AtomType.h"
-namespace mp4_demuxer {
+namespace mozilla {
class Box;
class Sinf : public Atom
{
public:
Sinf()
: mDefaultIVSize(0)
--- a/dom/media/mp4/moz.build
+++ b/dom/media/mp4/moz.build
@@ -4,26 +4,26 @@
# 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/.
EXPORTS += [
'Atom.h',
'AtomType.h',
'Box.h',
'BufferStream.h',
+ 'ByteStream.h',
'DecoderData.h',
'Index.h',
- 'Interval.h',
'MoofParser.h',
'MP4Decoder.h',
'MP4Demuxer.h',
+ 'MP4Interval.h',
'MP4Metadata.h',
'ResourceStream.h',
'SinfParser.h',
- 'Stream.h',
]
UNIFIED_SOURCES += [
'Box.cpp',
'BufferStream.cpp',
'DecoderData.cpp',
'Index.cpp',
'MoofParser.cpp',