-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathTC_WEBRTCPTestBase.py
More file actions
196 lines (166 loc) · 9.81 KB
/
TC_WEBRTCPTestBase.py
File metadata and controls
196 lines (166 loc) · 9.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#
# Copyright (c) 2025 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.
import logging
from mobly import asserts
import matter.clusters as Clusters
from matter.clusters import Globals
from matter.interaction_model import InteractionModelError, Status
log = logging.getLogger(__name__)
class WEBRTCPTestBase:
async def allocate_one_audio_stream(self):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
commands = Clusters.CameraAvStreamManagement.Commands
# First verify that ADO is supported
aFeatureMap = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attr.FeatureMap)
log.info(f"Rx'd FeatureMap: {aFeatureMap}")
adoSupport = aFeatureMap & cluster.Bitmaps.Feature.kAudio
asserts.assert_equal(adoSupport, cluster.Bitmaps.Feature.kAudio, "Audio Feature is not supported.")
# Check if audio stream has already been allocated
aAllocatedAudioStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedAudioStreams
)
log.info(f"Rx'd AllocatedAudioStreams: {aAllocatedAudioStreams}")
if len(aAllocatedAudioStreams) > 0:
return aAllocatedAudioStreams[0].audioStreamID
# Allocate one for the test steps based on SnapshotCapabilities
aMicrophoneCapabilities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MicrophoneCapabilities
)
log.info(f"Rx'd MicrophoneCapabilities: {aMicrophoneCapabilities}")
aStreamUsagePriorities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.StreamUsagePriorities
)
log.info(f"Rx'd StreamUsagePriorities : {aStreamUsagePriorities}")
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
if (Globals.Enums.StreamUsageEnum.kLiveView not in aStreamUsagePriorities):
asserts.fail("Camera doesn't support live view")
try:
adoStreamAllocateCmd = commands.AudioStreamAllocate(
streamUsage=Globals.Enums.StreamUsageEnum.kLiveView,
audioCodec=aMicrophoneCapabilities.supportedCodecs[0],
channelCount=aMicrophoneCapabilities.maxNumberOfChannels,
sampleRate=aMicrophoneCapabilities.supportedSampleRates[0],
bitRate=1024,
bitDepth=aMicrophoneCapabilities.supportedBitDepths[0],
)
audioStreamAllocateResponse = await self.send_single_cmd(endpoint=endpoint, cmd=adoStreamAllocateCmd)
log.info(f"Rx'd AudioStreamAllocateResponse: {audioStreamAllocateResponse}")
asserts.assert_is_not_none(
audioStreamAllocateResponse.audioStreamID, "AudioStreamAllocateResponse does not contain StreamID"
)
return audioStreamAllocateResponse.audioStreamID
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
pass
async def allocate_one_video_stream(self):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
commands = Clusters.CameraAvStreamManagement.Commands
# First verify that VDO is supported
aFeatureMap = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attr.FeatureMap)
log.info(f"Rx'd FeatureMap: {aFeatureMap}")
vdoSupport = aFeatureMap & cluster.Bitmaps.Feature.kVideo
asserts.assert_equal(vdoSupport, cluster.Bitmaps.Feature.kVideo, "Video Feature is not supported.")
# Check if video stream has already been allocated
aAllocatedVideoStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedVideoStreams
)
log.info(f"Rx'd AllocatedVideoStreams: {aAllocatedVideoStreams}")
if len(aAllocatedVideoStreams) > 0:
return aAllocatedVideoStreams[0].videoStreamID
# Allocate one for the test steps
aStreamUsagePriorities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.StreamUsagePriorities
)
log.info(f"Rx'd StreamUsagePriorities: {aStreamUsagePriorities}")
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
if (Globals.Enums.StreamUsageEnum.kLiveView not in aStreamUsagePriorities):
asserts.fail("Camera doesn't support live view")
aRateDistortionTradeOffPoints = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.RateDistortionTradeOffPoints
)
log.info(f"Rx'd RateDistortionTradeOffPoints: {aRateDistortionTradeOffPoints}")
aMinViewportRes = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MinViewportResolution
)
log.info(f"Rx'd MinViewportResolution: {aMinViewportRes}")
aVideoSensorParams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.VideoSensorParams
)
log.info(f"Rx'd VideoSensorParams: {aVideoSensorParams}")
aMaxEncodedPixelRate = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MaxEncodedPixelRate
)
log.info(f"Rx'd MaxEncodedPixelRate: {aMaxEncodedPixelRate}")
# Check for Watermark and OSD features
watermark = True if (aFeatureMap & cluster.Bitmaps.Feature.kWatermark) != 0 else None
osd = True if (aFeatureMap & cluster.Bitmaps.Feature.kOnScreenDisplay) != 0 else None
try:
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
asserts.assert_greater(len(aRateDistortionTradeOffPoints), 0, "RateDistortionTradeOffPoints is empty")
videoStreamAllocateCmd = commands.VideoStreamAllocate(
streamUsage=Globals.Enums.StreamUsageEnum.kLiveView,
videoCodec=aRateDistortionTradeOffPoints[0].codec,
minFrameRate=min(self.matter_test_config.min_frame_rate, aVideoSensorParams.maxFPS),
maxFrameRate=aVideoSensorParams.maxFPS,
minResolution=aMinViewportRes,
maxResolution=cluster.Structs.VideoResolutionStruct(
width=aVideoSensorParams.sensorWidth, height=aVideoSensorParams.sensorHeight
),
minBitRate=aRateDistortionTradeOffPoints[0].minBitRate,
maxBitRate=aRateDistortionTradeOffPoints[0].minBitRate,
keyFrameInterval=4000,
watermarkEnabled=watermark,
OSDEnabled=osd
)
videoStreamAllocateResponse = await self.send_single_cmd(endpoint=endpoint, cmd=videoStreamAllocateCmd)
log.info(f"Rx'd VideoStreamAllocateResponse: {videoStreamAllocateResponse}")
asserts.assert_is_not_none(
videoStreamAllocateResponse.videoStreamID, "VideoStreamAllocateResponse does not contain StreamID"
)
return videoStreamAllocateResponse.videoStreamID
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
pass
async def validate_allocated_video_stream(self, videoStreamID):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
# Make sure the DUT allocated sterams as requested
aAllocatedVideoStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedVideoStreams
)
if not any(stream.videoStreamID == videoStreamID for stream in aAllocatedVideoStreams):
asserts.fail(f"Video Stream with ID {videoStreamID} not found as expected")
async def validate_allocated_audio_stream(self, audioStreamID):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
# Make sure the DUT allocated sterams as requested
aAllocatedAudioStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedAudioStreams
)
if not any(stream.audioStreamID == audioStreamID for stream in aAllocatedAudioStreams):
asserts.fail(f"Audio Stream with ID {audioStreamID} not found as expected")
async def is_battery_powered(self):
# Check if battery feature is supported, Power Source has to be on the Root Node
aFeatureMap = await self.read_single_attribute_check_success(
endpoint=0, cluster=Clusters.PowerSource, attribute=Clusters.PowerSource.Attributes.FeatureMap
)
return aFeatureMap & Clusters.PowerSource.Bitmaps.Feature.kBattery