Skip to content

Commit 4569574

Browse files
sharadb-amazonpull[bot]
authored andcommitted
Linux tv-casting-app: simplified Endpoints APIs and post-connection flow (#30940)
1 parent 9a7d20a commit 4569574

19 files changed

+1181
-44
lines changed

examples/tv-casting-app/APIs.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Commissioner. In the context of the
3838
[Matter Video Player architecture](https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/app_clusters/media/VideoPlayerArchitecture.adoc),
3939
a `CastingPlayer` would map to
4040
[Casting "Video" Player](https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/app_clusters/media/VideoPlayerArchitecture.adoc#1-introduction).
41-
The `CastingPlayer` is expected to be hosting one or more `Endpoints` (similar
42-
to
41+
The `CastingPlayer` is expected to be hosting one or more `Endpoints` (some of
42+
which can represent
4343
[Content Apps](https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/app_clusters/media/VideoPlayerArchitecture.adoc#1-introduction)
4444
in the Matter Video Player architecture) that support one or more Matter Media
4545
`Clusters`.
@@ -73,7 +73,10 @@ The Casting Client is expected to consume the Matter TV Casting library built
7373
for its respective platform which implements the APIs described in this
7474
document. Refer to the tv-casting-app READMEs for [Linux](linux/README.md),
7575
Android and [iOS](darwin/TvCasting/README.md) to understand how to build and
76-
consume each platform's specific libraries.
76+
consume each platform's specific libraries. The libraries MUST be built with the
77+
client's specific values for `CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID` and
78+
`CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID` updated in the
79+
[CHIPProjectAppConfig.h](tv-casting-common/include/CHIPProjectAppConfig.h) file.
7780

7881
### Initialize the Casting Client
7982

@@ -474,19 +477,33 @@ to a `CastingPlayer`, once the Casting client has been commissioned by it. After
474477
that, the Casting client is able to skip the full UDC process by establishing
475478
CASE with the `CastingPlayer` directly. Once connected, the `CastingPlayer`
476479
object will contain the list of available Endpoints on that `CastingPlayer`.
480+
Optionally, the following arguments may also be passed in. The optional
481+
`commissioningWindowTimeoutSec` indicates how long to keep the commissioning
482+
window open, if commissioning is required. And `DesiredEndpointFilter` specifies
483+
the attributes, such as Vendor ID and Product ID of the `Endpoint`, the Casting
484+
client desires to interact with after connecting. This forces the Matter TV
485+
Casting library to go through the full UDC process in search of the desired
486+
Endpoint, in cases where it is not available in the Casting client's cache.
477487
478488
On Linux, the Casting Client can connect to a `CastingPlayer` by successfully
479489
calling `VerifyOrEstablishConnection` on it.
480490
481491
```c
492+
493+
const uint16_t kDesiredEndpointVendorId = 65521;
494+
482495
void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer)
483496
{
484497
ChipLogProgress(AppServer, "ConnectionHandler called with %" CHIP_ERROR_FORMAT, err.Format());
485498
}
486499
487500
...
488501
// targetCastingPlayer is a discovered CastingPlayer
489-
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler);
502+
matter::casting::core::EndpointFilter desiredEndpointFilter;
503+
desiredEndpointFilter.vendorId = kDesiredEndpointVendorId;
504+
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler,
505+
matter::casting::core::kCommissioningWindowTimeoutSec,
506+
desiredEndpointFilter);
490507
...
491508
```
492509

examples/tv-casting-app/linux/simple-app-helper.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
#include "simple-app-helper.h"
1818

19+
#include "clusters/ContentLauncherCluster.h"
20+
1921
#include "app/clusters/bindings/BindingManager.h"
2022
#include <inttypes.h>
2123
#include <lib/core/CHIPCore.h>
@@ -27,6 +29,9 @@
2729
#include <lib/support/CodeUtils.h>
2830
#include <platform/CHIPDeviceLayer.h>
2931

32+
// VendorId of the Endpoint on the CastingPlayer that the CastingApp desires to interact with after connection
33+
const uint16_t kDesiredEndpointVendorId = 65521;
34+
3035
DiscoveryDelegateImpl * DiscoveryDelegateImpl::_discoveryDelegateImpl = nullptr;
3136

3237
DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()
@@ -102,7 +107,11 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
102107
VerifyOrReturnValue(0 <= index && index < castingPlayers.size(), CHIP_ERROR_INVALID_ARGUMENT,
103108
ChipLogError(AppServer, "Invalid casting player index provided: %lu", index));
104109
std::shared_ptr<matter::casting::core::CastingPlayer> targetCastingPlayer = castingPlayers.at(index);
105-
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler);
110+
111+
matter::casting::core::EndpointFilter desiredEndpointFilter;
112+
desiredEndpointFilter.vendorId = kDesiredEndpointVendorId;
113+
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler, matter::casting::core::kCommissioningWindowTimeoutSec,
114+
desiredEndpointFilter);
106115
return CHIP_NO_ERROR;
107116
}
108117
if (strcmp(argv[0], "print-bindings") == 0)

examples/tv-casting-app/linux/simple-app-helper.h

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "core/CastingPlayer.h"
2222
#include "core/CastingPlayerDiscovery.h"
2323
#include "core/Types.h"
24-
2524
#include <platform/CHIPDeviceLayer.h>
2625

2726
/**

examples/tv-casting-app/tv-casting-common/BUILD.gn

+8
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,27 @@ chip_data_model("tv-casting-common") {
9393

9494
# Add simplified casting API files here
9595
sources += [
96+
"clusters/ContentLauncherCluster.h",
97+
"clusters/MediaPlaybackCluster.h",
98+
"clusters/TargetNavigatorCluster.h",
99+
"core/Attribute.h",
96100
"core/CastingApp.cpp",
97101
"core/CastingApp.h",
98102
"core/CastingPlayer.cpp",
99103
"core/CastingPlayer.h",
100104
"core/CastingPlayerDiscovery.cpp",
101105
"core/CastingPlayerDiscovery.h",
106+
"core/Cluster.h",
107+
"core/Endpoint.h",
102108
"core/Types.h",
103109
"support/AppParameters.h",
104110
"support/CastingStore.cpp",
105111
"support/CastingStore.h",
106112
"support/ChipDeviceEventHandler.cpp",
107113
"support/ChipDeviceEventHandler.h",
108114
"support/DataProvider.h",
115+
"support/EndpointListLoader.cpp",
116+
"support/EndpointListLoader.h",
109117
]
110118

111119
deps = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "core/Endpoint.h"
22+
#include "core/Types.h"
23+
24+
#include "lib/support/logging/CHIPLogging.h"
25+
26+
namespace matter {
27+
namespace casting {
28+
namespace clusters {
29+
30+
class ContentLauncherCluster : public core::BaseCluster
31+
{
32+
private:
33+
protected:
34+
public:
35+
ContentLauncherCluster(memory::Weak<core::Endpoint> endpoint) : core::BaseCluster(endpoint) {}
36+
37+
// TODO:
38+
// LaunchURL(const char * contentUrl, const char * contentDisplayStr,
39+
// chip::Optional<chip::app::Clusters::ContentLauncher::Structs::BrandingInformationStruct::Type> brandingInformation);
40+
};
41+
42+
}; // namespace clusters
43+
}; // namespace casting
44+
}; // namespace matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "core/Endpoint.h"
22+
#include "core/Types.h"
23+
24+
#include "lib/support/logging/CHIPLogging.h"
25+
26+
namespace matter {
27+
namespace casting {
28+
namespace clusters {
29+
30+
class MediaPlaybackCluster : public core::BaseCluster
31+
{
32+
private:
33+
protected:
34+
public:
35+
MediaPlaybackCluster(memory::Weak<core::Endpoint> endpoint) : core::BaseCluster(endpoint) {}
36+
37+
// TODO: add commands
38+
};
39+
40+
}; // namespace clusters
41+
}; // namespace casting
42+
}; // namespace matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "core/Endpoint.h"
22+
#include "core/Types.h"
23+
24+
#include "lib/support/logging/CHIPLogging.h"
25+
26+
namespace matter {
27+
namespace casting {
28+
namespace clusters {
29+
30+
class TargetNavigatorCluster : public core::BaseCluster
31+
{
32+
private:
33+
protected:
34+
public:
35+
TargetNavigatorCluster(memory::Weak<core::Endpoint> endpoint) : core::BaseCluster(endpoint) {}
36+
37+
// TODO: add commands
38+
};
39+
40+
}; // namespace clusters
41+
}; // namespace casting
42+
}; // namespace matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "Cluster.h"
22+
#include "Types.h"
23+
24+
#include "lib/support/logging/CHIPLogging.h"
25+
26+
namespace matter {
27+
namespace casting {
28+
namespace core {
29+
30+
enum ReadAttributeError
31+
{
32+
READ_ATTRIBUTE_NO_ERROR
33+
};
34+
35+
enum WriteAttributeError
36+
{
37+
WRITE_ATTRIBUTE_NO_ERROR
38+
};
39+
40+
template <typename ValueType>
41+
using ReadAttributeCallback = std::function<void(Optional<ValueType> before, ValueType after, ReadAttributeError)>;
42+
43+
using WriteAttributeCallback = std::function<void(WriteAttributeError)>;
44+
45+
class BaseCluster;
46+
47+
template <typename ValueType>
48+
class Attribute
49+
{
50+
private:
51+
memory::Weak<BaseCluster> cluster;
52+
ValueType value;
53+
54+
public:
55+
Attribute(memory::Weak<BaseCluster> cluster) { this->cluster = cluster; }
56+
57+
~Attribute() {}
58+
59+
Attribute() = delete;
60+
Attribute(Attribute & other) = delete;
61+
void operator=(const Attribute &) = delete;
62+
63+
protected:
64+
memory::Strong<BaseCluster> GetCluster() const { return cluster.lock(); }
65+
66+
public:
67+
ValueType GetValue();
68+
void Read(ReadAttributeCallback<ValueType> onRead);
69+
void Write(ValueType value, WriteAttributeCallback onWrite);
70+
bool SubscribeAttribute(AttributeId attributeId, ReadAttributeCallback<ValueType> callback);
71+
bool UnsubscribeAttribute(AttributeId attributeId, ReadAttributeCallback<ValueType> callback);
72+
};
73+
74+
}; // namespace core
75+
}; // namespace casting
76+
}; // namespace matter

0 commit comments

Comments
 (0)