Bug 1278198 - Enforce codecs match the capability and content type in GetSupportedCapabilities(). r=gerald

We're supposed to reject MediaKeySystemCapabilities which have a contentType
that has codecs which don't match their major type, i.e. audio codecs in a
video container type.

I missed that, and it's causing us to fail the
test_eme_requestMediaKeySystemAccess case "MP4 video container with both audio
and video codec type in videoType".


MozReview-Commit-ID: KQVGk9hX3eC

--HG--
extra : rebase_source : f8ed145d050bb27f2f6867ec4b308bbcd30d17a5
This commit is contained in:
Chris Pearce 2016-07-21 19:22:59 +12:00
Родитель 30716f1d57
Коммит c45d37db14
1 изменённых файлов: 48 добавлений и 9 удалений

Просмотреть файл

@ -619,9 +619,37 @@ GetMajorType(const nsAString& aContentType)
return Invalid;
}
static CodecType
GetCodecType(const GMPCodecString& aCodec)
{
if (aCodec.Equals(GMP_CODEC_AAC) ||
aCodec.Equals(GMP_CODEC_OPUS) ||
aCodec.Equals(GMP_CODEC_VORBIS)) {
return Audio;
}
if (aCodec.Equals(GMP_CODEC_H264) ||
aCodec.Equals(GMP_CODEC_VP8) ||
aCodec.Equals(GMP_CODEC_VP9)) {
return Video;
}
return Invalid;
}
static bool
AllCodecsOfType(const nsTArray<GMPCodecString>& aCodecs, const CodecType aCodecType)
{
for (const GMPCodecString& codec : aCodecs) {
if (GetCodecType(codec) != aCodecType) {
return false;
}
}
return true;
}
// 3.1.2.3 Get Supported Capabilities for Audio/Video Type
static Sequence<MediaKeySystemMediaCapability>
GetSupportedCapabilities(mozIGeckoMediaPluginService* aGMPService,
GetSupportedCapabilities(const CodecType aCodecType,
mozIGeckoMediaPluginService* aGMPService,
const nsTArray<MediaKeySystemMediaCapability>& aRequestedCapabilities,
const MediaKeySystemConfiguration& aPartialConfig,
const KeySystemConfig& aKeySystem,
@ -732,20 +760,19 @@ GetSupportedCapabilities(mozIGeckoMediaPluginService* aGMPService,
// (Note: codecs array is 'parameter').
// If media types is empty:
const auto majorType = GetMajorType(container);
if (codecs.IsEmpty()) {
// If container normatively implies a specific set of codecs and codec constraints:
// Let parameters be that set.
if (isMP4) {
if (majorType == Audio) {
if (aCodecType == Audio) {
codecs.AppendElement(GMP_CODEC_AAC);
} else if (majorType == Video) {
} else if (aCodecType == Video) {
codecs.AppendElement(GMP_CODEC_H264);
}
} else if (isWebM) {
if (majorType == Audio) {
if (aCodecType == Audio) {
codecs.AppendElement(GMP_CODEC_VORBIS);
} else if (majorType == Video) {
} else if (aCodecType == Video) {
codecs.AppendElement(GMP_CODEC_VP8);
}
}
@ -754,6 +781,7 @@ GetSupportedCapabilities(mozIGeckoMediaPluginService* aGMPService,
}
// If content type is not strictly a audio/video type, continue to the next iteration.
const auto majorType = GetMajorType(container);
if (majorType == Invalid) {
EME_LOG("MediaKeySystemConfiguration (label='%s') "
"MediaKeySystemMediaCapability('%s','%s') unsupported; "
@ -763,7 +791,16 @@ GetSupportedCapabilities(mozIGeckoMediaPluginService* aGMPService,
NS_ConvertUTF16toUTF8(robustness).get());
continue;
}
if (majorType != aCodecType || !AllCodecsOfType(codecs, aCodecType)) {
EME_LOG("MediaKeySystemConfiguration (label='%s') "
"MediaKeySystemMediaCapability('%s','%s') unsupported; "
"MIME type mixes audio codecs in video capabilities "
"or video codecs in audio capabilities.",
NS_ConvertUTF16toUTF8(aPartialConfig.mLabel).get(),
NS_ConvertUTF16toUTF8(contentType).get(),
NS_ConvertUTF16toUTF8(robustness).get());
continue;
}
// If robustness is not the empty string and contains an unrecognized
// value or a value not supported by implementation, continue to the
// next iteration. String comparison is case-sensitive.
@ -1016,7 +1053,8 @@ GetSupportedConfig(mozIGeckoMediaPluginService* aGMPService,
// configuration's videoCapabilities member, accumulated configuration,
// and restrictions.
Sequence<MediaKeySystemMediaCapability> caps =
GetSupportedCapabilities(aGMPService,
GetSupportedCapabilities(Video,
aGMPService,
aCandidate.mVideoCapabilities,
config,
aKeySystem,
@ -1041,7 +1079,8 @@ GetSupportedConfig(mozIGeckoMediaPluginService* aGMPService,
// for Audio/Video Type algorithm on Audio, candidate configuration's audioCapabilities
// member, accumulated configuration, and restrictions.
Sequence<MediaKeySystemMediaCapability> caps =
GetSupportedCapabilities(aGMPService,
GetSupportedCapabilities(Audio,
aGMPService,
aCandidate.mAudioCapabilities,
config,
aKeySystem,