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 MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ | 5 #ifndef MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ |
6 #define MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ | 6 #define MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 class DecoderBuffer; | 28 class DecoderBuffer; |
29 class FFmpegCdmAudioDecoder; | 29 class FFmpegCdmAudioDecoder; |
30 | 30 |
31 // Clear key implementation of the cdm::ContentDecryptionModule interface. | 31 // Clear key implementation of the cdm::ContentDecryptionModule interface. |
32 class ClearKeyCdm : public ClearKeyCdmInterface { | 32 class ClearKeyCdm : public ClearKeyCdmInterface { |
33 public: | 33 public: |
34 ClearKeyCdm(Host* host, const std::string& key_system); | 34 ClearKeyCdm(Host* host, const std::string& key_system); |
35 virtual ~ClearKeyCdm(); | 35 virtual ~ClearKeyCdm(); |
36 | 36 |
37 // ContentDecryptionModule implementation. | 37 // ContentDecryptionModule implementation. |
38 virtual void CreateSession( | 38 virtual void CreateSession(uint32 promise_id, |
39 uint32 session_id, | 39 const char* init_data_type, |
40 const char* type, uint32 type_size, | 40 uint32 init_data_type_size, |
41 const uint8* init_data, uint32 init_data_size) OVERRIDE; | 41 const uint8* init_data, |
42 virtual void LoadSession( | 42 uint32 init_data_size, |
43 uint32_t session_id, | 43 cdm::SessionType session_type) OVERRIDE; |
44 const char* web_session_id, uint32_t web_session_id_length) OVERRIDE; | 44 virtual void LoadSession(uint32 promise_id, |
45 virtual void UpdateSession( | 45 const char* web_session_id, |
46 uint32 session_id, | 46 uint32_t web_session_id_length) OVERRIDE; |
47 const uint8* response, uint32 response_size) OVERRIDE; | 47 virtual void UpdateSession(uint32 promise_id, |
48 virtual void ReleaseSession(uint32 session_id) OVERRIDE; | 48 const char* web_session_id, |
| 49 uint32_t web_session_id_length, |
| 50 const uint8* response, |
| 51 uint32 response_size) OVERRIDE; |
| 52 virtual void ReleaseSession(uint32 promise_id, |
| 53 const char* web_session_id, |
| 54 uint32_t web_session_id_length) OVERRIDE; |
49 virtual void TimerExpired(void* context) OVERRIDE; | 55 virtual void TimerExpired(void* context) OVERRIDE; |
50 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, | 56 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, |
51 cdm::DecryptedBlock* decrypted_block) OVERRIDE; | 57 cdm::DecryptedBlock* decrypted_block) OVERRIDE; |
52 virtual cdm::Status InitializeAudioDecoder( | 58 virtual cdm::Status InitializeAudioDecoder( |
53 const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE; | 59 const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE; |
54 virtual cdm::Status InitializeVideoDecoder( | 60 virtual cdm::Status InitializeVideoDecoder( |
55 const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE; | 61 const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE; |
56 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE; | 62 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE; |
57 virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE; | 63 virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE; |
58 virtual cdm::Status DecryptAndDecodeFrame( | 64 virtual cdm::Status DecryptAndDecodeFrame( |
59 const cdm::InputBuffer& encrypted_buffer, | 65 const cdm::InputBuffer& encrypted_buffer, |
60 cdm::VideoFrame* video_frame) OVERRIDE; | 66 cdm::VideoFrame* video_frame) OVERRIDE; |
61 virtual cdm::Status DecryptAndDecodeSamples( | 67 virtual cdm::Status DecryptAndDecodeSamples( |
62 const cdm::InputBuffer& encrypted_buffer, | 68 const cdm::InputBuffer& encrypted_buffer, |
63 cdm::AudioFrames* audio_frames) OVERRIDE; | 69 cdm::AudioFrames* audio_frames) OVERRIDE; |
64 virtual void Destroy() OVERRIDE; | 70 virtual void Destroy() OVERRIDE; |
65 virtual void OnPlatformChallengeResponse( | 71 virtual void OnPlatformChallengeResponse( |
66 const cdm::PlatformChallengeResponse& response) OVERRIDE; | 72 const cdm::PlatformChallengeResponse& response) OVERRIDE; |
67 virtual void OnQueryOutputProtectionStatus( | 73 virtual void OnQueryOutputProtectionStatus( |
68 uint32_t link_mask, uint32_t output_protection_mask) OVERRIDE; | 74 uint32_t link_mask, uint32_t output_protection_mask) OVERRIDE; |
69 | 75 |
70 private: | 76 private: |
71 // Emulates a session stored for |session_id_for_emulated_loadsession_|. This | 77 // Emulates a session stored for |session_id_for_emulated_loadsession_|. This |
72 // is necessary since aes_decryptor.cc does not support storing sessions. | 78 // is necessary since aes_decryptor.cc does not support storing sessions. |
73 void LoadLoadableSession(); | 79 void LoadLoadableSession(); |
74 | 80 |
75 // ContentDecryptionModule callbacks. | 81 // ContentDecryptionModule callbacks. |
76 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 82 void OnSessionMessage(const std::string& web_session_id, |
77 void OnSessionMessage(uint32 session_id, | |
78 const std::vector<uint8>& message, | 83 const std::vector<uint8>& message, |
79 const std::string& destination_url); | 84 const std::string& destination_url); |
80 void OnSessionReady(uint32 session_id); | 85 |
81 void OnSessionClosed(uint32 session_id); | 86 // Handle the success of a promise. These methods are responsible to calling |
82 void OnSessionError(uint32 session_id, | 87 // |host_| to acknowledge the promise. |
83 MediaKeys::KeyError error_code, | 88 void OnSessionCreated(uint32 promise_id, const std::string& web_session_id); |
84 uint32 system_code); | 89 void OnSessionLoaded(uint32 promise_id, const std::string& web_session_id); |
| 90 void OnSessionReady(uint32 promise_id, const std::string& web_session_id); |
| 91 void OnSessionClosed(uint32 promise_id, const std::string& web_session_id); |
| 92 void OnSessionError(uint32 promise_id, |
| 93 const std::string& error_name, |
| 94 uint32 system_code, |
| 95 const std::string& error_message); |
85 | 96 |
86 // Prepares next heartbeat message and sets a timer for it. | 97 // Prepares next heartbeat message and sets a timer for it. |
87 void ScheduleNextHeartBeat(); | 98 void ScheduleNextHeartBeat(); |
88 | 99 |
89 // Decrypts the |encrypted_buffer| and puts the result in |decrypted_buffer|. | 100 // Decrypts the |encrypted_buffer| and puts the result in |decrypted_buffer|. |
90 // Returns cdm::kSuccess if decryption succeeded. The decrypted result is | 101 // Returns cdm::kSuccess if decryption succeeded. The decrypted result is |
91 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the | 102 // put in |decrypted_buffer|. If |encrypted_buffer| is empty, the |
92 // |decrypted_buffer| is set to an empty (EOS) buffer. | 103 // |decrypted_buffer| is set to an empty (EOS) buffer. |
93 // Returns cdm::kNoKey if no decryption key was available. In this case | 104 // Returns cdm::kNoKey if no decryption key was available. In this case |
94 // |decrypted_buffer| should be ignored by the caller. | 105 // |decrypted_buffer| should be ignored by the caller. |
(...skipping 15 matching lines...) Expand all Loading... |
110 // Returns cdm::kSuccess if any audio frame is successfully generated. | 121 // Returns cdm::kSuccess if any audio frame is successfully generated. |
111 cdm::Status GenerateFakeAudioFrames(int64 timestamp_in_microseconds, | 122 cdm::Status GenerateFakeAudioFrames(int64 timestamp_in_microseconds, |
112 cdm::AudioFrames* audio_frames); | 123 cdm::AudioFrames* audio_frames); |
113 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 124 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
114 | 125 |
115 void StartFileIOTest(); | 126 void StartFileIOTest(); |
116 | 127 |
117 // Callback for CDM File IO test. | 128 // Callback for CDM File IO test. |
118 void OnFileIOTestComplete(bool success); | 129 void OnFileIOTestComplete(bool success); |
119 | 130 |
| 131 // Keep track of the last session created. |
| 132 void SetSessionId(const std::string& web_session_id); |
| 133 |
120 AesDecryptor decryptor_; | 134 AesDecryptor decryptor_; |
121 | 135 |
122 ClearKeyCdmHost* host_; | 136 ClearKeyCdmHost* host_; |
123 | 137 |
124 const std::string key_system_; | 138 const std::string key_system_; |
125 | 139 |
126 uint32 last_session_id_; | 140 std::string last_session_id_; |
127 std::string next_heartbeat_message_; | 141 std::string next_heartbeat_message_; |
128 | 142 |
129 // TODO(xhwang): Extract testing code from main implementation. | 143 // TODO(xhwang): Extract testing code from main implementation. |
130 // See http://crbug.com/341751 | 144 // See http://crbug.com/341751 |
131 uint32 session_id_for_emulated_loadsession_; | 145 std::string session_id_for_emulated_loadsession_; |
| 146 uint32_t promise_id_for_emulated_loadsession_; |
132 | 147 |
133 // Timer delay in milliseconds for the next host_->SetTimer() call. | 148 // Timer delay in milliseconds for the next host_->SetTimer() call. |
134 int64 timer_delay_ms_; | 149 int64 timer_delay_ms_; |
135 | 150 |
136 // Indicates whether a heartbeat timer has been set to prevent multiple timers | 151 // Indicates whether a heartbeat timer has been set to prevent multiple timers |
137 // from running. | 152 // from running. |
138 bool heartbeat_timer_set_; | 153 bool heartbeat_timer_set_; |
139 | 154 |
140 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 155 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
141 int channel_count_; | 156 int channel_count_; |
(...skipping 10 matching lines...) Expand all Loading... |
152 scoped_ptr<CdmVideoDecoder> video_decoder_; | 167 scoped_ptr<CdmVideoDecoder> video_decoder_; |
153 | 168 |
154 scoped_ptr<FileIOTestRunner> file_io_test_runner_; | 169 scoped_ptr<FileIOTestRunner> file_io_test_runner_; |
155 | 170 |
156 DISALLOW_COPY_AND_ASSIGN(ClearKeyCdm); | 171 DISALLOW_COPY_AND_ASSIGN(ClearKeyCdm); |
157 }; | 172 }; |
158 | 173 |
159 } // namespace media | 174 } // namespace media |
160 | 175 |
161 #endif // MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ | 176 #endif // MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_CLEAR_KEY_CDM_H_ |
OLD | NEW |