| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/android/proxy_media_keys.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "content/renderer/media/android/renderer_media_player_manager.h" | |
| 12 #include "content/renderer/media/crypto/key_systems.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 int ProxyMediaKeys::next_cdm_id_ = | |
| 17 RendererMediaPlayerManager::kInvalidCdmId + 1; | |
| 18 | |
| 19 scoped_ptr<ProxyMediaKeys> ProxyMediaKeys::Create( | |
| 20 const std::string& key_system, | |
| 21 const GURL& security_origin, | |
| 22 RendererMediaPlayerManager* manager, | |
| 23 const media::SessionCreatedCB& session_created_cb, | |
| 24 const media::SessionMessageCB& session_message_cb, | |
| 25 const media::SessionReadyCB& session_ready_cb, | |
| 26 const media::SessionClosedCB& session_closed_cb, | |
| 27 const media::SessionErrorCB& session_error_cb) { | |
| 28 DCHECK(manager); | |
| 29 scoped_ptr<ProxyMediaKeys> proxy_media_keys( | |
| 30 new ProxyMediaKeys(manager, | |
| 31 session_created_cb, | |
| 32 session_message_cb, | |
| 33 session_ready_cb, | |
| 34 session_closed_cb, | |
| 35 session_error_cb)); | |
| 36 proxy_media_keys->InitializeCdm(key_system, security_origin); | |
| 37 return proxy_media_keys.Pass(); | |
| 38 } | |
| 39 | |
| 40 ProxyMediaKeys::~ProxyMediaKeys() { | |
| 41 manager_->DestroyCdm(cdm_id_); | |
| 42 } | |
| 43 | |
| 44 bool ProxyMediaKeys::CreateSession(uint32 session_id, | |
| 45 const std::string& content_type, | |
| 46 const uint8* init_data, | |
| 47 int init_data_length) { | |
| 48 // TODO(xhwang): Move these checks up to blink and DCHECK here. | |
| 49 // See http://crbug.com/342510 | |
| 50 CdmHostMsg_CreateSession_ContentType session_type; | |
| 51 if (content_type == "audio/mp4" || content_type == "video/mp4") { | |
| 52 session_type = CREATE_SESSION_TYPE_MP4; | |
| 53 } else if (content_type == "audio/webm" || content_type == "video/webm") { | |
| 54 session_type = CREATE_SESSION_TYPE_WEBM; | |
| 55 } else { | |
| 56 DLOG(ERROR) << "Unsupported EME CreateSession content type of " | |
| 57 << content_type; | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 manager_->CreateSession( | |
| 62 cdm_id_, | |
| 63 session_id, | |
| 64 session_type, | |
| 65 std::vector<uint8>(init_data, init_data + init_data_length)); | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 void ProxyMediaKeys::LoadSession(uint32 session_id, | |
| 70 const std::string& web_session_id) { | |
| 71 // TODO(xhwang): Check key system and platform support for LoadSession in | |
| 72 // blink and add NOTREACHED() here. | |
| 73 DLOG(ERROR) << "ProxyMediaKeys doesn't support session loading."; | |
| 74 OnSessionError(session_id, media::MediaKeys::kUnknownError, 0); | |
| 75 } | |
| 76 | |
| 77 void ProxyMediaKeys::UpdateSession(uint32 session_id, | |
| 78 const uint8* response, | |
| 79 int response_length) { | |
| 80 manager_->UpdateSession( | |
| 81 cdm_id_, | |
| 82 session_id, | |
| 83 std::vector<uint8>(response, response + response_length)); | |
| 84 } | |
| 85 | |
| 86 void ProxyMediaKeys::ReleaseSession(uint32 session_id) { | |
| 87 manager_->ReleaseSession(cdm_id_, session_id); | |
| 88 } | |
| 89 | |
| 90 void ProxyMediaKeys::OnSessionCreated(uint32 session_id, | |
| 91 const std::string& web_session_id) { | |
| 92 session_created_cb_.Run(session_id, web_session_id); | |
| 93 } | |
| 94 | |
| 95 void ProxyMediaKeys::OnSessionMessage(uint32 session_id, | |
| 96 const std::vector<uint8>& message, | |
| 97 const GURL& destination_url) { | |
| 98 session_message_cb_.Run(session_id, message, destination_url); | |
| 99 } | |
| 100 | |
| 101 void ProxyMediaKeys::OnSessionReady(uint32 session_id) { | |
| 102 session_ready_cb_.Run(session_id); | |
| 103 } | |
| 104 | |
| 105 void ProxyMediaKeys::OnSessionClosed(uint32 session_id) { | |
| 106 session_closed_cb_.Run(session_id); | |
| 107 } | |
| 108 | |
| 109 void ProxyMediaKeys::OnSessionError(uint32 session_id, | |
| 110 media::MediaKeys::KeyError error_code, | |
| 111 uint32 system_code) { | |
| 112 session_error_cb_.Run(session_id, error_code, system_code); | |
| 113 } | |
| 114 | |
| 115 int ProxyMediaKeys::GetCdmId() const { | |
| 116 return cdm_id_; | |
| 117 } | |
| 118 | |
| 119 ProxyMediaKeys::ProxyMediaKeys( | |
| 120 RendererMediaPlayerManager* manager, | |
| 121 const media::SessionCreatedCB& session_created_cb, | |
| 122 const media::SessionMessageCB& session_message_cb, | |
| 123 const media::SessionReadyCB& session_ready_cb, | |
| 124 const media::SessionClosedCB& session_closed_cb, | |
| 125 const media::SessionErrorCB& session_error_cb) | |
| 126 : manager_(manager), | |
| 127 cdm_id_(next_cdm_id_++), | |
| 128 session_created_cb_(session_created_cb), | |
| 129 session_message_cb_(session_message_cb), | |
| 130 session_ready_cb_(session_ready_cb), | |
| 131 session_closed_cb_(session_closed_cb), | |
| 132 session_error_cb_(session_error_cb) { | |
| 133 } | |
| 134 | |
| 135 void ProxyMediaKeys::InitializeCdm(const std::string& key_system, | |
| 136 const GURL& security_origin) { | |
| 137 manager_->InitializeCdm(cdm_id_, this, key_system, security_origin); | |
| 138 } | |
| 139 | |
| 140 } // namespace content | |
| OLD | NEW |