From 9bed45dcb28999cb01b52018c46942527059f8f6 Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Wed, 1 Feb 2023 17:05:14 -0800 Subject: [PATCH] Changing caching logic to match video players using hostname before other attributes --- .../com/chip/casting/DiscoveredNodeData.java | 3 ++ .../jni/com/chip/casting/VideoPlayer.java | 11 +++++++ .../app/src/main/jni/cpp/ConversionUtils.cpp | 28 ++++++++++++----- .../CastingServerBridge.mm | 3 +- .../MatterTvCastingBridge/ConversionUtils.mm | 14 ++++++--- .../tv-casting-common/include/CastingServer.h | 1 + .../include/PersistenceManager.h | 1 + .../include/TargetVideoPlayerInfo.h | 8 +++-- .../tv-casting-common/src/CastingServer.cpp | 5 +++- .../src/PersistenceManager.cpp | 13 +++++++- .../src/TargetVideoPlayerInfo.cpp | 30 +++++++++++++++---- 11 files changed, 93 insertions(+), 24 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java index b8a051036edd54..e3bc55388658ed 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java @@ -52,6 +52,9 @@ public class DiscoveredNodeData { public DiscoveredNodeData(NsdServiceInfo serviceInfo) { Map attributes = serviceInfo.getAttributes(); this.deviceName = new String(attributes.get(KEY_DEVICE_NAME), StandardCharsets.UTF_8); + if (serviceInfo.getHost() != null) { + this.hostName = serviceInfo.getHost().getHostName(); + } this.deviceType = Long.parseLong(new String(attributes.get(KEY_DEVICE_TYPE), StandardCharsets.UTF_8)); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java index 9ba557c910b704..e440acdce093d4 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java @@ -37,6 +37,7 @@ public class VideoPlayer { private int numIPs; private List ipAddresses; + private String hostName; private boolean isInitialized = false; @@ -50,6 +51,7 @@ public VideoPlayer( List contentApps, int numIPs, List ipAddresses, + String hostName, boolean isConnected) { this.nodeId = nodeId; this.fabricIndex = fabricIndex; @@ -61,6 +63,7 @@ public VideoPlayer( this.isConnected = isConnected; this.numIPs = numIPs; this.ipAddresses = ipAddresses; + this.hostName = hostName; this.isInitialized = true; } @@ -70,6 +73,11 @@ public boolean isSameAs(DiscoveredNodeData discoveredNodeData) { return false; } + // return true if hostNames match + if (Objects.equals(hostName, discoveredNodeData.getHostName())) { + return true; + } + // return false because deviceNames are different if (Objects.equals(deviceName, discoveredNodeData.getDeviceName()) == false) { return false; @@ -133,6 +141,9 @@ public java.lang.String toString() { + ", ipAddresses=" + ipAddresses + ", isInitialized=" + + ", hostName='" + + hostName + + '\'' + isInitialized + '}'; } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp index 3b5832af055963..16b2cec60f201f 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp @@ -24,7 +24,7 @@ CHIP_ERROR convertJAppParametersToCppAppParams(jobject appParameters, AppParams & outAppParams) { - ChipLogProgress(AppServer, "convertJContentAppToTargetEndpointInfo called"); + ChipLogProgress(AppServer, "convertJAppParametersToCppAppParams called"); JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(appParameters != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -149,7 +149,13 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe jfieldID getDeviceNameField = env->GetFieldID(jVideoPlayerClass, "deviceName", "Ljava/lang/String;"); jstring jDeviceName = static_cast(env->GetObjectField(videoPlayer, getDeviceNameField)); const char * deviceName = env->GetStringUTFChars(jDeviceName, 0); - outTargetVideoPlayerInfo.Initialize(nodeId, fabricIndex, nullptr, nullptr, vendorId, productId, deviceType, deviceName); + + jfieldID getHostNameField = env->GetFieldID(jVideoPlayerClass, "hostName", "Ljava/lang/String;"); + jstring jHostName = static_cast(env->GetObjectField(videoPlayer, getHostNameField)); + const char * hostName = env->GetStringUTFChars(jHostName, 0); + + outTargetVideoPlayerInfo.Initialize(nodeId, fabricIndex, nullptr, nullptr, vendorId, productId, deviceType, deviceName, + hostName); jfieldID jContentAppsField = env->GetFieldID(jVideoPlayerClass, "contentApps", "Ljava/util/List;"); jobject jContentApps = env->GetObjectField(videoPlayer, jContentAppsField); @@ -189,8 +195,8 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta jclass jVideoPlayerClass; ReturnErrorOnFailure( chip::JniReferences::GetInstance().GetClassRef(env, "com/chip/casting/VideoPlayer", jVideoPlayerClass)); - jmethodID jVideoPlayerConstructor = - env->GetMethodID(jVideoPlayerClass, "", "(JBLjava/lang/String;IIILjava/util/List;ILjava/util/List;Z)V"); + jmethodID jVideoPlayerConstructor = env->GetMethodID( + jVideoPlayerClass, "", "(JBLjava/lang/String;IIILjava/util/List;ILjava/util/List;Ljava/lang/String;Z)V"); jobject jContentAppList = nullptr; TargetEndpointInfo * endpoints = targetVideoPlayerInfo->GetEndpoints(); @@ -208,6 +214,9 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta jstring deviceName = targetVideoPlayerInfo->GetDeviceName() == nullptr ? nullptr : env->NewStringUTF(targetVideoPlayerInfo->GetDeviceName()); + jstring hostName = + targetVideoPlayerInfo->GetHostName() == nullptr ? nullptr : env->NewStringUTF(targetVideoPlayerInfo->GetHostName()); + jobject jIPAddressList = nullptr; const chip::Inet::IPAddress * ipAddresses = targetVideoPlayerInfo->GetIpAddresses(); if (ipAddresses != nullptr) @@ -233,7 +242,7 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta outVideoPlayer = env->NewObject(jVideoPlayerClass, jVideoPlayerConstructor, targetVideoPlayerInfo->GetNodeId(), targetVideoPlayerInfo->GetFabricIndex(), deviceName, targetVideoPlayerInfo->GetVendorId(), targetVideoPlayerInfo->GetProductId(), targetVideoPlayerInfo->GetDeviceType(), - jContentAppList, targetVideoPlayerInfo->GetNumIPs(), jIPAddressList, + jContentAppList, targetVideoPlayerInfo->GetNumIPs(), jIPAddressList, hostName, targetVideoPlayerInfo->GetOperationalDeviceProxy() != nullptr); } return CHIP_NO_ERROR; @@ -259,7 +268,7 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered env->GetStringUTFChars(jHostName, 0)); } - jfieldID getInstanceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;"); + jfieldID getInstanceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "instanceName", "Ljava/lang/String;"); jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField)); if (jInstanceName != nullptr) { @@ -289,8 +298,11 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;"); jstring jDeviceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getDeviceNameField)); - chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - env->GetStringUTFChars(jDeviceName, 0)); + if (jDeviceName != nullptr) + { + chip::Platform::CopyString(outCppDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + env->GetStringUTFChars(jDeviceName, 0)); + } // TODO: map rotating ID jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I"); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm index 1c6038ef0eb609..73dcec1946c8b5 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm @@ -622,7 +622,8 @@ - (void)stopMatterServer self->_previouslyConnectedVideoPlayer->Initialize(currentTargetVideoPlayerInfo->GetNodeId(), currentTargetVideoPlayerInfo->GetFabricIndex(), nullptr, nullptr, currentTargetVideoPlayerInfo->GetVendorId(), currentTargetVideoPlayerInfo->GetProductId(), currentTargetVideoPlayerInfo->GetDeviceType(), - currentTargetVideoPlayerInfo->GetDeviceName(), currentTargetVideoPlayerInfo->GetNumIPs(), + currentTargetVideoPlayerInfo->GetDeviceName(), currentTargetVideoPlayerInfo->GetHostName(), + currentTargetVideoPlayerInfo->GetNumIPs(), const_cast(currentTargetVideoPlayerInfo->GetIpAddresses())); TargetEndpointInfo * prevEndpoints = self->_previouslyConnectedVideoPlayer->GetEndpoints(); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm index f71cab0bf0e1c6..3f98f96d2286c3 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ConversionUtils.mm @@ -54,16 +54,22 @@ + (CHIP_ERROR)convertToCppDiscoveredNodeDataFrom:(DiscoveredNodeData * _Nonnull) outDiscoveredNodeData.commissionData.longDiscriminator = objCDiscoveredNodeData.longDiscriminator; outDiscoveredNodeData.commissionData.commissioningMode = objCDiscoveredNodeData.commissioningMode; outDiscoveredNodeData.commissionData.pairingHint = objCDiscoveredNodeData.pairingHint; - chip::Platform::CopyString(outDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, - [objCDiscoveredNodeData.deviceName UTF8String]); + memset(outDiscoveredNodeData.commissionData.deviceName, '\0', sizeof(outDiscoveredNodeData.commissionData.deviceName)); + if (objCDiscoveredNodeData.deviceName != nullptr) { + chip::Platform::CopyString(outDiscoveredNodeData.commissionData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1, + [objCDiscoveredNodeData.deviceName UTF8String]); + } outDiscoveredNodeData.commissionData.rotatingIdLen = objCDiscoveredNodeData.rotatingIdLen; memcpy( outDiscoveredNodeData.commissionData.rotatingId, objCDiscoveredNodeData.rotatingId, objCDiscoveredNodeData.rotatingIdLen); // setting CommonResolutionData outDiscoveredNodeData.resolutionData.port = objCDiscoveredNodeData.port; - chip::Platform::CopyString(outDiscoveredNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, - [objCDiscoveredNodeData.hostName UTF8String]); + memset(outDiscoveredNodeData.resolutionData.hostName, '\0', sizeof(outDiscoveredNodeData.resolutionData.hostName)); + if (objCDiscoveredNodeData.hostName != nullptr) { + chip::Platform::CopyString(outDiscoveredNodeData.resolutionData.hostName, chip::Dnssd::kHostNameMaxLength + 1, + [objCDiscoveredNodeData.hostName UTF8String]); + } outDiscoveredNodeData.resolutionData.interfaceId = chip::Inet::InterfaceId(objCDiscoveredNodeData.platformInterface); outDiscoveredNodeData.resolutionData.numIPs = objCDiscoveredNodeData.numIPs; for (size_t i = 0; i < objCDiscoveredNodeData.numIPs; i++) { 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 60aea4867d18f2..8ab5dc5b358d73 100644 --- a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h +++ b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h @@ -438,6 +438,7 @@ class CastingServer uint16_t mTargetVideoPlayerProductId = 0; chip::DeviceTypeId mTargetVideoPlayerDeviceType = 0; char mTargetVideoPlayerDeviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; + char mTargetVideoPlayerHostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; size_t mTargetVideoPlayerNumIPs = 0; // number of valid IP addresses chip::Inet::IPAddress mTargetVideoPlayerIpAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses]; diff --git a/examples/tv-casting-app/tv-casting-common/include/PersistenceManager.h b/examples/tv-casting-app/tv-casting-common/include/PersistenceManager.h index b1e7bd6c58130d..6d3f36b7801416 100644 --- a/examples/tv-casting-app/tv-casting-common/include/PersistenceManager.h +++ b/examples/tv-casting-app/tv-casting-common/include/PersistenceManager.h @@ -49,6 +49,7 @@ class PersistenceManager kVideoPlayerProductIdTag, kVideoPlayerDeviceTypeIdTag, kVideoPlayerDeviceNameTag, + kVideoPlayerHostNameTag, kVideoPlayerNumIPsTag, kVideoPlayerIPAddressTag, kIpAddressesContainerTag, diff --git a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h index 26e939346d9b32..845655a441f77d 100644 --- a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h +++ b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h @@ -41,10 +41,11 @@ class TargetVideoPlayerInfo chip::NodeId GetNodeId() const { return mNodeId; } chip::FabricIndex GetFabricIndex() const { return mFabricIndex; } const char * GetDeviceName() const { return mDeviceName; } + const char * GetHostName() const { return mHostName; } size_t GetNumIPs() const { return mNumIPs; } const chip::Inet::IPAddress * GetIpAddresses() const { return mIpAddress; } bool IsSameAs(const chip::Dnssd::DiscoveredNodeData * discoveredNodeData); - bool IsSameAs(const char * deviceName, size_t numIPs, const chip::Inet::IPAddress * ipAddresses); + bool IsSameAs(const char * hostName, const char * deviceName, size_t numIPs, const chip::Inet::IPAddress * ipAddresses); chip::OperationalDeviceProxy * GetOperationalDeviceProxy() { @@ -58,8 +59,8 @@ class TargetVideoPlayerInfo CHIP_ERROR Initialize(chip::NodeId nodeId, chip::FabricIndex fabricIndex, std::function onConnectionSuccess, std::function onConnectionFailure, uint16_t vendorId = 0, uint16_t productId = 0, - chip::DeviceTypeId deviceType = 0, const char * deviceName = {}, size_t numIPs = 0, - chip::Inet::IPAddress * ipAddressList = nullptr); + chip::DeviceTypeId deviceType = 0, const char * deviceName = {}, const char * hostName = {}, + size_t numIPs = 0, chip::Inet::IPAddress * ipAddressList = nullptr); CHIP_ERROR FindOrEstablishCASESession(std::function onConnectionSuccess, std::function onConnectionFailure); TargetEndpointInfo * GetOrAddEndpoint(chip::EndpointId endpointId); @@ -110,6 +111,7 @@ class TargetVideoPlayerInfo uint16_t mProductId = 0; chip::DeviceTypeId mDeviceType = 0; char mDeviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; + char mHostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; size_t mNumIPs = 0; // number of valid IP addresses chip::Inet::IPAddress mIpAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses]; 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 fa4138deeeba43..e1490e6afbb270 100644 --- a/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp @@ -162,6 +162,8 @@ CHIP_ERROR CastingServer::SendUserDirectedCommissioningRequest(Dnssd::Discovered } chip::Platform::CopyString(mTargetVideoPlayerDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, selectedCommissioner->commissionData.deviceName); + chip::Platform::CopyString(mTargetVideoPlayerHostName, chip::Dnssd::kHostNameMaxLength + 1, + selectedCommissioner->resolutionData.hostName); return CHIP_NO_ERROR; } #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT @@ -412,7 +414,8 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve CastingServer::GetInstance()->mOnConnectionFailureClientCallback, CastingServer::GetInstance()->mTargetVideoPlayerVendorId, CastingServer::GetInstance()->mTargetVideoPlayerProductId, CastingServer::GetInstance()->mTargetVideoPlayerDeviceType, CastingServer::GetInstance()->mTargetVideoPlayerDeviceName, - CastingServer::GetInstance()->mTargetVideoPlayerNumIPs, CastingServer::GetInstance()->mTargetVideoPlayerIpAddress); + CastingServer::GetInstance()->mTargetVideoPlayerHostName, CastingServer::GetInstance()->mTargetVideoPlayerNumIPs, + CastingServer::GetInstance()->mTargetVideoPlayerIpAddress); if (err != CHIP_NO_ERROR) { diff --git a/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp b/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp index dea0277064b30c..b5c24ea6f5b9d1 100644 --- a/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp @@ -98,6 +98,10 @@ CHIP_ERROR PersistenceManager::WriteAllVideoPlayers(TargetVideoPlayerInfo videoP ReturnErrorOnFailure(tlvWriter.PutBytes(TLV::ContextTag(kVideoPlayerDeviceNameTag), (const uint8_t *) videoPlayer->GetDeviceName(), static_cast(strlen(videoPlayer->GetDeviceName()) + 1))); + ReturnErrorOnFailure(tlvWriter.PutBytes(TLV::ContextTag(kVideoPlayerHostNameTag), + (const uint8_t *) videoPlayer->GetHostName(), + static_cast(strlen(videoPlayer->GetHostName()) + 1))); + ReturnErrorOnFailure( tlvWriter.Put(TLV::ContextTag(kVideoPlayerNumIPsTag), static_cast(videoPlayer->GetNumIPs()))); const Inet::IPAddress * ipAddress = videoPlayer->GetIpAddresses(); @@ -205,6 +209,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide uint16_t productId = 0; uint16_t deviceType = 0; char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; + char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; size_t numIPs = 0; Inet::IPAddress ipAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses]; CHIP_ERROR err; @@ -254,6 +259,12 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide continue; } + if (videoPlayersContainerTagNum == kVideoPlayerHostNameTag) + { + ReturnErrorOnFailure(reader.GetBytes(reinterpret_cast(hostName), chip::Dnssd::kHostNameMaxLength + 1)); + continue; + } + if (videoPlayersContainerTagNum == kVideoPlayerNumIPsTag) { ReturnErrorOnFailure(reader.Get(reinterpret_cast(numIPs))); @@ -301,7 +312,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide if (videoPlayersContainerTagNum == kContentAppEndpointsContainerTag) { outVideoPlayers[videoPlayerIndex].Initialize(nodeId, fabricIndex, nullptr, nullptr, vendorId, productId, deviceType, - deviceName, numIPs, ipAddress); + deviceName, hostName, numIPs, ipAddress); // Entering Content App Endpoints container TLV::TLVType contentAppEndpointArrayContainerType = TLV::kTLVType_Array; ReturnErrorOnFailure(reader.EnterContainer(contentAppEndpointArrayContainerType)); diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index bff3bb2fa8380b..35f95bc84e475f 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -26,8 +26,8 @@ CASEClientPool gCASEClientPool; CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIndex, std::function onConnectionSuccess, std::function onConnectionFailure, uint16_t vendorId, - uint16_t productId, DeviceTypeId deviceType, const char * deviceName, size_t numIPs, - chip::Inet::IPAddress * ipAddress) + uint16_t productId, chip::DeviceTypeId deviceType, const char * deviceName, + const char * hostName, size_t numIPs, chip::Inet::IPAddress * ipAddress) { ChipLogProgress(NotSpecified, "TargetVideoPlayerInfo nodeId=0x" ChipLogFormatX64 " fabricIndex=%d", ChipLogValueX64(nodeId), fabricIndex); @@ -42,7 +42,18 @@ CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIn mIpAddress[i] = ipAddress[i]; } - chip::Platform::CopyString(mDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, deviceName); + memset(mDeviceName, '\0', sizeof(mDeviceName)); + if (deviceName != nullptr) + { + chip::Platform::CopyString(mDeviceName, chip::Dnssd::kMaxDeviceNameLen + 1, deviceName); + } + + memset(mHostName, '\0', sizeof(mHostName)); + if (hostName != nullptr) + { + chip::Platform::CopyString(mHostName, chip::Dnssd::kHostNameMaxLength + 1, hostName); + } + for (auto & endpointInfo : mEndpoints) { endpointInfo.Reset(); @@ -128,8 +139,15 @@ void TargetVideoPlayerInfo::PrintInfo() } } -bool TargetVideoPlayerInfo::IsSameAs(const char * deviceName, size_t numIPs, const chip::Inet::IPAddress * ipAddresses) +bool TargetVideoPlayerInfo::IsSameAs(const char * hostName, const char * deviceName, size_t numIPs, + const chip::Inet::IPAddress * ipAddresses) { + // return true if the hostNames match + if (strcmp(mHostName, hostName) == 0) + { + return true; + } + // return false because deviceNames are different if (strcmp(mDeviceName, deviceName) != 0) { @@ -173,6 +191,6 @@ bool TargetVideoPlayerInfo::IsSameAs(const chip::Dnssd::DiscoveredNodeData * dis return false; } - return IsSameAs(discoveredNodeData->commissionData.deviceName, discoveredNodeData->resolutionData.numIPs, - discoveredNodeData->resolutionData.ipAddress); + return IsSameAs(discoveredNodeData->resolutionData.hostName, discoveredNodeData->commissionData.deviceName, + discoveredNodeData->resolutionData.numIPs, discoveredNodeData->resolutionData.ipAddress); }