fake_encrypted_media.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2017 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. #ifndef MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_
  5. #define MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "media/base/cdm_context.h"
  8. #include "media/base/content_decryption_module.h"
  9. namespace media {
  10. class AesDecryptor;
  11. // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
  12. // They do not exercise the Decrypting{Audio|Video}Decoder path.
  13. class FakeEncryptedMedia {
  14. public:
  15. // Defines the behavior of the "app" that responds to EME events.
  16. class AppBase {
  17. public:
  18. virtual ~AppBase() {}
  19. virtual void OnSessionMessage(const std::string& session_id,
  20. CdmMessageType message_type,
  21. const std::vector<uint8_t>& message,
  22. AesDecryptor* decryptor) = 0;
  23. virtual void OnSessionClosed(const std::string& session_id,
  24. CdmSessionClosedReason reason) = 0;
  25. virtual void OnSessionKeysChange(const std::string& session_id,
  26. bool has_additional_usable_key,
  27. CdmKeysInfo keys_info) = 0;
  28. virtual void OnSessionExpirationUpdate(const std::string& session_id,
  29. base::Time new_expiry_time) = 0;
  30. virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
  31. const std::vector<uint8_t>& init_data,
  32. AesDecryptor* decryptor) = 0;
  33. };
  34. FakeEncryptedMedia(AppBase* app);
  35. FakeEncryptedMedia(const FakeEncryptedMedia&) = delete;
  36. FakeEncryptedMedia& operator=(const FakeEncryptedMedia&) = delete;
  37. ~FakeEncryptedMedia();
  38. CdmContext* GetCdmContext();
  39. // Callbacks for firing session events. Delegate to |app_|.
  40. void OnSessionMessage(const std::string& session_id,
  41. CdmMessageType message_type,
  42. const std::vector<uint8_t>& message);
  43. void OnSessionClosed(const std::string& session_id,
  44. CdmSessionClosedReason reason);
  45. void OnSessionKeysChange(const std::string& session_id,
  46. bool has_additional_usable_key,
  47. CdmKeysInfo keys_info);
  48. void OnSessionExpirationUpdate(const std::string& session_id,
  49. base::Time new_expiry_time);
  50. void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
  51. const std::vector<uint8_t>& init_data);
  52. private:
  53. class TestCdmContext : public CdmContext {
  54. public:
  55. TestCdmContext(Decryptor* decryptor);
  56. Decryptor* GetDecryptor() final;
  57. private:
  58. raw_ptr<Decryptor> decryptor_;
  59. };
  60. scoped_refptr<AesDecryptor> decryptor_;
  61. TestCdmContext cdm_context_;
  62. std::unique_ptr<AppBase> app_;
  63. };
  64. } // namespace media
  65. #endif // MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_