From 212f16ecdfb1470e9170fa2c83a3e814a35a48bf Mon Sep 17 00:00:00 2001 From: Portisch Date: Tue, 6 Jul 2021 15:23:43 +0200 Subject: [PATCH] wvdecrypter: centralize CloseSession Centralize and perform CloseSession call before dispose. --- wvdecrypter/wvdecrypter.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/wvdecrypter/wvdecrypter.cpp b/wvdecrypter/wvdecrypter.cpp index b3f37fa31..88b961f1f 100644 --- a/wvdecrypter/wvdecrypter.cpp +++ b/wvdecrypter/wvdecrypter.cpp @@ -174,12 +174,14 @@ class WV_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter void GetCapabilities(const uint8_t* key, uint32_t media, SSD_DECRYPTER::SSD_CAPS &caps); virtual const char *GetSessionId() override; + void CloseSessionId(); void SetSession(const char* session, uint32_t session_size, const uint8_t *data, size_t data_size) { std::lock_guard lock(renewal_lock_); session_ = std::string(session, session_size); challenge_.SetData(data, data_size); + Log(SSD_HOST::LL_DEBUG, "%s: opened session with Id: %s", __func__, session_.c_str()); } void AddSessionKey(const uint8_t *data, size_t data_size, uint32_t status); @@ -477,8 +479,7 @@ WV_CencSingleSampleDecrypter::WV_CencSingleSampleDecrypter(WV_DRM &drm, AP4_Data if (keys_.empty()) { Log(SSD_HOST::LL_ERROR, "License update not successful (no keys)"); - drm_.GetCdmAdapter()->CloseSession(++promise_id_, session_.data(), session_.size()); - session_.clear(); + CloseSessionId(); return; } Log(SSD_HOST::LL_DEBUG, "License update successful"); @@ -486,8 +487,6 @@ WV_CencSingleSampleDecrypter::WV_CencSingleSampleDecrypter(WV_DRM &drm, AP4_Data WV_CencSingleSampleDecrypter::~WV_CencSingleSampleDecrypter() { - if (!session_.empty()) - drm_.GetCdmAdapter()->CloseSession(++promise_id_, session_.data(), session_.size()); drm_.removessd(this); free(subsample_buffer_decrypt_); free(subsample_buffer_video_); @@ -573,6 +572,18 @@ const char *WV_CencSingleSampleDecrypter::GetSessionId() return session_.empty()? nullptr : session_.c_str(); } +void WV_CencSingleSampleDecrypter::CloseSessionId() +{ + if (!session_.empty()) + { + Log(SSD_HOST::LL_DEBUG, "%s: close session with Id: %s", __func__, session_.c_str()); + drm_.GetCdmAdapter()->CloseSession(++promise_id_, session_.data(), session_.size()); + session_.clear(); + + Log(SSD_HOST::LL_DEBUG, "%s: session closed", __func__); + } +} + void WV_CencSingleSampleDecrypter::CheckLicenseRenewal() { { @@ -1418,7 +1429,11 @@ class WVDecrypter : public SSD_DECRYPTER virtual void DestroySingleSampleDecrypter(AP4_CencSingleSampleDecrypter* decrypter) override { if (decrypter) + { + // close session before dispose + static_cast(decrypter)->CloseSessionId(); delete static_cast(decrypter); + } } virtual void GetCapabilities(AP4_CencSingleSampleDecrypter* decrypter, const uint8_t *keyid, uint32_t media, SSD_DECRYPTER::SSD_CAPS &caps) override