OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/crypto/proxy_decryptor.h" | 5 #include "webkit/media/crypto/proxy_decryptor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 is_waiting_for_decryptor_(false), | 73 is_waiting_for_decryptor_(false), |
74 is_canceling_decrypt_(false), | 74 is_canceling_decrypt_(false), |
75 has_new_key_added_(false) { | 75 has_new_key_added_(false) { |
76 } | 76 } |
77 | 77 |
78 ProxyDecryptor::~ProxyDecryptor() { | 78 ProxyDecryptor::~ProxyDecryptor() { |
79 } | 79 } |
80 | 80 |
81 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 81 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
82 // video and audio decoders). | 82 // video and audio decoders). |
83 void ProxyDecryptor::RequestDecryptorNotification( | 83 void ProxyDecryptor::RegisterDecryptorReadyNotification( |
84 const DecryptorNotificationCB& decryptor_notification_cb) { | 84 const media::DecryptorReadyCB& decryptor_ready_cb) { |
85 base::AutoLock auto_lock(lock_); | 85 base::AutoLock auto_lock(lock_); |
86 | 86 |
87 // Cancels the previous decryptor request. | 87 // Cancels the previous decryptor request. |
88 if (decryptor_notification_cb.is_null()) { | 88 if (decryptor_ready_cb.is_null()) { |
89 if (!decryptor_notification_cb_.is_null()) | 89 if (!decryptor_ready_cb_.is_null()) |
90 base::ResetAndReturn(&decryptor_notification_cb_).Run(NULL); | 90 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); |
91 return; | 91 return; |
92 } | 92 } |
93 | 93 |
94 // Normal decryptor request. | 94 // Normal decryptor request. |
95 DCHECK(decryptor_notification_cb_.is_null()); | 95 DCHECK(decryptor_ready_cb_.is_null()); |
96 if (decryptor_) { | 96 if (decryptor_) { |
97 decryptor_notification_cb.Run(decryptor_.get()); | 97 decryptor_ready_cb.Run(decryptor_.get()); |
98 return; | 98 return; |
99 } | 99 } |
100 decryptor_notification_cb_ = decryptor_notification_cb; | 100 decryptor_ready_cb_ = decryptor_ready_cb; |
101 } | 101 } |
102 | 102 |
103 bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, | 103 bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, |
104 const std::string& type, | 104 const std::string& type, |
105 const uint8* init_data, | 105 const uint8* init_data, |
106 int init_data_length) { | 106 int init_data_length) { |
107 // We do not support run-time switching of decryptors. GenerateKeyRequest() | 107 // We do not support run-time switching of decryptors. GenerateKeyRequest() |
108 // only creates a new decryptor when |decryptor_| is not initialized. | 108 // only creates a new decryptor when |decryptor_| is not initialized. |
109 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system; | 109 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system; |
110 | 110 |
111 base::AutoLock auto_lock(lock_); | 111 base::AutoLock auto_lock(lock_); |
112 | 112 |
113 if (!decryptor_) { | 113 if (!decryptor_) { |
114 decryptor_ = CreateDecryptor(key_system); | 114 decryptor_ = CreateDecryptor(key_system); |
115 if (!decryptor_) { | 115 if (!decryptor_) { |
116 client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); | 116 client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0); |
117 return false; | 117 return false; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 if (!decryptor_->GenerateKeyRequest(key_system, type, | 121 if (!decryptor_->GenerateKeyRequest(key_system, type, |
122 init_data, init_data_length)) { | 122 init_data, init_data_length)) { |
123 decryptor_.reset(); | 123 decryptor_.reset(); |
124 return false; | 124 return false; |
125 } | 125 } |
126 | 126 |
127 if (!decryptor_notification_cb_.is_null()) | 127 if (!decryptor_ready_cb_.is_null()) |
128 base::ResetAndReturn(&decryptor_notification_cb_).Run(decryptor_.get()); | 128 base::ResetAndReturn(&decryptor_ready_cb_).Run(decryptor_.get()); |
129 | 129 |
130 return true; | 130 return true; |
131 } | 131 } |
132 | 132 |
133 void ProxyDecryptor::AddKey(const std::string& key_system, | 133 void ProxyDecryptor::AddKey(const std::string& key_system, |
134 const uint8* key, | 134 const uint8* key, |
135 int key_length, | 135 int key_length, |
136 const uint8* init_data, | 136 const uint8* init_data, |
137 int init_data_length, | 137 int init_data_length, |
138 const std::string& session_id) { | 138 const std::string& session_id) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return; | 356 return; |
357 } | 357 } |
358 | 358 |
359 // TODO(xhwang): The same NeedKey may be fired multiple times here and also | 359 // TODO(xhwang): The same NeedKey may be fired multiple times here and also |
360 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave | 360 // in Decrypt(). While the spec says only one NeedKey should be fired. Leave |
361 // them as is since the spec about this may change. | 361 // them as is since the spec about this may change. |
362 FireNeedKey(client_, pending_buffer_to_decrypt_); | 362 FireNeedKey(client_, pending_buffer_to_decrypt_); |
363 } | 363 } |
364 | 364 |
365 } // namespace webkit_media | 365 } // namespace webkit_media |
OLD | NEW |