Commit 865dfbdd authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Refactor codec string to EmeCodec conversion

Instead of stripping the codec string and table look-up by stripped codec
string, use MimeUtil ParseAudioCodecString() and ParseVideoCodecString() to
convert the codec string to media AudioCodec/VideoCodec, then have dedicated
functions to convert media codecs to EmeCodecs.

Bug: 707127
Test: All existing tests pass.
Change-Id: I9a69a76bd8acc6ef7cb23ef6630c258df3f5347f
Reviewed-on: https://chromium-review.googlesource.com/c/1277613
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600033}
parent 546926a4
This diff is collapsed.
......@@ -44,7 +44,7 @@ class MEDIA_EXPORT KeySystems {
const std::string& key_system,
EncryptionMode encryption_scheme) const = 0;
// Returns the configuration rule for supporting a container and list of
// Returns the configuration rule for supporting a container and a list of
// codecs.
virtual EmeConfigRule GetContentTypeConfigRule(
const std::string& key_system,
......@@ -94,13 +94,13 @@ MEDIA_EXPORT bool CanUseAesDecryptor(const std::string& key_system);
#if defined(UNIT_TEST)
// Helper functions to add container/codec types for testing purposes.
// Call AddCodecMask() first to ensure the mask values passed to
// AddMimeTypeCodecMask() already exist.
MEDIA_EXPORT void AddCodecMask(EmeMediaType media_type,
const std::string& codec,
uint32_t mask);
MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type,
uint32_t mask);
// Call AddCodecMaskForTesting() first to ensure the mask values passed to
// AddMimeTypeCodecMaskForTesting() already exist.
MEDIA_EXPORT void AddCodecMaskForTesting(EmeMediaType media_type,
const std::string& codec,
uint32_t mask);
MEDIA_EXPORT void AddMimeTypeCodecMaskForTesting(const std::string& mime_type,
uint32_t mask);
#endif // defined(UNIT_TEST)
} // namespace media
......
......@@ -228,12 +228,12 @@ void AddContainerAndCodecMasksForTest() {
if (is_test_masks_added)
return;
AddCodecMask(EmeMediaType::AUDIO, "fooaudio", TEST_CODEC_FOO_AUDIO);
AddCodecMask(EmeMediaType::VIDEO, "foovideo", TEST_CODEC_FOO_VIDEO);
AddCodecMask(EmeMediaType::VIDEO, "securefoovideo",
TEST_CODEC_FOO_SECURE_VIDEO);
AddMimeTypeCodecMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
AddMimeTypeCodecMask("video/foo", TEST_CODEC_FOO_VIDEO_ALL);
AddCodecMaskForTesting(EmeMediaType::AUDIO, "fooaudio", TEST_CODEC_FOO_AUDIO);
AddCodecMaskForTesting(EmeMediaType::VIDEO, "foovideo", TEST_CODEC_FOO_VIDEO);
AddCodecMaskForTesting(EmeMediaType::VIDEO, "securefoovideo",
TEST_CODEC_FOO_SECURE_VIDEO);
AddMimeTypeCodecMaskForTesting("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
AddMimeTypeCodecMaskForTesting("video/foo", TEST_CODEC_FOO_VIDEO_ALL);
is_test_masks_added = true;
}
......
......@@ -167,16 +167,6 @@ bool IsSupportedMediaType(const std::string& container_mime_type,
return (support_result == IsSupported);
}
// Replaces any codec in |codecs| starting with "vp09.00." with "vp09-profile0".
void OverrideVp9Profile0(std::vector<std::string>* codecs) {
for (std::string& codec : *codecs) {
if (base::StartsWith(codec, "vp09.00.", base::CompareCase::SENSITIVE)) {
DVLOG(3) << "Replace codec " << codec << " with vp09-profile0";
codec = "vp09-profile0";
}
}
}
} // namespace
struct KeySystemConfigSelector::SelectionRequest {
......@@ -358,20 +348,13 @@ bool KeySystemConfigSelector::IsSupportedContentType(
return false;
}
// Before checking CDM support, split and strip the |codecs| because
// |key_systems_| does not handle extended codecs. Note that extended codec
// information was checked above.
std::vector<std::string> stripped_codec_vector;
SplitCodecs(codecs, &stripped_codec_vector);
// Since both "vp09.00.*" and "vp09.01.*" will be stripped to "vp09", before
// stripping codecs, replace "vp09.00.*" with "vp09-profile0" to avoid
// ambiguity.
OverrideVp9Profile0(&stripped_codec_vector);
StripCodecs(&stripped_codec_vector);
// Check that |container_mime_type| and |codecs| are supported by the CDM.
// Before checking CDM support, split |codecs| into a vector of codecs.
std::vector<std::string> codec_vector;
SplitCodecs(codecs, &codec_vector);
// Check that |container_lower| and |codec_vector| are supported by the CDM.
EmeConfigRule codecs_rule = key_systems_->GetContentTypeConfigRule(
key_system, media_type, container_lower, stripped_codec_vector);
key_system, media_type, container_lower, codec_vector);
if (!config_state->IsRuleSupported(codecs_rule)) {
DVLOG(3) << "Container mime type and codecs are not supported by CDM";
return false;
......
......@@ -247,8 +247,6 @@ class FakeKeySystems : public KeySystems {
for (const std::string& codec : codecs) {
DCHECK(IsValidCodec(codec)) << "Invalid codec should not be passed in";
DCHECK_NE(codec, kExtendedVideoCodec)
<< "Extended codec should already been stripped";
if (codec == kUnsupportedCodec ||
!IsCompatibleWithEmeMediaType(media_type, codec)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment