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..9ba76eba96e6ef 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 GetCachedVideoPlayerIndex(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..ede6d74e4b5bc7 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -481,6 +481,9 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta { return CHIP_ERROR_INVALID_ARGUMENT; } + int cacheIndex = GetCachedVideoPlayerIndex(&targetVideoPlayerInfo); + VerifyOrReturnError(cacheIndex >= 0, CHIP_ERROR_INVALID_ARGUMENT); + mOnConnectionSuccessClientCallback = onConnectionSuccess; mOnConnectionFailureClientCallback = onConnectionFailure; mOnNewOrUpdatedEndpoint = onNewOrUpdatedEndpoint; @@ -493,12 +496,13 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta prevDeviceProxy->Disconnect(); } - CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = targetVideoPlayerInfo; + CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = mCachedTargetVideoPlayerInfo[cacheIndex]; uint32_t delay = 0; - if (targetVideoPlayerInfo.IsAsleep()) + if (CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo.IsAsleep()) { ChipLogProgress(AppServer, "CastingServer::VerifyOrEstablishConnection(): Sending WoL to sleeping VideoPlayer and waiting"); - ReturnErrorOnFailure(CastingServer::GetInstance()->SendWakeOnLan(targetVideoPlayerInfo)); + ReturnErrorOnFailure( + CastingServer::GetInstance()->SendWakeOnLan(CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo)); #ifdef CHIP_DEVICE_CONFIG_STR_WAKE_UP_DELAY_SEC delay = CHIP_DEVICE_CONFIG_STR_WAKE_UP_DELAY_SEC * 1000; @@ -511,6 +515,21 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta nullptr); } +int CastingServer::GetCachedVideoPlayerIndex(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");