OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/media/cdm/browser_cdm_cast.h" | 5 #include "chromecast/media/cdm/browser_cdm_cast.h" |
6 | 6 |
7 #include "media/base/cdm_key_information.h" | 7 #include "media/base/cdm_key_information.h" |
8 | 8 |
9 namespace chromecast { | 9 namespace chromecast { |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 BrowserCdmCast::BrowserCdmCast() { | 12 BrowserCdmCast::BrowserCdmCast() { |
erickung1
2015/02/07 01:31:10
|next_registration_id_| initialization?
gunsch
2015/02/07 01:44:27
Done.
| |
13 } | 13 } |
14 | 14 |
15 BrowserCdmCast::~BrowserCdmCast() { | 15 BrowserCdmCast::~BrowserCdmCast() { |
16 player_tracker_.NotifyCdmUnset(); | 16 { |
erickung1
2015/02/07 01:31:10
Nit: maybe no need the parentheses?
gunsch
2015/02/07 01:44:27
Done.
| |
17 base::AutoLock auto_lock(callback_lock_); | |
18 for (std::map<uint32_t, base::Closure>::const_iterator it = | |
19 cdm_unset_callbacks_.begin(); it != cdm_unset_callbacks_.end(); ++it) { | |
20 it->second.Run(); | |
21 } | |
22 } | |
17 } | 23 } |
18 | 24 |
19 void BrowserCdmCast::SetCallbacks( | 25 void BrowserCdmCast::SetCallbacks( |
20 const ::media::SessionMessageCB& session_message_cb, | 26 const ::media::SessionMessageCB& session_message_cb, |
21 const ::media::SessionClosedCB& session_closed_cb, | 27 const ::media::SessionClosedCB& session_closed_cb, |
22 const ::media::SessionErrorCB& session_error_cb, | 28 const ::media::SessionErrorCB& session_error_cb, |
23 const ::media::SessionKeysChangeCB& session_keys_change_cb, | 29 const ::media::SessionKeysChangeCB& session_keys_change_cb, |
24 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) { | 30 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb) { |
25 session_message_cb_ = session_message_cb; | 31 session_message_cb_ = session_message_cb; |
26 session_closed_cb_ = session_closed_cb; | 32 session_closed_cb_ = session_closed_cb; |
27 session_error_cb_ = session_error_cb; | 33 session_error_cb_ = session_error_cb; |
28 session_keys_change_cb_ = session_keys_change_cb; | 34 session_keys_change_cb_ = session_keys_change_cb; |
29 session_expiration_update_cb_ = session_expiration_update_cb; | 35 session_expiration_update_cb_ = session_expiration_update_cb; |
30 } | 36 } |
31 | 37 |
32 int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, | 38 int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, |
33 const base::Closure& cdm_unset_cb) { | 39 const base::Closure& cdm_unset_cb) { |
34 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); | 40 int registration_id = next_registration_id_++; |
41 DCHECK(!new_key_cb.is_null()); | |
42 DCHECK(!cdm_unset_cb.is_null()); | |
43 { | |
44 base::AutoLock auto_lock(callback_lock_); | |
45 DCHECK(!ContainsKey(new_key_callbacks_, registration_id)); | |
46 DCHECK(!ContainsKey(cdm_unset_callbacks_, registration_id)); | |
47 new_key_callbacks_[registration_id] = new_key_cb; | |
48 cdm_unset_callbacks_[registration_id] = cdm_unset_cb; | |
49 } | |
50 return registration_id; | |
35 } | 51 } |
36 | 52 |
37 void BrowserCdmCast::UnregisterPlayer(int registration_id) { | 53 void BrowserCdmCast::UnregisterPlayer(int registration_id) { |
38 player_tracker_.UnregisterPlayer(registration_id); | 54 { |
erickung1
2015/02/07 01:31:10
Nit: maybe no need the parentheses?
gunsch
2015/02/07 01:44:27
Done.
| |
55 base::AutoLock auto_lock(callback_lock_); | |
56 DCHECK(ContainsKey(new_key_callbacks_, registration_id)); | |
57 DCHECK(ContainsKey(cdm_unset_callbacks_, registration_id)); | |
58 new_key_callbacks_.erase(registration_id); | |
59 cdm_unset_callbacks_.erase(registration_id); | |
60 } | |
39 } | 61 } |
40 | 62 |
41 void BrowserCdmCast::OnSessionMessage(const std::string& web_session_id, | 63 void BrowserCdmCast::OnSessionMessage(const std::string& web_session_id, |
42 const std::vector<uint8>& message, | 64 const std::vector<uint8>& message, |
43 const GURL& destination_url) { | 65 const GURL& destination_url) { |
44 // Note: Message type is not supported in Chromecast. Do our best guess here. | 66 // Note: Message type is not supported in Chromecast. Do our best guess here. |
45 ::media::MediaKeys::MessageType message_type = | 67 ::media::MediaKeys::MessageType message_type = |
46 destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST | 68 destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST |
47 : ::media::MediaKeys::LICENSE_RENEWAL; | 69 : ::media::MediaKeys::LICENSE_RENEWAL; |
48 session_message_cb_.Run(web_session_id, | 70 session_message_cb_.Run(web_session_id, |
(...skipping 12 matching lines...) Expand all Loading... | |
61 ::media::CdmKeysInfo cdm_keys_info; | 83 ::media::CdmKeysInfo cdm_keys_info; |
62 for (const std::pair<std::string, std::string>& key : keys) { | 84 for (const std::pair<std::string, std::string>& key : keys) { |
63 scoped_ptr< ::media::CdmKeyInformation> cdm_key_information( | 85 scoped_ptr< ::media::CdmKeyInformation> cdm_key_information( |
64 new ::media::CdmKeyInformation()); | 86 new ::media::CdmKeyInformation()); |
65 cdm_key_information->key_id.assign(key.first.begin(), key.first.end()); | 87 cdm_key_information->key_id.assign(key.first.begin(), key.first.end()); |
66 cdm_keys_info.push_back(cdm_key_information.release()); | 88 cdm_keys_info.push_back(cdm_key_information.release()); |
67 } | 89 } |
68 session_keys_change_cb_.Run(web_session_id, true, cdm_keys_info.Pass()); | 90 session_keys_change_cb_.Run(web_session_id, true, cdm_keys_info.Pass()); |
69 | 91 |
70 // Notify listeners of a new key. | 92 // Notify listeners of a new key. |
71 player_tracker_.NotifyNewKey(); | 93 { |
94 base::AutoLock auto_lock(callback_lock_); | |
95 for (std::map<uint32_t, base::Closure>::const_iterator it = | |
96 new_key_callbacks_.begin(); it != new_key_callbacks_.end(); ++it) { | |
97 it->second.Run(); | |
98 } | |
99 } | |
72 } | 100 } |
73 | 101 |
74 } // namespace media | 102 } // namespace media |
75 } // namespace chromecast | 103 } // namespace chromecast |
OLD | NEW |