Skip to content

Commit 66389a9

Browse files
authored
[WebRTCP] Validate that the StreamUsage is in the StreamUsagePriorities list (#41776)
* Validate that the StreamUsage is in the StreamUsagePriorities list * Address review comment
1 parent 6251801 commit 66389a9

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

examples/camera-app/linux/include/clusters/webrtc-provider/webrtc-provider-manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class WebRTCProviderManager : public Delegate, public WebRTCTransportProviderCon
8080

8181
CHIP_ERROR ValidateAudioStreamID(uint16_t audioStreamId) override;
8282

83+
CHIP_ERROR IsStreamUsageSupported(StreamUsageEnum streamUsage) override;
84+
8385
CHIP_ERROR IsHardPrivacyModeActive(bool & isActive) override;
8486

8587
CHIP_ERROR IsSoftRecordingPrivacyModeActive(bool & isActive) override;

examples/camera-app/linux/src/clusters/webrtc-provider/webrtc-provider-manager.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,30 @@ CHIP_ERROR WebRTCProviderManager::ValidateAudioStreamID(uint16_t audioStreamId)
529529
return avsmController.ValidateAudioStreamID(audioStreamId);
530530
}
531531

532+
CHIP_ERROR WebRTCProviderManager::IsStreamUsageSupported(StreamUsageEnum streamUsage)
533+
{
534+
if (mCameraDevice == nullptr)
535+
{
536+
ChipLogError(Camera, "CameraDeviceInterface not initialized");
537+
return CHIP_ERROR_INCORRECT_STATE;
538+
}
539+
540+
auto & hal = mCameraDevice->GetCameraHALInterface();
541+
auto & streamUsagePriorities = hal.GetStreamUsagePriorities();
542+
543+
// Check if the streamUsage is in the StreamUsagePriorities list
544+
for (const auto & usage : streamUsagePriorities)
545+
{
546+
if (usage == streamUsage)
547+
{
548+
return CHIP_NO_ERROR;
549+
}
550+
}
551+
552+
ChipLogError(Camera, "StreamUsage %u not found in StreamUsagePriorities", to_underlying(streamUsage));
553+
return CHIP_ERROR_NOT_FOUND;
554+
}
555+
532556
CHIP_ERROR WebRTCProviderManager::IsHardPrivacyModeActive(bool & isActive)
533557
{
534558
if (mCameraDevice == nullptr)

src/app/clusters/webrtc-transport-provider-server/webrtc-transport-provider-server.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,13 @@ void WebRTCTransportProviderServer::HandleSolicitOffer(HandlerContext & ctx, con
562562
return;
563563
}
564564

565-
// TODO:#41458 If the passed in StreamUsage is not found in the StreamUsagePriorities, return DYNAMIC_CONSTRAINT_ERROR
565+
// Validate that the StreamUsage is in the StreamUsagePriorities list
566+
if (mDelegate.IsStreamUsageSupported(req.streamUsage) != CHIP_NO_ERROR)
567+
{
568+
ChipLogError(Zcl, "HandleSolicitOffer: StreamUsage %u is not in StreamUsagePriorities", to_underlying(req.streamUsage));
569+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::DynamicConstraintError);
570+
return;
571+
}
566572

567573
// Validate VideoStreamID against AllocatedVideoStreams.
568574
// If present and null then a stream has to have been allocated.
@@ -845,7 +851,13 @@ void WebRTCTransportProviderServer::HandleProvideOffer(HandlerContext & ctx, con
845851
return;
846852
}
847853

848-
// TODO:#41458 If the passed in StreamUsage is not found in the StreamUsagePriorities, return DYNAMIC_CONSTRAINT_ERROR
854+
// Validate that the StreamUsage is in the StreamUsagePriorities list
855+
if (mDelegate.IsStreamUsageSupported(req.streamUsage) != CHIP_NO_ERROR)
856+
{
857+
ChipLogError(Zcl, "HandleProvideOffer: StreamUsage %u is not in StreamUsagePriorities", to_underlying(req.streamUsage));
858+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::DynamicConstraintError);
859+
return;
860+
}
849861

850862
// If VideoStreamID is present and is not null and does not match a value in AllocatedVideoStreams:
851863
// Fail the command with the status code DYNAMIC_CONSTRAINT_ERROR

src/app/clusters/webrtc-transport-provider-server/webrtc-transport-provider-server.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,23 @@ class Delegate
243243
*/
244244
virtual CHIP_ERROR ValidateAudioStreamID(uint16_t audioStreamId) = 0;
245245

246+
/**
247+
* @brief
248+
* Checks if the given StreamUsage is in the StreamUsagePriorities list.
249+
*
250+
* This method is called during SolicitOffer and ProvideOffer command processing
251+
* to ensure that the requested stream usage is supported by the device according
252+
* to its configured priorities.
253+
*
254+
* @param[in] streamUsage The stream usage to check.
255+
*
256+
* @return CHIP_ERROR
257+
* - CHIP_NO_ERROR - StreamUsage is found in StreamUsagePriorities.
258+
* - CHIP_ERROR_NOT_FOUND - StreamUsage is not in the StreamUsagePriorities list.
259+
* - Other error codes - For failures reading the attribute itself
260+
*/
261+
virtual CHIP_ERROR IsStreamUsageSupported(Globals::StreamUsageEnum streamUsage) = 0;
262+
246263
/**
247264
* @brief Check whether hard privacy mode is active.
248265
*

0 commit comments

Comments
 (0)