OLD | NEW |
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 <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 class ContentDecryptorDelegate { | 33 class ContentDecryptorDelegate { |
34 public: | 34 public: |
35 // ContentDecryptorDelegate does not take ownership of | 35 // ContentDecryptorDelegate does not take ownership of |
36 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| | 36 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| |
37 // must outlive this object. | 37 // must outlive this object. |
38 ContentDecryptorDelegate( | 38 ContentDecryptorDelegate( |
39 PP_Instance pp_instance, | 39 PP_Instance pp_instance, |
40 const PPP_ContentDecryptor_Private* plugin_decryption_interface); | 40 const PPP_ContentDecryptor_Private* plugin_decryption_interface); |
41 ~ContentDecryptorDelegate(); | 41 ~ContentDecryptorDelegate(); |
42 | 42 |
43 void Initialize(const std::string& key_system); | 43 // This object should not be accessed after |fatal_plugin_error_cb| is called. |
| 44 void Initialize(const std::string& key_system, |
| 45 const media::SessionCreatedCB& session_created_cb, |
| 46 const media::SessionMessageCB& session_message_cb, |
| 47 const media::SessionReadyCB& session_ready_cb, |
| 48 const media::SessionClosedCB& session_closed_cb, |
| 49 const media::SessionErrorCB& session_error_cb, |
| 50 const base::Closure& fatal_plugin_error_cb); |
44 | 51 |
45 void SetSessionEventCallbacks( | 52 void InstanceCrashed(); |
46 const media::SessionCreatedCB& session_created_cb, | |
47 const media::SessionMessageCB& session_message_cb, | |
48 const media::SessionReadyCB& session_ready_cb, | |
49 const media::SessionClosedCB& session_closed_cb, | |
50 const media::SessionErrorCB& session_error_cb); | |
51 | 53 |
52 // Provides access to PPP_ContentDecryptor_Private. | 54 // Provides access to PPP_ContentDecryptor_Private. |
53 bool CreateSession(uint32 session_id, | 55 bool CreateSession(uint32 session_id, |
54 const std::string& type, | 56 const std::string& type, |
55 const uint8* init_data, | 57 const uint8* init_data, |
56 int init_data_length); | 58 int init_data_length); |
57 bool UpdateSession(uint32 session_id, | 59 bool UpdateSession(uint32 session_id, |
58 const uint8* response, | 60 const uint8* response, |
59 int response_length); | 61 int response_length); |
60 bool ReleaseSession(uint32 session_id); | 62 bool ReleaseSession(uint32 session_id); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void DeliverFrame(PP_Resource decrypted_frame, | 104 void DeliverFrame(PP_Resource decrypted_frame, |
103 const PP_DecryptedFrameInfo* frame_info); | 105 const PP_DecryptedFrameInfo* frame_info); |
104 void DeliverSamples(PP_Resource audio_frames, | 106 void DeliverSamples(PP_Resource audio_frames, |
105 const PP_DecryptedSampleInfo* sample_info); | 107 const PP_DecryptedSampleInfo* sample_info); |
106 | 108 |
107 private: | 109 private: |
108 template <typename Callback> | 110 template <typename Callback> |
109 class TrackableCallback { | 111 class TrackableCallback { |
110 public: | 112 public: |
111 TrackableCallback() : id_(0u) {} | 113 TrackableCallback() : id_(0u) {} |
112 // TODO(xhwang): Check that no callback is pending in dtor. | 114 ~TrackableCallback() { |
113 ~TrackableCallback() {}; | 115 // Callbacks must be satisfied. |
| 116 DCHECK_EQ(id_, 0u); |
| 117 DCHECK(is_null()); |
| 118 }; |
114 | 119 |
115 bool Matches(uint32_t id) const { return id == id_; } | 120 bool Matches(uint32_t id) const { return id == id_; } |
116 | 121 |
117 bool is_null() const { return cb_.is_null(); } | 122 bool is_null() const { return cb_.is_null(); } |
118 | 123 |
119 void Set(uint32_t id, const Callback& cb) { | 124 void Set(uint32_t id, const Callback& cb) { |
120 DCHECK_EQ(id_, 0u); | 125 DCHECK_EQ(id_, 0u); |
121 DCHECK(cb_.is_null()); | 126 DCHECK(cb_.is_null()); |
122 id_ = id; | 127 id_ = id; |
123 cb_ = cb; | 128 cb_ = cb; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 160 |
156 void SetBufferToFreeInTrackingInfo(PP_DecryptTrackingInfo* tracking_info); | 161 void SetBufferToFreeInTrackingInfo(PP_DecryptTrackingInfo* tracking_info); |
157 | 162 |
158 // Deserializes audio data stored in |audio_frames| into individual audio | 163 // Deserializes audio data stored in |audio_frames| into individual audio |
159 // buffers in |frames|. Returns true upon success. | 164 // buffers in |frames|. Returns true upon success. |
160 bool DeserializeAudioFrames(PP_Resource audio_frames, | 165 bool DeserializeAudioFrames(PP_Resource audio_frames, |
161 size_t data_size, | 166 size_t data_size, |
162 media::SampleFormat sample_format, | 167 media::SampleFormat sample_format, |
163 media::Decryptor::AudioBuffers* frames); | 168 media::Decryptor::AudioBuffers* frames); |
164 | 169 |
| 170 void SatisfyAllPendingCallbacksOnError(); |
| 171 |
165 const PP_Instance pp_instance_; | 172 const PP_Instance pp_instance_; |
166 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; | 173 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; |
167 | 174 |
168 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. | 175 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. |
169 std::string key_system_; | 176 std::string key_system_; |
170 | 177 |
171 // Callbacks for firing session events. | 178 // Callbacks for firing session events. |
172 media::SessionCreatedCB session_created_cb_; | 179 media::SessionCreatedCB session_created_cb_; |
173 media::SessionMessageCB session_message_cb_; | 180 media::SessionMessageCB session_message_cb_; |
174 media::SessionReadyCB session_ready_cb_; | 181 media::SessionReadyCB session_ready_cb_; |
175 media::SessionClosedCB session_closed_cb_; | 182 media::SessionClosedCB session_closed_cb_; |
176 media::SessionErrorCB session_error_cb_; | 183 media::SessionErrorCB session_error_cb_; |
177 | 184 |
| 185 // Callback to notify that unexpected error happened and |this| should not |
| 186 // be used anymore. |
| 187 base::Closure fatal_plugin_error_cb_; |
| 188 |
178 gfx::Size natural_size_; | 189 gfx::Size natural_size_; |
179 | 190 |
180 // Request ID for tracking pending content decryption callbacks. | 191 // Request ID for tracking pending content decryption callbacks. |
181 // Note that zero indicates an invalid request ID. | 192 // Note that zero indicates an invalid request ID. |
182 // TODO(xhwang): Add completion callbacks for Reset/Stop and remove the use | 193 // TODO(xhwang): Add completion callbacks for Reset/Stop and remove the use |
183 // of request IDs. | 194 // of request IDs. |
184 uint32_t next_decryption_request_id_; | 195 uint32_t next_decryption_request_id_; |
185 | 196 |
186 TrackableCallback<media::Decryptor::DecryptCB> audio_decrypt_cb_; | 197 TrackableCallback<media::Decryptor::DecryptCB> audio_decrypt_cb_; |
187 TrackableCallback<media::Decryptor::DecryptCB> video_decrypt_cb_; | 198 TrackableCallback<media::Decryptor::DecryptCB> video_decrypt_cb_; |
(...skipping 14 matching lines...) Expand all Loading... |
202 | 213 |
203 base::WeakPtr<ContentDecryptorDelegate> weak_this_; | 214 base::WeakPtr<ContentDecryptorDelegate> weak_this_; |
204 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; | 215 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; |
205 | 216 |
206 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); | 217 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); |
207 }; | 218 }; |
208 | 219 |
209 } // namespace content | 220 } // namespace content |
210 | 221 |
211 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ | 222 #endif // CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_ |
OLD | NEW |