| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_PLUGINS_PPAPI_CONTENT_DECRYPTOR_DELEGATE_H_ | |
| 6 #define WEBKIT_PLUGINS_PPAPI_CONTENT_DECRYPTOR_DELEGATE_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "media/base/decryptor.h" | |
| 16 #include "media/base/media_keys.h" | |
| 17 #include "media/base/sample_format.h" | |
| 18 #include "ppapi/c/private/pp_content_decryptor.h" | |
| 19 #include "ppapi/c/private/ppp_content_decryptor_private.h" | |
| 20 #include "ui/gfx/size.h" | |
| 21 #include "webkit/plugins/webkit_plugins_export.h" | |
| 22 | |
| 23 namespace media { | |
| 24 class AudioDecoderConfig; | |
| 25 class DecoderBuffer; | |
| 26 class VideoDecoderConfig; | |
| 27 } | |
| 28 | |
| 29 namespace webkit { | |
| 30 namespace ppapi { | |
| 31 | |
| 32 class PPB_Buffer_Impl; | |
| 33 | |
| 34 class WEBKIT_PLUGINS_EXPORT ContentDecryptorDelegate { | |
| 35 public: | |
| 36 // ContentDecryptorDelegate does not take ownership of | |
| 37 // |plugin_decryption_interface|. Therefore |plugin_decryption_interface| | |
| 38 // must outlive this object. | |
| 39 ContentDecryptorDelegate( | |
| 40 PP_Instance pp_instance, | |
| 41 const PPP_ContentDecryptor_Private* plugin_decryption_interface); | |
| 42 | |
| 43 void Initialize(const std::string& key_system); | |
| 44 | |
| 45 void SetKeyEventCallbacks(const media::KeyAddedCB& key_added_cb, | |
| 46 const media::KeyErrorCB& key_error_cb, | |
| 47 const media::KeyMessageCB& key_message_cb); | |
| 48 | |
| 49 // Provides access to PPP_ContentDecryptor_Private. | |
| 50 bool GenerateKeyRequest(const std::string& type, | |
| 51 const uint8* init_data, | |
| 52 int init_data_length); | |
| 53 bool AddKey(const std::string& session_id, | |
| 54 const uint8* key, | |
| 55 int key_length, | |
| 56 const uint8* init_data, | |
| 57 int init_data_length); | |
| 58 bool CancelKeyRequest(const std::string& session_id); | |
| 59 bool Decrypt(media::Decryptor::StreamType stream_type, | |
| 60 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
| 61 const media::Decryptor::DecryptCB& decrypt_cb); | |
| 62 bool CancelDecrypt(media::Decryptor::StreamType stream_type); | |
| 63 bool InitializeAudioDecoder( | |
| 64 const media::AudioDecoderConfig& decoder_config, | |
| 65 const media::Decryptor::DecoderInitCB& decoder_init_cb); | |
| 66 bool InitializeVideoDecoder( | |
| 67 const media::VideoDecoderConfig& decoder_config, | |
| 68 const media::Decryptor::DecoderInitCB& decoder_init_cb); | |
| 69 // TODO(tomfinegan): Add callback args for DeinitializeDecoder() and | |
| 70 // ResetDecoder() | |
| 71 bool DeinitializeDecoder(media::Decryptor::StreamType stream_type); | |
| 72 bool ResetDecoder(media::Decryptor::StreamType stream_type); | |
| 73 // Note: These methods can be used with unencrypted data. | |
| 74 bool DecryptAndDecodeAudio( | |
| 75 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
| 76 const media::Decryptor::AudioDecodeCB& audio_decode_cb); | |
| 77 bool DecryptAndDecodeVideo( | |
| 78 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
| 79 const media::Decryptor::VideoDecodeCB& video_decode_cb); | |
| 80 | |
| 81 // PPB_ContentDecryptor_Private dispatching methods. | |
| 82 // TODO(ddorwin): Remove this method. | |
| 83 void NeedKey(PP_Var key_system, PP_Var session_id, PP_Var init_data); | |
| 84 // TODO(ddorwin): Remove key_system_var parameter from these methods. | |
| 85 void KeyAdded(PP_Var key_system, PP_Var session_id); | |
| 86 void KeyMessage(PP_Var key_system, | |
| 87 PP_Var session_id, | |
| 88 PP_Var message, | |
| 89 PP_Var default_url); | |
| 90 void KeyError(PP_Var key_system, | |
| 91 PP_Var session_id, | |
| 92 int32_t media_error, | |
| 93 int32_t system_code); | |
| 94 void DeliverBlock(PP_Resource decrypted_block, | |
| 95 const PP_DecryptedBlockInfo* block_info); | |
| 96 void DecoderInitializeDone(PP_DecryptorStreamType decoder_type, | |
| 97 uint32_t request_id, | |
| 98 PP_Bool success); | |
| 99 void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type, | |
| 100 uint32_t request_id); | |
| 101 void DecoderResetDone(PP_DecryptorStreamType decoder_type, | |
| 102 uint32_t request_id); | |
| 103 void DeliverFrame(PP_Resource decrypted_frame, | |
| 104 const PP_DecryptedFrameInfo* frame_info); | |
| 105 void DeliverSamples(PP_Resource audio_frames, | |
| 106 const PP_DecryptedBlockInfo* block_info); | |
| 107 | |
| 108 private: | |
| 109 // Cancels the pending decrypt-and-decode callback for |stream_type|. | |
| 110 void CancelDecode(media::Decryptor::StreamType stream_type); | |
| 111 | |
| 112 // Fills |resource| with a PPB_Buffer_Impl and copies the data from | |
| 113 // |encrypted_buffer| into the buffer resource. This method reuses | |
| 114 // |audio_input_resource_| and |video_input_resource_| to reduce the latency | |
| 115 // in requesting new PPB_Buffer_Impl resources. The caller must make sure that | |
| 116 // |audio_input_resource_| or |video_input_resource_| is available before | |
| 117 // calling this method. | |
| 118 // | |
| 119 // An end of stream |encrypted_buffer| is represented as a null |resource|. | |
| 120 // | |
| 121 // Returns true upon success and false if any error happened. | |
| 122 bool MakeMediaBufferResource( | |
| 123 media::Decryptor::StreamType stream_type, | |
| 124 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | |
| 125 scoped_refptr<PPB_Buffer_Impl>* resource); | |
| 126 | |
| 127 void FreeBuffer(uint32_t buffer_id); | |
| 128 | |
| 129 void SetBufferToFreeInTrackingInfo(PP_DecryptTrackingInfo* tracking_info); | |
| 130 | |
| 131 // Deserializes audio data stored in |audio_frames| into individual audio | |
| 132 // buffers in |frames|. Returns true upon success. | |
| 133 bool DeserializeAudioFrames(PP_Resource audio_frames, | |
| 134 size_t data_size, | |
| 135 media::Decryptor::AudioBuffers* frames); | |
| 136 | |
| 137 const PP_Instance pp_instance_; | |
| 138 const PPP_ContentDecryptor_Private* const plugin_decryption_interface_; | |
| 139 | |
| 140 // TODO(ddorwin): Remove after updating the Pepper API to not use key system. | |
| 141 std::string key_system_; | |
| 142 | |
| 143 // Callbacks for firing key events. | |
| 144 media::KeyAddedCB key_added_cb_; | |
| 145 media::KeyErrorCB key_error_cb_; | |
| 146 media::KeyMessageCB key_message_cb_; | |
| 147 | |
| 148 gfx::Size natural_size_; | |
| 149 | |
| 150 // Request ID for tracking pending content decryption callbacks. | |
| 151 // Note that zero indicates an invalid request ID. | |
| 152 // TODO(xhwang): Add completion callbacks for Reset/Stop and remove the use | |
| 153 // of request IDs. | |
| 154 uint32_t next_decryption_request_id_; | |
| 155 | |
| 156 uint32_t pending_audio_decrypt_request_id_; | |
| 157 media::Decryptor::DecryptCB pending_audio_decrypt_cb_; | |
| 158 | |
| 159 uint32_t pending_video_decrypt_request_id_; | |
| 160 media::Decryptor::DecryptCB pending_video_decrypt_cb_; | |
| 161 | |
| 162 uint32_t pending_audio_decoder_init_request_id_; | |
| 163 media::Decryptor::DecoderInitCB pending_audio_decoder_init_cb_; | |
| 164 | |
| 165 uint32_t pending_video_decoder_init_request_id_; | |
| 166 media::Decryptor::DecoderInitCB pending_video_decoder_init_cb_; | |
| 167 | |
| 168 uint32_t pending_audio_decode_request_id_; | |
| 169 media::Decryptor::AudioDecodeCB pending_audio_decode_cb_; | |
| 170 | |
| 171 uint32_t pending_video_decode_request_id_; | |
| 172 media::Decryptor::VideoDecodeCB pending_video_decode_cb_; | |
| 173 | |
| 174 // Cached audio and video input buffers. See MakeMediaBufferResource. | |
| 175 scoped_refptr<PPB_Buffer_Impl> audio_input_resource_; | |
| 176 scoped_refptr<PPB_Buffer_Impl> video_input_resource_; | |
| 177 | |
| 178 std::queue<uint32_t> free_buffers_; | |
| 179 | |
| 180 base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_; | |
| 181 base::WeakPtr<ContentDecryptorDelegate> weak_this_; | |
| 182 | |
| 183 // Keep track of audio parameters. | |
| 184 media::SampleFormat audio_sample_format_; | |
| 185 int audio_samples_per_second_; | |
| 186 int audio_channel_count_; | |
| 187 int audio_bytes_per_frame_; | |
| 188 | |
| 189 DISALLOW_COPY_AND_ASSIGN(ContentDecryptorDelegate); | |
| 190 }; | |
| 191 | |
| 192 } // namespace ppapi | |
| 193 } // namespace webkit | |
| 194 | |
| 195 #endif // WEBKIT_PLUGINS_PPAPI_CONTENT_DECRYPTOR_DELEGATE_H_ | |
| OLD | NEW |