Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: content/renderer/media/android/proxy_media_keys.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_
6 #define CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ 6 #define CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_
7 7
8 #include <map>
9 #include <string>
10
8 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
9 #include "media/base/media_keys.h" 13 #include "media/base/media_keys.h"
10 14
11 class GURL; 15 class GURL;
12 16
13 namespace content { 17 namespace content {
14 18
15 class RendererMediaPlayerManager; 19 class RendererMediaPlayerManager;
16 20
17 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. 21 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager.
18 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let 22 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let
19 // RendererMediaPlayerManager return a MediaKeys object that can be used by 23 // RendererMediaPlayerManager return a MediaKeys object that can be used by
20 // ProxyDecryptor directly. Then we can remove this class! 24 // ProxyDecryptor directly. Then we can remove this class!
21 class ProxyMediaKeys : public media::MediaKeys { 25 class ProxyMediaKeys : public media::MediaKeys {
22 public: 26 public:
23 static scoped_ptr<ProxyMediaKeys> Create( 27 static scoped_ptr<ProxyMediaKeys> Create(
24 const std::string& key_system, 28 const std::string& key_system,
25 const GURL& security_origin, 29 const GURL& security_origin,
26 RendererMediaPlayerManager* manager, 30 RendererMediaPlayerManager* manager,
27 const media::SessionCreatedCB& session_created_cb,
28 const media::SessionMessageCB& session_message_cb, 31 const media::SessionMessageCB& session_message_cb,
29 const media::SessionReadyCB& session_ready_cb, 32 const media::SessionReadyCB& session_ready_cb,
30 const media::SessionClosedCB& session_closed_cb, 33 const media::SessionClosedCB& session_closed_cb,
31 const media::SessionErrorCB& session_error_cb); 34 const media::SessionErrorCB& session_error_cb);
32 35
33 virtual ~ProxyMediaKeys(); 36 virtual ~ProxyMediaKeys();
34 37
35 // MediaKeys implementation. 38 // MediaKeys implementation.
36 virtual bool CreateSession(uint32 session_id, 39 virtual void CreateSession(
37 const std::string& content_type, 40 const std::string& init_data_type,
38 const uint8* init_data, 41 const uint8* init_data,
39 int init_data_length) OVERRIDE; 42 int init_data_length,
40 virtual void LoadSession(uint32 session_id, 43 SessionType session_type,
41 const std::string& web_session_id) OVERRIDE; 44 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE;
42 virtual void UpdateSession(uint32 session_id, 45 virtual void LoadSession(
43 const uint8* response, 46 const std::string& web_session_id,
44 int response_length) OVERRIDE; 47 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE;
45 virtual void ReleaseSession(uint32 session_id) OVERRIDE; 48 virtual void UpdateSession(
49 const std::string& web_session_id,
50 const uint8* response,
51 int response_length,
52 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE;
53 virtual void ReleaseSession(
54 const std::string& web_session_id,
55 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE;
46 56
47 // Callbacks. 57 // Callbacks.
48 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); 58 void OnSessionCreated(uint32 session_id, const std::string& web_session_id);
49 void OnSessionMessage(uint32 session_id, 59 void OnSessionMessage(uint32 session_id,
50 const std::vector<uint8>& message, 60 const std::vector<uint8>& message,
51 const std::string& destination_url); 61 const std::string& destination_url);
52 void OnSessionReady(uint32 session_id); 62 void OnSessionReady(uint32 session_id);
53 void OnSessionClosed(uint32 session_id); 63 void OnSessionClosed(uint32 session_id);
54 void OnSessionError(uint32 session_id, 64 void OnSessionError(uint32 session_id,
55 media::MediaKeys::KeyError error_code, 65 media::MediaKeys::KeyError error_code,
56 uint32 system_code); 66 uint32 system_code);
57 67
58 int GetCdmId() const; 68 int GetCdmId() const;
59 69
60 private: 70 private:
71 typedef base::hash_map<std::string, uint32_t> SessionIdMap;
72 typedef std::map<uint32_t, media::SimpleCdmPromise*> SimplePromiseMap;
73 typedef std::map<uint32_t, media::NewSessionCdmPromise*> NewSessionPromiseMap;
74
61 ProxyMediaKeys(RendererMediaPlayerManager* manager, 75 ProxyMediaKeys(RendererMediaPlayerManager* manager,
62 const media::SessionCreatedCB& session_created_cb,
63 const media::SessionMessageCB& session_message_cb, 76 const media::SessionMessageCB& session_message_cb,
64 const media::SessionReadyCB& session_ready_cb, 77 const media::SessionReadyCB& session_ready_cb,
65 const media::SessionClosedCB& session_closed_cb, 78 const media::SessionClosedCB& session_closed_cb,
66 const media::SessionErrorCB& session_error_cb); 79 const media::SessionErrorCB& session_error_cb);
67 80
68 void InitializeCdm(const std::string& key_system, 81 void InitializeCdm(const std::string& key_system,
69 const GURL& security_origin); 82 const GURL& security_origin);
70 83
84 // The Android-specific code that handles sessions uses integer session ids
85 // (basically a reference id), but media::MediaKeys bases everything on
86 // web_session_id (a string representing the actual session id as generated
87 // by the CDM). These functions keep track of session_ids <-> web_session_ids
88 // mappings.
89 // TODO(jrummell): Remove this once the Android-specific code changes to
90 // support string session ids.
91 uint32_t CreateSessionId();
92 void AssignWebSessionId(uint32_t session_id,
93 const std::string& web_session_id);
94 uint32_t LookupSessionId(const std::string& web_session_id);
95 std::string LookupWebSessionId(uint32_t session_id);
96 void DropWebSessionId(std::string web_session_id);
97
98 // Helper function to keep track of promises. Adding takes ownership of the
99 // promise, transferred back to caller on lookup.
100 void RegisterSimplePromise(uint32_t session_id,
101 scoped_ptr<media::SimpleCdmPromise> promise);
102 scoped_ptr<media::SimpleCdmPromise> TakeSimplePromise(uint32_t session_id);
103 void RegisterNewSessionPromise(
104 uint32_t session_id,
105 scoped_ptr<media::NewSessionCdmPromise> promise);
106 scoped_ptr<media::NewSessionCdmPromise> TakeNewSessionPromise(
107 uint32_t session_id);
108
71 // CDM ID should be unique per renderer process. 109 // CDM ID should be unique per renderer process.
72 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. 110 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior.
73 static int next_cdm_id_; 111 static int next_cdm_id_;
74 112
75 RendererMediaPlayerManager* manager_; 113 RendererMediaPlayerManager* manager_;
76 int cdm_id_; 114 int cdm_id_;
77 media::SessionCreatedCB session_created_cb_;
78 media::SessionMessageCB session_message_cb_; 115 media::SessionMessageCB session_message_cb_;
79 media::SessionReadyCB session_ready_cb_; 116 media::SessionReadyCB session_ready_cb_;
80 media::SessionClosedCB session_closed_cb_; 117 media::SessionClosedCB session_closed_cb_;
81 media::SessionErrorCB session_error_cb_; 118 media::SessionErrorCB session_error_cb_;
82 119
120 // Android-specific. See comment above CreateSessionId().
121 uint32_t next_session_id_;
122 SessionIdMap web_session_to_session_id_map_;
123
124 // Keep track of outstanding promises. These maps owns the promise object.
125 SimplePromiseMap session_id_to_change_session_promise_map_;
ddorwin 2014/05/15 23:15:32 s/change_session/simple/ ?
jrummell 2014/05/16 00:49:53 Done.
126 NewSessionPromiseMap session_id_to_new_session_promise_map_;
127
83 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); 128 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys);
84 }; 129 };
85 130
86 } // namespace content 131 } // namespace content
87 132
88 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ 133 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698