Commit c22e3814 authored by sandersd@chromium.org's avatar sandersd@chromium.org

Convert between |init_data_type| and content type.

This allows both to be used while Blink and the tests are transitioned.

BUG=385874

Review URL: https://codereview.chromium.org/472493003

Cr-Commit-Position: refs/heads/master@{#289605}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289605 0039d316-1c4b-4281-b951-d872f2087c98
parent 78d9c190
......@@ -128,8 +128,20 @@ bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type,
media::MediaKeys::SessionType session_type =
persistent ? media::MediaKeys::PERSISTENT_SESSION
: media::MediaKeys::TEMPORARY_SESSION;
media_keys_->CreateSession(
content_type, init_data, init_data_length, session_type, promise.Pass());
// Convert MIME types used in the prefixed implementation.
std::string init_data_type;
if (content_type == "audio/mp4" || content_type == "video/mp4") {
init_data_type = "cenc";
} else if (content_type == "audio/webm" || content_type == "video/webm") {
init_data_type = "webm";
} else {
NOTREACHED();
init_data_type = content_type;
}
media_keys_->CreateSession(init_data_type, init_data, init_data_length,
session_type, promise.Pass());
return true;
}
......
......@@ -57,9 +57,9 @@ void ProxyMediaKeys::CreateSession(
// TODO(xhwang): Move these checks up to blink and DCHECK here.
// See http://crbug.com/342510
CdmHostMsg_CreateSession_ContentType create_session_content_type;
if (init_data_type == "audio/mp4" || init_data_type == "video/mp4") {
if (init_data_type == "cenc") {
create_session_content_type = CREATE_SESSION_TYPE_MP4;
} else if (init_data_type == "audio/webm" || init_data_type == "video/webm") {
} else if (init_data_type == "webm") {
create_session_content_type = CREATE_SESSION_TYPE_WEBM;
} else {
DLOG(ERROR) << "Unsupported EME CreateSession content type of "
......
......@@ -87,22 +87,23 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession(
const blink::WebString& init_data_type,
const uint8* init_data,
size_t init_data_length) {
// TODO(ddorwin): Guard against this in supported types check and remove this.
// Chromium only supports ASCII MIME types.
if (!base::IsStringASCII(init_data_type)) {
NOTREACHED();
OnSessionError(media::MediaKeys::NOT_SUPPORTED_ERROR,
0,
"The initialization data type " + init_data_type.utf8() +
" is not supported by the key system.");
return;
}
DCHECK(base::IsStringASCII(init_data_type));
std::string init_data_type_as_ascii = base::UTF16ToASCII(init_data_type);
DLOG_IF(WARNING, init_data_type_as_ascii.find('/') != std::string::npos)
<< "init_data_type '" << init_data_type_as_ascii
<< "' may be a MIME type";
// Attempt to translate content types.
// TODO(sandersd): Remove once tests stop using content types.
// http://crbug.com/385874
std::string content_type = base::StringToLowerASCII(init_data_type_as_ascii);
if (content_type == "audio/mp4" || content_type == "video/mp4") {
init_data_type_as_ascii = "cenc";
} else if (content_type == "audio/webm" || content_type == "video/webm") {
init_data_type_as_ascii = "webm";
}
scoped_ptr<media::NewSessionCdmPromise> promise(
new media::NewSessionCdmPromise(
base::Bind(&WebContentDecryptionModuleSessionImpl::SessionCreated,
......
......@@ -127,6 +127,12 @@ class CdmWrapper {
virtual void ConvertInputBuffer(const cdm::InputBuffer& v2,
cdm::InputBuffer_1* v1) = 0;
// Prior to CDM_6, |init_data_type| was a content type. This helper convererts
// an |init_data_type| to a content type.
// TODO(sandersd): Remove once Host_4 and Host_5 interfaces are removed.
virtual const char* ConvertInitDataTypeToContentType(
const char* init_data_type) const = 0;
protected:
CdmWrapper() {}
......@@ -339,6 +345,15 @@ class CdmWrapperImpl : public CdmWrapper {
v1->timestamp = v2.timestamp;
}
virtual const char* ConvertInitDataTypeToContentType(
const char* init_data_type) const {
if (!strcmp(init_data_type, "cenc"))
return "video/mp4";
if (!strcmp(init_data_type, "webm"))
return "video/webm";
return init_data_type;
}
private:
CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) {
PP_DCHECK(cdm_);
......@@ -361,7 +376,8 @@ class CdmWrapperImpl : public CdmWrapper {
// create a new session_id to pass to the CDM. For update and release, we need
// to look up |web_session_id| and convert it into the existing |session_id|.
// Since the callbacks don't come through this interface, cdm_adapter needs to
// create the mapping (and delete it on release).
// create the mapping (and delete it on release). Finally, for create, we need
// to translate |init_data_type| to a MIME type.
// TODO(jrummell): Remove these once Host_4 interface is removed.
template <>
......@@ -375,7 +391,7 @@ void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::CreateSession(
uint32_t session_id = CreateSessionId();
RegisterPromise(session_id, promise_id);
cdm_->CreateSession(session_id,
init_data_type,
ConvertInitDataTypeToContentType(init_data_type),
init_data_type_size,
init_data,
init_data_size);
......@@ -471,6 +487,22 @@ CdmWrapperImpl<cdm::ContentDecryptionModule_4>::DecryptAndDecodeSamples(
// Overrides for the cdm::Host_5 methods.
// TODO(jrummell): Remove these once Host_5 interface is removed.
template <>
void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::CreateSession(
uint32_t promise_id,
const char* init_data_type,
uint32_t init_data_type_size,
const uint8_t* init_data,
uint32_t init_data_size,
cdm::SessionType session_type) {
cdm_->CreateSession(promise_id,
ConvertInitDataTypeToContentType(init_data_type),
init_data_type_size,
init_data,
init_data_size,
session_type);
}
template <>
void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::LoadSession(
uint32_t promise_id,
......
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