Skip to content

Commit

Permalink
Merge branch 'master' into crash_issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-hh authored Mar 1, 2023
2 parents df5e427 + eff5773 commit ad48773
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 60 deletions.
4 changes: 4 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ config("strict_warnings") {
]
}

if (current_os == "mac" || current_os == "ios") {
cflags += [ "-Wconversion" ]
}

if (build_java_matter_controller) {
cflags -= [ "-Wshadow" ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class DiscoveredNodeData {
public DiscoveredNodeData(NsdServiceInfo serviceInfo) {
Map<String, byte[]> 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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class VideoPlayer {

private int numIPs;
private List<InetAddress> ipAddresses;
private String hostName;

private boolean isInitialized = false;

Expand All @@ -50,6 +51,7 @@ public VideoPlayer(
List<ContentApp> contentApps,
int numIPs,
List<InetAddress> ipAddresses,
String hostName,
boolean isConnected) {
this.nodeId = nodeId;
this.fabricIndex = fabricIndex;
Expand All @@ -61,6 +63,7 @@ public VideoPlayer(
this.isConnected = isConnected;
this.numIPs = numIPs;
this.ipAddresses = ipAddresses;
this.hostName = hostName;
this.isInitialized = true;
}

Expand All @@ -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;
Expand Down Expand Up @@ -133,6 +141,9 @@ public java.lang.String toString() {
+ ", ipAddresses="
+ ipAddresses
+ ", isInitialized="
+ ", hostName='"
+ hostName
+ '\''
+ isInitialized
+ '}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -149,7 +149,13 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe
jfieldID getDeviceNameField = env->GetFieldID(jVideoPlayerClass, "deviceName", "Ljava/lang/String;");
jstring jDeviceName = static_cast<jstring>(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<jstring>(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);
Expand Down Expand Up @@ -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, "<init>", "(JBLjava/lang/String;IIILjava/util/List;ILjava/util/List;Z)V");
jmethodID jVideoPlayerConstructor = env->GetMethodID(
jVideoPlayerClass, "<init>", "(JBLjava/lang/String;IIILjava/util/List;ILjava/util/List;Ljava/lang/String;Z)V");

jobject jContentAppList = nullptr;
TargetEndpointInfo * endpoints = targetVideoPlayerInfo->GetEndpoints();
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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<jstring>(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField));
if (jInstanceName != nullptr)
{
Expand Down Expand Up @@ -289,8 +298,11 @@ CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscovered

jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;");
jstring jDeviceName = static_cast<jstring>(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ JNI_METHOD(jboolean, verifyOrEstablishConnection)
[](CHIP_ERROR err) { TvCastingAppJNIMgr().getOnConnectionFailureHandler(true).Handle(err); },
[](TargetEndpointInfo * endpoint) { TvCastingAppJNIMgr().getOnNewOrUpdatedEndpointHandler(true).Handle(endpoint); });
VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "CastingServer::OpenBasicCommissioningWindow failed: %" CHIP_ERROR_FORMAT, err.Format()));
ChipLogError(AppServer, "CastingServer::verifyOrEstablishConnection failed: %" CHIP_ERROR_FORMAT, err.Format()));

exit:
return (err == CHIP_NO_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<chip::Inet::IPAddress *>(currentTargetVideoPlayerInfo->GetIpAddresses()));

TargetEndpointInfo * prevEndpoints = self->_previouslyConnectedVideoPlayer->GetEndpoints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CastingServer
std::function<void(CHIP_ERROR)> onConnectionFailure,
std::function<void(TargetEndpointInfo *)> onNewOrUpdatedEndpoint);

void LogCachedVideoPlayers();
CHIP_ERROR PurgeVideoPlayerCache();

/**
Expand Down Expand Up @@ -438,6 +439,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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PersistenceManager
kVideoPlayerProductIdTag,
kVideoPlayerDeviceTypeIdTag,
kVideoPlayerDeviceNameTag,
kVideoPlayerHostNameTag,
kVideoPlayerNumIPsTag,
kVideoPlayerIPAddressTag,
kIpAddressesContainerTag,
Expand Down
Loading

0 comments on commit ad48773

Please sign in to comment.