Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tv-casting-app: fix TargetVideoPlayerInfo mem corruption #257

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved

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];
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
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
Loading