Skip to content

Commit

Permalink
tv-casting-app: fix TargetVideoPlayerInfo mem corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Feb 5, 2024
1 parent 9483084 commit e653cec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,20 @@ public void discoverVideoPlayerCommissioners(
}

List<VideoPlayer> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 22 additions & 3 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<int>(i);
}
}
}
return -1;
}

void CastingServer::VerifyOrEstablishConnectionTask(chip::System::Layer * aSystemLayer, void * context)
{
ChipLogProgress(AppServer, "CastingServer::VerifyOrEstablishConnectionTask called");
Expand Down

0 comments on commit e653cec

Please sign in to comment.