mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1331289 - Use MediaContainerType in MediaResource, SourceBuffer, TrackBuffersManager, and dependencies - r=jya
Continuing the work of replacing MIME strings with MediaContainerType, starting from MediaResource and following the dependencies. Most changes are mechanical: Just change ns*String into MediaContainerType, and MIME string literals into MEDIAMIMETYPE("a/b"). Some checks for empty/invalid strings and lowercase comparisons can go, thanks to the always-valid always-lowercase-MIME invariants of MediaContainerType. One special case in is MediaSourceResource, which used to have an empty string as its type (because its own type is not relevant, but its SourceBuffers carry types). Because the inherited GetContentType *must* be overridden, and must return a MediaContainerType, we needed a valid type even though it should not be seen in the real world. I've chosen "application/x.mediasource" for that. MozReview-Commit-ID: 1aCH75Kh2e6 --HG-- extra : rebase_source : 0d9cd9b69c264e5dcfc3845f80ee107f4bcbcd9a
This commit is contained in:
parent
8a55ba31d3
commit
f17dd305d6
@ -44,8 +44,9 @@ VP9Benchmark::IsVP9DecodeFast()
|
||||
sHasRunTest = true;
|
||||
|
||||
RefPtr<WebMDemuxer> demuxer =
|
||||
new WebMDemuxer(new BufferMediaResource(sWebMSample, sizeof(sWebMSample), nullptr,
|
||||
NS_LITERAL_CSTRING("video/webm")));
|
||||
new WebMDemuxer(
|
||||
new BufferMediaResource(sWebMSample, sizeof(sWebMSample), nullptr,
|
||||
MediaContainerType(MEDIAMIMETYPE("video/webm"))));
|
||||
RefPtr<Benchmark> estimiser =
|
||||
new Benchmark(demuxer,
|
||||
{
|
||||
|
@ -23,12 +23,12 @@ public:
|
||||
BufferMediaResource(const uint8_t* aBuffer,
|
||||
uint32_t aLength,
|
||||
nsIPrincipal* aPrincipal,
|
||||
const nsACString& aContentType) :
|
||||
const MediaContainerType& aContainerType) :
|
||||
mBuffer(aBuffer),
|
||||
mLength(aLength),
|
||||
mOffset(0),
|
||||
mPrincipal(aPrincipal),
|
||||
mContentType(aContentType)
|
||||
mContainerType(aContainerType)
|
||||
{
|
||||
}
|
||||
|
||||
@ -105,9 +105,9 @@ private:
|
||||
|
||||
bool IsTransportSeekable() override { return true; }
|
||||
|
||||
const nsCString& GetContentType() const override
|
||||
const MediaContainerType& GetContentType() const override
|
||||
{
|
||||
return mContentType;
|
||||
return mContainerType;
|
||||
}
|
||||
|
||||
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
||||
@ -116,7 +116,7 @@ private:
|
||||
// - mBuffer
|
||||
// - mPrincipal
|
||||
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
||||
size += mContentType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
size += mContainerType.SizeOfExcludingThis(aMallocSizeOf);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -131,7 +131,7 @@ private:
|
||||
uint32_t mLength;
|
||||
uint32_t mOffset;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
const nsCString mContentType;
|
||||
const MediaContainerType mContainerType;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -837,11 +837,8 @@ MediaDecoder::EnsureTelemetryReported()
|
||||
codecs.AppendElement(mInfo->mVideo.GetAsVideoInfo()->mMimeType);
|
||||
}
|
||||
if (codecs.IsEmpty()) {
|
||||
if (mResource->GetContentType().IsEmpty()) {
|
||||
NS_WARNING("Somehow the resource's content type is empty");
|
||||
return;
|
||||
}
|
||||
codecs.AppendElement(nsPrintfCString("resource; %s", mResource->GetContentType().get()));
|
||||
codecs.AppendElement(nsPrintfCString("resource; %s",
|
||||
mResource->GetContentType().OriginalString().Data()));
|
||||
}
|
||||
for (const nsCString& codec : codecs) {
|
||||
DECODER_LOG("Telemetry MEDIA_CODEC_USED= '%s'", codec.get());
|
||||
|
@ -65,8 +65,8 @@ NS_IMPL_QUERY_INTERFACE0(MediaResource)
|
||||
ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
|
||||
nsIChannel* aChannel,
|
||||
nsIURI* aURI,
|
||||
const nsACString& aContentType)
|
||||
: BaseMediaResource(aCallback, aChannel, aURI, aContentType),
|
||||
const MediaContainerType& aContainerType)
|
||||
: BaseMediaResource(aCallback, aChannel, aURI, aContainerType),
|
||||
mOffset(0),
|
||||
mReopenOnError(false),
|
||||
mIgnoreClose(false),
|
||||
@ -837,9 +837,7 @@ ChannelMediaResource::RecreateChannel()
|
||||
// the channel to avoid a sniffing failure, which would be expected because we
|
||||
// are probably seeking in the middle of the bitstream, and sniffing relies
|
||||
// on the presence of a magic number at the beginning of the stream.
|
||||
NS_ASSERTION(!GetContentType().IsEmpty(),
|
||||
"When recreating a channel, we should know the Content-Type.");
|
||||
mChannel->SetContentType(GetContentType());
|
||||
mChannel->SetContentType(GetContentType().OriginalString());
|
||||
mSuspendAgent.NotifyChannelOpened(mChannel);
|
||||
|
||||
// Tell the cache to reset the download status when the channel is reopened.
|
||||
@ -1111,8 +1109,8 @@ public:
|
||||
FileMediaResource(MediaResourceCallback* aCallback,
|
||||
nsIChannel* aChannel,
|
||||
nsIURI* aURI,
|
||||
const nsACString& aContentType) :
|
||||
BaseMediaResource(aCallback, aChannel, aURI, aContentType),
|
||||
const MediaContainerType& aContainerType) :
|
||||
BaseMediaResource(aCallback, aChannel, aURI, aContainerType),
|
||||
mSize(-1),
|
||||
mLock("FileMediaResource.mLock"),
|
||||
mSizeInitialized(false)
|
||||
@ -1497,15 +1495,19 @@ MediaResource::Create(MediaResourceCallback* aCallback, nsIChannel* aChannel)
|
||||
nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
nsAutoCString contentType;
|
||||
aChannel->GetContentType(contentType);
|
||||
nsAutoCString contentTypeString;
|
||||
aChannel->GetContentType(contentTypeString);
|
||||
Maybe<MediaContainerType> containerType = MakeMediaContainerType(contentTypeString);
|
||||
if (!containerType) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(aChannel);
|
||||
RefPtr<MediaResource> resource;
|
||||
if (fc || IsBlobURI(uri)) {
|
||||
resource = new FileMediaResource(aCallback, aChannel, uri, contentType);
|
||||
resource = new FileMediaResource(aCallback, aChannel, uri, *containerType);
|
||||
} else {
|
||||
resource = new ChannelMediaResource(aCallback, aChannel, uri, contentType);
|
||||
resource = new ChannelMediaResource(aCallback, aChannel, uri, *containerType);
|
||||
}
|
||||
return resource.forget();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "Intervals.h"
|
||||
#include "MediaCache.h"
|
||||
#include "MediaContainerType.h"
|
||||
#include "MediaData.h"
|
||||
#include "MediaResourceCallback.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
@ -337,10 +338,10 @@ public:
|
||||
// Notify that the last data byte range was loaded.
|
||||
virtual void NotifyLastByteRange() { }
|
||||
|
||||
// Returns the content type of the resource. This is copied from the
|
||||
// Returns the container content type of the resource. This is copied from the
|
||||
// nsIChannel when the MediaResource is created. Safe to call from
|
||||
// any thread.
|
||||
virtual const nsCString& GetContentType() const = 0;
|
||||
virtual const MediaContainerType& GetContentType() const = 0;
|
||||
|
||||
// Return true if the stream is a live stream
|
||||
virtual bool IsRealTime() {
|
||||
@ -383,7 +384,7 @@ public:
|
||||
// Not owned:
|
||||
// - mCallback
|
||||
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
||||
size += mContentType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
size += mContainerType.SizeOfExcludingThis(aMallocSizeOf);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -403,23 +404,22 @@ protected:
|
||||
BaseMediaResource(MediaResourceCallback* aCallback,
|
||||
nsIChannel* aChannel,
|
||||
nsIURI* aURI,
|
||||
const nsACString& aContentType) :
|
||||
const MediaContainerType& aContainerType) :
|
||||
mCallback(aCallback),
|
||||
mChannel(aChannel),
|
||||
mURI(aURI),
|
||||
mContentType(aContentType),
|
||||
mContainerType(aContainerType),
|
||||
mLoadInBackground(false)
|
||||
{
|
||||
NS_ASSERTION(!mContentType.IsEmpty(), "Must know content type");
|
||||
mURI->GetSpec(mContentURL);
|
||||
}
|
||||
virtual ~BaseMediaResource()
|
||||
{
|
||||
}
|
||||
|
||||
const nsCString& GetContentType() const override
|
||||
const MediaContainerType& GetContentType() const override
|
||||
{
|
||||
return mContentType;
|
||||
return mContainerType;
|
||||
}
|
||||
|
||||
// Set the request's load flags to aFlags. If the request is part of a
|
||||
@ -444,7 +444,7 @@ protected:
|
||||
// Content-Type of the channel. This is copied from the nsIChannel when the
|
||||
// MediaResource is created. This is constant, so accessing from any thread
|
||||
// is safe.
|
||||
const nsCString mContentType;
|
||||
const MediaContainerType mContainerType;
|
||||
|
||||
// Copy of the url of the channel resource.
|
||||
nsCString mContentURL;
|
||||
@ -511,7 +511,7 @@ public:
|
||||
ChannelMediaResource(MediaResourceCallback* aDecoder,
|
||||
nsIChannel* aChannel,
|
||||
nsIURI* aURI,
|
||||
const nsACString& aContentType);
|
||||
const MediaContainerType& aContainerType);
|
||||
~ChannelMediaResource();
|
||||
|
||||
// These are called on the main thread by MediaCache. These must
|
||||
|
@ -10,10 +10,11 @@
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
MockMediaResource::MockMediaResource(const char* aFileName, const nsACString& aContentType)
|
||||
MockMediaResource::MockMediaResource(const char* aFileName,
|
||||
const MediaContainerType& aContainerType)
|
||||
: mFileHandle(nullptr)
|
||||
, mFileName(aFileName)
|
||||
, mContentType(aContentType)
|
||||
, mContainerType(aContainerType)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@ namespace mozilla
|
||||
class MockMediaResource : public MediaResource
|
||||
{
|
||||
public:
|
||||
explicit MockMediaResource(const char* aFileName, const nsACString& aMimeType = NS_LITERAL_CSTRING("video/mp4"));
|
||||
explicit MockMediaResource(const char* aFileName,
|
||||
const MediaContainerType& aMimeType =
|
||||
MediaContainerType(MEDIAMIMETYPE("video/mp4")));
|
||||
nsIURI* URI() const override { return nullptr; }
|
||||
nsresult Close() override { return NS_OK; }
|
||||
void Suspend(bool aCloseImmediately) override {}
|
||||
@ -59,9 +61,9 @@ public:
|
||||
bool IsTransportSeekable() override { return true; }
|
||||
nsresult Open(nsIStreamListener** aStreamListener) override;
|
||||
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
|
||||
const nsCString& GetContentType() const override
|
||||
const MediaContainerType& GetContentType() const override
|
||||
{
|
||||
return mContentType;
|
||||
return mContainerType;
|
||||
}
|
||||
|
||||
void MockClearBufferedRanges();
|
||||
@ -75,7 +77,7 @@ private:
|
||||
const char* mFileName;
|
||||
MediaByteRangeSet mRanges;
|
||||
Atomic<int> mEntry;
|
||||
const nsCString mContentType;
|
||||
const MediaContainerType mContainerType;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -51,7 +51,7 @@ TEST(MediaDataDecoder, H264)
|
||||
EXPECT_TRUE(true);
|
||||
} else {
|
||||
RefPtr<MediaResource> resource =
|
||||
new MockMediaResource("gizmo.mp4", NS_LITERAL_CSTRING("video/mp4"));
|
||||
new MockMediaResource("gizmo.mp4", MediaContainerType(MEDIAMIMETYPE("video/mp4")));
|
||||
nsresult rv = resource->Open(nullptr);
|
||||
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
@ -66,7 +66,7 @@ TEST(MediaDataDecoder, VP9)
|
||||
EXPECT_TRUE(true);
|
||||
} else {
|
||||
RefPtr<MediaResource> resource =
|
||||
new MockMediaResource("vp9cake.webm", NS_LITERAL_CSTRING("video/webm"));
|
||||
new MockMediaResource("vp9cake.webm", MediaContainerType(MEDIAMIMETYPE("video/webm")));
|
||||
nsresult rv = resource->Open(nullptr);
|
||||
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
|
@ -26,12 +26,12 @@ extern mozilla::LogModule* GetMediaSourceSamplesLog();
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
#define MSE_DEBUG(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Verbose, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUG(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(name, arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Verbose, (TOSTRING(name) "(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
ContainerParser::ContainerParser(const nsACString& aType)
|
||||
ContainerParser::ContainerParser(const MediaContainerType& aType)
|
||||
: mHasInitData(false)
|
||||
, mType(aType)
|
||||
{
|
||||
@ -115,7 +115,7 @@ ContainerParser::MediaSegmentRange()
|
||||
|
||||
class WebMContainerParser : public ContainerParser {
|
||||
public:
|
||||
explicit WebMContainerParser(const nsACString& aType)
|
||||
explicit WebMContainerParser(const MediaContainerType& aType)
|
||||
: ContainerParser(aType)
|
||||
, mParser(0)
|
||||
, mOffset(0)
|
||||
@ -205,7 +205,8 @@ public:
|
||||
mParser = WebMBufferedParser(0);
|
||||
mOverlappedMapping.Clear();
|
||||
mInitData = new MediaByteBuffer();
|
||||
mResource = new SourceBufferResource(NS_LITERAL_CSTRING("video/webm"));
|
||||
mResource = new SourceBufferResource(
|
||||
MediaContainerType(MEDIAMIMETYPE("video/webm")));
|
||||
mCompleteMediaHeaderRange = MediaByteRange();
|
||||
mCompleteMediaSegmentRange = MediaByteRange();
|
||||
}
|
||||
@ -339,7 +340,7 @@ private:
|
||||
#ifdef MOZ_FMP4
|
||||
class MP4ContainerParser : public ContainerParser {
|
||||
public:
|
||||
explicit MP4ContainerParser(const nsACString& aType)
|
||||
explicit MP4ContainerParser(const MediaContainerType& aType)
|
||||
: ContainerParser(aType)
|
||||
{}
|
||||
|
||||
@ -378,9 +379,9 @@ public:
|
||||
private:
|
||||
class AtomParser {
|
||||
public:
|
||||
AtomParser(const nsACString& aType, const MediaByteBuffer* aData)
|
||||
AtomParser(const MediaContainerType& aType, const MediaByteBuffer* aData)
|
||||
{
|
||||
const nsCString mType(aType); // for logging macro.
|
||||
const MediaContainerType mType(aType); // for logging macro.
|
||||
mp4_demuxer::ByteReader reader(aData);
|
||||
mp4_demuxer::AtomType initAtom("ftyp");
|
||||
mp4_demuxer::AtomType mediaAtom("moof");
|
||||
@ -471,7 +472,8 @@ public:
|
||||
{
|
||||
bool initSegment = NS_SUCCEEDED(IsInitSegmentPresent(aData));
|
||||
if (initSegment) {
|
||||
mResource = new SourceBufferResource(NS_LITERAL_CSTRING("video/mp4"));
|
||||
mResource = new SourceBufferResource(
|
||||
MediaContainerType(MEDIAMIMETYPE("video/mp4")));
|
||||
mStream = new MP4Stream(mResource);
|
||||
// We use a timestampOffset of 0 for ContainerParser, and require
|
||||
// consumers of ParseStartAndEndTimestamps to add their timestamp offset
|
||||
@ -547,7 +549,7 @@ private:
|
||||
#ifdef MOZ_FMP4
|
||||
class ADTSContainerParser : public ContainerParser {
|
||||
public:
|
||||
explicit ADTSContainerParser(const nsACString& aType)
|
||||
explicit ADTSContainerParser(const MediaContainerType& aType)
|
||||
: ContainerParser(aType)
|
||||
{}
|
||||
|
||||
@ -692,17 +694,19 @@ public:
|
||||
#endif // MOZ_FMP4
|
||||
|
||||
/*static*/ ContainerParser*
|
||||
ContainerParser::CreateForMIMEType(const nsACString& aType)
|
||||
ContainerParser::CreateForMIMEType(const MediaContainerType& aType)
|
||||
{
|
||||
if (aType.LowerCaseEqualsLiteral("video/webm") || aType.LowerCaseEqualsLiteral("audio/webm")) {
|
||||
if (aType.Type() == MEDIAMIMETYPE("video/webm")
|
||||
|| aType.Type() == MEDIAMIMETYPE("audio/webm")) {
|
||||
return new WebMContainerParser(aType);
|
||||
}
|
||||
|
||||
#ifdef MOZ_FMP4
|
||||
if (aType.LowerCaseEqualsLiteral("video/mp4") || aType.LowerCaseEqualsLiteral("audio/mp4")) {
|
||||
if (aType.Type() == MEDIAMIMETYPE("video/mp4")
|
||||
|| aType.Type() == MEDIAMIMETYPE("audio/mp4")) {
|
||||
return new MP4ContainerParser(aType);
|
||||
}
|
||||
if (aType.LowerCaseEqualsLiteral("audio/aac")) {
|
||||
if (aType.Type() == MEDIAMIMETYPE("audio/aac")) {
|
||||
return new ADTSContainerParser(aType);
|
||||
}
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#define MOZILLA_CONTAINERPARSER_H_
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "MediaContainerType.h"
|
||||
#include "MediaResource.h"
|
||||
#include "MediaResult.h"
|
||||
|
||||
@ -19,7 +19,7 @@ class SourceBufferResource;
|
||||
|
||||
class ContainerParser {
|
||||
public:
|
||||
explicit ContainerParser(const nsACString& aType);
|
||||
explicit ContainerParser(const MediaContainerType& aType);
|
||||
virtual ~ContainerParser();
|
||||
|
||||
// Return true if aData starts with an initialization segment.
|
||||
@ -73,7 +73,7 @@ public:
|
||||
// range if not complete.
|
||||
MediaByteRange MediaSegmentRange();
|
||||
|
||||
static ContainerParser* CreateForMIMEType(const nsACString& aType);
|
||||
static ContainerParser* CreateForMIMEType(const MediaContainerType& aType);
|
||||
|
||||
protected:
|
||||
RefPtr<MediaByteBuffer> mInitData;
|
||||
@ -82,7 +82,7 @@ protected:
|
||||
MediaByteRange mCompleteInitSegmentRange;
|
||||
MediaByteRange mCompleteMediaHeaderRange;
|
||||
MediaByteRange mCompleteMediaSegmentRange;
|
||||
const nsCString mType;
|
||||
const MediaContainerType mType;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -243,8 +243,7 @@ MediaSource::AddSourceBuffer(const nsAString& aType, ErrorResult& aRv)
|
||||
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
const nsACString& mimeType = containerType->Type().AsString();
|
||||
RefPtr<SourceBuffer> sourceBuffer = new SourceBuffer(this, mimeType);
|
||||
RefPtr<SourceBuffer> sourceBuffer = new SourceBuffer(this, *containerType);
|
||||
if (!sourceBuffer) {
|
||||
aRv.Throw(NS_ERROR_FAILURE); // XXX need a better error here
|
||||
return nullptr;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
extern mozilla::LogModule* GetMediaSourceLog();
|
||||
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSourceResource(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSourceResource(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
#define UNIMPLEMENTED() MSE_DEBUG("UNIMPLEMENTED FUNCTION at %s:%d", __FILE__, __LINE__)
|
||||
|
||||
@ -24,6 +24,8 @@ class MediaSourceResource final : public MediaResource
|
||||
public:
|
||||
explicit MediaSourceResource(nsIPrincipal* aPrincipal = nullptr)
|
||||
: mPrincipal(aPrincipal)
|
||||
// Fake-but-valid MIME type, unused but necessary to implement GetContentType().
|
||||
, mType(MEDIAMIMETYPE("application/x.mediasource"))
|
||||
, mMonitor("MediaSourceResource")
|
||||
, mEnded(false)
|
||||
{}
|
||||
@ -62,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
bool IsTransportSeekable() override { return true; }
|
||||
const nsCString& GetContentType() const override { return mType; }
|
||||
const MediaContainerType& GetContentType() const override { return mType; }
|
||||
|
||||
bool IsLiveStream() override
|
||||
{
|
||||
@ -85,7 +87,7 @@ private:
|
||||
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
||||
{
|
||||
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
||||
size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
size += mType.SizeOfExcludingThis(aMallocSizeOf);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -96,7 +98,7 @@ private:
|
||||
}
|
||||
|
||||
RefPtr<nsIPrincipal> mPrincipal;
|
||||
const nsCString mType;
|
||||
const MediaContainerType mType;
|
||||
Monitor mMonitor;
|
||||
bool mEnded; // protected by mMonitor
|
||||
};
|
||||
|
@ -35,9 +35,9 @@ class JSObject;
|
||||
extern mozilla::LogModule* GetMediaSourceLog();
|
||||
extern mozilla::LogModule* GetMediaSourceAPILog();
|
||||
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -297,11 +297,12 @@ SourceBuffer::Ended()
|
||||
mTrackBuffersManager->Ended();
|
||||
}
|
||||
|
||||
SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
|
||||
SourceBuffer::SourceBuffer(MediaSource* aMediaSource,
|
||||
const MediaContainerType& aType)
|
||||
: DOMEventTargetHelper(aMediaSource->GetParentObject())
|
||||
, mMediaSource(aMediaSource)
|
||||
, mCurrentAttributes(aType.LowerCaseEqualsLiteral("audio/mpeg") ||
|
||||
aType.LowerCaseEqualsLiteral("audio/aac"))
|
||||
, mCurrentAttributes(aType.Type() == MEDIAMIMETYPE("audio/mpeg") ||
|
||||
aType.Type() == MEDIAMIMETYPE("audio/aac"))
|
||||
, mUpdating(false)
|
||||
, mActive(false)
|
||||
, mType(aType)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define mozilla_dom_SourceBuffer_h_
|
||||
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "MediaContainerType.h"
|
||||
#include "MediaSource.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
@ -22,7 +23,6 @@
|
||||
#include "nsCycleCollectionNoteChild.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nscore.h"
|
||||
#include "TrackBuffersManager.h"
|
||||
#include "SourceBufferTask.h"
|
||||
@ -99,7 +99,7 @@ public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper)
|
||||
|
||||
SourceBuffer(MediaSource* aMediaSource, const nsACString& aType);
|
||||
SourceBuffer(MediaSource* aMediaSource, const MediaContainerType& aType);
|
||||
|
||||
MediaSource* GetParentObject() const;
|
||||
|
||||
@ -177,7 +177,7 @@ private:
|
||||
|
||||
MozPromiseRequestHolder<SourceBufferTask::AppendPromise> mPendingAppend;
|
||||
MozPromiseRequestHolder<SourceBufferTask::RangeRemovalPromise> mPendingRemoval;
|
||||
const nsCString mType;
|
||||
const MediaContainerType mType;
|
||||
|
||||
RefPtr<TimeRanges> mBuffered;
|
||||
};
|
||||
|
@ -19,8 +19,8 @@ mozilla::LogModule* GetSourceBufferResourceLog()
|
||||
return sLogModule;
|
||||
}
|
||||
|
||||
#define SBR_DEBUG(arg, ...) MOZ_LOG(GetSourceBufferResourceLog(), mozilla::LogLevel::Debug, ("SourceBufferResource(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define SBR_DEBUGV(arg, ...) MOZ_LOG(GetSourceBufferResourceLog(), mozilla::LogLevel::Verbose, ("SourceBufferResource(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define SBR_DEBUG(arg, ...) MOZ_LOG(GetSourceBufferResourceLog(), mozilla::LogLevel::Debug, ("SourceBufferResource(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
#define SBR_DEBUGV(arg, ...) MOZ_LOG(GetSourceBufferResourceLog(), mozilla::LogLevel::Verbose, ("SourceBufferResource(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -168,7 +168,7 @@ SourceBufferResource::~SourceBufferResource()
|
||||
SBR_DEBUG("");
|
||||
}
|
||||
|
||||
SourceBufferResource::SourceBufferResource(const nsACString& aType)
|
||||
SourceBufferResource::SourceBufferResource(const MediaContainerType& aType)
|
||||
: mType(aType)
|
||||
, mMonitor("mozilla::SourceBufferResource::mMonitor")
|
||||
, mOffset(0)
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nscore.h"
|
||||
#include "mozilla/Logging.h"
|
||||
@ -38,7 +37,7 @@ class SourceBuffer;
|
||||
class SourceBufferResource final : public MediaResource
|
||||
{
|
||||
public:
|
||||
explicit SourceBufferResource(const nsACString& aType);
|
||||
explicit SourceBufferResource(const MediaContainerType& aType);
|
||||
nsresult Close() override;
|
||||
void Suspend(bool aCloseImmediately) override { UNIMPLEMENTED(); }
|
||||
void Resume() override { UNIMPLEMENTED(); }
|
||||
@ -80,14 +79,14 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsCString& GetContentType() const override { return mType; }
|
||||
const MediaContainerType& GetContentType() const override { return mType; }
|
||||
|
||||
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
||||
{
|
||||
ReentrantMonitorAutoEnter mon(mMonitor);
|
||||
|
||||
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
||||
size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
size += mType.SizeOfExcludingThis(aMallocSizeOf);
|
||||
size += mInputBuffer.SizeOfExcludingThis(aMallocSizeOf);
|
||||
|
||||
return size;
|
||||
@ -138,7 +137,7 @@ private:
|
||||
virtual ~SourceBufferResource();
|
||||
nsresult ReadAtInternal(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes, bool aMayBlock);
|
||||
|
||||
const nsCString mType;
|
||||
const MediaContainerType mType;
|
||||
|
||||
// Provides synchronization between SourceBuffers and InputAdapters.
|
||||
// Protects all of the member variables below. Read() will await a
|
||||
|
@ -23,15 +23,15 @@
|
||||
|
||||
extern mozilla::LogModule* GetMediaSourceLog();
|
||||
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
#define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
mozilla::LogModule* GetMediaSourceSamplesLog()
|
||||
{
|
||||
static mozilla::LazyLogModule sLogModule("MediaSourceSamples");
|
||||
return sLogModule;
|
||||
}
|
||||
#define SAMPLE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
|
||||
#define SAMPLE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceSamplesLog(), mozilla::LogLevel::Debug, ("TrackBuffersManager(%p:%s)::%s: " arg, this, mType.OriginalString().Data(), __func__, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -85,7 +85,7 @@ private:
|
||||
};
|
||||
|
||||
TrackBuffersManager::TrackBuffersManager(MediaSourceDecoder* aParentDecoder,
|
||||
const nsACString& aType)
|
||||
const MediaContainerType& aType)
|
||||
: mInputBuffer(new MediaByteBuffer)
|
||||
, mBufferFull(false)
|
||||
, mFirstInitializationSegmentReceived(false)
|
||||
@ -810,15 +810,15 @@ TrackBuffersManager::CreateDemuxerforMIMEType()
|
||||
{
|
||||
ShutdownDemuxers();
|
||||
|
||||
if (mType.LowerCaseEqualsLiteral("video/webm") ||
|
||||
mType.LowerCaseEqualsLiteral("audio/webm")) {
|
||||
if (mType.Type() == MEDIAMIMETYPE("video/webm") ||
|
||||
mType.Type() == MEDIAMIMETYPE("audio/webm")) {
|
||||
mInputDemuxer = new WebMDemuxer(mCurrentInputBuffer, true /* IsMediaSource*/ );
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef MOZ_FMP4
|
||||
if (mType.LowerCaseEqualsLiteral("video/mp4") ||
|
||||
mType.LowerCaseEqualsLiteral("audio/mp4")) {
|
||||
if (mType.Type() == MEDIAMIMETYPE("video/mp4")
|
||||
|| mType.Type() == MEDIAMIMETYPE("audio/mp4")) {
|
||||
mInputDemuxer = new MP4Demuxer(mCurrentInputBuffer);
|
||||
return;
|
||||
}
|
||||
@ -1698,8 +1698,8 @@ TrackBuffersManager::InsertFrames(TrackBuffer& aSamples,
|
||||
|
||||
if (intersection.Length()) {
|
||||
if (aSamples[0]->mKeyframe &&
|
||||
(mType.LowerCaseEqualsLiteral("video/webm") ||
|
||||
mType.LowerCaseEqualsLiteral("audio/webm"))) {
|
||||
(mType.Type() == MEDIAMIMETYPE("video/webm")
|
||||
|| mType.Type() == MEDIAMIMETYPE("audio/webm"))) {
|
||||
// We are starting a new GOP, we do not have to worry about breaking an
|
||||
// existing current coded frame group. Reset the next insertion index
|
||||
// so the search for when to start our frames removal can be exhaustive.
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "AutoTaskQueue.h"
|
||||
#include "mozilla/dom/SourceBufferBinding.h"
|
||||
|
||||
#include "MediaContainerType.h"
|
||||
#include "MediaData.h"
|
||||
#include "MediaDataDemuxer.h"
|
||||
#include "MediaResult.h"
|
||||
@ -21,7 +22,6 @@
|
||||
#include "TimeUnits.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -91,7 +91,7 @@ public:
|
||||
|
||||
// Interface for SourceBuffer
|
||||
TrackBuffersManager(MediaSourceDecoder* aParentDecoder,
|
||||
const nsACString& aType);
|
||||
const MediaContainerType& aType);
|
||||
|
||||
// Queue a task to add data to the end of the input buffer and run the MSE
|
||||
// Buffer Append Algorithm
|
||||
@ -212,7 +212,7 @@ private:
|
||||
// Set to true once a new segment is started.
|
||||
bool mNewMediaSegmentStarted;
|
||||
bool mActiveTrack;
|
||||
nsCString mType;
|
||||
MediaContainerType mType;
|
||||
|
||||
// ContainerParser objects and methods.
|
||||
// Those are used to parse the incoming input buffer.
|
||||
|
@ -13,7 +13,7 @@
|
||||
using namespace mozilla;
|
||||
|
||||
TEST(ContainerParser, MIMETypes) {
|
||||
const char* content_types[] = {
|
||||
const char* containerTypes[] = {
|
||||
"video/webm",
|
||||
"audio/webm",
|
||||
"video/mp4",
|
||||
@ -21,9 +21,10 @@ TEST(ContainerParser, MIMETypes) {
|
||||
"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);
|
||||
for (size_t i = 0; i < ArrayLength(containerTypes); ++i) {
|
||||
Maybe<MediaContainerType> containerType = MakeMediaContainerType(containerTypes[i]);
|
||||
ASSERT_TRUE(containerType.isSome());
|
||||
parser = ContainerParser::CreateForMIMEType(*containerType);
|
||||
ASSERT_NE(parser, nullptr);
|
||||
}
|
||||
}
|
||||
@ -39,7 +40,8 @@ already_AddRefed<MediaByteBuffer> make_adts_header()
|
||||
|
||||
TEST(ContainerParser, ADTSHeader) {
|
||||
nsAutoPtr<ContainerParser> parser;
|
||||
parser = ContainerParser::CreateForMIMEType(NS_LITERAL_CSTRING("audio/aac"));
|
||||
parser = ContainerParser::CreateForMIMEType(MediaContainerType(
|
||||
MEDIAMIMETYPE("audio/aac")));
|
||||
ASSERT_NE(parser, nullptr);
|
||||
|
||||
// Audio data should have no gaps.
|
||||
@ -101,7 +103,8 @@ TEST(ContainerParser, ADTSHeader) {
|
||||
|
||||
TEST(ContainerParser, ADTSBlankMedia) {
|
||||
nsAutoPtr<ContainerParser> parser;
|
||||
parser = ContainerParser::CreateForMIMEType(NS_LITERAL_CSTRING("audio/aac"));
|
||||
parser = ContainerParser::CreateForMIMEType(MediaContainerType(
|
||||
MEDIAMIMETYPE("audio/aac")));
|
||||
ASSERT_NE(parser, nullptr);
|
||||
|
||||
// Audio data should have no gaps.
|
||||
|
@ -195,7 +195,7 @@ MediaDecodeTask::CreateReader()
|
||||
|
||||
RefPtr<BufferMediaResource> resource =
|
||||
new BufferMediaResource(static_cast<uint8_t*> (mBuffer),
|
||||
mLength, principal, mContainerType.Type().AsString());
|
||||
mLength, principal, mContainerType);
|
||||
|
||||
MOZ_ASSERT(!mBufferDecoder);
|
||||
mBufferDecoder = new BufferDecoder(resource,
|
||||
|
Loading…
Reference in New Issue
Block a user