1 // Copyright 2015 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.
5 #include "media/cdm/stub/stub_cdm.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
10 // Version number for this stub. The third number represents the
11 // cdm::ContentDecryptionModule version.
12 const char kStubCdmVersion
[] = "1.4.8.0";
14 void INITIALIZE_CDM_MODULE() {
17 void DeinitializeCdmModule() {
20 void* CreateCdmInstance(int cdm_interface_version
,
21 const char* /* key_system */,
22 uint32_t /* key_system_size */,
23 GetCdmHostFunc get_cdm_host_func
,
25 DVLOG(1) << "CreateCdmInstance()";
27 if (cdm_interface_version
!= media::StubCdmInterface::kVersion
)
30 media::StubCdmInterface::Host
* host
=
31 static_cast<media::StubCdmInterface::Host
*>(get_cdm_host_func(
32 media::StubCdmInterface::Host::kVersion
, user_data
));
36 return new media::StubCdm(host
);
39 const char* GetCdmVersion() {
40 return kStubCdmVersion
;
45 StubCdm::StubCdm(Host
* host
) : host_(host
), next_session_id_(0) {
51 void StubCdm::Initialize(bool /* allow_distinctive_identifier */,
52 bool /* allow_persistent_state */) {
55 void StubCdm::CreateSessionAndGenerateRequest(
57 cdm::SessionType
/* session_type */,
58 cdm::InitDataType
/* init_data_type */,
59 const uint8
* /* init_data */,
60 uint32
/* init_data_size */) {
61 // Provide a dummy message (with a trivial session ID) to enable some testing
62 // and be consistent with existing testing without a license server.
63 std::string
session_id(base::UintToString(next_session_id_
++));
64 host_
->OnResolveNewSessionPromise(promise_id
, session_id
.data(),
66 host_
->OnSessionMessage(session_id
.data(), session_id
.length(),
67 cdm::kLicenseRequest
, nullptr, 0, nullptr, 0);
70 void StubCdm::LoadSession(uint32 promise_id
,
71 cdm::SessionType
/* session_type */,
72 const char* /* session_id */,
73 uint32_t /* session_id_length */) {
74 FailRequest(promise_id
);
77 void StubCdm::UpdateSession(uint32 promise_id
,
78 const char* /* session_id */,
79 uint32_t /* session_id_length */,
80 const uint8
* /* response */,
81 uint32
/* response_size */) {
82 FailRequest(promise_id
);
85 void StubCdm::CloseSession(uint32 promise_id
,
86 const char* /* session_id */,
87 uint32_t /* session_id_length */) {
88 FailRequest(promise_id
);
91 void StubCdm::RemoveSession(uint32 promise_id
,
92 const char* /* session_id */,
93 uint32_t /* session_id_length */) {
94 FailRequest(promise_id
);
97 void StubCdm::SetServerCertificate(
99 const uint8_t* /* server_certificate_data */,
100 uint32_t /* server_certificate_data_size */) {
101 FailRequest(promise_id
);
104 void StubCdm::TimerExpired(void* /* context */) {
107 cdm::Status
StubCdm::Decrypt(const cdm::InputBuffer
& /* encrypted_buffer */,
108 cdm::DecryptedBlock
* /* decrypted_block */) {
109 return cdm::kDecryptError
;
112 cdm::Status
StubCdm::InitializeAudioDecoder(
113 const cdm::AudioDecoderConfig
& /* audio_decoder_config */) {
114 return cdm::kDecryptError
;
117 cdm::Status
StubCdm::InitializeVideoDecoder(
118 const cdm::VideoDecoderConfig
& /* video_decoder_config */) {
119 return cdm::kDecryptError
;
122 void StubCdm::ResetDecoder(cdm::StreamType
/* decoder_type */) {
125 void StubCdm::DeinitializeDecoder(cdm::StreamType
/* decoder_type */) {
128 cdm::Status
StubCdm::DecryptAndDecodeFrame(
129 const cdm::InputBuffer
& /* encrypted_buffer */,
130 cdm::VideoFrame
* /* decoded_frame */) {
131 return cdm::kDecryptError
;
134 cdm::Status
StubCdm::DecryptAndDecodeSamples(
135 const cdm::InputBuffer
& /* encrypted_buffer */,
136 cdm::AudioFrames
* /* audio_frames */) {
137 return cdm::kDecryptError
;
140 void StubCdm::Destroy() {
144 void StubCdm::OnPlatformChallengeResponse(
145 const cdm::PlatformChallengeResponse
& /* response */) {
149 void StubCdm::OnQueryOutputProtectionStatus(
150 cdm::QueryResult
/* result */,
151 uint32_t /* link_mask */,
152 uint32_t /* output_protection_mask */) {
156 void StubCdm::FailRequest(uint32 promise_id
) {
157 std::string
message("Operation not supported by stub CDM.");
158 host_
->OnRejectPromise(promise_id
, cdm::kInvalidAccessError
, 0,
159 message
.data(), message
.length());