#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/cdm/cdm_adapter.h"
#include <stddef.h>
#include <iomanip>
#include <memory>
#include <utility>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/callback_registry.h"
#include "media/base/cdm_initialized_promise.h"
#include "media/base/cdm_key_information.h"
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
#include "media/base/key_systems.h"
#include "media/base/limits.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "media/cdm/cdm_auxiliary_helper.h"
#include "media/cdm/cdm_helpers.h"
#include "media/cdm/cdm_type_conversion.h"
#include "media/cdm/cdm_wrapper.h"
#include "media/media_buildflags.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h"
#include "url/origin.h"
namespace media {
namespace …
void CdmAdapter::Create(
const CdmConfig& cdm_config,
CreateCdmFunc create_cdm_func,
std::unique_ptr<CdmAuxiliaryHelper> helper,
const SessionMessageCB& session_message_cb,
const SessionClosedCB& session_closed_cb,
const SessionKeysChangeCB& session_keys_change_cb,
const SessionExpirationUpdateCB& session_expiration_update_cb,
CdmCreatedCB cdm_created_cb) { … }
CdmAdapter::CdmAdapter(
const CdmConfig& cdm_config,
CreateCdmFunc create_cdm_func,
std::unique_ptr<CdmAuxiliaryHelper> helper,
const SessionMessageCB& session_message_cb,
const SessionClosedCB& session_closed_cb,
const SessionKeysChangeCB& session_keys_change_cb,
const SessionExpirationUpdateCB& session_expiration_update_cb)
: … { … }
CdmAdapter::~CdmAdapter() { … }
CdmWrapper* CdmAdapter::CreateCdmInstance(const std::string& key_system) { … }
void CdmAdapter::Initialize(std::unique_ptr<media::SimpleCdmPromise> promise) { … }
int CdmAdapter::GetInterfaceVersion() { … }
void CdmAdapter::SetServerCertificate(
const std::vector<uint8_t>& certificate,
std::unique_ptr<SimpleCdmPromise> promise) { … }
void CdmAdapter::GetStatusForPolicy(
HdcpVersion min_hdcp_version,
std::unique_ptr<KeyStatusCdmPromise> promise) { … }
void CdmAdapter::CreateSessionAndGenerateRequest(
CdmSessionType session_type,
EmeInitDataType init_data_type,
const std::vector<uint8_t>& init_data,
std::unique_ptr<NewSessionCdmPromise> promise) { … }
void CdmAdapter::LoadSession(CdmSessionType session_type,
const std::string& session_id,
std::unique_ptr<NewSessionCdmPromise> promise) { … }
void CdmAdapter::UpdateSession(const std::string& session_id,
const std::vector<uint8_t>& response,
std::unique_ptr<SimpleCdmPromise> promise) { … }
void CdmAdapter::CloseSession(const std::string& session_id,
std::unique_ptr<SimpleCdmPromise> promise) { … }
void CdmAdapter::RemoveSession(const std::string& session_id,
std::unique_ptr<SimpleCdmPromise> promise) { … }
CdmContext* CdmAdapter::GetCdmContext() { … }
std::unique_ptr<CallbackRegistration> CdmAdapter::RegisterEventCB(
EventCB event_cb) { … }
Decryptor* CdmAdapter::GetDecryptor() { … }
std::optional<base::UnguessableToken> CdmAdapter::GetCdmId() const { … }
void CdmAdapter::Decrypt(StreamType stream_type,
scoped_refptr<DecoderBuffer> encrypted,
DecryptCB decrypt_cb) { … }
void CdmAdapter::CancelDecrypt(StreamType stream_type) { … }
void CdmAdapter::InitializeAudioDecoder(const AudioDecoderConfig& config,
DecoderInitCB init_cb) { … }
void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
DecoderInitCB init_cb) { … }
void CdmAdapter::DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
AudioDecodeCB audio_decode_cb) { … }
void CdmAdapter::DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
VideoDecodeCB video_decode_cb) { … }
void CdmAdapter::ResetDecoder(StreamType stream_type) { … }
void CdmAdapter::DeinitializeDecoder(StreamType stream_type) { … }
cdm::Buffer* CdmAdapter::Allocate(uint32_t capacity) { … }
void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { … }
void CdmAdapter::TimerExpired(void* context) { … }
cdm::Time CdmAdapter::GetCurrentWallTime() { … }
void CdmAdapter::OnInitialized(bool success) { … }
void CdmAdapter::OnResolveKeyStatusPromise(uint32_t promise_id,
cdm::KeyStatus key_status) { … }
void CdmAdapter::OnResolvePromise(uint32_t promise_id) { … }
void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id,
const char* session_id,
uint32_t session_id_size) { … }
void CdmAdapter::OnRejectPromise(uint32_t promise_id,
cdm::Exception exception,
uint32_t system_code,
const char* error_message,
uint32_t error_message_size) { … }
void CdmAdapter::OnSessionMessage(const char* session_id,
uint32_t session_id_size,
cdm::MessageType message_type,
const char* message,
uint32_t message_size) { … }
void CdmAdapter::OnSessionKeysChange(const char* session_id,
uint32_t session_id_size,
bool has_additional_usable_key,
const cdm::KeyInformation* keys_info,
uint32_t keys_info_count) { … }
void CdmAdapter::OnExpirationChange(const char* session_id,
uint32_t session_id_size,
cdm::Time new_expiry_time) { … }
void CdmAdapter::OnSessionClosed(const char* session_id,
uint32_t session_id_size) { … }
void CdmAdapter::SendPlatformChallenge(const char* service_id,
uint32_t service_id_size,
const char* challenge,
uint32_t challenge_size) { … }
void CdmAdapter::OnChallengePlatformDone(
bool success,
const std::string& signed_data,
const std::string& signed_data_signature,
const std::string& platform_key_certificate) { … }
void CdmAdapter::EnableOutputProtection(uint32_t desired_protection_mask) { … }
void CdmAdapter::OnEnableOutputProtectionDone(bool success) { … }
void CdmAdapter::QueryOutputProtectionStatus() { … }
void CdmAdapter::OnQueryOutputProtectionStatusDone(bool success,
uint32_t link_mask,
uint32_t protection_mask) { … }
void CdmAdapter::ReportOutputProtectionQuery() { … }
void CdmAdapter::ReportOutputProtectionQueryResult(uint32_t link_mask,
uint32_t protection_mask) { … }
void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type,
cdm::Status decoder_status) { … }
cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) { … }
void CdmAdapter::RequestStorageId(uint32_t version) { … }
void CdmAdapter::OnStorageIdObtained(uint32_t version,
const std::vector<uint8_t>& storage_id) { … }
bool CdmAdapter::AudioFramesDataToAudioFrames(
std::unique_ptr<AudioFramesImpl> audio_frames,
Decryptor::AudioFrames* result_frames) { … }
void CdmAdapter::OnFileRead(int file_size_bytes) { … }
}