Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Oct 15, 2022
1 parent 70be782 commit aad708c
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.chip.casting;

public class ContentApp
{
private short endpointId;
private List<Integer> clusterIds;

private boolean isInitialized = false;

public ContentApp(short endpointId, List<Integer> clusterIds) {
this.endpointId = endpointId;
this.clusterIds = clusterIds;
this.isInitialized = true;
}

public short getEndpointId() {
return endpointId;
}

public List<Integer> getClusterIds() {
return clusterIds;
}

public boolean isInitialized() {
return isInitialized;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.chip.casting;

public class VideoPlayer
{
private long nodeId;
private byte fabricIndex;
private String deviceName;
private short vendorId;
private short productId;
private short deviceType;
private List<ContentApp> contentApps;
private boolean isConnected = false;

private boolean isInitialized = false;

public VideoPlayer(long nodeId, byte fabricIndex, String deviceName, short vendorId, short productId, short deviceType, List<ContentApp> contentApps, boolean isConnected) {
this.nodeId = nodeId;
this.fabricIndex = fabricIndex;
this.deviceName = deviceName;
this.vendorId = vendorId;
this.productId = productId;
this.deviceType = deviceType;
this.contentApps = contentApps;
this.isConnected = isConnected;
this.isInitialized = true;
}

public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
if (!super.equals(object)) return false;
VideoPlayer that = (VideoPlayer) object;
return nodeId == that.nodeId && fabricIndex == that.fabricIndex;
}

public int hashCode() {
return Objects.hash(super.hashCode(), nodeId, fabricIndex);
}

public long getNodeId() {
return nodeId;
}

public byte getFabricIndex() {
return fabricIndex;
}

public boolean isConnected() {
return isConnected;
}

public List<ContentApp> getContentApps() {
return contentApps;
}

public String getDeviceName() {
return deviceName;
}

public short getVendorId() {
return vendorId;
}

public short getProductId() {
return productId;
}

public short getDeviceType() {
return deviceType;
}

public boolean isInitialized() {
return isInitialized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,9 @@ - (void)readCachedVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue
videoPlayers = [NSMutableArray new];
for (size_t i = 0; cppTargetVideoPlayerInfos[i].IsInitialized(); i++) {
ChipLogProgress(AppServer,
"CastingServerBridge().readCachedVideoPlayers() with nodeId: %lu fabricIndex: %d deviceName: %s vendorId: %d",
cppTargetVideoPlayerInfos[i].GetNodeId(), cppTargetVideoPlayerInfos[i].GetFabricIndex(),
"CastingServerBridge().readCachedVideoPlayers() with nodeId: 0x" ChipLogFormatX64
" fabricIndex: %d deviceName: %s vendorId: %d",
ChipLogValueX64(cppTargetVideoPlayerInfos[i].GetNodeId()), cppTargetVideoPlayerInfos[i].GetFabricIndex(),
cppTargetVideoPlayerInfos[i].GetDeviceName(), cppTargetVideoPlayerInfos[i].GetVendorId());
videoPlayers[i] = [ConversionUtils convertToObjCVideoPlayerFrom:&cppTargetVideoPlayerInfos[i]];
}
Expand Down
17 changes: 9 additions & 8 deletions examples/tv-casting-app/linux/CastingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ void doCastingDemoActions(TargetEndpointInfo * endpoint)
void OnConnectionSuccess(TargetVideoPlayerInfo * videoPlayer)
{
ChipLogProgress(AppServer,
"OnConnectionSuccess with Video Player(nodeId: %lu, fabricIndex: %d, deviceName: %s, vendorId: %d, productId: "
"OnConnectionSuccess with Video Player(nodeId: 0x" ChipLogFormatX64
", fabricIndex: %d, deviceName: %s, vendorId: %d, productId: "
"%d, deviceType: %d)",
videoPlayer->GetNodeId(), videoPlayer->GetFabricIndex(), videoPlayer->GetDeviceName(),
ChipLogValueX64(videoPlayer->GetNodeId()), videoPlayer->GetFabricIndex(), videoPlayer->GetDeviceName(),
videoPlayer->GetVendorId(), videoPlayer->GetProductId(), videoPlayer->GetDeviceType());

TargetEndpointInfo * endpoints = videoPlayer->GetEndpoints();
Expand Down Expand Up @@ -245,15 +246,15 @@ CHIP_ERROR ConnectToCachedVideoPlayer()
{
if (cachedVideoPlayers[i].IsInitialized())
{
ChipLogProgress(AppServer, "Found a Cached video player with nodeId: %lu, fabricIndex: %d",
cachedVideoPlayers[i].GetNodeId(), cachedVideoPlayers[i].GetFabricIndex());
ChipLogProgress(AppServer, "Found a Cached video player with nodeId: 0x" ChipLogFormatX64 ", fabricIndex: %d",
ChipLogValueX64(cachedVideoPlayers[i].GetNodeId()), cachedVideoPlayers[i].GetFabricIndex());
if (CastingServer::GetInstance()->VerifyOrEstablishConnection(
cachedVideoPlayers[i], OnConnectionSuccess, OnConnectionFailure, OnNewOrUpdatedEndpoint) == CHIP_NO_ERROR)
{
ChipLogProgress(
AppServer,
"FindOrEstablish CASESession attempted for cached video player with nodeId: %lu, fabricIndex: %d",
cachedVideoPlayers[i].GetNodeId(), cachedVideoPlayers[i].GetFabricIndex());
ChipLogProgress(AppServer,
"FindOrEstablish CASESession attempted for cached video player with nodeId: 0x" ChipLogFormatX64
", fabricIndex: %d",
ChipLogValueX64(cachedVideoPlayers[i].GetNodeId()), cachedVideoPlayers[i].GetFabricIndex());
return CHIP_NO_ERROR;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ class CastingServer
CHIP_ERROR SendUserDirectedCommissioningRequest(chip::Dnssd::DiscoveredNodeData * selectedCommissioner);
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT

TargetVideoPlayerInfo * GetActiveTargetVideoPlayer()
{
return mActiveTargetVideoPlayerInfo.IsInitialized() && mActiveTargetVideoPlayerInfo.GetOperationalDeviceProxy() != nullptr
? &mActiveTargetVideoPlayerInfo
: nullptr;
}
TargetVideoPlayerInfo * GetActiveTargetVideoPlayer() { return &mActiveTargetVideoPlayerInfo; }

CHIP_ERROR TargetVideoPlayerInfoInit(chip::NodeId nodeId, chip::FabricIndex fabricIndex,
std::function<void(TargetVideoPlayerInfo *)> onConnectionSuccess,
std::function<void(CHIP_ERROR)> onConnectionFailure,
Expand Down
6 changes: 4 additions & 2 deletions examples/tv-casting-app/tv-casting-common/include/MediaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class MediaBase
auto deviceProxy = targetVideoPlayerInfo.GetOperationalDeviceProxy();
if (deviceProxy == nullptr)
{
ChipLogError(AppServer, "Failed in getting an instance of OperationalDeviceProxy for nodeId: %lu, fabricIndex: %d",
targetVideoPlayerInfo.GetNodeId(), targetVideoPlayerInfo.GetFabricIndex());
ChipLogError(AppServer,
"Failed in getting an instance of OperationalDeviceProxy for nodeId: 0x" ChipLogFormatX64
", fabricIndex: %d",
ChipLogValueX64(targetVideoPlayerInfo.GetNodeId()), targetVideoPlayerInfo.GetFabricIndex());
return CHIP_ERROR_PEER_NODE_NOT_FOUND;
}
mTargetVideoPlayerInfo = &targetVideoPlayerInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class TargetVideoPlayerInfo
_this->mDeviceProxy = chip::OperationalDeviceProxy(&exchangeMgr, sessionHandle);
_this->mInitialized = true;
ChipLogProgress(AppServer,
"HandleDeviceConnected created an instance of OperationalDeviceProxy for nodeId: %lu, fabricIndex: %d",
_this->GetNodeId(), _this->GetFabricIndex());
"HandleDeviceConnected created an instance of OperationalDeviceProxy for nodeId: 0x" ChipLogFormatX64
", fabricIndex: %d",
ChipLogValueX64(_this->GetNodeId()), _this->GetFabricIndex());

if (_this->mOnConnectionSuccessClientCallback)
{
Expand All @@ -85,10 +86,10 @@ class TargetVideoPlayerInfo

static void HandleDeviceConnectionFailure(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
{
ChipLogError(
AppServer,
"HandleDeviceConnectionFailure called for peerId.nodeId: %lu, peer.fabricIndex: %d with error: %" CHIP_ERROR_FORMAT,
peerId.GetNodeId(), peerId.GetFabricIndex(), error.AsString());
ChipLogError(AppServer,
"HandleDeviceConnectionFailure called for peerId.nodeId: 0x" ChipLogFormatX64
", peer.fabricIndex: %d with error: %" CHIP_ERROR_FORMAT,
ChipLogValueX64(peerId.GetNodeId()), peerId.GetFabricIndex(), error.AsString());
TargetVideoPlayerInfo * _this = static_cast<TargetVideoPlayerInfo *>(context);
_this->mDeviceProxy = chip::OperationalDeviceProxy();
if (_this->mOnConnectionFailureClientCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta
mOnNewOrUpdatedEndpoint = onNewOrUpdatedEndpoint;

return targetVideoPlayerInfo.FindOrEstablishCASESession(
[](TargetVideoPlayerInfo * targetVideoPlayerInfo) {
[](TargetVideoPlayerInfo * videoPlayer) {
ChipLogProgress(AppServer, "CastingServer::OnConnectionSuccess lambda called");
chip::OperationalDeviceProxy * prevDeviceProxy =
CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo.GetOperationalDeviceProxy();
Expand All @@ -264,8 +264,8 @@ CHIP_ERROR CastingServer::VerifyOrEstablishConnection(TargetVideoPlayerInfo & ta
ChipLogProgress(AppServer, "CastingServer::OnConnectionSuccess lambda Disconnecting deviceProxy");
prevDeviceProxy->Disconnect();
}
CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = *targetVideoPlayerInfo;
CastingServer::GetInstance()->mOnConnectionSuccessClientCallback(targetVideoPlayerInfo);
CastingServer::GetInstance()->mActiveTargetVideoPlayerInfo = *videoPlayer;
CastingServer::GetInstance()->mOnConnectionSuccessClientCallback(videoPlayer);
},
onConnectionFailure);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide
size_t castingDataSize = 0;
ReturnErrorOnFailure(chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(kCastingDataKey, castingData,
kCastingDataMaxBytes, &castingDataSize));
ChipLogProgress(AppServer, "PersistenceManager::ReadAllVideoPlayers Read TLV(CastingData) from KVS store with size: %zu bytes",
ChipLogProgress(AppServer, "PersistenceManager::ReadAllVideoPlayers Read TLV(CastingData) from KVS store with size: %lu bytes",
castingDataSize);

TLV::TLVReader reader;
Expand Down

0 comments on commit aad708c

Please sign in to comment.