Bug 1144409 - Encrypted event should be fired once per initData; part 1: first initData. r=cpearce

This commit is contained in:
Gerald Squelart 2015-03-22 23:26:00 -04:00
parent 321d8637a6
commit 8a1b12bdcf
4 changed files with 39 additions and 30 deletions

View File

@ -3093,7 +3093,10 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
}
#ifdef MOZ_EME
DispatchEncrypted(aInfo->mCrypto.mInitData, aInfo->mCrypto.mType);
// Dispatch a distinct 'encrypted' event for each initData we have.
for (const auto& initData : aInfo->mCrypto.mInitDatas) {
DispatchEncrypted(initData.mInitData, initData.mType);
}
#endif
}

View File

@ -105,16 +105,39 @@ public:
class EncryptionInfo {
public:
EncryptionInfo() : mIsEncrypted(false) {}
struct InitData {
InitData(const nsString& aType, nsTArray<uint8_t>&& aInitData)
: mType(aType)
, mInitData(Move(aInitData))
{
}
// Encryption type to be passed to JS. Usually `cenc'.
nsString mType;
// Encryption type to be passed to JS. Usually `cenc'.
nsString mType;
// Encryption data.
nsTArray<uint8_t> mInitData;
// Encryption data.
nsTArray<uint8_t> mInitData;
};
typedef nsTArray<InitData> InitDatas;
// True if the stream has encryption metadata
bool mIsEncrypted;
bool IsEncrypted() const
{
return !mInitDatas.IsEmpty();
}
void AddInitData(const nsString& aType, nsTArray<uint8_t>&& aInitData)
{
mInitDatas.AppendElement(InitData(aType, Move(aInitData)));
}
void AddInitData(const EncryptionInfo& aInfo)
{
mInitDatas.AppendElements(aInfo.mInitDatas);
}
// One 'InitData' per encrypted buffer.
InitDatas mInitDatas;
};
class MediaInfo {
@ -131,7 +154,7 @@ public:
bool IsEncrypted() const
{
return mCrypto.mIsEncrypted;
return mCrypto.IsEncrypted();
}
bool HasValidMedia() const

View File

@ -368,7 +368,7 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo,
{
MonitorAutoUnlock unlock(mDemuxerMonitor);
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mInfo.mCrypto.mIsEncrypted = mIsEncrypted = mCrypto.valid;
mIsEncrypted = mCrypto.valid;
}
// Remember that we've initialized the demuxer, so that if we're decoding
@ -400,15 +400,14 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo,
}
}
if (mIsEncrypted) {
if (mCrypto.valid) {
nsTArray<uint8_t> initData;
ExtractCryptoInitData(initData);
if (initData.Length() == 0) {
return NS_ERROR_FAILURE;
}
mInfo.mCrypto.mInitData = initData;
mInfo.mCrypto.mType = NS_LITERAL_STRING("cenc");
mInfo.mCrypto.AddInitData(NS_LITERAL_STRING("cenc"), Move(initData));
}
// Get the duration, and report it to the decoder if we have it.

View File

@ -1054,22 +1054,6 @@ MediaSourceReader::MaybeNotifyHaveData()
IsSeeking(), haveAudio, haveVideo, ended);
}
static void
CombineEncryptionData(EncryptionInfo& aTo, const EncryptionInfo& aFrom)
{
if (!aFrom.mIsEncrypted) {
return;
}
aTo.mIsEncrypted = true;
if (!aTo.mType.IsEmpty() && !aTo.mType.Equals(aFrom.mType)) {
NS_WARNING("mismatched encryption types");
}
aTo.mType = aFrom.mType;
aTo.mInitData.AppendElements(aFrom.mInitData);
}
nsresult
MediaSourceReader::ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags)
{
@ -1093,7 +1077,7 @@ MediaSourceReader::ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags)
const MediaInfo& info = GetAudioReader()->GetMediaInfo();
MOZ_ASSERT(info.HasAudio());
mInfo.mAudio = info.mAudio;
CombineEncryptionData(mInfo.mCrypto, info.mCrypto);
mInfo.mCrypto.AddInitData(info.mCrypto);
MSE_DEBUG("audio reader=%p duration=%lld",
mAudioSourceDecoder.get(),
mAudioSourceDecoder->GetReader()->GetDecoder()->GetMediaDuration());
@ -1106,7 +1090,7 @@ MediaSourceReader::ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags)
const MediaInfo& info = GetVideoReader()->GetMediaInfo();
MOZ_ASSERT(info.HasVideo());
mInfo.mVideo = info.mVideo;
CombineEncryptionData(mInfo.mCrypto, info.mCrypto);
mInfo.mCrypto.AddInitData(info.mCrypto);
MSE_DEBUG("video reader=%p duration=%lld",
GetVideoReader(),
GetVideoReader()->GetDecoder()->GetMediaDuration());