| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cdm/ppapi/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 host, key_system_string == kExternalClearKeyDecryptOnlyKeySystem); | 152 host, key_system_string == kExternalClearKeyDecryptOnlyKeySystem); |
| 153 } | 153 } |
| 154 | 154 |
| 155 const char* GetCdmVersion() { | 155 const char* GetCdmVersion() { |
| 156 return kClearKeyCdmVersion; | 156 return kClearKeyCdmVersion; |
| 157 } | 157 } |
| 158 | 158 |
| 159 namespace media { | 159 namespace media { |
| 160 | 160 |
| 161 // Since all the calls to AesDecryptor are synchronous, pass a dummy value for | 161 // Since all the calls to AesDecryptor are synchronous, pass a dummy value for |
| 162 // reference_id that is never exposed outside this class. | 162 // session_id that is never exposed outside this class. |
| 163 // TODO(jrummell): Remove usage of this when the CDM interface is updated | 163 // TODO(jrummell): Remove usage of this when the CDM interface is updated |
| 164 // to use reference_id. | 164 // to use session_id. |
| 165 | 165 |
| 166 ClearKeyCdm::Client::Client() | 166 ClearKeyCdm::Client::Client() |
| 167 : status_(kNone), error_code_(MediaKeys::kUnknownError), system_code_(0) {} | 167 : status_(kNone), error_code_(MediaKeys::kUnknownError), system_code_(0) {} |
| 168 | 168 |
| 169 ClearKeyCdm::Client::~Client() {} | 169 ClearKeyCdm::Client::~Client() {} |
| 170 | 170 |
| 171 void ClearKeyCdm::Client::Reset() { | 171 void ClearKeyCdm::Client::Reset() { |
| 172 status_ = kNone; | 172 status_ = kNone; |
| 173 session_id_.clear(); | 173 web_session_id_.clear(); |
| 174 message_.clear(); | 174 message_.clear(); |
| 175 destination_url_.clear(); | 175 destination_url_.clear(); |
| 176 error_code_ = MediaKeys::kUnknownError; | 176 error_code_ = MediaKeys::kUnknownError; |
| 177 system_code_ = 0; | 177 system_code_ = 0; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void ClearKeyCdm::Client::OnSessionCreated(uint32 reference_id, | 180 void ClearKeyCdm::Client::OnSessionCreated(uint32 session_id, |
| 181 const std::string& session_id) { | 181 const std::string& web_session_id) { |
| 182 status_ = static_cast<Status>(status_ | kCreated); | 182 status_ = static_cast<Status>(status_ | kCreated); |
| 183 session_id_ = session_id; | 183 web_session_id_ = web_session_id; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void ClearKeyCdm::Client::OnSessionMessage(uint32 reference_id, | 186 void ClearKeyCdm::Client::OnSessionMessage(uint32 session_id, |
| 187 const std::vector<uint8>& message, | 187 const std::vector<uint8>& message, |
| 188 const std::string& destination_url) { | 188 const std::string& destination_url) { |
| 189 status_ = static_cast<Status>(status_ | kMessage); | 189 status_ = static_cast<Status>(status_ | kMessage); |
| 190 message_ = message; | 190 message_ = message; |
| 191 destination_url_ = destination_url; | 191 destination_url_ = destination_url; |
| 192 } | 192 } |
| 193 | 193 |
| 194 void ClearKeyCdm::Client::OnSessionReady(uint32 reference_id) { | 194 void ClearKeyCdm::Client::OnSessionReady(uint32 session_id) { |
| 195 status_ = static_cast<Status>(status_ | kReady); | 195 status_ = static_cast<Status>(status_ | kReady); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ClearKeyCdm::Client::OnSessionClosed(uint32 reference_id) { | 198 void ClearKeyCdm::Client::OnSessionClosed(uint32 session_id) { |
| 199 status_ = static_cast<Status>(status_ | kClosed); | 199 status_ = static_cast<Status>(status_ | kClosed); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ClearKeyCdm::Client::OnSessionError(uint32 reference_id, | 202 void ClearKeyCdm::Client::OnSessionError(uint32 session_id, |
| 203 media::MediaKeys::KeyError error_code, | 203 media::MediaKeys::KeyError error_code, |
| 204 int system_code) { | 204 int system_code) { |
| 205 status_ = static_cast<Status>(status_ | kError); | 205 status_ = static_cast<Status>(status_ | kError); |
| 206 error_code_ = error_code; | 206 error_code_ = error_code; |
| 207 system_code_ = system_code; | 207 system_code_ = system_code; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, bool is_decrypt_only) | 210 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, bool is_decrypt_only) |
| 211 : decryptor_( | 211 : decryptor_( |
| 212 base::Bind(&Client::OnSessionCreated, base::Unretained(&client_)), | 212 base::Bind(&Client::OnSessionCreated, base::Unretained(&client_)), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 229 | 229 |
| 230 ClearKeyCdm::~ClearKeyCdm() {} | 230 ClearKeyCdm::~ClearKeyCdm() {} |
| 231 | 231 |
| 232 cdm::Status ClearKeyCdm::GenerateKeyRequest(const char* type, | 232 cdm::Status ClearKeyCdm::GenerateKeyRequest(const char* type, |
| 233 uint32_t type_size, | 233 uint32_t type_size, |
| 234 const uint8_t* init_data, | 234 const uint8_t* init_data, |
| 235 uint32_t init_data_size) { | 235 uint32_t init_data_size) { |
| 236 DVLOG(1) << "GenerateKeyRequest()"; | 236 DVLOG(1) << "GenerateKeyRequest()"; |
| 237 base::AutoLock auto_lock(client_lock_); | 237 base::AutoLock auto_lock(client_lock_); |
| 238 ScopedResetter<Client> auto_resetter(&client_); | 238 ScopedResetter<Client> auto_resetter(&client_); |
| 239 decryptor_.CreateSession(MediaKeys::kInvalidReferenceId, | 239 decryptor_.CreateSession(MediaKeys::kInvalidSessionId, |
| 240 std::string(type, type_size), | 240 std::string(type, type_size), |
| 241 init_data, init_data_size); | 241 init_data, init_data_size); |
| 242 | 242 |
| 243 if (client_.status() != (Client::kMessage | Client::kCreated)) { | 243 if (client_.status() != (Client::kMessage | Client::kCreated)) { |
| 244 // Use values returned to client if possible. | 244 // Use values returned to client if possible. |
| 245 host_->SendKeyError(client_.session_id().data(), | 245 host_->SendKeyError(client_.web_session_id().data(), |
| 246 client_.session_id().size(), | 246 client_.web_session_id().size(), |
| 247 static_cast<cdm::MediaKeyError>(client_.error_code()), | 247 static_cast<cdm::MediaKeyError>(client_.error_code()), |
| 248 client_.system_code()); | 248 client_.system_code()); |
| 249 return cdm::kSessionError; | 249 return cdm::kSessionError; |
| 250 } | 250 } |
| 251 | 251 |
| 252 host_->SendKeyMessage( | 252 host_->SendKeyMessage( |
| 253 client_.session_id().data(), client_.session_id().size(), | 253 client_.web_session_id().data(), client_.web_session_id().size(), |
| 254 reinterpret_cast<const char*>(&client_.message()[0]), | 254 reinterpret_cast<const char*>(&client_.message()[0]), |
| 255 client_.message().size(), | 255 client_.message().size(), |
| 256 client_.destination_url().data(), client_.destination_url().size()); | 256 client_.destination_url().data(), client_.destination_url().size()); |
| 257 | 257 |
| 258 // Only save the latest session ID for heartbeat messages. | 258 // Only save the latest session ID for heartbeat messages. |
| 259 heartbeat_session_id_ = client_.session_id(); | 259 heartbeat_session_id_ = client_.web_session_id(); |
| 260 | 260 |
| 261 return cdm::kSuccess; | 261 return cdm::kSuccess; |
| 262 } | 262 } |
| 263 | 263 |
| 264 cdm::Status ClearKeyCdm::AddKey(const char* session_id, | 264 cdm::Status ClearKeyCdm::AddKey(const char* session_id, |
| 265 uint32_t session_id_size, | 265 uint32_t session_id_size, |
| 266 const uint8_t* key, | 266 const uint8_t* key, |
| 267 uint32_t key_size, | 267 uint32_t key_size, |
| 268 const uint8_t* key_id, | 268 const uint8_t* key_id, |
| 269 uint32_t key_id_size) { | 269 uint32_t key_id_size) { |
| 270 DVLOG(1) << "AddKey()"; | 270 DVLOG(1) << "AddKey()"; |
| 271 DCHECK(!key_id && !key_id_size); | 271 DCHECK(!key_id && !key_id_size); |
| 272 base::AutoLock auto_lock(client_lock_); | 272 base::AutoLock auto_lock(client_lock_); |
| 273 ScopedResetter<Client> auto_resetter(&client_); | 273 ScopedResetter<Client> auto_resetter(&client_); |
| 274 decryptor_.UpdateSession(MediaKeys::kInvalidReferenceId, key, key_size); | 274 decryptor_.UpdateSession(MediaKeys::kInvalidSessionId, key, key_size); |
| 275 | 275 |
| 276 if (client_.status() != Client::kReady) { | 276 if (client_.status() != Client::kReady) { |
| 277 host_->SendKeyError(session_id, session_id_size, | 277 host_->SendKeyError(session_id, session_id_size, |
| 278 static_cast<cdm::MediaKeyError>(client_.error_code()), | 278 static_cast<cdm::MediaKeyError>(client_.error_code()), |
| 279 client_.system_code()); | 279 client_.system_code()); |
| 280 return cdm::kSessionError; | 280 return cdm::kSessionError; |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (!timer_set_) { | 283 if (!timer_set_) { |
| 284 ScheduleNextHeartBeat(); | 284 ScheduleNextHeartBeat(); |
| 285 timer_set_ = true; | 285 timer_set_ = true; |
| 286 } | 286 } |
| 287 | 287 |
| 288 return cdm::kSuccess; | 288 return cdm::kSuccess; |
| 289 } | 289 } |
| 290 | 290 |
| 291 cdm::Status ClearKeyCdm::CancelKeyRequest(const char* session_id, | 291 cdm::Status ClearKeyCdm::CancelKeyRequest(const char* session_id, |
| 292 uint32_t session_id_size) { | 292 uint32_t session_id_size) { |
| 293 DVLOG(1) << "CancelKeyRequest()"; | 293 DVLOG(1) << "CancelKeyRequest()"; |
| 294 base::AutoLock auto_lock(client_lock_); | 294 base::AutoLock auto_lock(client_lock_); |
| 295 ScopedResetter<Client> auto_resetter(&client_); | 295 ScopedResetter<Client> auto_resetter(&client_); |
| 296 decryptor_.ReleaseSession(MediaKeys::kInvalidReferenceId); | 296 decryptor_.ReleaseSession(MediaKeys::kInvalidSessionId); |
| 297 | 297 |
| 298 // No message normally sent by Release(), but if an error occurred, | 298 // No message normally sent by Release(), but if an error occurred, |
| 299 // report it as a failure. | 299 // report it as a failure. |
| 300 if (client_.status() == Client::kError) { | 300 if (client_.status() == Client::kError) { |
| 301 host_->SendKeyError(session_id, session_id_size, | 301 host_->SendKeyError(session_id, session_id_size, |
| 302 static_cast<cdm::MediaKeyError>(client_.error_code()), | 302 static_cast<cdm::MediaKeyError>(client_.error_code()), |
| 303 client_.system_code()); | 303 client_.system_code()); |
| 304 return cdm::kSessionError; | 304 return cdm::kSessionError; |
| 305 } | 305 } |
| 306 | 306 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 int samples_generated = GenerateFakeAudioFramesFromDuration( | 615 int samples_generated = GenerateFakeAudioFramesFromDuration( |
| 616 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), | 616 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), |
| 617 audio_frames); | 617 audio_frames); |
| 618 total_samples_generated_ += samples_generated; | 618 total_samples_generated_ += samples_generated; |
| 619 | 619 |
| 620 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; | 620 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; |
| 621 } | 621 } |
| 622 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 622 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
| 623 | 623 |
| 624 } // namespace media | 624 } // namespace media |
| OLD | NEW |