From bbf184d94f9cfe52965911bb3f96bc4f51640dff Mon Sep 17 00:00:00 2001 From: Subramanian Date: Fri, 30 Oct 2026 23:48:45 -0400 Subject: [PATCH] RDKEMW-28121: Pass buffers by reference to avoid unnecessary copies - PlayerScheduler::ScheduleTask: move the by-value PlayerAsyncTaskObj into the queue instead of copying it. - DrmSessionManager::IsKeyIdProcessed and initializeDrmSession: take const references; both are read-only over the parameter. - DrmHelper::transformLicenseResponse (ClearKeyHelper, VerimatrixHelper): take const std::shared_ptr& to avoid an atomic ref-count bump per license-response transform. - GetAudioTracksOta / GetTextTracksOta: changed to non-const out-references. These were passed by value but filled inside; the populated track data never reached callers and every call copied. - PlayerThunderAccess::StartRmf url param: read-only, now const ref. - BusMessageCallback typedef: pass BusEventData by const ref, avoiding a copy of the event payload on every GStreamer bus-message dispatch. StartOta intentionally left by value: its parameters are forwarded with std::move into the SetPreferredAudioLanguages_OTA sink, so the by-value + move idiom is already optimal there. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- InterfacePlayerRDK.h | 2 +- PlayerScheduler.cpp | 2 +- drm/DrmSessionManager.cpp | 4 ++-- drm/DrmSessionManager.h | 4 ++-- drm/helper/ClearKeyHelper.cpp | 2 +- drm/helper/ClearKeyHelper.h | 2 +- drm/helper/DrmHelper.h | 2 +- drm/helper/VerimatrixHelper.cpp | 2 +- drm/helper/VerimatrixHelper.h | 2 +- externals/PlayerThunderAccessBase.h | 6 +++--- externals/PlayerThunderInterface.cpp | 12 ++++++------ externals/PlayerThunderInterface.h | 6 +++--- externals/rdk/PlayerThunderAccess.cpp | 6 +++--- externals/rdk/PlayerThunderAccess.h | 6 +++--- test/utests/fakes/FakePlayerThunderInterface.cpp | 6 +++--- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/InterfacePlayerRDK.h b/InterfacePlayerRDK.h index 2b125fa0b..83134de8a 100644 --- a/InterfacePlayerRDK.h +++ b/InterfacePlayerRDK.h @@ -230,7 +230,7 @@ class InterfacePlayerRDK */ static gboolean IdleCallbackFirstVideoFrameDisplayed(gpointer user_data); /*Callback function types for various GStreamer events*/ - using BusMessageCallback = std::function; + using BusMessageCallback = std::function; using HandleOnGstBufferUnderflowCb = std::function; using HandleOnGstDecodeErrorCb = std::function; using HandleOnGstPtsErrorCb = std::function; diff --git a/PlayerScheduler.cpp b/PlayerScheduler.cpp index d66fdde65..b491138eb 100644 --- a/PlayerScheduler.cpp +++ b/PlayerScheduler.cpp @@ -83,7 +83,7 @@ int PlayerScheduler::ScheduleTask(PlayerAsyncTaskObj obj) mNextTaskId = PLAYER_SCHEDULER_ID_DEFAULT; } obj.mId = id; - mTaskQueue.push_back(obj); + mTaskQueue.push_back(std::move(obj)); mQCond.notify_one(); } else diff --git a/drm/DrmSessionManager.cpp b/drm/DrmSessionManager.cpp index 29e62cfaa..29942628f 100755 --- a/drm/DrmSessionManager.cpp +++ b/drm/DrmSessionManager.cpp @@ -349,7 +349,7 @@ string _extractSubstring(string parentStr, string startStr, string endStr) * @return bool - true if keyId is already marked as failed or cached, * false if key is not cached */ -bool DrmSessionManager::IsKeyIdProcessed(std::vector keyIdArray, bool &status) +bool DrmSessionManager::IsKeyIdProcessed(const std::vector &keyIdArray, bool &status) { bool ret = false; std::lock_guard guard(cachedKeyMutex); @@ -950,7 +950,7 @@ KeyState DrmSessionManager::getDrmSession(int &err, std::shared_ptr d /** * @brief Initialize the Drm System with InitData(PSSH) */ -KeyState DrmSessionManager::initializeDrmSession(std::shared_ptr drmHelper, int sessionSlot, int &err ) +KeyState DrmSessionManager::initializeDrmSession(const std::shared_ptr &drmHelper, int sessionSlot, int &err ) { KeyState code = KEY_ERROR; diff --git a/drm/DrmSessionManager.h b/drm/DrmSessionManager.h index 7ff90da7e..b922e65d8 100644 --- a/drm/DrmSessionManager.h +++ b/drm/DrmSessionManager.h @@ -329,7 +329,7 @@ class DrmSessionManager * @return bool - true if keyId is already marked as failed or processed, * false if key is not cached */ - bool IsKeyIdProcessed(std::vector keyIdArray, bool &status); + bool IsKeyIdProcessed(const std::vector &keyIdArray, bool &status); /** * @fn Validate multiple key IDs for a given DRM session slot using the provided DrmHelper * @@ -437,7 +437,7 @@ class DrmSessionManager /** * @fn initializeDrmSession */ - KeyState initializeDrmSession(DrmHelperPtr drmHelper, int sessionSlot, int &err ); + KeyState initializeDrmSession(const DrmHelperPtr &drmHelper, int sessionSlot, int &err ); /** * @fn notifyCleanup */ diff --git a/drm/helper/ClearKeyHelper.cpp b/drm/helper/ClearKeyHelper.cpp index 374d9506c..79f6db3fa 100644 --- a/drm/helper/ClearKeyHelper.cpp +++ b/drm/helper/ClearKeyHelper.cpp @@ -206,7 +206,7 @@ void ClearKeyHelper::generateLicenseRequest(const ChallengeInfo& challengeInfo, } } -void ClearKeyHelper::transformLicenseResponse(std::shared_ptr licenseResponse) const +void ClearKeyHelper::transformLicenseResponse(const std::shared_ptr &licenseResponse) const { // HLS requires the returned key to be transformed into a JWK. // For DASH it will already be in JWK format diff --git a/drm/helper/ClearKeyHelper.h b/drm/helper/ClearKeyHelper.h index b902cbbc7..d51f47a32 100755 --- a/drm/helper/ClearKeyHelper.h +++ b/drm/helper/ClearKeyHelper.h @@ -49,7 +49,7 @@ class ClearKeyHelper : public DrmHelper void generateLicenseRequest(const ChallengeInfo& challengeInfo, LicenseRequest& licenseRequest) const override; - void transformLicenseResponse(std::shared_ptr licenseResponse) const override; + void transformLicenseResponse(const std::shared_ptr &licenseResponse) const override; virtual const std::string& friendlyName() const override { return FRIENDLY_NAME; }; diff --git a/drm/helper/DrmHelper.h b/drm/helper/DrmHelper.h index 65004616e..18722ec27 100755 --- a/drm/helper/DrmHelper.h +++ b/drm/helper/DrmHelper.h @@ -218,7 +218,7 @@ class DrmHelper * @brief Transform the license response from the server into the necessary format for OCDM * @param licenseResponse license response from the server to transform */ - virtual void transformLicenseResponse(std::shared_ptr licenseResponse) const {} + virtual void transformLicenseResponse(const std::shared_ptr &licenseResponse) const {} /** * @brief Get the memory system used to transform data for transmission diff --git a/drm/helper/VerimatrixHelper.cpp b/drm/helper/VerimatrixHelper.cpp index 6afeffc2c..c946edc4c 100755 --- a/drm/helper/VerimatrixHelper.cpp +++ b/drm/helper/VerimatrixHelper.cpp @@ -120,7 +120,7 @@ void VerimatrixHelper::generateLicenseRequest(const ChallengeInfo& challengeInfo licenseRequest.payload = ""; } -void VerimatrixHelper::transformLicenseResponse(std::shared_ptr licenseResponse) const +void VerimatrixHelper::transformLicenseResponse(const std::shared_ptr &licenseResponse) const { if(!licenseResponse) { diff --git a/drm/helper/VerimatrixHelper.h b/drm/helper/VerimatrixHelper.h index 6c1cc23de..8e5816d75 100755 --- a/drm/helper/VerimatrixHelper.h +++ b/drm/helper/VerimatrixHelper.h @@ -48,7 +48,7 @@ class VerimatrixHelper: public DrmHelper void generateLicenseRequest(const ChallengeInfo& challengeInfo, LicenseRequest& licenseRequest) const; - void transformLicenseResponse(std::shared_ptr licenseResponse) const; + void transformLicenseResponse(const std::shared_ptr &licenseResponse) const; virtual const std::string& friendlyName() const override { return FRIENDLY_NAME; }; diff --git a/externals/PlayerThunderAccessBase.h b/externals/PlayerThunderAccessBase.h index 8bde0c7cd..a6bea03f7 100644 --- a/externals/PlayerThunderAccessBase.h +++ b/externals/PlayerThunderAccessBase.h @@ -288,7 +288,7 @@ class PlayerThunderAccessBase * @param audData vector to be filled with audio data * @return string of current track pk */ - virtual std::string GetAudioTracksOta(std::vector audData) = 0; + virtual std::string GetAudioTracksOta(std::vector &audData) = 0; /** * @fn SetAudioTrackOta @@ -303,7 +303,7 @@ class PlayerThunderAccessBase * @param txtData vector to be filled with text data * @return true if successful, false if failed */ - virtual bool GetTextTracksOta(std::vector txtData) = 0; + virtual bool GetTextTracksOta(std::vector &txtData) = 0; /** * @fn DisableContentRestrictionsOta @@ -333,7 +333,7 @@ class PlayerThunderAccessBase * @param onPlayerErrorHandlerCb player error handler callback * @return true if successful, false if failed */ - virtual bool StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) = 0; + virtual bool StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) = 0; /** * @fn StopRmf diff --git a/externals/PlayerThunderInterface.cpp b/externals/PlayerThunderInterface.cpp index f4a4289c8..b7f6c8e8f 100644 --- a/externals/PlayerThunderInterface.cpp +++ b/externals/PlayerThunderInterface.cpp @@ -371,9 +371,9 @@ void PlayerThunderInterface::SetPreferredAudioLanguages(PlayerPreferredAudioData m_pThunderAccess->SetPreferredAudioLanguages(std::move(data), shim); } -std::string PlayerThunderInterface::GetAudioTracksOta(std::vector audData) +std::string PlayerThunderInterface::GetAudioTracksOta(std::vector &audData) { - return m_pThunderAccess->GetAudioTracksOta(std::move(audData)); + return m_pThunderAccess->GetAudioTracksOta(audData); } std::string PlayerThunderInterface::SetAudioTrackOta(int index, int primaryKey) @@ -381,9 +381,9 @@ std::string PlayerThunderInterface::SetAudioTrackOta(int index, int primaryKey) return m_pThunderAccess->SetAudioTrackOta(index, primaryKey); } -bool PlayerThunderInterface::GetTextTracksOta(std::vector txtData) +bool PlayerThunderInterface::GetTextTracksOta(std::vector &txtData) { - return m_pThunderAccess->GetTextTracksOta(std::move(txtData)); + return m_pThunderAccess->GetTextTracksOta(txtData); } void PlayerThunderInterface::DisableContentRestrictionsOta(long grace, long time, bool eventChange) @@ -401,9 +401,9 @@ bool PlayerThunderInterface::InitRmf() return m_pThunderAccess->InitRmf(); } -bool PlayerThunderInterface::StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) +bool PlayerThunderInterface::StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) { - return m_pThunderAccess->StartRmf(std::move(url), std::move(onPlayerStatusHandlerCb), std::move(onPlayerErrorHandlerCb)); + return m_pThunderAccess->StartRmf(url, std::move(onPlayerStatusHandlerCb), std::move(onPlayerErrorHandlerCb)); } void PlayerThunderInterface::StopRmf() diff --git a/externals/PlayerThunderInterface.h b/externals/PlayerThunderInterface.h index 54db5e8ca..e64864c60 100644 --- a/externals/PlayerThunderInterface.h +++ b/externals/PlayerThunderInterface.h @@ -168,7 +168,7 @@ class PlayerThunderInterface * @param audData vector to be filled with audio data * @return string of current track pk */ - std::string GetAudioTracksOta(std::vector audData); + std::string GetAudioTracksOta(std::vector &audData); /** * @fn SetAudioTrackOta @@ -183,7 +183,7 @@ class PlayerThunderInterface * @param txtData vector to be filled with text data * @return true if successful, false if failed */ - bool GetTextTracksOta(std::vector txtData); + bool GetTextTracksOta(std::vector &txtData); /** * @fn DisableContentRestrictionsOta @@ -217,7 +217,7 @@ class PlayerThunderInterface * @param onPlayerErrorHandlerCb player error handler callback * @return true if successful, false if failed */ - bool StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb); + bool StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb); /** * @fn StopRmf diff --git a/externals/rdk/PlayerThunderAccess.cpp b/externals/rdk/PlayerThunderAccess.cpp index 53b3be7e8..72c7efd09 100644 --- a/externals/rdk/PlayerThunderAccess.cpp +++ b/externals/rdk/PlayerThunderAccess.cpp @@ -714,7 +714,7 @@ int PlayerThunderAccess::GetAudioTrackInternal_OTA() /** * @brief GetAudioTracks get the available audio tracks for the selected service / media */ -std::string PlayerThunderAccess::GetAudioTracksOta(std::vector audData) +std::string PlayerThunderAccess::GetAudioTracksOta(std::vector &audData) { JsonObject param; JsonObject result; @@ -789,7 +789,7 @@ std::string PlayerThunderAccess::SetAudioTrackOta(int trackId, int primaryKey) /** * @brief GetTextTracks get the available text tracks for the selected service / media */ -bool PlayerThunderAccess::GetTextTracksOta(std::vector txtData) +bool PlayerThunderAccess::GetTextTracksOta(std::vector &txtData) { MW_LOG_TRACE("[OTA_SHIM]"); JsonObject param; @@ -930,7 +930,7 @@ void PlayerThunderAccess::onPlayerErrorHandler_RMF(const JsonObject& parameters) mOnPlayerErrorHandlerCb(std::move(error_message)); } -bool PlayerThunderAccess::StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) +bool PlayerThunderAccess::StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) { bool bRet = true; mOnPlayerStatusHandlerCb = std::move(onPlayerStatusHandlerCb); diff --git a/externals/rdk/PlayerThunderAccess.h b/externals/rdk/PlayerThunderAccess.h index 427d2f5ce..445b985bc 100644 --- a/externals/rdk/PlayerThunderAccess.h +++ b/externals/rdk/PlayerThunderAccess.h @@ -180,7 +180,7 @@ class PlayerThunderAccess : public PlayerThunderAccessBase * @param audData vector to be filled with audio data * @return string of current track pk */ - std::string GetAudioTracksOta(std::vector audData) override; + std::string GetAudioTracksOta(std::vector &audData) override; /** * @fn SetAudioTrackOta @@ -195,7 +195,7 @@ class PlayerThunderAccess : public PlayerThunderAccessBase * @param txtData vector to be filled with text data * @return true if successful, false if failed */ - bool GetTextTracksOta(std::vector txtData) override; + bool GetTextTracksOta(std::vector &txtData) override; /** * @fn DisableContentRestrictionsOta @@ -225,7 +225,7 @@ class PlayerThunderAccess : public PlayerThunderAccessBase * @param onPlayerErrorHandlerCb player error handler callback * @return true if successful, false if failed */ - bool StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) override; + bool StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) override; /** * @fn StopRmf diff --git a/test/utests/fakes/FakePlayerThunderInterface.cpp b/test/utests/fakes/FakePlayerThunderInterface.cpp index 085c4b718..2073cf11b 100644 --- a/test/utests/fakes/FakePlayerThunderInterface.cpp +++ b/test/utests/fakes/FakePlayerThunderInterface.cpp @@ -84,7 +84,7 @@ void PlayerThunderInterface::StopOta() { } -std::string PlayerThunderInterface::GetAudioTracksOta(std::vector audData) +std::string PlayerThunderInterface::GetAudioTracksOta(std::vector &audData) { std::string ret = ""; return ret; @@ -96,7 +96,7 @@ std::string PlayerThunderInterface::SetAudioTrackOta(int index, int primaryKey) return ret; } -bool PlayerThunderInterface::GetTextTracksOta(std::vector txtData) +bool PlayerThunderInterface::GetTextTracksOta(std::vector &txtData) { return false; } @@ -114,7 +114,7 @@ bool PlayerThunderInterface::InitRmf() return false; } -bool PlayerThunderInterface::StartRmf(std::string url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) +bool PlayerThunderInterface::StartRmf(const std::string &url, std::function onPlayerStatusHandlerCb, std::function onPlayerErrorHandlerCb) { return false; }