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