Bug 1027875 - Add MP4 support to MSE; r=kinetik

This commit is contained in:
Anthony Jones 2014-07-04 20:31:20 +12:00
parent 4854f48994
commit 7278429f4a
3 changed files with 27 additions and 5 deletions

View File

@ -61,6 +61,9 @@ IsTypeSupported(const nsAString& aType)
if (aType.IsEmpty()) {
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
if (Preferences::GetBool("media.mediasource.ignore_codecs", false)) {
return NS_OK;
}
// TODO: Further restrict this to formats in the spec.
nsContentTypeParser parser(aType);
nsAutoString mimeType;
@ -78,9 +81,6 @@ IsTypeSupported(const nsAString& aType)
if (!found) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
if (Preferences::GetBool("media.mediasource.ignore_codecs", false)) {
return NS_OK;
}
// Check aType against HTMLMediaElement list of MIME types. Since we've
// already restricted the container format, this acts as a specific check
// of any specified "codecs" parameter of aType.

View File

@ -10,6 +10,7 @@
#include "MediaDecoder.h"
#include "MediaSourceDecoder.h"
#include "SourceBufferResource.h"
#include "mozilla/Endian.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/dom/MediaSourceBinding.h"
@ -152,6 +153,25 @@ public:
}
};
class MP4ContainerParser : public ContainerParser {
public:
bool IsInitSegmentPresent(const uint8_t* aData, uint32_t aLength)
{
// Each MP4 atom has a chunk size and chunk type. The root chunk in an MP4
// file is the 'ftyp' atom followed by a file type. We just check for a
// vaguely valid 'ftyp' atom.
if (aLength < 8) {
return false;
}
uint32_t chunk_size = BigEndian::readUint32(aData);
return chunk_size > 8 && aData[4] == 'f' && aData[5] == 't' &&
aData[6] == 'y' && aData[7] == 'p';
}
};
/*static*/ ContainerParser*
ContainerParser::CreateForMIMEType(const nsACString& aType)
{
@ -159,7 +179,9 @@ ContainerParser::CreateForMIMEType(const nsACString& aType)
return new WebMContainerParser();
}
// XXX: Plug in parsers for MPEG4, etc. here.
if (aType.LowerCaseEqualsLiteral("video/mp4") || aType.LowerCaseEqualsLiteral("audio/mp4")) {
return new MP4ContainerParser();
}
return new ContainerParser();
}

View File

@ -233,7 +233,7 @@ public:
virtual void Unpin() MOZ_OVERRIDE {}
virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { return 0; }
virtual int64_t GetLength() MOZ_OVERRIDE { return mInputBuffer.GetLength(); }
virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE { return aOffset; }
virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE { return GetLength() == aOffset ? -1 : aOffset; }
virtual int64_t GetCachedDataEnd(int64_t aOffset) MOZ_OVERRIDE { return GetLength(); }
virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { return false; }
virtual bool IsSuspendedByCache() MOZ_OVERRIDE { return false; }