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

Side by Side Diff: content/renderer/pepper/content_decryptor_delegate.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more trybot issue Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_
6 #define CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ 6 #define CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_
7 7
8 #include <map>
8 #include <queue> 9 #include <queue>
9 #include <string> 10 #include <string>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
13 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "media/base/cdm_promise.h"
16 #include "media/base/channel_layout.h" 19 #include "media/base/channel_layout.h"
17 #include "media/base/decryptor.h" 20 #include "media/base/decryptor.h"
18 #include "media/base/media_keys.h" 21 #include "media/base/media_keys.h"
19 #include "media/base/sample_format.h" 22 #include "media/base/sample_format.h"
20 #include "ppapi/c/private/pp_content_decryptor.h" 23 #include "ppapi/c/private/pp_content_decryptor.h"
21 #include "ppapi/c/private/ppp_content_decryptor_private.h" 24 #include "ppapi/c/private/ppp_content_decryptor_private.h"
22 #include "ui/gfx/size.h" 25 #include "ui/gfx/size.h"
23 26
24 namespace media { 27 namespace media {
25 class AudioDecoderConfig; 28 class AudioDecoderConfig;
(...skipping 10 matching lines...) Expand all
36 // ContentDecryptorDelegate does not take ownership of 39 // ContentDecryptorDelegate does not take ownership of
37 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| 40 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface|
38 // must outlive this object. 41 // must outlive this object.
39 ContentDecryptorDelegate( 42 ContentDecryptorDelegate(
40 PP_Instance pp_instance, 43 PP_Instance pp_instance,
41 const PPP_ContentDecryptor_Private* plugin_decryption_interface); 44 const PPP_ContentDecryptor_Private* plugin_decryption_interface);
42 ~ContentDecryptorDelegate(); 45 ~ContentDecryptorDelegate();
43 46
44 // This object should not be accessed after |fatal_plugin_error_cb| is called. 47 // This object should not be accessed after |fatal_plugin_error_cb| is called.
45 void Initialize(const std::string& key_system, 48 void Initialize(const std::string& key_system,
46 const media::SessionCreatedCB& session_created_cb,
47 const media::SessionMessageCB& session_message_cb, 49 const media::SessionMessageCB& session_message_cb,
48 const media::SessionReadyCB& session_ready_cb, 50 const media::SessionReadyCB& session_ready_cb,
49 const media::SessionClosedCB& session_closed_cb, 51 const media::SessionClosedCB& session_closed_cb,
50 const media::SessionErrorCB& session_error_cb, 52 const media::SessionErrorCB& session_error_cb,
51 const base::Closure& fatal_plugin_error_cb); 53 const base::Closure& fatal_plugin_error_cb);
52 54
53 void InstanceCrashed(); 55 void InstanceCrashed();
54 56
55 // Provides access to PPP_ContentDecryptor_Private. 57 // Provides access to PPP_ContentDecryptor_Private.
56 bool CreateSession(uint32 session_id, 58 void CreateSession(const std::string& init_data_type,
57 const std::string& content_type,
58 const uint8* init_data, 59 const uint8* init_data,
59 int init_data_length); 60 int init_data_length,
60 void LoadSession(uint32 session_id, const std::string& web_session_id); 61 media::MediaKeys::SessionType session_type,
61 bool UpdateSession(uint32 session_id, 62 scoped_ptr<media::NewSessionCdmPromise> promise);
63 void LoadSession(const std::string& web_session_id,
64 scoped_ptr<media::NewSessionCdmPromise> promise);
65 void UpdateSession(const std::string& web_session_id,
62 const uint8* response, 66 const uint8* response,
63 int response_length); 67 int response_length,
64 bool ReleaseSession(uint32 session_id); 68 scoped_ptr<media::SimpleCdmPromise> promise);
69 void ReleaseSession(const std::string& web_session_id,
70 scoped_ptr<media::SimpleCdmPromise> promise);
65 bool Decrypt(media::Decryptor::StreamType stream_type, 71 bool Decrypt(media::Decryptor::StreamType stream_type,
66 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 72 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
67 const media::Decryptor::DecryptCB& decrypt_cb); 73 const media::Decryptor::DecryptCB& decrypt_cb);
68 bool CancelDecrypt(media::Decryptor::StreamType stream_type); 74 bool CancelDecrypt(media::Decryptor::StreamType stream_type);
69 bool InitializeAudioDecoder( 75 bool InitializeAudioDecoder(
70 const media::AudioDecoderConfig& decoder_config, 76 const media::AudioDecoderConfig& decoder_config,
71 const media::Decryptor::DecoderInitCB& decoder_init_cb); 77 const media::Decryptor::DecoderInitCB& decoder_init_cb);
72 bool InitializeVideoDecoder( 78 bool InitializeVideoDecoder(
73 const media::VideoDecoderConfig& decoder_config, 79 const media::VideoDecoderConfig& decoder_config,
74 const media::Decryptor::DecoderInitCB& decoder_init_cb); 80 const media::Decryptor::DecoderInitCB& decoder_init_cb);
75 // TODO(tomfinegan): Add callback args for DeinitializeDecoder() and 81 // TODO(tomfinegan): Add callback args for DeinitializeDecoder() and
76 // ResetDecoder() 82 // ResetDecoder()
77 bool DeinitializeDecoder(media::Decryptor::StreamType stream_type); 83 bool DeinitializeDecoder(media::Decryptor::StreamType stream_type);
78 bool ResetDecoder(media::Decryptor::StreamType stream_type); 84 bool ResetDecoder(media::Decryptor::StreamType stream_type);
79 // Note: These methods can be used with unencrypted data. 85 // Note: These methods can be used with unencrypted data.
80 bool DecryptAndDecodeAudio( 86 bool DecryptAndDecodeAudio(
81 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 87 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
82 const media::Decryptor::AudioDecodeCB& audio_decode_cb); 88 const media::Decryptor::AudioDecodeCB& audio_decode_cb);
83 bool DecryptAndDecodeVideo( 89 bool DecryptAndDecodeVideo(
84 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 90 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
85 const media::Decryptor::VideoDecodeCB& video_decode_cb); 91 const media::Decryptor::VideoDecodeCB& video_decode_cb);
86 92
87 // PPB_ContentDecryptor_Private dispatching methods. 93 // PPB_ContentDecryptor_Private dispatching methods.
88 void OnSessionCreated(uint32 session_id, PP_Var web_session_id_var); 94 void OnPromiseResolved(uint32 promise_id);
89 void OnSessionMessage(uint32 session_id, 95 void OnPromiseResolvedWithSession(uint32 promise_id, PP_Var web_session_id);
96 void OnPromiseRejected(uint32 promise_id,
97 PP_CdmExceptionCode exception_code,
98 uint32 system_code,
99 PP_Var error_description);
100 void OnSessionMessage(PP_Var web_session_id,
90 PP_Var message, 101 PP_Var message,
91 PP_Var destination_url_var); 102 PP_Var destination_url);
92 void OnSessionReady(uint32 session_id); 103 void OnSessionReady(PP_Var web_session_id);
93 void OnSessionClosed(uint32 session_id); 104 void OnSessionClosed(PP_Var web_session_id);
94 void OnSessionError(uint32 session_id, 105 void OnSessionError(PP_Var web_session_id,
95 int32_t media_error, 106 PP_CdmExceptionCode exception_code,
96 uint32_t system_code); 107 uint32 system_code,
108 PP_Var error_description);
97 void DeliverBlock(PP_Resource decrypted_block, 109 void DeliverBlock(PP_Resource decrypted_block,
98 const PP_DecryptedBlockInfo* block_info); 110 const PP_DecryptedBlockInfo* block_info);
99 void DecoderInitializeDone(PP_DecryptorStreamType decoder_type, 111 void DecoderInitializeDone(PP_DecryptorStreamType decoder_type,
100 uint32_t request_id, 112 uint32_t request_id,
101 PP_Bool success); 113 PP_Bool success);
102 void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type, 114 void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type,
103 uint32_t request_id); 115 uint32_t request_id);
104 void DecoderResetDone(PP_DecryptorStreamType decoder_type, 116 void DecoderResetDone(PP_DecryptorStreamType decoder_type,
105 uint32_t request_id); 117 uint32_t request_id);
106 void DeliverFrame(PP_Resource decrypted_frame, 118 void DeliverFrame(PP_Resource decrypted_frame,
107 const PP_DecryptedFrameInfo* frame_info); 119 const PP_DecryptedFrameInfo* frame_info);
108 void DeliverSamples(PP_Resource audio_frames, 120 void DeliverSamples(PP_Resource audio_frames,
109 const PP_DecryptedSampleInfo* sample_info); 121 const PP_DecryptedSampleInfo* sample_info);
110 122
111 private: 123 private:
124 // The following types keep track of Promises. The index is the promise_id,
125 // so that returning results can be matched to the corresponding promise.
126 typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap;
127
112 template <typename Callback> 128 template <typename Callback>
113 class TrackableCallback { 129 class TrackableCallback {
114 public: 130 public:
115 TrackableCallback() : id_(0u) {} 131 TrackableCallback() : id_(0u) {}
116 ~TrackableCallback() { 132 ~TrackableCallback() {
117 // Callbacks must be satisfied. 133 // Callbacks must be satisfied.
118 DCHECK_EQ(id_, 0u); 134 DCHECK_EQ(id_, 0u);
119 DCHECK(is_null()); 135 DCHECK(is_null());
120 }; 136 };
121 137
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 180
165 // Deserializes audio data stored in |audio_frames| into individual audio 181 // Deserializes audio data stored in |audio_frames| into individual audio
166 // buffers in |frames|. Returns true upon success. 182 // buffers in |frames|. Returns true upon success.
167 bool DeserializeAudioFrames(PP_Resource audio_frames, 183 bool DeserializeAudioFrames(PP_Resource audio_frames,
168 size_t data_size, 184 size_t data_size,
169 media::SampleFormat sample_format, 185 media::SampleFormat sample_format,
170 media::Decryptor::AudioBuffers* frames); 186 media::Decryptor::AudioBuffers* frames);
171 187
172 void SatisfyAllPendingCallbacksOnError(); 188 void SatisfyAllPendingCallbacksOnError();
173 189
190 // Takes ownership of |promise| and returns an identifier to be passed via
191 // Pepper.
192 uint32_t SavePromise(scoped_ptr<media::CdmPromise> promise);
193
194 // Find the promise for a specified |promise_id|. Caller is responsible to
195 // delete the CdmPromise<> once done with it.
196 scoped_ptr<media::CdmPromise> TakePromise(uint32_t promise_id);
197
174 const PP_Instance pp_instance_; 198 const PP_Instance pp_instance_;
175 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; 199 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_;
176 200
177 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. 201 // TODO(ddorwin): Remove after updating the Pepper API to not use key system.
178 std::string key_system_; 202 std::string key_system_;
179 203
180 // Callbacks for firing session events. 204 // Callbacks for firing session events.
181 media::SessionCreatedCB session_created_cb_;
182 media::SessionMessageCB session_message_cb_; 205 media::SessionMessageCB session_message_cb_;
183 media::SessionReadyCB session_ready_cb_; 206 media::SessionReadyCB session_ready_cb_;
184 media::SessionClosedCB session_closed_cb_; 207 media::SessionClosedCB session_closed_cb_;
185 media::SessionErrorCB session_error_cb_; 208 media::SessionErrorCB session_error_cb_;
186 209
187 // Callback to notify that unexpected error happened and |this| should not 210 // Callback to notify that unexpected error happened and |this| should not
188 // be used anymore. 211 // be used anymore.
189 base::Closure fatal_plugin_error_cb_; 212 base::Closure fatal_plugin_error_cb_;
190 213
191 gfx::Size natural_size_; 214 gfx::Size natural_size_;
(...skipping 15 matching lines...) Expand all
207 scoped_refptr<PPB_Buffer_Impl> audio_input_resource_; 230 scoped_refptr<PPB_Buffer_Impl> audio_input_resource_;
208 scoped_refptr<PPB_Buffer_Impl> video_input_resource_; 231 scoped_refptr<PPB_Buffer_Impl> video_input_resource_;
209 232
210 std::queue<uint32_t> free_buffers_; 233 std::queue<uint32_t> free_buffers_;
211 234
212 // Keep track of audio parameters. 235 // Keep track of audio parameters.
213 int audio_samples_per_second_; 236 int audio_samples_per_second_;
214 int audio_channel_count_; 237 int audio_channel_count_;
215 media::ChannelLayout audio_channel_layout_; 238 media::ChannelLayout audio_channel_layout_;
216 239
240 // Keep track of outstanding promises. Maps have ownership of the promises.
241 uint32_t next_promise_id_;
242 PromiseMap promises_;
243
217 base::WeakPtr<ContentDecryptorDelegate> weak_this_; 244 base::WeakPtr<ContentDecryptorDelegate> weak_this_;
218 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; 245 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_;
219 246
220 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); 247 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate);
221 }; 248 };
222 249
223 } // namespace content 250 } // namespace content
224 251
225 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ 252 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698