@@ -107,24 +107,28 @@ CHIP_ERROR CameraAVStreamMgmtServer::Init()
107
107
108
108
if (SupportsOptAttr (OptionalAttribute::kSupportsNightVision ) || SupportsOptAttr (OptionalAttribute::kSupportsNightVisionIllum ))
109
109
{
110
- VerifyOrReturnError (
111
- HasFeature (Feature::kVideo ) || HasFeature (Feature::kSnapshot ), CHIP_ERROR_INVALID_ARGUMENT,
112
- ChipLogError (Zcl, " CameraAVStreamMgmt: Feature configuration error. if NIghtVision is enabled, then Video|Snapshot feature required" ));
110
+ VerifyOrReturnError (HasFeature (Feature::kVideo ) || HasFeature (Feature::kSnapshot ), CHIP_ERROR_INVALID_ARGUMENT,
111
+ ChipLogError (Zcl,
112
+ " CameraAVStreamMgmt: Feature configuration error. if NIghtVision is enabled, then "
113
+ " Video|Snapshot feature required" ));
113
114
}
114
115
115
116
if (SupportsOptAttr (OptionalAttribute::kSupportsMicrophoneAGCEnabled ))
116
117
{
117
118
VerifyOrReturnError (
118
119
HasFeature (Feature::kAudio ), CHIP_ERROR_INVALID_ARGUMENT,
119
- ChipLogError (Zcl, " CameraAVStreamMgmt: Feature configuration error. if MicrophoneAGCEnabled, then Audio feature required" ));
120
+ ChipLogError (Zcl,
121
+ " CameraAVStreamMgmt: Feature configuration error. if MicrophoneAGCEnabled, then Audio feature required" ));
120
122
}
121
123
122
- if (SupportsOptAttr (OptionalAttribute::kSupportsImageFlipHorizontal ) || SupportsOptAttr (OptionalAttribute::kSupportsImageFlipVertical ) ||
124
+ if (SupportsOptAttr (OptionalAttribute::kSupportsImageFlipHorizontal ) ||
125
+ SupportsOptAttr (OptionalAttribute::kSupportsImageFlipVertical ) ||
123
126
SupportsOptAttr (OptionalAttribute::kSupportsImageRotation ))
124
127
{
125
- VerifyOrReturnError (
126
- HasFeature (Feature::kImageControl ), CHIP_ERROR_INVALID_ARGUMENT,
127
- ChipLogError (Zcl, " CameraAVStreamMgmt: Feature configuration error. if ImageFlip or Rotation enabled, then ImageControl feature required" ));
128
+ VerifyOrReturnError (HasFeature (Feature::kImageControl ), CHIP_ERROR_INVALID_ARGUMENT,
129
+ ChipLogError (Zcl,
130
+ " CameraAVStreamMgmt: Feature configuration error. if ImageFlip or Rotation enabled, then "
131
+ " ImageControl feature required" ));
128
132
}
129
133
130
134
LoadPersistentAttributes ();
@@ -1463,7 +1467,7 @@ void CameraAVStreamMgmtServer::HandleVideoStreamAllocate(HandlerContext & ctx,
1463
1467
auto & maxFragmentLen = commandData.maxFragmentLen ;
1464
1468
auto & isWaterMarkEnabled = commandData.watermarkEnabled ;
1465
1469
auto & isOSDEnabled = commandData.OSDEnabled ;
1466
- uint16_t videoStreamID = 0 ;
1470
+ uint16_t videoStreamID = 0 ;
1467
1471
1468
1472
// If Watermark feature is supported, then command should have the
1469
1473
// isWaterMarkEnabled param. Or, if it is not supported, then command should
@@ -1479,6 +1483,22 @@ void CameraAVStreamMgmtServer::HandleVideoStreamAllocate(HandlerContext & ctx,
1479
1483
(!HasFeature (Feature::kOnScreenDisplay ) && !commandData.OSDEnabled .HasValue ()),
1480
1484
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::InvalidCommand));
1481
1485
1486
+ VerifyOrReturn (IsStreamUsageValid (streamUsage), {
1487
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid stream usage" );
1488
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::InvalidCommand);
1489
+ });
1490
+
1491
+ VerifyOrReturn (IsVideoCodecValid (videoCodec), {
1492
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid video codec" );
1493
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::InvalidCommand);
1494
+ });
1495
+
1496
+ VerifyOrReturn (minFrameRate <= maxFrameRate, ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError));
1497
+
1498
+ VerifyOrReturn (minBitRate <= maxBitRate, ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError));
1499
+
1500
+ VerifyOrReturn (minFragmentLen <= maxFragmentLen, ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError));
1501
+
1482
1502
// Call the delegate
1483
1503
status =
1484
1504
mDelegate .VideoStreamAllocate (streamUsage, videoCodec, minFrameRate, maxFrameRate, minResolution, maxResolution, minBitRate,
@@ -1558,6 +1578,31 @@ void CameraAVStreamMgmtServer::HandleAudioStreamAllocate(HandlerContext & ctx,
1558
1578
auto & bitDepth = commandData.bitDepth ;
1559
1579
uint16_t audioStreamID = 0 ;
1560
1580
1581
+ VerifyOrReturn (IsStreamUsageValid (streamUsage), {
1582
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid stream usage" );
1583
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1584
+ });
1585
+
1586
+ VerifyOrReturn (IsAudioCodecValid (audioCodec), {
1587
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid audio codec" );
1588
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1589
+ });
1590
+
1591
+ VerifyOrReturn (sampleRate > 0 && bitRate > 0 , {
1592
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid sampleRate or bitRate " );
1593
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1594
+ });
1595
+
1596
+ VerifyOrReturn (IsBitDepthValid (bitDepth), {
1597
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid bitDepth" );
1598
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1599
+ });
1600
+
1601
+ VerifyOrReturn (channelCount <= kMaxChannelCount , {
1602
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid channel count" );
1603
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1604
+ });
1605
+
1561
1606
// Call the delegate
1562
1607
Status status =
1563
1608
mDelegate .AudioStreamAllocate (streamUsage, audioCodec, channelCount, sampleRate, bitRate, bitDepth, audioStreamID);
@@ -1604,6 +1649,21 @@ void CameraAVStreamMgmtServer::HandleSnapshotStreamAllocate(HandlerContext & ctx
1604
1649
auto & quality = commandData.quality ;
1605
1650
uint16_t snapshotStreamID = 0 ;
1606
1651
1652
+ VerifyOrReturn (IsImageCodecValid (imageCodec), {
1653
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid image codec" );
1654
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Protocols::InteractionModel::Status::InvalidCommand);
1655
+ });
1656
+
1657
+ VerifyOrReturn (maxFrameRate > 0 && bitRate > 0 , {
1658
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid maxFrameRate or bitRate" );
1659
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1660
+ });
1661
+
1662
+ VerifyOrReturn (quality > 0 && quality <= kMaxImageQualityMetric , {
1663
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid image quality" );
1664
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::ConstraintError);
1665
+ });
1666
+
1607
1667
// Call the delegate
1608
1668
Status status = mDelegate .SnapshotStreamAllocate (imageCodec, maxFrameRate, bitRate, minResolution, maxResolution, quality,
1609
1669
snapshotStreamID);
@@ -1642,16 +1702,22 @@ void CameraAVStreamMgmtServer::HandleSetStreamPriorities(HandlerContext & ctx,
1642
1702
{
1643
1703
1644
1704
auto & streamPriorities = commandData.streamPriorities ;
1645
- // auto & streamPriorities = commandData.streamPriorities;
1705
+ // auto & streamPriorities = commandData.streamPriorities;
1646
1706
1647
1707
auto iter = streamPriorities.begin ();
1648
1708
StreamUsageEnum rankedStreamPriorities[kNumOfStreamUsageTypes ];
1649
1709
int i = 0 ;
1650
- while (iter.Next ())
1710
+ while (iter.Next ())
1651
1711
{
1652
- auto & streamUsage = iter.GetValue ();
1712
+ auto & streamUsage = iter.GetValue ();
1653
1713
rankedStreamPriorities[i++] = streamUsage;
1654
1714
}
1715
+
1716
+ VerifyOrReturn (i == kNumOfStreamUsageTypes , {
1717
+ ChipLogError (Zcl, " CameraAVStreamMgmt: Invalid num of stream usages" );
1718
+ ctx.mCommandHandler .AddStatus (ctx.mRequestPath , Status::InvalidCommand);
1719
+ });
1720
+
1655
1721
CHIP_ERROR err = SetRankedVideoStreamPriorities (rankedStreamPriorities);
1656
1722
1657
1723
if (err != CHIP_NO_ERROR)
0 commit comments