mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-24 21:57:08 +08:00
[refactor] share mobile controller protocol and video timing
This commit is contained in:
@@ -7,35 +7,11 @@
|
|||||||
#ifndef _CONTROLLER_PROTOCOL_H_
|
#ifndef _CONTROLLER_PROTOCOL_H_
|
||||||
#define _CONTROLLER_PROTOCOL_H_
|
#define _CONTROLLER_PROTOCOL_H_
|
||||||
|
|
||||||
#include <minirtc.h>
|
#include "../../../libs/controller/include/mobile_controller_protocol.h"
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <remote_action.h>
|
|
||||||
|
|
||||||
namespace crossdesk::android_controller {
|
namespace crossdesk::android_controller {
|
||||||
inline std::string SecureAttentionMessage() {
|
using mobile_controller::SecureAttentionMessage;
|
||||||
RemoteAction action{};
|
using mobile_controller::VideoSettingsMessage;
|
||||||
action.type = service_command;
|
using mobile_controller::NetworkReport;
|
||||||
action.c.flag = send_sas;
|
|
||||||
return action.to_json();
|
|
||||||
}
|
}
|
||||||
inline std::string VideoSettingsMessage(int quality, int frame_rate, int preference,
|
|
||||||
uint32_t request_id) {
|
|
||||||
RemoteAction action{};
|
|
||||||
action.type = video_settings;
|
|
||||||
action.vs = {quality, frame_rate, preference, request_id, false};
|
|
||||||
return action.to_json();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline nlohmann::json NetworkReport(const MiniRtcNetTrafficStats& stats, TraversalMode mode) {
|
|
||||||
const auto traffic = [](const MiniRtcInboundStats& in, const MiniRtcOutboundStats& out) {
|
|
||||||
return nlohmann::json{{"inbound", in.bitrate}, {"outbound", out.bitrate}, {"loss", in.loss_rate}};
|
|
||||||
};
|
|
||||||
return {{"rtt", stats.rtt_ms}, {"mode", mode}, {"srtp", stats.srtp_active},
|
|
||||||
{"video", traffic(stats.video_inbound_stats, stats.video_outbound_stats)},
|
|
||||||
{"audio", traffic(stats.audio_inbound_stats, stats.audio_outbound_stats)},
|
|
||||||
{"data", traffic(stats.data_inbound_stats, stats.data_outbound_stats)},
|
|
||||||
{"total", traffic(stats.total_inbound_stats, stats.total_outbound_stats)}};
|
|
||||||
}
|
|
||||||
} // namespace crossdesk::android_controller
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,21 +7,9 @@
|
|||||||
#ifndef _VIDEO_TIMING_H_
|
#ifndef _VIDEO_TIMING_H_
|
||||||
#define _VIDEO_TIMING_H_
|
#define _VIDEO_TIMING_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include "../../../libs/controller/include/mobile_video_timing.h"
|
||||||
|
|
||||||
namespace crossdesk::android_controller {
|
namespace crossdesk::android_controller {
|
||||||
inline double VideoLatencyMilliseconds(uint64_t captured_us,
|
using mobile_controller::VideoLatencyMilliseconds;
|
||||||
uint64_t received_us,
|
|
||||||
int64_t submitted_us) {
|
|
||||||
// MiniRTC calibrates capture time when the frame is reassembled. Validate
|
|
||||||
// that mapping at reception, not after decoding/Surface waits: a real local
|
|
||||||
// backlog over five seconds must remain visible in the latency measurement.
|
|
||||||
if (!captured_us || received_us < captured_us || submitted_us <= 0 ||
|
|
||||||
received_us > static_cast<uint64_t>(submitted_us) ||
|
|
||||||
received_us - captured_us > 5'000'000)
|
|
||||||
return -1;
|
|
||||||
return (static_cast<uint64_t>(submitted_us) - captured_us) / 1000.0;
|
|
||||||
}
|
}
|
||||||
} // namespace crossdesk::android_controller
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-10-02
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MOBILE_CONTROLLER_PROTOCOL_H_
|
||||||
|
#define _MOBILE_CONTROLLER_PROTOCOL_H_
|
||||||
|
|
||||||
|
#include <minirtc.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <remote_action.h>
|
||||||
|
|
||||||
|
namespace crossdesk::mobile_controller {
|
||||||
|
inline std::string SecureAttentionMessage() {
|
||||||
|
RemoteAction action{};
|
||||||
|
action.type = service_command;
|
||||||
|
action.c.flag = send_sas;
|
||||||
|
return action.to_json();
|
||||||
|
}
|
||||||
|
inline std::string VideoSettingsMessage(int quality, int frame_rate, int preference,
|
||||||
|
uint32_t request_id) {
|
||||||
|
RemoteAction action{};
|
||||||
|
action.type = video_settings;
|
||||||
|
action.vs = {quality, frame_rate, preference, request_id, false};
|
||||||
|
return action.to_json();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline nlohmann::json NetworkReport(const MiniRtcNetTrafficStats& stats, TraversalMode mode) {
|
||||||
|
const auto traffic = [](const MiniRtcInboundStats& in, const MiniRtcOutboundStats& out) {
|
||||||
|
return nlohmann::json{{"inbound", in.bitrate}, {"outbound", out.bitrate}, {"loss", in.loss_rate}};
|
||||||
|
};
|
||||||
|
return {{"rtt", stats.rtt_ms}, {"mode", mode}, {"srtp", stats.srtp_active},
|
||||||
|
{"video", traffic(stats.video_inbound_stats, stats.video_outbound_stats)},
|
||||||
|
{"audio", traffic(stats.audio_inbound_stats, stats.audio_outbound_stats)},
|
||||||
|
{"data", traffic(stats.data_inbound_stats, stats.data_outbound_stats)},
|
||||||
|
{"total", traffic(stats.total_inbound_stats, stats.total_outbound_stats)}};
|
||||||
|
}
|
||||||
|
} // namespace crossdesk::mobile_controller
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-10-02
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MOBILE_VIDEO_TIMING_H_
|
||||||
|
#define _MOBILE_VIDEO_TIMING_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace crossdesk::mobile_controller {
|
||||||
|
inline double VideoLatencyMilliseconds(uint64_t captured_us,
|
||||||
|
uint64_t received_us,
|
||||||
|
int64_t submitted_us) {
|
||||||
|
// MiniRTC calibrates capture time when the frame is reassembled. Validate
|
||||||
|
// that mapping at reception, not after decoding/Surface waits: a real local
|
||||||
|
// backlog over five seconds must remain visible in the latency measurement.
|
||||||
|
if (!captured_us || received_us < captured_us || submitted_us <= 0 ||
|
||||||
|
received_us > static_cast<uint64_t>(submitted_us) ||
|
||||||
|
received_us - captured_us > 5'000'000)
|
||||||
|
return -1;
|
||||||
|
return (static_cast<uint64_t>(submitted_us) - captured_us) / 1000.0;
|
||||||
|
}
|
||||||
|
} // namespace crossdesk::mobile_controller
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user