Add ability for NetLogLogger to gather data from more than just NetLog
[chromium-blink-merge.git] / chromecast / media / cdm / browser_cdm_cast.h
blobf1770aaa7910f61e8b5022bc695da5dfe9cf6ac1
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>
13 #include "base/callback.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
17 #include "media/base/browser_cdm.h"
18 #include "media/cdm/json_web_key.h"
20 namespace chromecast {
21 namespace media {
22 class DecryptContext;
24 // BrowserCdmCast is an extension of BrowserCdm that provides common
25 // functionality across CDM implementations.
26 // All these additional functions are synchronous so:
27 // - either both the CDM and the media pipeline must be running on the same
28 // thread,
29 // - or BrowserCdmCast implementations must use some locks.
31 class BrowserCdmCast : public ::media::BrowserCdm {
32 public:
33 BrowserCdmCast();
34 ~BrowserCdmCast() override;
36 void SetCallbacks(
37 const ::media::SessionMessageCB& session_message_cb,
38 const ::media::SessionClosedCB& session_closed_cb,
39 const ::media::SessionErrorCB& session_error_cb,
40 const ::media::SessionKeysChangeCB& session_keys_change_cb,
41 const ::media::SessionExpirationUpdateCB& session_expiration_update_cb);
43 // PlayerTracker implementation.
44 int RegisterPlayer(const base::Closure& new_key_cb,
45 const base::Closure& cdm_unset_cb) override;
46 void UnregisterPlayer(int registration_id) override;
48 // ::media::BrowserCdm implementation:
49 void LoadSession(::media::MediaKeys::SessionType session_type,
50 const std::string& session_id,
51 scoped_ptr<::media::NewSessionCdmPromise> promise) override;
52 ::media::CdmContext* GetCdmContext() override;
54 // Returns the decryption context needed to decrypt frames encrypted with
55 // |key_id|.
56 // Returns null if |key_id| is not available.
57 virtual scoped_refptr<DecryptContext> GetDecryptContext(
58 const std::string& key_id) = 0;
60 protected:
61 void OnSessionMessage(const std::string& session_id,
62 const std::vector<uint8>& message,
63 const GURL& destination_url);
64 void OnSessionClosed(const std::string& session_id);
65 void OnSessionKeysChange(const std::string& session_id,
66 const ::media::KeyIdAndKeyPairs& keys);
68 private:
69 ::media::SessionMessageCB session_message_cb_;
70 ::media::SessionClosedCB session_closed_cb_;
71 ::media::SessionErrorCB session_error_cb_;
72 ::media::SessionKeysChangeCB session_keys_change_cb_;
73 ::media::SessionExpirationUpdateCB session_expiration_update_cb_;
75 base::Lock callback_lock_;
76 uint32_t next_registration_id_;
77 std::map<uint32_t, base::Closure> new_key_callbacks_;
78 std::map<uint32_t, base::Closure> cdm_unset_callbacks_;
80 DISALLOW_COPY_AND_ASSIGN(BrowserCdmCast);
83 } // namespace media
84 } // namespace chromecast
86 #endif // CHROMECAST_MEDIA_CDM_BROWSER_CDM_CAST_H_