Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / media / cdm / stub / stub_cdm.cc
blob9fb15924d9c842ca19fdfc8c05d7d18388e51304
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/numerics/safe_conversions.h"
9 #include "base/strings/string_number_conversions.h"
11 // Version number for this stub. The third number represents the
12 // cdm::ContentDecryptionModule version.
13 const char kStubCdmVersion[] = "1.4.8.0";
15 void INITIALIZE_CDM_MODULE() {
18 void DeinitializeCdmModule() {
21 void* CreateCdmInstance(int cdm_interface_version,
22 const char* /* key_system */,
23 uint32_t /* key_system_size */,
24 GetCdmHostFunc get_cdm_host_func,
25 void* user_data) {
26 DVLOG(1) << "CreateCdmInstance()";
28 if (cdm_interface_version != media::StubCdmInterface::kVersion)
29 return nullptr;
31 media::StubCdmInterface::Host* host =
32 static_cast<media::StubCdmInterface::Host*>(get_cdm_host_func(
33 media::StubCdmInterface::Host::kVersion, user_data));
34 if (!host)
35 return nullptr;
37 return new media::StubCdm(host);
40 const char* GetCdmVersion() {
41 return kStubCdmVersion;
44 namespace media {
46 StubCdm::StubCdm(Host* host) : host_(host), next_session_id_(0) {
49 StubCdm::~StubCdm() {
52 void StubCdm::Initialize(bool /* allow_distinctive_identifier */,
53 bool /* allow_persistent_state */) {
56 void StubCdm::CreateSessionAndGenerateRequest(
57 uint32 promise_id,
58 cdm::SessionType /* session_type */,
59 cdm::InitDataType /* init_data_type */,
60 const uint8* /* init_data */,
61 uint32 /* init_data_size */) {
62 // Provide a dummy message (with a trivial session ID) to enable some testing
63 // and be consistent with existing testing without a license server.
64 std::string session_id(base::UintToString(next_session_id_++));
65 host_->OnResolveNewSessionPromise(
66 promise_id, session_id.data(),
67 base::checked_cast<uint32_t>(session_id.length()));
68 host_->OnSessionMessage(session_id.data(),
69 base::checked_cast<uint32_t>(session_id.length()),
70 cdm::kLicenseRequest, nullptr, 0, nullptr, 0);
73 void StubCdm::LoadSession(uint32 promise_id,
74 cdm::SessionType /* session_type */,
75 const char* /* session_id */,
76 uint32_t /* session_id_length */) {
77 FailRequest(promise_id);
80 void StubCdm::UpdateSession(uint32 promise_id,
81 const char* /* session_id */,
82 uint32_t /* session_id_length */,
83 const uint8* /* response */,
84 uint32 /* response_size */) {
85 FailRequest(promise_id);
88 void StubCdm::CloseSession(uint32 promise_id,
89 const char* /* session_id */,
90 uint32_t /* session_id_length */) {
91 FailRequest(promise_id);
94 void StubCdm::RemoveSession(uint32 promise_id,
95 const char* /* session_id */,
96 uint32_t /* session_id_length */) {
97 FailRequest(promise_id);
100 void StubCdm::SetServerCertificate(
101 uint32 promise_id,
102 const uint8_t* /* server_certificate_data */,
103 uint32_t /* server_certificate_data_size */) {
104 FailRequest(promise_id);
107 void StubCdm::TimerExpired(void* /* context */) {
110 cdm::Status StubCdm::Decrypt(const cdm::InputBuffer& /* encrypted_buffer */,
111 cdm::DecryptedBlock* /* decrypted_block */) {
112 return cdm::kDecryptError;
115 cdm::Status StubCdm::InitializeAudioDecoder(
116 const cdm::AudioDecoderConfig& /* audio_decoder_config */) {
117 return cdm::kDecryptError;
120 cdm::Status StubCdm::InitializeVideoDecoder(
121 const cdm::VideoDecoderConfig& /* video_decoder_config */) {
122 return cdm::kDecryptError;
125 void StubCdm::ResetDecoder(cdm::StreamType /* decoder_type */) {
128 void StubCdm::DeinitializeDecoder(cdm::StreamType /* decoder_type */) {
131 cdm::Status StubCdm::DecryptAndDecodeFrame(
132 const cdm::InputBuffer& /* encrypted_buffer */,
133 cdm::VideoFrame* /* decoded_frame */) {
134 return cdm::kDecryptError;
137 cdm::Status StubCdm::DecryptAndDecodeSamples(
138 const cdm::InputBuffer& /* encrypted_buffer */,
139 cdm::AudioFrames* /* audio_frames */) {
140 return cdm::kDecryptError;
143 void StubCdm::Destroy() {
144 delete this;
147 void StubCdm::OnPlatformChallengeResponse(
148 const cdm::PlatformChallengeResponse& /* response */) {
149 NOTREACHED();
152 void StubCdm::OnQueryOutputProtectionStatus(
153 cdm::QueryResult /* result */,
154 uint32_t /* link_mask */,
155 uint32_t /* output_protection_mask */) {
156 NOTREACHED();
159 void StubCdm::FailRequest(uint32 promise_id) {
160 std::string message("Operation not supported by stub CDM.");
161 host_->OnRejectPromise(promise_id, cdm::kInvalidAccessError, 0,
162 message.data(),
163 base::checked_cast<uint32_t>(message.length()));
166 } // namespace media