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 CDM_CONTENT_DECRYPTION_MODULE_H_ | 5 #ifndef CDM_CONTENT_DECRYPTION_MODULE_H_ |
6 #define CDM_CONTENT_DECRYPTION_MODULE_H_ | 6 #define CDM_CONTENT_DECRYPTION_MODULE_H_ |
7 | 7 |
8 #if defined(_MSC_VER) | 8 #if defined(_MSC_VER) |
9 typedef unsigned char uint8_t; | 9 typedef unsigned char uint8_t; |
10 typedef unsigned int uint32_t; | 10 typedef unsigned int uint32_t; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // TODO(xhwang): Add checks to make sure these structs have fixed layout. | 153 // TODO(xhwang): Add checks to make sure these structs have fixed layout. |
154 struct SubsampleEntry { | 154 struct SubsampleEntry { |
155 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) | 155 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes) |
156 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} | 156 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {} |
157 | 157 |
158 uint32_t clear_bytes; | 158 uint32_t clear_bytes; |
159 uint32_t cipher_bytes; | 159 uint32_t cipher_bytes; |
160 }; | 160 }; |
161 | 161 |
162 // Represents an input buffer to be decrypted (and possibly decoded). It does | 162 // Represents an input buffer to be decrypted (and possibly decoded). It does |
163 // own any pointers in this struct. | 163 // not own any pointers in this struct. |
164 struct InputBuffer { | 164 // Deprecated: New CDM implementations should use InputBuffer. |
165 InputBuffer() | 165 struct InputBuffer_1 { |
| 166 InputBuffer_1() |
166 : data(NULL), | 167 : data(NULL), |
167 data_size(0), | 168 data_size(0), |
168 data_offset(0), | 169 data_offset(0), |
169 key_id(NULL), | 170 key_id(NULL), |
170 key_id_size(0), | 171 key_id_size(0), |
171 iv(NULL), | 172 iv(NULL), |
172 iv_size(0), | 173 iv_size(0), |
173 subsamples(NULL), | 174 subsamples(NULL), |
174 num_subsamples(0), | 175 num_subsamples(0), |
175 timestamp(0) {} | 176 timestamp(0) {} |
176 | 177 |
177 const uint8_t* data; // Pointer to the beginning of the input data. | 178 const uint8_t* data; // Pointer to the beginning of the input data. |
178 uint32_t data_size; // Size (in bytes) of |data|. | 179 uint32_t data_size; // Size (in bytes) of |data|. |
179 | 180 |
180 uint32_t data_offset; // Number of bytes to be discarded before decryption. | 181 uint32_t data_offset; // Number of bytes to be discarded before decryption. |
181 | 182 |
182 const uint8_t* key_id; // Key ID to identify the decryption key. | 183 const uint8_t* key_id; // Key ID to identify the decryption key. |
183 uint32_t key_id_size; // Size (in bytes) of |key_id|. | 184 uint32_t key_id_size; // Size (in bytes) of |key_id|. |
184 | 185 |
185 const uint8_t* iv; // Initialization vector. | 186 const uint8_t* iv; // Initialization vector. |
186 uint32_t iv_size; // Size (in bytes) of |iv|. | 187 uint32_t iv_size; // Size (in bytes) of |iv|. |
187 | 188 |
188 const struct SubsampleEntry* subsamples; | 189 const struct SubsampleEntry* subsamples; |
189 uint32_t num_subsamples; // Number of subsamples in |subsamples|. | 190 uint32_t num_subsamples; // Number of subsamples in |subsamples|. |
190 | 191 |
191 int64_t timestamp; // Presentation timestamp in microseconds. | 192 int64_t timestamp; // Presentation timestamp in microseconds. |
192 }; | 193 }; |
193 | 194 |
| 195 // Represents an input buffer to be decrypted (and possibly decoded). It does |
| 196 // not own any pointers in this struct. |
| 197 struct InputBuffer_2 { |
| 198 InputBuffer_2() |
| 199 : data(NULL), |
| 200 data_size(0), |
| 201 key_id(NULL), |
| 202 key_id_size(0), |
| 203 iv(NULL), |
| 204 iv_size(0), |
| 205 subsamples(NULL), |
| 206 num_subsamples(0), |
| 207 timestamp(0) {} |
| 208 |
| 209 const uint8_t* data; // Pointer to the beginning of the input data. |
| 210 uint32_t data_size; // Size (in bytes) of |data|. |
| 211 |
| 212 const uint8_t* key_id; // Key ID to identify the decryption key. |
| 213 uint32_t key_id_size; // Size (in bytes) of |key_id|. |
| 214 |
| 215 const uint8_t* iv; // Initialization vector. |
| 216 uint32_t iv_size; // Size (in bytes) of |iv|. |
| 217 |
| 218 const struct SubsampleEntry* subsamples; |
| 219 uint32_t num_subsamples; // Number of subsamples in |subsamples|. |
| 220 |
| 221 int64_t timestamp; // Presentation timestamp in microseconds. |
| 222 }; |
| 223 |
| 224 typedef InputBuffer_2 InputBuffer; |
| 225 |
194 struct AudioDecoderConfig { | 226 struct AudioDecoderConfig { |
195 enum AudioCodec { | 227 enum AudioCodec { |
196 kUnknownAudioCodec = 0, | 228 kUnknownAudioCodec = 0, |
197 kCodecVorbis, | 229 kCodecVorbis, |
198 kCodecAac | 230 kCodecAac |
199 }; | 231 }; |
200 | 232 |
201 AudioDecoderConfig() | 233 AudioDecoderConfig() |
202 : codec(kUnknownAudioCodec), | 234 : codec(kUnknownAudioCodec), |
203 channel_count(0), | 235 channel_count(0), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // Decrypts the |encrypted_buffer|. | 491 // Decrypts the |encrypted_buffer|. |
460 // | 492 // |
461 // Returns kSuccess if decryption succeeded, in which case the callee | 493 // Returns kSuccess if decryption succeeded, in which case the callee |
462 // should have filled the |decrypted_buffer| and passed the ownership of | 494 // should have filled the |decrypted_buffer| and passed the ownership of |
463 // |data| in |decrypted_buffer| to the caller. | 495 // |data| in |decrypted_buffer| to the caller. |
464 // Returns kNoKey if the CDM did not have the necessary decryption key | 496 // Returns kNoKey if the CDM did not have the necessary decryption key |
465 // to decrypt. | 497 // to decrypt. |
466 // Returns kDecryptError if any other error happened. | 498 // Returns kDecryptError if any other error happened. |
467 // If the return value is not kSuccess, |decrypted_buffer| should be ignored | 499 // If the return value is not kSuccess, |decrypted_buffer| should be ignored |
468 // by the caller. | 500 // by the caller. |
469 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 501 virtual Status Decrypt(const InputBuffer_1& encrypted_buffer, |
470 DecryptedBlock* decrypted_buffer) = 0; | 502 DecryptedBlock* decrypted_buffer) = 0; |
471 | 503 |
472 // Initializes the CDM audio decoder with |audio_decoder_config|. This | 504 // Initializes the CDM audio decoder with |audio_decoder_config|. This |
473 // function must be called before DecryptAndDecodeSamples() is called. | 505 // function must be called before DecryptAndDecodeSamples() is called. |
474 // | 506 // |
475 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM | 507 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM |
476 // audio decoder is successfully initialized. | 508 // audio decoder is successfully initialized. |
477 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM | 509 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM |
478 // may still be able to do Decrypt(). | 510 // may still be able to do Decrypt(). |
479 // Returns kDeferredInitialization if the CDM is not ready to initialize the | 511 // Returns kDeferredInitialization if the CDM is not ready to initialize the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // the callee will have filled the |video_frame| and passed the ownership of | 546 // the callee will have filled the |video_frame| and passed the ownership of |
515 // |frame_buffer| in |video_frame| to the caller. | 547 // |frame_buffer| in |video_frame| to the caller. |
516 // Returns kNoKey if the CDM did not have the necessary decryption key | 548 // Returns kNoKey if the CDM did not have the necessary decryption key |
517 // to decrypt. | 549 // to decrypt. |
518 // Returns kNeedMoreData if more data was needed by the decoder to generate | 550 // Returns kNeedMoreData if more data was needed by the decoder to generate |
519 // a decoded frame (e.g. during initialization and end-of-stream). | 551 // a decoded frame (e.g. during initialization and end-of-stream). |
520 // Returns kDecryptError if any decryption error happened. | 552 // Returns kDecryptError if any decryption error happened. |
521 // Returns kDecodeError if any decoding error happened. | 553 // Returns kDecodeError if any decoding error happened. |
522 // If the return value is not kSuccess, |video_frame| should be ignored by | 554 // If the return value is not kSuccess, |video_frame| should be ignored by |
523 // the caller. | 555 // the caller. |
524 virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer, | 556 virtual Status DecryptAndDecodeFrame(const InputBuffer_1& encrypted_buffer, |
525 VideoFrame* video_frame) = 0; | 557 VideoFrame* video_frame) = 0; |
526 | 558 |
527 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into | 559 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into |
528 // |audio_frames|. Upon end-of-stream, the caller should call this function | 560 // |audio_frames|. Upon end-of-stream, the caller should call this function |
529 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty | 561 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty |
530 // |audio_frames| is produced. | 562 // |audio_frames| is produced. |
531 // | 563 // |
532 // Returns kSuccess if decryption and decoding both succeeded, in which case | 564 // Returns kSuccess if decryption and decoding both succeeded, in which case |
533 // the callee will have filled |audio_frames| and passed the ownership of | 565 // the callee will have filled |audio_frames| and passed the ownership of |
534 // |data| in |audio_frames| to the caller. | 566 // |data| in |audio_frames| to the caller. |
535 // Returns kNoKey if the CDM did not have the necessary decryption key | 567 // Returns kNoKey if the CDM did not have the necessary decryption key |
536 // to decrypt. | 568 // to decrypt. |
537 // Returns kNeedMoreData if more data was needed by the decoder to generate | 569 // Returns kNeedMoreData if more data was needed by the decoder to generate |
538 // audio samples (e.g. during initialization and end-of-stream). | 570 // audio samples (e.g. during initialization and end-of-stream). |
539 // Returns kDecryptError if any decryption error happened. | 571 // Returns kDecryptError if any decryption error happened. |
540 // Returns kDecodeError if any decoding error happened. | 572 // Returns kDecodeError if any decoding error happened. |
541 // If the return value is not kSuccess, |audio_frames| should be ignored by | 573 // If the return value is not kSuccess, |audio_frames| should be ignored by |
542 // the caller. | 574 // the caller. |
543 virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer, | 575 virtual Status DecryptAndDecodeSamples(const InputBuffer_1& encrypted_buffer, |
544 AudioFrames* audio_frames) = 0; | 576 AudioFrames* audio_frames) = 0; |
545 | 577 |
546 // Called by the host after a platform challenge was initiated via | 578 // Called by the host after a platform challenge was initiated via |
547 // Host::SendPlatformChallenge(). | 579 // Host::SendPlatformChallenge(). |
548 virtual void OnPlatformChallengeResponse( | 580 virtual void OnPlatformChallengeResponse( |
549 const PlatformChallengeResponse& response) = 0; | 581 const PlatformChallengeResponse& response) = 0; |
550 | 582 |
551 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The | 583 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The |
552 // |link_mask| is a bit mask of OutputLinkTypes. The |output_protection_mask| | 584 // |link_mask| is a bit mask of OutputLinkTypes. The |output_protection_mask| |
553 // is a bit mask of OutputProtectionMethods, indicating whether all | 585 // is a bit mask of OutputProtectionMethods, indicating whether all |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 // Decrypts the |encrypted_buffer|. | 655 // Decrypts the |encrypted_buffer|. |
624 // | 656 // |
625 // Returns kSuccess if decryption succeeded, in which case the callee | 657 // Returns kSuccess if decryption succeeded, in which case the callee |
626 // should have filled the |decrypted_buffer| and passed the ownership of | 658 // should have filled the |decrypted_buffer| and passed the ownership of |
627 // |data| in |decrypted_buffer| to the caller. | 659 // |data| in |decrypted_buffer| to the caller. |
628 // Returns kNoKey if the CDM did not have the necessary decryption key | 660 // Returns kNoKey if the CDM did not have the necessary decryption key |
629 // to decrypt. | 661 // to decrypt. |
630 // Returns kDecryptError if any other error happened. | 662 // Returns kDecryptError if any other error happened. |
631 // If the return value is not kSuccess, |decrypted_buffer| should be ignored | 663 // If the return value is not kSuccess, |decrypted_buffer| should be ignored |
632 // by the caller. | 664 // by the caller. |
633 virtual Status Decrypt(const InputBuffer& encrypted_buffer, | 665 virtual Status Decrypt(const InputBuffer_1& encrypted_buffer, |
634 DecryptedBlock* decrypted_buffer) = 0; | 666 DecryptedBlock* decrypted_buffer) = 0; |
635 | 667 |
636 // Initializes the CDM audio decoder with |audio_decoder_config|. This | 668 // Initializes the CDM audio decoder with |audio_decoder_config|. This |
637 // function must be called before DecryptAndDecodeSamples() is called. | 669 // function must be called before DecryptAndDecodeSamples() is called. |
638 // | 670 // |
639 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM | 671 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM |
640 // audio decoder is successfully initialized. | 672 // audio decoder is successfully initialized. |
641 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM | 673 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM |
642 // may still be able to do Decrypt(). | 674 // may still be able to do Decrypt(). |
643 // Returns kDeferredInitialization if the CDM is not ready to initialize the | 675 // Returns kDeferredInitialization if the CDM is not ready to initialize the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 // the callee will have filled the |video_frame| and passed the ownership of | 710 // the callee will have filled the |video_frame| and passed the ownership of |
679 // |frame_buffer| in |video_frame| to the caller. | 711 // |frame_buffer| in |video_frame| to the caller. |
680 // Returns kNoKey if the CDM did not have the necessary decryption key | 712 // Returns kNoKey if the CDM did not have the necessary decryption key |
681 // to decrypt. | 713 // to decrypt. |
682 // Returns kNeedMoreData if more data was needed by the decoder to generate | 714 // Returns kNeedMoreData if more data was needed by the decoder to generate |
683 // a decoded frame (e.g. during initialization and end-of-stream). | 715 // a decoded frame (e.g. during initialization and end-of-stream). |
684 // Returns kDecryptError if any decryption error happened. | 716 // Returns kDecryptError if any decryption error happened. |
685 // Returns kDecodeError if any decoding error happened. | 717 // Returns kDecodeError if any decoding error happened. |
686 // If the return value is not kSuccess, |video_frame| should be ignored by | 718 // If the return value is not kSuccess, |video_frame| should be ignored by |
687 // the caller. | 719 // the caller. |
688 virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer, | 720 virtual Status DecryptAndDecodeFrame(const InputBuffer_1& encrypted_buffer, |
689 VideoFrame* video_frame) = 0; | 721 VideoFrame* video_frame) = 0; |
690 | 722 |
691 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into | 723 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into |
692 // |audio_frames|. Upon end-of-stream, the caller should call this function | 724 // |audio_frames|. Upon end-of-stream, the caller should call this function |
693 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty | 725 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty |
694 // |audio_frames| is produced. | 726 // |audio_frames| is produced. |
695 // | 727 // |
696 // Returns kSuccess if decryption and decoding both succeeded, in which case | 728 // Returns kSuccess if decryption and decoding both succeeded, in which case |
697 // the callee will have filled |audio_frames| and passed the ownership of | 729 // the callee will have filled |audio_frames| and passed the ownership of |
698 // |data| in |audio_frames| to the caller. | 730 // |data| in |audio_frames| to the caller. |
699 // Returns kNoKey if the CDM did not have the necessary decryption key | 731 // Returns kNoKey if the CDM did not have the necessary decryption key |
700 // to decrypt. | 732 // to decrypt. |
701 // Returns kNeedMoreData if more data was needed by the decoder to generate | 733 // Returns kNeedMoreData if more data was needed by the decoder to generate |
702 // audio samples (e.g. during initialization and end-of-stream). | 734 // audio samples (e.g. during initialization and end-of-stream). |
703 // Returns kDecryptError if any decryption error happened. | 735 // Returns kDecryptError if any decryption error happened. |
704 // Returns kDecodeError if any decoding error happened. | 736 // Returns kDecodeError if any decoding error happened. |
705 // If the return value is not kSuccess, |audio_frames| should be ignored by | 737 // If the return value is not kSuccess, |audio_frames| should be ignored by |
706 // the caller. | 738 // the caller. |
707 virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer, | 739 virtual Status DecryptAndDecodeSamples(const InputBuffer_1& encrypted_buffer, |
708 AudioFrames* audio_frames) = 0; | 740 AudioFrames* audio_frames) = 0; |
709 | 741 |
710 // Called by the host after a platform challenge was initiated via | 742 // Called by the host after a platform challenge was initiated via |
711 // Host::SendPlatformChallenge(). | 743 // Host::SendPlatformChallenge(). |
712 virtual void OnPlatformChallengeResponse( | 744 virtual void OnPlatformChallengeResponse( |
713 const PlatformChallengeResponse& response) = 0; | 745 const PlatformChallengeResponse& response) = 0; |
714 | 746 |
715 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The | 747 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The |
716 // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask| | 748 // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask| |
717 // is a bit mask of OutputProtectionMethods. | 749 // is a bit mask of OutputProtectionMethods. |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 virtual AudioFormat Format() const = 0; | 1373 virtual AudioFormat Format() const = 0; |
1342 | 1374 |
1343 protected: | 1375 protected: |
1344 AudioFrames_2() {} | 1376 AudioFrames_2() {} |
1345 virtual ~AudioFrames_2() {} | 1377 virtual ~AudioFrames_2() {} |
1346 }; | 1378 }; |
1347 | 1379 |
1348 } // namespace cdm | 1380 } // namespace cdm |
1349 | 1381 |
1350 #endif // CDM_CONTENT_DECRYPTION_MODULE_H_ | 1382 #endif // CDM_CONTENT_DECRYPTION_MODULE_H_ |
OLD | NEW |