From 22851a415bff2a92fa24c2794ffc768188137a3c Mon Sep 17 00:00:00 2001 From: sandersd Date: Thu, 2 Oct 2014 11:49:44 -0700 Subject: [PATCH] Reland: Pass initDataType instead of contentType to OnNeedKey(). BUG=224786 Cr-Commit-Position: refs/heads/master@{#297523} (cherry picked from commit 2983dc91cc0bc7be6014f4bfc5cb19cc6e262a0b) Review URL: https://codereview.chromium.org/617333003 Cr-Commit-Position: refs/heads/master@{#297872} --- content/renderer/media/android/webmediaplayer_android.cc | 6 +++--- .../media/crypto/encrypted_media_player_support_impl.cc | 6 +++--- content/renderer/media/crypto/proxy_decryptor.cc | 13 +------------ content/renderer/media/crypto/proxy_decryptor.h | 2 +- media/filters/pipeline_integration_test.cc | 5 ++--- media/formats/mp4/mp4_stream_parser.cc | 5 ++--- media/formats/mp4/mp4_stream_parser_unittest.cc | 5 ++--- media/formats/webm/webm_crypto_helpers.h | 5 +---- 8 files changed, 15 insertions(+), 32 deletions(-) diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index 32f81d15cd5a..0c8910d9e738 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -1498,11 +1498,11 @@ WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( // so we keep it as simple as possible without breaking major use cases. static std::string GuessInitDataType(const unsigned char* init_data, unsigned init_data_length) { - // Most WebM files use KeyId of 16 bytes. MP4 init data are always >16 bytes. + // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. if (init_data_length == 16) - return "video/webm"; + return "webm"; - return "video/mp4"; + return "cenc"; } // TODO(xhwang): Report an error when there is encrypted stream but EME is diff --git a/content/renderer/media/crypto/encrypted_media_player_support_impl.cc b/content/renderer/media/crypto/encrypted_media_player_support_impl.cc index 42f86b6e461d..e3f70b393d18 100644 --- a/content/renderer/media/crypto/encrypted_media_player_support_impl.cc +++ b/content/renderer/media/crypto/encrypted_media_player_support_impl.cc @@ -117,11 +117,11 @@ static void ReportMediaKeyExceptionToUMA(const std::string& method, // so we keep it as simple as possible without breaking major use cases. static std::string GuessInitDataType(const unsigned char* init_data, unsigned init_data_length) { - // Most WebM files use KeyId of 16 bytes. MP4 init data are always >16 bytes. + // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. if (init_data_length == 16) - return "video/webm"; + return "webm"; - return "video/mp4"; + return "cenc"; } scoped_ptr diff --git a/content/renderer/media/crypto/proxy_decryptor.cc b/content/renderer/media/crypto/proxy_decryptor.cc index 98c301c573c2..c24e0d2a8216 100644 --- a/content/renderer/media/crypto/proxy_decryptor.cc +++ b/content/renderer/media/crypto/proxy_decryptor.cc @@ -95,7 +95,7 @@ bool HasHeader(const uint8* data, int data_length, const std::string& header) { std::equal(data, data + header.size(), header.begin()); } -bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, +bool ProxyDecryptor::GenerateKeyRequest(const std::string& init_data_type, const uint8* init_data, int init_data_length) { DVLOG(1) << "GenerateKeyRequest()"; @@ -134,17 +134,6 @@ bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, ? media::MediaKeys::PERSISTENT_SESSION : media::MediaKeys::TEMPORARY_SESSION; - // 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; diff --git a/content/renderer/media/crypto/proxy_decryptor.h b/content/renderer/media/crypto/proxy_decryptor.h index 0a6c298d682f..66d402ec77f9 100644 --- a/content/renderer/media/crypto/proxy_decryptor.h +++ b/content/renderer/media/crypto/proxy_decryptor.h @@ -72,7 +72,7 @@ class ProxyDecryptor { const GURL& security_origin); // May only be called after InitializeCDM() succeeds. - bool GenerateKeyRequest(const std::string& type, + bool GenerateKeyRequest(const std::string& init_data_type, const uint8* init_data, int init_data_length); void AddKey(const uint8* key, int key_length, diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc index d9904f611ec0..27e6344b7281 100644 --- a/media/filters/pipeline_integration_test.cc +++ b/media/filters/pipeline_integration_test.cc @@ -29,6 +29,7 @@ using testing::SaveArg; namespace media { const char kSourceId[] = "SourceId"; +const char kCencInitDataType[] = "cenc"; const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\""; @@ -36,8 +37,6 @@ const char kWebMVP9[] = "video/webm; codecs=\"vp9\""; const char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\""; const char kOpusAudioOnlyWebM[] = "video/webm; codecs=\"opus\""; const char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\""; -const char kMP4VideoType[] = "video/mp4"; -const char kMP4AudioType[] = "audio/mp4"; #if defined(USE_PROPRIETARY_CODECS) const char kADTS[] = "audio/aac"; const char kMP4[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\""; @@ -267,7 +266,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase { // correct key ID. const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; size_t key_id_length = init_data.size(); - if (type == kMP4AudioType || type == kMP4VideoType) { + if (type == kCencInitDataType) { key_id = kKeyId; key_id_length = arraysize(kKeyId); } diff --git a/media/formats/mp4/mp4_stream_parser.cc b/media/formats/mp4/mp4_stream_parser.cc index 7ad3ccc38649..c6163bf35b69 100644 --- a/media/formats/mp4/mp4_stream_parser.cc +++ b/media/formats/mp4/mp4_stream_parser.cc @@ -22,8 +22,7 @@ namespace media { namespace mp4 { -// TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. -static const char kMp4InitDataType[] = "video/mp4"; +static const char kCencInitDataType[] = "cenc"; MP4StreamParser::MP4StreamParser(const std::set& audio_object_types, bool has_sbr) @@ -354,7 +353,7 @@ void MP4StreamParser::EmitNeedKeyIfNecessary( headers[i].raw_box.size()); pos += headers[i].raw_box.size(); } - need_key_cb_.Run(kMp4InitDataType, init_data); + need_key_cb_.Run(kCencInitDataType, init_data); } bool MP4StreamParser::PrepareAVCBuffer( diff --git a/media/formats/mp4/mp4_stream_parser_unittest.cc b/media/formats/mp4/mp4_stream_parser_unittest.cc index c44e0ce96ccb..5bcb7add29f4 100644 --- a/media/formats/mp4/mp4_stream_parser_unittest.cc +++ b/media/formats/mp4/mp4_stream_parser_unittest.cc @@ -25,8 +25,7 @@ using base::TimeDelta; namespace media { namespace mp4 { -// TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. -static const char kMp4InitDataType[] = "video/mp4"; +static const char kCencInitDataType[] = "cenc"; class MP4StreamParserTest : public testing::Test { public: @@ -122,7 +121,7 @@ class MP4StreamParserTest : public testing::Test { void KeyNeededF(const std::string& type, const std::vector& init_data) { DVLOG(1) << "KeyNeededF: " << init_data.size(); - EXPECT_EQ(kMp4InitDataType, type); + EXPECT_EQ(kCencInitDataType, type); EXPECT_FALSE(init_data.empty()); } diff --git a/media/formats/webm/webm_crypto_helpers.h b/media/formats/webm/webm_crypto_helpers.h index 23095f31d3d8..d602e63398c6 100644 --- a/media/formats/webm/webm_crypto_helpers.h +++ b/media/formats/webm/webm_crypto_helpers.h @@ -11,10 +11,7 @@ namespace media { -// TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. -// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=19096 for more -// information. -const char kWebMEncryptInitDataType[] = "video/webm"; +const char kWebMEncryptInitDataType[] = "webm"; // Fills an initialized DecryptConfig, which can be sent to the Decryptor if // the stream has potentially encrypted frames. Also sets |data_offset| which -- 2.11.4.GIT