| OLD | NEW |
| 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 WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 5 #ifndef MEDIA_CDM_PPAPI_CLEAR_KEY_CDM_H_ |
| 6 #define WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 6 #define MEDIA_CDM_PPAPI_CLEAR_KEY_CDM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "media/crypto/aes_decryptor.h" | 16 #include "media/cdm/aes_decryptor.h" |
| 17 #include "webkit/renderer/media/crypto/ppapi/cdm/content_decryption_module.h" | 17 #include "media/cdm/ppapi/api/content_decryption_module.h" |
| 18 | 18 |
| 19 // Enable this to use the fake decoder for testing. | 19 // Enable this to use the fake decoder for testing. |
| 20 // TODO(tomfinegan): Move fake audio decoder into a separate class. | 20 // TODO(tomfinegan): Move fake audio decoder into a separate class. |
| 21 #if 0 | 21 #if 0 |
| 22 #define CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 22 #define CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 class CdmVideoDecoder; |
| 26 class DecoderBuffer; | 27 class DecoderBuffer; |
| 27 } | |
| 28 | |
| 29 namespace webkit_media { | |
| 30 | |
| 31 class CdmVideoDecoder; | |
| 32 class FFmpegCdmAudioDecoder; | 28 class FFmpegCdmAudioDecoder; |
| 33 | 29 |
| 34 // Clear key implementation of the cdm::ContentDecryptionModule interface. | 30 // Clear key implementation of the cdm::ContentDecryptionModule interface. |
| 35 class ClearKeyCdm : public cdm::ContentDecryptionModule { | 31 class ClearKeyCdm : public cdm::ContentDecryptionModule { |
| 36 public: | 32 public: |
| 37 explicit ClearKeyCdm(cdm::Host* host); | 33 explicit ClearKeyCdm(cdm::Host* host); |
| 38 virtual ~ClearKeyCdm(); | 34 virtual ~ClearKeyCdm(); |
| 39 | 35 |
| 40 // ContentDecryptionModule implementation. | 36 // ContentDecryptionModule implementation. |
| 41 virtual cdm::Status GenerateKeyRequest( | 37 virtual cdm::Status GenerateKeyRequest( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 Status status() { return status_; } | 76 Status status() { return status_; } |
| 81 const std::string& session_id() { return session_id_; } | 77 const std::string& session_id() { return session_id_; } |
| 82 const std::vector<uint8>& key_message() { return key_message_; } | 78 const std::vector<uint8>& key_message() { return key_message_; } |
| 83 const std::string& default_url() { return default_url_; } | 79 const std::string& default_url() { return default_url_; } |
| 84 | 80 |
| 85 // Resets the Client to a clean state. | 81 // Resets the Client to a clean state. |
| 86 void Reset(); | 82 void Reset(); |
| 87 | 83 |
| 88 void KeyAdded(const std::string& session_id); | 84 void KeyAdded(const std::string& session_id); |
| 89 void KeyError(const std::string& session_id, | 85 void KeyError(const std::string& session_id, |
| 90 media::MediaKeys::KeyError error_code, | 86 MediaKeys::KeyError error_code, |
| 91 int system_code); | 87 int system_code); |
| 92 void KeyMessage(const std::string& session_id, | 88 void KeyMessage(const std::string& session_id, |
| 93 const std::vector<uint8>& message, | 89 const std::vector<uint8>& message, |
| 94 const std::string& default_url); | 90 const std::string& default_url); |
| 95 | 91 |
| 96 private: | 92 private: |
| 97 Status status_; | 93 Status status_; |
| 98 std::string session_id_; | 94 std::string session_id_; |
| 99 std::vector<uint8> key_message_; | 95 std::vector<uint8> key_message_; |
| 100 std::string default_url_; | 96 std::string default_url_; |
| 101 }; | 97 }; |
| 102 | 98 |
| 103 // Prepares next heartbeat message and sets a timer for it. | 99 // Prepares next heartbeat message and sets a timer for it. |
| 104 void ScheduleNextHeartBeat(); | 100 void ScheduleNextHeartBeat(); |
| 105 | 101 |
| 106 // Decrypts the |encrypted_buffer| and puts the result in |decrypted_buffer|. | 102 // Decrypts the |encrypted_buffer| and puts the result in |decrypted_buffer|. |
| 107 // Returns cdm::kSuccess if decryption succeeded. The decrypted result is | 103 // Returns cdm::kSuccess if decryption succeeded. The decrypted result is |
| 108 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the | 104 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the |
| 109 // |decrypted_buffer| is set to an empty (EOS) buffer. | 105 // |decrypted_buffer| is set to an empty (EOS) buffer. |
| 110 // Returns cdm::kNoKey if no decryption key was available. In this case | 106 // Returns cdm::kNoKey if no decryption key was available. In this case |
| 111 // |decrypted_buffer| should be ignored by the caller. | 107 // |decrypted_buffer| should be ignored by the caller. |
| 112 // Returns cdm::kDecryptError if any decryption error occurred. In this case | 108 // Returns cdm::kDecryptError if any decryption error occurred. In this case |
| 113 // |decrypted_buffer| should be ignored by the caller. | 109 // |decrypted_buffer| should be ignored by the caller. |
| 114 cdm::Status DecryptToMediaDecoderBuffer( | 110 cdm::Status DecryptToMediaDecoderBuffer( |
| 115 const cdm::InputBuffer& encrypted_buffer, | 111 const cdm::InputBuffer& encrypted_buffer, |
| 116 scoped_refptr<media::DecoderBuffer>* decrypted_buffer); | 112 scoped_refptr<DecoderBuffer>* decrypted_buffer); |
| 117 | 113 |
| 118 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 114 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
| 119 int64 CurrentTimeStampInMicroseconds() const; | 115 int64 CurrentTimeStampInMicroseconds() const; |
| 120 | 116 |
| 121 // Generates fake video frames with |duration_in_microseconds|. | 117 // Generates fake video frames with |duration_in_microseconds|. |
| 122 // Returns the number of samples generated in the |audio_frames|. | 118 // Returns the number of samples generated in the |audio_frames|. |
| 123 int GenerateFakeAudioFramesFromDuration(int64 duration_in_microseconds, | 119 int GenerateFakeAudioFramesFromDuration(int64 duration_in_microseconds, |
| 124 cdm::AudioFrames* audio_frames) const; | 120 cdm::AudioFrames* audio_frames) const; |
| 125 | 121 |
| 126 // Generates fake video frames given |input_timestamp|. | 122 // Generates fake video frames given |input_timestamp|. |
| 127 // Returns cdm::kSuccess if any audio frame is successfully generated. | 123 // Returns cdm::kSuccess if any audio frame is successfully generated. |
| 128 cdm::Status GenerateFakeAudioFrames(int64 timestamp_in_microseconds, | 124 cdm::Status GenerateFakeAudioFrames(int64 timestamp_in_microseconds, |
| 129 cdm::AudioFrames* audio_frames); | 125 cdm::AudioFrames* audio_frames); |
| 130 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 126 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
| 131 | 127 |
| 132 Client client_; | 128 Client client_; |
| 133 media::AesDecryptor decryptor_; | 129 AesDecryptor decryptor_; |
| 134 | 130 |
| 135 // Protects the |client_| from being accessed by the |decryptor_| | 131 // Protects the |client_| from being accessed by the |decryptor_| |
| 136 // simultaneously. | 132 // simultaneously. |
| 137 base::Lock client_lock_; | 133 base::Lock client_lock_; |
| 138 | 134 |
| 139 cdm::Host* host_; | 135 cdm::Host* host_; |
| 140 | 136 |
| 141 std::string heartbeat_session_id_; | 137 std::string heartbeat_session_id_; |
| 142 std::string next_heartbeat_message_; | 138 std::string next_heartbeat_message_; |
| 143 | 139 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 158 | 154 |
| 159 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 155 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
| 160 scoped_ptr<FFmpegCdmAudioDecoder> audio_decoder_; | 156 scoped_ptr<FFmpegCdmAudioDecoder> audio_decoder_; |
| 161 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 157 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
| 162 | 158 |
| 163 scoped_ptr<CdmVideoDecoder> video_decoder_; | 159 scoped_ptr<CdmVideoDecoder> video_decoder_; |
| 164 | 160 |
| 165 DISALLOW_COPY_AND_ASSIGN(ClearKeyCdm); | 161 DISALLOW_COPY_AND_ASSIGN(ClearKeyCdm); |
| 166 }; | 162 }; |
| 167 | 163 |
| 168 } // namespace webkit_media | 164 } // namespace media |
| 169 | 165 |
| 170 #endif // WEBKIT_RENDERER_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 166 #endif // MEDIA_CDM_PPAPI_CLEAR_KEY_CDM_H_ |
| OLD | NEW |