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 #ifndef CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ | 5 #ifndef CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ |
6 #define CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ | 6 #define CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/sequenced_task_runner_helpers.h" |
17 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
18 #include "media/base/browser_cdm.h" | 19 #include "media/base/media_keys.h" |
| 20 #include "media/base/player_tracker.h" |
19 #include "media/cdm/json_web_key.h" | 21 #include "media/cdm/json_web_key.h" |
20 | 22 |
21 namespace base { | 23 namespace base { |
22 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
23 } | 25 } |
24 | 26 |
25 namespace media { | 27 namespace media { |
26 class PlayerTrackerImpl; | 28 class PlayerTrackerImpl; |
27 } | 29 } |
28 | 30 |
29 namespace chromecast { | 31 namespace chromecast { |
30 namespace media { | 32 namespace media { |
31 class DecryptContextImpl; | 33 class DecryptContextImpl; |
32 | 34 |
33 // BrowserCdmCast is an extension of BrowserCdm that provides common | 35 // BrowserCdmCast is an extension of MediaKeys that provides common |
34 // functionality across CDM implementations. | 36 // functionality across CDM implementations. |
35 // All these additional functions are synchronous so: | 37 // All these additional functions are synchronous so: |
36 // - either both the CDM and the media pipeline must be running on the same | 38 // - either both the CDM and the media pipeline must be running on the same |
37 // thread, | 39 // thread, |
38 // - or BrowserCdmCast implementations must use some locks. | 40 // - or BrowserCdmCast implementations must use some locks. |
39 // | 41 // |
40 class BrowserCdmCast : public ::media::BrowserCdm { | 42 class BrowserCdmCast : public ::media::MediaKeys, |
| 43 public ::media::PlayerTracker { |
41 public: | 44 public: |
42 BrowserCdmCast(); | 45 BrowserCdmCast(); |
43 ~BrowserCdmCast() override; | |
44 | 46 |
45 void Initialize( | 47 void Initialize( |
46 const ::media::SessionMessageCB& session_message_cb, | 48 const ::media::SessionMessageCB& session_message_cb, |
47 const ::media::SessionClosedCB& session_closed_cb, | 49 const ::media::SessionClosedCB& session_closed_cb, |
48 const ::media::LegacySessionErrorCB& legacy_session_error_cb, | 50 const ::media::LegacySessionErrorCB& legacy_session_error_cb, |
49 const ::media::SessionKeysChangeCB& session_keys_change_cb, | 51 const ::media::SessionKeysChangeCB& session_keys_change_cb, |
50 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb); | 52 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb); |
51 | 53 |
52 // PlayerTracker implementation. | 54 // ::media::PlayerTracker implementation. |
53 int RegisterPlayer(const base::Closure& new_key_cb, | 55 int RegisterPlayer(const base::Closure& new_key_cb, |
54 const base::Closure& cdm_unset_cb) override; | 56 const base::Closure& cdm_unset_cb) override; |
55 void UnregisterPlayer(int registration_id) override; | 57 void UnregisterPlayer(int registration_id) override; |
56 | 58 |
57 // ::media::BrowserCdm implementation: | 59 // ::media::MediaKeys implementation: |
58 ::media::CdmContext* GetCdmContext() override; | 60 ::media::CdmContext* GetCdmContext() override; |
59 | 61 |
60 // Returns the decryption context needed to decrypt frames encrypted with | 62 // Returns the decryption context needed to decrypt frames encrypted with |
61 // |key_id|. | 63 // |key_id|. |
62 // Returns null if |key_id| is not available. | 64 // Returns null if |key_id| is not available. |
63 virtual scoped_ptr<DecryptContextImpl> GetDecryptContext( | 65 virtual scoped_ptr<DecryptContextImpl> GetDecryptContext( |
64 const std::string& key_id) const = 0; | 66 const std::string& key_id) const = 0; |
65 | 67 |
66 protected: | 68 protected: |
67 void OnSessionMessage(const std::string& session_id, | 69 void OnSessionMessage(const std::string& session_id, |
68 const std::vector<uint8_t>& message, | 70 const std::vector<uint8_t>& message, |
69 const GURL& destination_url, | 71 const GURL& destination_url, |
70 ::media::MediaKeys::MessageType message_type); | 72 ::media::MediaKeys::MessageType message_type); |
71 void OnSessionClosed(const std::string& session_id); | 73 void OnSessionClosed(const std::string& session_id); |
72 void OnSessionKeysChange(const std::string& session_id, | 74 void OnSessionKeysChange(const std::string& session_id, |
73 const ::media::KeyIdAndKeyPairs& keys); | 75 const ::media::KeyIdAndKeyPairs& keys); |
74 | 76 |
75 private: | 77 private: |
76 friend class BrowserCdmCastUi; | 78 friend class BrowserCdmCastUi; |
77 | 79 |
| 80 ~BrowserCdmCast() override; |
| 81 |
78 // Allow subclasses to override to provide key sysytem specific | 82 // Allow subclasses to override to provide key sysytem specific |
79 // initialization. | 83 // initialization. |
80 virtual void InitializeInternal(); | 84 virtual void InitializeInternal(); |
81 | 85 |
82 ::media::SessionMessageCB session_message_cb_; | 86 ::media::SessionMessageCB session_message_cb_; |
83 ::media::SessionClosedCB session_closed_cb_; | 87 ::media::SessionClosedCB session_closed_cb_; |
84 ::media::LegacySessionErrorCB legacy_session_error_cb_; | 88 ::media::LegacySessionErrorCB legacy_session_error_cb_; |
85 ::media::SessionKeysChangeCB session_keys_change_cb_; | 89 ::media::SessionKeysChangeCB session_keys_change_cb_; |
86 ::media::SessionExpirationUpdateCB session_expiration_update_cb_; | 90 ::media::SessionExpirationUpdateCB session_expiration_update_cb_; |
87 | 91 |
88 scoped_ptr<::media::PlayerTrackerImpl> player_tracker_impl_; | 92 scoped_ptr<::media::PlayerTrackerImpl> player_tracker_impl_; |
89 | 93 |
90 base::ThreadChecker thread_checker_; | 94 base::ThreadChecker thread_checker_; |
91 | 95 |
92 DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast); | 96 DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast); |
93 }; | 97 }; |
94 | 98 |
95 // BrowserCdm implementation that lives on the UI thread and forwards all calls | 99 // MediaKeys implementation that lives on the UI thread and forwards all calls |
96 // to a BrowserCdmCast instance on the CMA thread. This is used to simplify the | 100 // to a BrowserCdmCast instance on the CMA thread. This is used to simplify the |
97 // UI-CMA threading interaction. | 101 // UI-CMA threading interaction. |
98 class BrowserCdmCastUi : public ::media::BrowserCdm { | 102 class BrowserCdmCastUi : public ::media::MediaKeys { |
99 public: | 103 public: |
100 BrowserCdmCastUi( | 104 BrowserCdmCastUi( |
101 scoped_ptr<BrowserCdmCast> browser_cdm_cast, | 105 const scoped_refptr<BrowserCdmCast>& browser_cdm_cast, |
102 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 106 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
103 ~BrowserCdmCastUi() override; | |
104 | |
105 // PlayerTracker implementation: | |
106 int RegisterPlayer(const base::Closure& new_key_cb, | |
107 const base::Closure& cdm_unset_cb) override; | |
108 void UnregisterPlayer(int registration_id) override; | |
109 | 107 |
110 BrowserCdmCast* browser_cdm_cast() const; | 108 BrowserCdmCast* browser_cdm_cast() const; |
111 | 109 |
112 private: | 110 private: |
| 111 ~BrowserCdmCastUi() override; |
| 112 |
113 // ::media::MediaKeys implementation: | 113 // ::media::MediaKeys implementation: |
114 void SetServerCertificate( | 114 void SetServerCertificate( |
115 const std::vector<uint8_t>& certificate, | 115 const std::vector<uint8_t>& certificate, |
116 scoped_ptr<::media::SimpleCdmPromise> promise) override; | 116 scoped_ptr<::media::SimpleCdmPromise> promise) override; |
117 void CreateSessionAndGenerateRequest( | 117 void CreateSessionAndGenerateRequest( |
118 ::media::MediaKeys::SessionType session_type, | 118 ::media::MediaKeys::SessionType session_type, |
119 ::media::EmeInitDataType init_data_type, | 119 ::media::EmeInitDataType init_data_type, |
120 const std::vector<uint8_t>& init_data, | 120 const std::vector<uint8_t>& init_data, |
121 scoped_ptr<::media::NewSessionCdmPromise> promise) override; | 121 scoped_ptr<::media::NewSessionCdmPromise> promise) override; |
122 void LoadSession(::media::MediaKeys::SessionType session_type, | 122 void LoadSession(::media::MediaKeys::SessionType session_type, |
123 const std::string& session_id, | 123 const std::string& session_id, |
124 scoped_ptr<::media::NewSessionCdmPromise> promise) override; | 124 scoped_ptr<::media::NewSessionCdmPromise> promise) override; |
125 void UpdateSession(const std::string& session_id, | 125 void UpdateSession(const std::string& session_id, |
126 const std::vector<uint8_t>& response, | 126 const std::vector<uint8_t>& response, |
127 scoped_ptr<::media::SimpleCdmPromise> promise) override; | 127 scoped_ptr<::media::SimpleCdmPromise> promise) override; |
128 void CloseSession(const std::string& session_id, | 128 void CloseSession(const std::string& session_id, |
129 scoped_ptr<::media::SimpleCdmPromise> promise) override; | 129 scoped_ptr<::media::SimpleCdmPromise> promise) override; |
130 void RemoveSession(const std::string& session_id, | 130 void RemoveSession(const std::string& session_id, |
131 scoped_ptr<::media::SimpleCdmPromise> promise) override; | 131 scoped_ptr<::media::SimpleCdmPromise> promise) override; |
132 ::media::CdmContext* GetCdmContext() override; | 132 ::media::CdmContext* GetCdmContext() override; |
133 | 133 |
134 scoped_ptr<BrowserCdmCast> browser_cdm_cast_; | 134 scoped_refptr<BrowserCdmCast> browser_cdm_cast_; |
135 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
136 | 136 |
137 base::ThreadChecker thread_checker_; | 137 base::ThreadChecker thread_checker_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(BrowserCdmCastUi); | 139 DISALLOW_COPY_AND_ASSIGN(BrowserCdmCastUi); |
140 }; | 140 }; |
141 | 141 |
142 } // namespace media | 142 } // namespace media |
143 } // namespace chromecast | 143 } // namespace chromecast |
144 | 144 |
145 #endif // CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ | 145 #endif // CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_ |
OLD | NEW |