113113function CameraAttributeHandlers .rate_distortion_trade_off_points_handler (driver , device , ib , response )
114114 if not ib .data .elements then return end
115115 local resolutions = {}
116- local max_encoded_pixel_rate = device :get_field (camera_fields .MAX_ENCODED_PIXEL_RATE )
117- local max_fps = device :get_field (camera_fields .MAX_FRAMES_PER_SECOND )
118- local emit_capability = max_encoded_pixel_rate ~= nil and max_fps ~= nil
119116 for _ , v in ipairs (ib .data .elements ) do
120117 local rate_distortion_trade_off_points = v .elements
121118 local width = rate_distortion_trade_off_points .resolution .elements .width .value
@@ -124,77 +121,63 @@ function CameraAttributeHandlers.rate_distortion_trade_off_points_handler(driver
124121 width = width ,
125122 height = height
126123 })
127- if emit_capability then
128- local fps = camera_utils .compute_fps (max_encoded_pixel_rate , width , height , max_fps )
129- if fps > 0 then
130- resolutions [# resolutions ].fps = fps
131- end
132- end
133- end
134- if emit_capability then
135- device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (resolutions ))
136124 end
137125 device :set_field (camera_fields .SUPPORTED_RESOLUTIONS , resolutions )
126+ local max_encoded_pixel_rate = device :get_field (camera_fields .MAX_ENCODED_PIXEL_RATE )
127+ local max_fps = device :get_field (camera_fields .MAX_FRAMES_PER_SECOND )
128+ if max_encoded_pixel_rate and max_fps and device :get_field (camera_fields .MAX_RESOLUTION ) and device :get_field (camera_fields .MIN_RESOLUTION ) then
129+ local supported_resolutions = camera_utils .build_supported_resolutions (device , max_encoded_pixel_rate , max_fps )
130+ device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (supported_resolutions ))
131+ end
138132end
139133
140134function CameraAttributeHandlers .max_encoded_pixel_rate_handler (driver , device , ib , response )
141- local resolutions = device :get_field (camera_fields .SUPPORTED_RESOLUTIONS )
135+ device :set_field (camera_fields .MAX_ENCODED_PIXEL_RATE , ib . data . value )
142136 local max_fps = device :get_field (camera_fields .MAX_FRAMES_PER_SECOND )
143- local emit_capability = resolutions ~= nil and max_fps ~= nil
144- if emit_capability then
145- for _ , v in pairs (resolutions or {}) do
146- local fps = camera_utils .compute_fps (ib .data .value , v .width , v .height , max_fps )
147- if fps > 0 then
148- v .fps = fps
149- end
150- end
151- device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (resolutions ))
137+ if max_fps and device :get_field (camera_fields .SUPPORTED_RESOLUTIONS ) and device :get_field (camera_fields .MAX_RESOLUTION ) and device :get_field (camera_fields .MIN_RESOLUTION ) then
138+ local supported_resolutions = camera_utils .build_supported_resolutions (device , ib .data .value , max_fps )
139+ device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (supported_resolutions ))
152140 end
153- device :set_field (camera_fields .MAX_ENCODED_PIXEL_RATE , ib .data .value )
154141end
155142
156143function CameraAttributeHandlers .video_sensor_parameters_handler (driver , device , ib , response )
157144 if not ib .data .elements then return end
158- local resolutions = device :get_field (camera_fields .SUPPORTED_RESOLUTIONS )
145+ local sensor_width = ib .data .elements .sensor_width .value
146+ local sensor_height = ib .data .elements .sensor_height .value
147+ local max_fps = ib .data .elements .max_fps .value
148+ device :set_field (camera_fields .MAX_RESOLUTION , {
149+ width = sensor_width ,
150+ height = sensor_height
151+ })
152+ device :set_field (camera_fields .MAX_FRAMES_PER_SECOND , max_fps )
153+ device :emit_event_for_endpoint (ib , capabilities .cameraViewportSettings .videoSensorParameters ({
154+ width = sensor_width ,
155+ height = sensor_height ,
156+ maxFPS = max_fps
157+ }))
159158 local max_encoded_pixel_rate = device :get_field (camera_fields .MAX_ENCODED_PIXEL_RATE )
160- local emit_capability = resolutions ~= nil and max_encoded_pixel_rate ~= nil
161- local sensor_width , sensor_height , max_fps
162- for _ , v in pairs (ib .data .elements ) do
163- if v .field_id == 0 then
164- sensor_width = v .value
165- elseif v .field_id == 1 then
166- sensor_height = v .value
167- elseif v .field_id == 2 then
168- max_fps = v .value
169- end
170- end
171-
172- if max_fps then
173- if sensor_width and sensor_height then
174- device :emit_event_for_endpoint (ib , capabilities .cameraViewportSettings .videoSensorParameters ({
175- width = sensor_width ,
176- height = sensor_height ,
177- maxFPS = max_fps
178- }))
179- end
180- if emit_capability then
181- for _ , v in pairs (resolutions or {}) do
182- local fps = camera_utils .compute_fps (max_encoded_pixel_rate , v .width , v .height , max_fps )
183- if fps > 0 then
184- v .fps = fps
185- end
186- end
187- device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (resolutions ))
188- end
189- device :set_field (camera_fields .MAX_FRAMES_PER_SECOND , max_fps )
159+ if max_encoded_pixel_rate and max_fps and device :get_field (camera_fields .SUPPORTED_RESOLUTIONS ) and device :get_field (camera_fields .MIN_RESOLUTION ) then
160+ local supported_resolutions = camera_utils .build_supported_resolutions (device , max_encoded_pixel_rate , max_fps )
161+ device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (supported_resolutions ))
190162 end
191163end
192164
193165function CameraAttributeHandlers .min_viewport_handler (driver , device , ib , response )
166+ if not ib .data .elements then return end
194167 device :emit_event_for_endpoint (ib , capabilities .cameraViewportSettings .minViewportResolution ({
195168 width = ib .data .elements .width .value ,
196169 height = ib .data .elements .height .value
197170 }))
171+ device :set_field (camera_fields .MIN_RESOLUTION , {
172+ width = ib .data .elements .width .value ,
173+ height = ib .data .elements .height .value
174+ })
175+ local max_encoded_pixel_rate = device :get_field (camera_fields .MAX_ENCODED_PIXEL_RATE )
176+ local max_fps = device :get_field (camera_fields .MAX_FRAMES_PER_SECOND )
177+ if max_encoded_pixel_rate and max_fps and device :get_field (camera_fields .SUPPORTED_RESOLUTIONS ) and device :get_field (camera_fields .MAX_RESOLUTION ) then
178+ local supported_resolutions = camera_utils .build_supported_resolutions (device , max_encoded_pixel_rate , max_fps )
179+ device :emit_event_for_endpoint (ib , capabilities .videoStreamSettings .supportedResolutions (supported_resolutions ))
180+ end
198181end
199182
200183function CameraAttributeHandlers .allocated_video_streams_handler (driver , device , ib , response )
0 commit comments