1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
media / test / fake_encrypted_media.h [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_
#define MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_
#include "base/memory/raw_ptr.h"
#include "media/base/cdm_context.h"
#include "media/base/content_decryption_module.h"
namespace media {
class AesDecryptor;
// Note: Tests using this class only exercise the DecryptingDemuxerStream path.
// They do not exercise the Decrypting{Audio|Video}Decoder path.
class FakeEncryptedMedia {
public:
// Defines the behavior of the "app" that responds to EME events.
class AppBase {
public:
virtual ~AppBase() {}
virtual void OnSessionMessage(const std::string& session_id,
CdmMessageType message_type,
const std::vector<uint8_t>& message,
AesDecryptor* decryptor) = 0;
virtual void OnSessionClosed(const std::string& session_id,
CdmSessionClosedReason reason) = 0;
virtual void OnSessionKeysChange(const std::string& session_id,
bool has_additional_usable_key,
CdmKeysInfo keys_info) = 0;
virtual void OnSessionExpirationUpdate(const std::string& session_id,
base::Time new_expiry_time) = 0;
virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
const std::vector<uint8_t>& init_data,
AesDecryptor* decryptor) = 0;
};
FakeEncryptedMedia(AppBase* app);
FakeEncryptedMedia(const FakeEncryptedMedia&) = delete;
FakeEncryptedMedia& operator=(const FakeEncryptedMedia&) = delete;
~FakeEncryptedMedia();
CdmContext* GetCdmContext();
// Callbacks for firing session events. Delegate to |app_|.
void OnSessionMessage(const std::string& session_id,
CdmMessageType message_type,
const std::vector<uint8_t>& message);
void OnSessionClosed(const std::string& session_id,
CdmSessionClosedReason reason);
void OnSessionKeysChange(const std::string& session_id,
bool has_additional_usable_key,
CdmKeysInfo keys_info);
void OnSessionExpirationUpdate(const std::string& session_id,
base::Time new_expiry_time);
void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
const std::vector<uint8_t>& init_data);
private:
class TestCdmContext : public CdmContext {
public:
TestCdmContext(Decryptor* decryptor);
Decryptor* GetDecryptor() final;
private:
raw_ptr<Decryptor> decryptor_;
};
scoped_refptr<AesDecryptor> decryptor_;
TestCdmContext cdm_context_;
std::unique_ptr<AppBase> app_;
};
} // namespace media
#endif // MEDIA_TEST_FAKE_ENCRYPTED_MEDIA_H_