From 0dbeb3622cb21ee482a9452c5ce6a65e79ba6d0b Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Fri, 2 Feb 2024 14:33:37 -0800 Subject: [PATCH] tv-casting-app: fix TargetVideoPlayerInfo mem corruption --- .../jni/com/chip/casting/TvCastingApp.java | 15 ++++++++++++++- .../tv-casting-common/include/CastingServer.h | 1 + .../tv-casting-common/src/CastingServer.cpp | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java index 5eb1c0241438be..dd4bb42b698917 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java @@ -140,7 +140,20 @@ public void discoverVideoPlayerCommissioners( } List preCommissionedVideoPlayers = readCachedVideoPlayers(); - + if (preCommissionedVideoPlayers != null) { + for (VideoPlayer videoPlayer : preCommissionedVideoPlayers) { + Log.d( + TAG, + "preCommissionedVideoPlayer hostName: " + + videoPlayer.getHostName() + + " MACAddress: " + + videoPlayer.getMACAddress() + + " numIPs: " + + videoPlayer.getNumIPs() + + " IP Addresses: " + + videoPlayer.getIpAddresses()); + } + } WifiManager wifiManager = (WifiManager) applicationContext.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiManager.createMulticastLock("multicastLock"); diff --git a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h index 0728a71b25211e..74fc4fcb489621 100644 --- a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h +++ b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h @@ -446,6 +446,7 @@ class CastingServer : public AppDelegate static void VerifyOrEstablishConnectionTask(chip::System::Layer * aSystemLayer, void * context); CHIP_ERROR ReadMACAddress(TargetEndpointInfo * endpoint); + int GetVideoPlayerIndex(TargetVideoPlayerInfo * targetVideoPlayerInfo); /** * @brief Retrieve the IP Address to use for the UDC request. diff --git a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp index a5878fdb130cbe..562cc4e634f9c8 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -493,7 +493,8 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta prevDeviceProxy->Disconnect(); } - CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = targetVideoPlayerInfo; + int cacheIndex = GetVideoPlayerIndex(&targetVideoPlayerInfo); + CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = mCachedTargetVideoPlayerInfo[cacheIndex]; uint32_t delay = 0; if (targetVideoPlayerInfo.IsAsleep()) { @@ -511,6 +512,21 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta nullptr); } +int CastingServer::GetVideoPlayerIndex(TargetVideoPlayerInfo * targetVideoPlayerInfo) +{ + if (targetVideoPlayerInfo != nullptr) + { + for (size_t i = 0; i < kMaxCachedVideoPlayers && mCachedTargetVideoPlayerInfo[i].IsInitialized(); i++) + { + if (mCachedTargetVideoPlayerInfo[i] == *targetVideoPlayerInfo) + { + return static_cast(i); + } + } + } + return -1; +} + void CastingServer::VerifyOrEstablishConnectionTask(chip::System::Layer * aSystemLayer, void * context) { ChipLogProgress(AppServer, "CastingServer::VerifyOrEstablishConnectionTask called");