| 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 WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "media/base/channel_layout.h" |
| 15 #include "media/base/decryptor_client.h" | 16 #include "media/base/decryptor_client.h" |
| 16 #include "media/crypto/aes_decryptor.h" | 17 #include "media/crypto/aes_decryptor.h" |
| 17 #include "webkit/media/crypto/ppapi/content_decryption_module.h" | 18 #include "webkit/media/crypto/ppapi/content_decryption_module.h" |
| 18 | 19 |
| 19 // Enable this to use the fake decoder for testing. | 20 // Enable this to use the fake decoder for testing. |
| 20 // #define CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 21 #if 0 |
| 22 #define CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
| 23 #endif |
| 24 |
| 25 #if 0 |
| 26 #define CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 27 #endif |
| 21 | 28 |
| 22 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 29 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 23 #undef CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 30 #undef CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
| 24 #endif | 31 #endif |
| 25 | 32 |
| 26 namespace media { | 33 namespace media { |
| 27 class DecoderBuffer; | 34 class DecoderBuffer; |
| 28 } | 35 } |
| 29 | 36 |
| 30 namespace webkit_media { | 37 namespace webkit_media { |
| 31 | 38 |
| 39 class FFmpegCdmAudioDecoder; |
| 32 class FFmpegCdmVideoDecoder; | 40 class FFmpegCdmVideoDecoder; |
| 33 | 41 |
| 34 // Clear key implementation of the cdm::ContentDecryptionModule interface. | 42 // Clear key implementation of the cdm::ContentDecryptionModule interface. |
| 35 class ClearKeyCdm : public cdm::ContentDecryptionModule { | 43 class ClearKeyCdm : public cdm::ContentDecryptionModule { |
| 36 public: | 44 public: |
| 37 explicit ClearKeyCdm(cdm::Allocator* allocator, cdm::CdmHost*); | 45 explicit ClearKeyCdm(cdm::Allocator* allocator, cdm::CdmHost*); |
| 38 virtual ~ClearKeyCdm(); | 46 virtual ~ClearKeyCdm(); |
| 39 | 47 |
| 40 // ContentDecryptionModule implementation. | 48 // ContentDecryptionModule implementation. |
| 41 virtual cdm::Status GenerateKeyRequest( | 49 virtual cdm::Status GenerateKeyRequest( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE; | 65 const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE; |
| 58 virtual cdm::Status InitializeVideoDecoder( | 66 virtual cdm::Status InitializeVideoDecoder( |
| 59 const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE; | 67 const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE; |
| 60 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE; | 68 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE; |
| 61 virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE; | 69 virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE; |
| 62 virtual cdm::Status DecryptAndDecodeFrame( | 70 virtual cdm::Status DecryptAndDecodeFrame( |
| 63 const cdm::InputBuffer& encrypted_buffer, | 71 const cdm::InputBuffer& encrypted_buffer, |
| 64 cdm::VideoFrame* video_frame) OVERRIDE; | 72 cdm::VideoFrame* video_frame) OVERRIDE; |
| 65 virtual cdm::Status DecryptAndDecodeSamples( | 73 virtual cdm::Status DecryptAndDecodeSamples( |
| 66 const cdm::InputBuffer& encrypted_buffer, | 74 const cdm::InputBuffer& encrypted_buffer, |
| 67 cdm::Buffer* sample_buffer) OVERRIDE; | 75 cdm::AudioFrames* audio_frames) OVERRIDE; |
| 68 | 76 |
| 69 private: | 77 private: |
| 70 class Client : public media::DecryptorClient { | 78 class Client : public media::DecryptorClient { |
| 71 public: | 79 public: |
| 72 enum Status { | 80 enum Status { |
| 73 kKeyAdded, | 81 kKeyAdded, |
| 74 kKeyError, | 82 kKeyError, |
| 75 kKeyMessage, | 83 kKeyMessage, |
| 76 kNeedKey | 84 kNeedKey |
| 77 }; | 85 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the | 126 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the |
| 119 // |decrypted_buffer| is set to an empty (EOS) buffer. | 127 // |decrypted_buffer| is set to an empty (EOS) buffer. |
| 120 // Returns cdm::kNoKey if no decryption key was available. In this case | 128 // Returns cdm::kNoKey if no decryption key was available. In this case |
| 121 // |decrypted_buffer| should be ignored by the caller. | 129 // |decrypted_buffer| should be ignored by the caller. |
| 122 // Returns cdm::kDecryptError if any decryption error occurred. In this case | 130 // Returns cdm::kDecryptError if any decryption error occurred. In this case |
| 123 // |decrypted_buffer| should be ignored by the caller. | 131 // |decrypted_buffer| should be ignored by the caller. |
| 124 cdm::Status DecryptToMediaDecoderBuffer( | 132 cdm::Status DecryptToMediaDecoderBuffer( |
| 125 const cdm::InputBuffer& encrypted_buffer, | 133 const cdm::InputBuffer& encrypted_buffer, |
| 126 scoped_refptr<media::DecoderBuffer>* decrypted_buffer); | 134 scoped_refptr<media::DecoderBuffer>* decrypted_buffer); |
| 127 | 135 |
| 136 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
| 137 void GenerateFakeAudioFrames(cdm::AudioFrames* audio_frames); |
| 138 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 139 |
| 128 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 140 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 129 void GenerateFakeVideoFrame(base::TimeDelta timestamp, | 141 void GenerateFakeVideoFrame(base::TimeDelta timestamp, |
| 130 cdm::VideoFrame* video_frame); | 142 cdm::VideoFrame* video_frame); |
| 131 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 143 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 132 | 144 |
| 133 Client client_; | 145 Client client_; |
| 134 media::AesDecryptor decryptor_; | 146 media::AesDecryptor decryptor_; |
| 135 | 147 |
| 136 // Protects the |client_| from being accessed by the |decryptor_| | 148 // Protects the |client_| from being accessed by the |decryptor_| |
| 137 // simultaneously. | 149 // simultaneously. |
| 138 base::Lock client_lock_; | 150 base::Lock client_lock_; |
| 139 | 151 |
| 140 cdm::Allocator* const allocator_; | 152 cdm::Allocator* const allocator_; |
| 141 | 153 |
| 154 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
| 155 int channel_count_; |
| 156 int bits_per_channel_; |
| 157 int samples_per_second_; |
| 158 base::TimeDelta last_timestamp_; |
| 159 base::TimeDelta last_duration_; |
| 160 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
| 161 |
| 142 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 162 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
| 163 scoped_ptr<FFmpegCdmAudioDecoder> audio_decoder_; |
| 143 scoped_ptr<FFmpegCdmVideoDecoder> video_decoder_; | 164 scoped_ptr<FFmpegCdmVideoDecoder> video_decoder_; |
| 144 #endif | 165 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
| 145 | 166 |
| 146 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 167 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 147 cdm::Size video_size_; | 168 cdm::Size video_size_; |
| 148 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 169 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 149 }; | 170 }; |
| 150 | 171 |
| 151 } // namespace webkit_media | 172 } // namespace webkit_media |
| 152 | 173 |
| 153 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ | 174 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_CLEAR_KEY_CDM_H_ |
| OLD | NEW |