Skip to content

Commit

Permalink
Add OnSessionClosed to run on task_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sideb0ard committed Nov 8, 2024
1 parent 5a79ce4 commit f7e70bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions media/cdm/starboard/starboard_cdm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ void StarboardCdm::OnServerCertificateUpdated(
ticket_to_server_certificate_updated_map_.erase(iter);
}

void StarboardCdm::OnSessionClosed(const std::string& session_id) {
// Find the session by ID.
auto session_iterator = session_map_.find(session_id);
if (session_iterator == session_map_.end()) {
LOG(ERROR) << "Unknown session id: " << session_id << ".";
return;
}

closed_cb_.Run(session_id, media::CdmSessionClosedReason::kClose);
session_map_.erase(session_iterator);
}

// static
void StarboardCdm::OnSessionUpdateRequestGeneratedFunc(
SbDrmSystem sb_drm,
Expand Down Expand Up @@ -497,22 +509,16 @@ void StarboardCdm::OnSessionClosedFunc(SbDrmSystem sb_drm,
StarboardCdm* cdm = static_cast<StarboardCdm*>(context);
DCHECK_EQ(sb_drm, cdm->sb_drm_);

LOG(INFO) << "YO THOR _ CDM ON SESISON CLOSED";

DCHECK(session_id != NULL);

std::string session_id_copy =
std::string(static_cast<const char*>(session_id),
static_cast<const char*>(session_id) + session_id_size);
// Find the session by ID.
auto session_iterator = cdm->session_map_.find(session_id_copy);
if (session_iterator == cdm->session_map_.end()) {
LOG(ERROR) << "Unknown session id: " << session_id_copy << ".";
return;
}

cdm->closed_cb_.Run(session_id_copy, media::CdmSessionClosedReason::kClose);
cdm->session_map_.erase(session_iterator);
cdm->task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&StarboardCdm::OnSessionClosed,
cdm->weak_factory_.GetWeakPtr(), session_id_copy));
}

} // namespace media
2 changes: 1 addition & 1 deletion media/cdm/starboard/starboard_cdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MEDIA_EXPORT StarboardCdm : public ContentDecryptionModule,
void OnServerCertificateUpdated(int ticket,
SbDrmStatus status,
const std::string& error_message);
// void OnSessionClosed(const std::string& session_id);
void OnSessionClosed(const std::string& session_id);

// SbDrm functions
static void OnSessionUpdateRequestGeneratedFunc(
Expand Down

0 comments on commit f7e70bd

Please sign in to comment.