MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / apply_stream_quality_payload

Function apply_stream_quality_payload

packages/server/src/api/routes.rs:1385–1450  ·  view source on GitHub ↗
(
    state: &AppState,
    payload: &StreamQualityPayload,
)

Source from the content-addressed store, hash-verified

1383}
1384
1385pub(crate) fn apply_stream_quality_payload(
1386 state: &AppState,
1387 payload: &StreamQualityPayload,
1388) -> Result<Value, AppError> {
1389 if !payload.has_any_value() {
1390 return Ok(stream_quality_response(&state.config));
1391 }
1392 let video_codec = payload
1393 .video_codec
1394 .as_deref()
1395 .map(str::trim)
1396 .filter(|value| !value.is_empty())
1397 .map(|value| {
1398 normalize_video_codec(value)
1399 .ok_or_else(|| AppError::bad_request(format!("Unknown video codec `{value}`.")))
1400 })
1401 .transpose()?;
1402 let profile = payload
1403 .profile
1404 .as_deref()
1405 .map(str::trim)
1406 .filter(|value| !value.is_empty())
1407 .map(stream_quality_profile)
1408 .transpose()?;
1409 let limits = resolved_stream_quality_limits(payload, profile);
1410
1411 let _stream_config_guard = STREAM_CONFIG_LOCK
1412 .get_or_init(|| StdMutex::new(()))
1413 .lock()
1414 .unwrap();
1415 let current = current_stream_quality_state(active_video_codec(&state.config));
1416 let next_video_codec = video_codec.unwrap_or(current.video_codec.as_str());
1417 let next_profile = profile.map(|profile| profile.id).unwrap_or("custom");
1418 if current.max_edge == limits.max_edge
1419 && current.fps == limits.fps
1420 && current.min_bitrate == limits.min_bitrate
1421 && current.bits_per_pixel == limits.bits_per_pixel
1422 && current.profile == next_profile
1423 && current.video_codec == next_video_codec
1424 {
1425 return Ok(stream_quality_response(&state.config));
1426 }
1427
1428 env::set_var("SIMDECK_REALTIME_MAX_EDGE", limits.max_edge.to_string());
1429 env::set_var("SIMDECK_REALTIME_FPS", limits.fps.to_string());
1430 env::set_var("SIMDECK_LOCAL_STREAM_FPS", limits.fps.to_string());
1431 env::set_var(
1432 "SIMDECK_REALTIME_MIN_BITRATE",
1433 limits.min_bitrate.to_string(),
1434 );
1435 env::set_var(
1436 "SIMDECK_REALTIME_BITS_PER_PIXEL",
1437 limits.bits_per_pixel.to_string(),
1438 );
1439 if let Some(profile) = profile {
1440 env::set_var("SIMDECK_STREAM_QUALITY_PROFILE", profile.id);
1441 } else {
1442 env::set_var("SIMDECK_STREAM_QUALITY_PROFILE", "custom");

Callers 3

create_answerFunction · 0.85
set_stream_qualityFunction · 0.85

Calls 9

stream_quality_responseFunction · 0.85
normalize_video_codecFunction · 0.85
active_video_codecFunction · 0.85
has_any_valueMethod · 0.80
is_emptyMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected