USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面
This commit is contained in:
@@ -0,0 +1,353 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/rtsp_playback_tuning.dart';
|
||||
|
||||
/// 调参弹窗用的公共小组件(标题 / 预设档位 / 传输方式 / 毫秒输入框)。
|
||||
|
||||
class TuningSectionTitle extends StatelessWidget {
|
||||
const TuningSectionTitle({super.key, required this.text});
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFFEDEDED),
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TuningHint extends StatelessWidget {
|
||||
const TuningHint({super.key, required this.text});
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
text,
|
||||
// 不用 white38:在 #141414 底上对比度只有 2.3:1,太阳底下根本看不清。
|
||||
style: const TextStyle(color: Color(0xFF9AA0A6), fontSize: 11, height: 1.5),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 预设档位:现场试验直接点一个再微调,省得对着数字猜。
|
||||
class TuningPresetRow extends StatelessWidget {
|
||||
const TuningPresetRow({super.key, required this.draft, required this.onPick});
|
||||
|
||||
final RtspPlaybackTuning draft;
|
||||
final ValueChanged<RtspPlaybackTuning> onPick;
|
||||
|
||||
static const List<(String, RtspPlaybackTuning)> presets = <(String, RtspPlaybackTuning)>[
|
||||
('原生默认', RtspPlaybackTuning.defaults),
|
||||
('均衡', RtspPlaybackTuning.balanced),
|
||||
('抗花屏', RtspPlaybackTuning.antiArtifact),
|
||||
('低延迟', RtspPlaybackTuning.lowLatency),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final p in presets)
|
||||
_TuningPresetPill(
|
||||
label: p.$1,
|
||||
selected: p.$2 == draft,
|
||||
onTap: () => onPick(p.$2),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 预设档位药丸。
|
||||
///
|
||||
/// 之前用的是 ChoiceChip:弹窗底色是写死的深色,而 APP 可能是浅色主题,
|
||||
/// chip 会拿到「浅色底 + 白色字」这种看不清的组合,且和下面的自绘卡片风格不统一。
|
||||
/// 自己画可以彻底不依赖主题,也不随用户的浅色/深色设置漂移。
|
||||
class _TuningPresetPill extends StatelessWidget {
|
||||
const _TuningPresetPill({
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? const Color(0xFF165DFF) : const Color(0xFF2A2A2A),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(
|
||||
color: selected ? const Color(0xFF5B8DEF) : const Color(0xFF4A4A4A),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.white : const Color(0xFFDDDDDD),
|
||||
fontSize: 12,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// UDP / TCP 二选一。用两个可点卡片而不是 Switch,是为了把各自的代价直接写在脸上。
|
||||
class TuningTransportPicker extends StatelessWidget {
|
||||
const TuningTransportPicker({super.key, required this.forceTcp, required this.onChanged});
|
||||
|
||||
final bool forceTcp;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _TuningTransportOption(
|
||||
title: 'UDP',
|
||||
subtitle: '延迟低 / 丢包即花屏',
|
||||
selected: !forceTcp,
|
||||
onTap: () => onChanged(false),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _TuningTransportOption(
|
||||
title: 'TCP',
|
||||
subtitle: '画面完整 / 可能卡顿',
|
||||
selected: forceTcp,
|
||||
onTap: () => onChanged(true),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TuningTransportOption extends StatelessWidget {
|
||||
const _TuningTransportOption({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? const Color(0xFF165DFF).withValues(alpha: 0.30)
|
||||
: const Color(0xFF232323),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? const Color(0xFF5B8DEF)
|
||||
: const Color(0xFF3D3D3D),
|
||||
width: selected ? 1.4 : 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.white : const Color(0xFFCCCCCC),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(color: Color(0xFF9AA0A6), fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 毫秒参数输入框:右侧常驻一句“这个值到底影响什么”,避免瞎填。
|
||||
class TuningMsField extends StatefulWidget {
|
||||
const TuningMsField({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.hint,
|
||||
required this.onChanged,
|
||||
this.suffix = 'ms',
|
||||
});
|
||||
|
||||
final String label;
|
||||
final int value;
|
||||
final String hint;
|
||||
final ValueChanged<int> onChanged;
|
||||
|
||||
/// 单位后缀。水位类是 ms,缓冲字节类是 KB。
|
||||
final String suffix;
|
||||
|
||||
@override
|
||||
State<TuningMsField> createState() => _TuningMsFieldState();
|
||||
}
|
||||
|
||||
class _TuningMsFieldState extends State<TuningMsField> {
|
||||
late final TextEditingController _ctrl =
|
||||
TextEditingController(text: '${widget.value}');
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant TuningMsField oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// 点预设档位时要同步回填输入框;光标还在框里(用户正在输入)时不覆盖。
|
||||
if (widget.value != oldWidget.value && !_ctrl.selection.isValid) {
|
||||
_ctrl.text = '${widget.value}';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.label,
|
||||
style: const TextStyle(color: Color(0xFFCCCCCC), fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 110,
|
||||
child: TextField(
|
||||
controller: _ctrl,
|
||||
keyboardType: TextInputType.number,
|
||||
// 浅色主题下默认 cursor 是深色,在深底输入框里几乎看不见。
|
||||
cursorColor: const Color(0xFF94BFFF),
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
suffixText: widget.suffix,
|
||||
suffixStyle: const TextStyle(
|
||||
color: Color(0xFF9AA0A6),
|
||||
fontSize: 11,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFF232323),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 8,
|
||||
),
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Color(0xFF3D3D3D)),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Color(0xFF5B8DEF)),
|
||||
),
|
||||
),
|
||||
onChanged: (v) => widget.onChanged(int.tryParse(v.trim()) ?? 0),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
widget.hint,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF9AA0A6),
|
||||
fontSize: 11,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 多选一卡片行:把每个选项的代价直接写在卡片上,比下拉框更适合现场试参数。
|
||||
class TuningChoiceRow<T> extends StatelessWidget {
|
||||
const TuningChoiceRow({
|
||||
super.key,
|
||||
required this.options,
|
||||
required this.labelOf,
|
||||
required this.selected,
|
||||
required this.onChanged,
|
||||
this.subtitleOf,
|
||||
});
|
||||
|
||||
final List<T> options;
|
||||
final String Function(T) labelOf;
|
||||
final String Function(T)? subtitleOf;
|
||||
final T selected;
|
||||
final ValueChanged<T> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
for (int i = 0; i < options.length; i++) ...[
|
||||
if (i > 0) const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _TuningTransportOption(
|
||||
title: labelOf(options[i]),
|
||||
subtitle: subtitleOf?.call(options[i]) ?? '',
|
||||
selected: options[i] == selected,
|
||||
onTap: () => onChanged(options[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../data/rtsp_link_probe.dart';
|
||||
import '../../data/rtsp_playback_tuning.dart';
|
||||
import '../cubit/local_camera_cubit.dart';
|
||||
import 'rtsp_tuning_fields.dart';
|
||||
|
||||
/// 链路条上方的「调参条」:一行显示当前生效策略,点开弹窗慢慢改。
|
||||
///
|
||||
/// 放这里而不是画面上:画面区域要留给视频本身,且改完参数会立刻重拉流,
|
||||
/// 任何浮层都会干扰肉眼判断花屏/延迟的变化。
|
||||
class RtspTuningBar extends StatelessWidget {
|
||||
const RtspTuningBar({
|
||||
super.key,
|
||||
required this.tuning,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final RtspPlaybackTuning tuning;
|
||||
final VoidCallback onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: const Color(0xFF0A0A0A),
|
||||
child: InkWell(
|
||||
onTap: onOpen,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 8, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.tune, color: Color(0xFF165DFF), size: 18),
|
||||
const SizedBox(width: 8),
|
||||
const Text('调参', style: TextStyle(color: Color(0xFFCCCCCC), fontSize: 12)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
tuning.summary,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: tuning.isDefault
|
||||
? const Color(0xFF9AA0A6)
|
||||
: const Color(0xFFFFC53D),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!tuning.isDefault)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 6),
|
||||
child: Text(
|
||||
'已自定义',
|
||||
style: TextStyle(color: Color(0xFFFFC53D), fontSize: 11),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: Color(0xFF8A8A8A), size: 18),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 链路探针条:固定在三块信息区最上方,只读不改任何行为。
|
||||
///
|
||||
/// 它回答的是“图传送过来的数据到底缺不缺”:
|
||||
/// 进给率明显低于实时 = 数据没到齐(链路吐不上/丢包,病在图传段);
|
||||
/// 进给完整但画面仍花 = 数据都收到了还花,不是“不够”而是“内容坏了”。
|
||||
class RtspLinkProbeBar extends StatelessWidget {
|
||||
const RtspLinkProbeBar({super.key, required this.probe});
|
||||
|
||||
final ValueListenable<RtspLinkSnapshot?> probe;
|
||||
|
||||
static Color _colorOf(LinkVerdict v) {
|
||||
switch (v) {
|
||||
case LinkVerdict.healthy:
|
||||
return const Color(0xFF3DDC84);
|
||||
case LinkVerdict.lightLoss:
|
||||
return const Color(0xFFFFC53D);
|
||||
case LinkVerdict.starved:
|
||||
return const Color(0xFFFF6B4A);
|
||||
case LinkVerdict.decoderStalled:
|
||||
return const Color(0xFFB388FF);
|
||||
case LinkVerdict.backlogGrowing:
|
||||
return const Color(0xFFFFB74D);
|
||||
case LinkVerdict.unknown:
|
||||
return const Color(0xFF8A8A8A);
|
||||
}
|
||||
}
|
||||
|
||||
static IconData _iconOf(LinkVerdict v) {
|
||||
switch (v) {
|
||||
case LinkVerdict.healthy:
|
||||
return Icons.signal_cellular_alt;
|
||||
case LinkVerdict.lightLoss:
|
||||
case LinkVerdict.starved:
|
||||
return Icons.network_check;
|
||||
case LinkVerdict.decoderStalled:
|
||||
return Icons.memory;
|
||||
case LinkVerdict.backlogGrowing:
|
||||
return Icons.hourglass_top;
|
||||
case LinkVerdict.unknown:
|
||||
return Icons.sensors_off;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<RtspLinkSnapshot?>(
|
||||
valueListenable: probe,
|
||||
builder: (context, snap, _) {
|
||||
final LinkVerdict v = snap?.verdict ?? LinkVerdict.unknown;
|
||||
final Color accent = _colorOf(v);
|
||||
return Material(
|
||||
color: const Color(0xFF0A0A0A),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 6, 12, 7),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(_iconOf(v), color: accent, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
snap == null
|
||||
? '链路探针:采样中(进画面后 2~4 秒出结果)'
|
||||
: '${v.label} · ${snap.detail}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: accent,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
snap == null
|
||||
? '靠 position/buffered 的增量判断进给完整度,不需重新编译'
|
||||
: v.advice,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF9AA0A6),
|
||||
fontSize: 10.5,
|
||||
height: 1.35,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (snap != null && snap.estLossPct > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Text(
|
||||
'丢帧≈${snap.estLossPct}%',
|
||||
style: TextStyle(color: accent, fontSize: 11),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 弹出调参面板。关闭时 Cubit 已完成「保存 + 下发(+ 视按钮重拉流)」。
|
||||
///
|
||||
/// 必须把 Cubit 从调用方的上下文传进来:showModalBottomSheet 走的是
|
||||
/// Navigator 里的 Overlay,它在页面 BlocProvider 的**上层**,弹窗内部
|
||||
/// context 原本看不到 LocalCameraCubit,会抛 ProviderNotFoundException。
|
||||
/// 这里用 BlocProvider.value 把它重新注入到弹窗子树(不负责 dispose)。
|
||||
Future<void> showRtspTuningSheet(BuildContext context, LocalCameraCubit cubit) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: const Color(0xFF141414),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: cubit,
|
||||
child: const _RtspTuningSheet(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _RtspTuningSheet extends StatefulWidget {
|
||||
const _RtspTuningSheet();
|
||||
|
||||
@override
|
||||
State<_RtspTuningSheet> createState() => _RtspTuningSheetState();
|
||||
}
|
||||
|
||||
class _RtspTuningSheetState extends State<_RtspTuningSheet> {
|
||||
late RtspPlaybackTuning _draft;
|
||||
String _nativeEcho = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_draft = context.read<LocalCameraCubit>().tuning;
|
||||
}
|
||||
|
||||
/// 读回原生侧真正生效的值:用来定性「改了到底有没有进插件」。
|
||||
Future<void> _readBack() async {
|
||||
final RtspPlaybackTuning? live =
|
||||
await context.read<LocalCameraCubit>().readBackTuning();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_nativeEcho = live == null
|
||||
? '读回失败:调参通道不存在(确认本地覆盖包已生效 / 是否 Android 端)'
|
||||
: '原生当前生效:TCP=${live.forceRtpTcp} · ${live.minBufferMs}~'
|
||||
'${live.maxBufferMs}ms · 起播${live.bufferForPlaybackMs}ms · '
|
||||
'超时${live.rtspTimeoutMs == 0 ? '默认' : '${live.rtspTimeoutMs}ms'} · '
|
||||
'字节${live.targetBufferBytes == 0 ? '默认' : '${live.targetBufferBytes ~/ 1024}KB'} · '
|
||||
'${live.decoderMode.label}';
|
||||
});
|
||||
}
|
||||
|
||||
void _apply({required bool replay}) {
|
||||
context.read<LocalCameraCubit>().updateTuning(_draft, reconnect: replay);
|
||||
final ScaffoldMessengerState messenger = ScaffoldMessenger.of(context);
|
||||
Navigator.of(context).pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
replay ? '已应用并重拉流:${_draft.summary}' : '已应用(下次拉流生效):${_draft.summary}',
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double maxHeight = MediaQuery.sizeOf(context).height * 0.9;
|
||||
// 弹窗底色是写死的深色,但 APP 可能跑在浅色主题上:不锁主题的话,
|
||||
// 没显式给色的控件(按钮文字 / chip / 输入框 / 水波纹)会继承浅色主题的默认色,
|
||||
// 就出现「白底 + 白字」看不清。只钉本弹窗这一棵子树,不影响全局主题。
|
||||
return Theme(
|
||||
data: _darkThemeOf(context),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: maxHeight),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const _SheetHandle(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'直播调参(花屏 / 延迟)',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
setState(() => _draft = RtspPlaybackTuning.defaults),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF94BFFF),
|
||||
),
|
||||
child: const Text('恢复默认', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Flexible(child: _buildForm()),
|
||||
_buildActions(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 把弹窗子树锁到深色主题:保留宿主主题的字号/字体族(随系统无障碍缩放),
|
||||
/// 只换 brightness / colorScheme / textTheme 这三样决定前景色的东西。
|
||||
ThemeData _darkThemeOf(BuildContext context) {
|
||||
final ThemeData base = Theme.of(context);
|
||||
return base.copyWith(
|
||||
brightness: Brightness.dark,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFF165DFF),
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
textTheme: base.textTheme.apply(
|
||||
bodyColor: const Color(0xFFE8E8E8),
|
||||
displayColor: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildForm() {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
children: [
|
||||
const TuningSectionTitle(text: '预设档位(先点一个再微调)'),
|
||||
TuningPresetRow(
|
||||
draft: _draft,
|
||||
onPick: (t) => setState(() => _draft = t),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const TuningSectionTitle(text: '策略一:传输方式(治花屏)'),
|
||||
TuningTransportPicker(
|
||||
forceTcp: _draft.forceRtpTcp,
|
||||
onChanged: (v) => setState(() => _draft = _draft.copyWith(forceRtpTcp: v)),
|
||||
),
|
||||
const TuningHint(
|
||||
text: 'UDP 不重传,空口丢包直接解出马赛克;TCP 会重传把画面补全,'
|
||||
'代价是弱链路下卡顿与延迟上升。',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const TuningSectionTitle(text: '策略二:缓冲水位(治延迟)'),
|
||||
TuningMsField(
|
||||
label: 'minBufferMs(重新加载水位)',
|
||||
value: _draft.minBufferMs,
|
||||
hint: 'Media3 有 500ms 硬下限,填更小不生效',
|
||||
onChanged: (v) => setState(() => _draft = _draft.copyWith(minBufferMs: v)),
|
||||
),
|
||||
TuningMsField(
|
||||
label: 'maxBufferMs(停止加载水位 = 延迟上限)',
|
||||
value: _draft.maxBufferMs,
|
||||
hint: '平均积压约 (min+max)/2;越小越跟手,太小易卡',
|
||||
onChanged: (v) => setState(() => _draft = _draft.copyWith(maxBufferMs: v)),
|
||||
),
|
||||
TuningMsField(
|
||||
label: 'bufferForPlaybackMs(起播所需缓冲)',
|
||||
value: _draft.bufferForPlaybackMs,
|
||||
hint: '直播建议 0:首帧到达即渲染',
|
||||
onChanged: (v) =>
|
||||
setState(() => _draft = _draft.copyWith(bufferForPlaybackMs: v)),
|
||||
),
|
||||
TuningMsField(
|
||||
label: 'bufferForPlaybackAfterRebufferMs(卡完恢复所需缓冲)',
|
||||
value: _draft.bufferForPlaybackAfterRebufferMs,
|
||||
hint: '直播建议 0:避免每次卡完再攒一段',
|
||||
onChanged: (v) => setState(
|
||||
() => _draft = _draft.copyWith(bufferForPlaybackAfterRebufferMs: v),
|
||||
),
|
||||
),
|
||||
TuningMsField(
|
||||
label: 'rtspTimeoutMs(RTSP 超时,0=用默认)',
|
||||
value: _draft.rtspTimeoutMs,
|
||||
hint: '过小会在弱链路上误判「流结束」而断流',
|
||||
onChanged: (v) => setState(() => _draft = _draft.copyWith(rtspTimeoutMs: v)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildStreamAndDecoder(),
|
||||
const SizedBox(height: 8),
|
||||
_buildSummary(),
|
||||
TextButton(
|
||||
onPressed: _readBack,
|
||||
child: const Text(
|
||||
'读回原生实际生效值(验证参数有没有真的进插件)',
|
||||
style: TextStyle(color: Color(0xFF94BFFF), fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 策略三:取哪一路码流 + 由谁解码 + 字节上限。
|
||||
/// 这一区才是「播放层」:前面两项只能决定“坏数据怎么补”,这里决定“拿到的是什么数据”。
|
||||
Widget _buildStreamAndDecoder() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const TuningSectionTitle(text: '策略三:取流与解码(播放层)'),
|
||||
TuningChoiceRow<RtspProfileSelect>(
|
||||
options: RtspProfileSelect.values,
|
||||
labelOf: (p) => p.label,
|
||||
selected: _draft.profileSelect,
|
||||
onChanged: (p) =>
|
||||
setState(() => _draft = _draft.copyWith(profileSelect: p)),
|
||||
),
|
||||
TuningHint(text: '当前:${_draft.profileSelect.desc}。改这一档会重新走 ONVIF 取流(URL 会变)。'),
|
||||
const SizedBox(height: 12),
|
||||
TuningChoiceRow<RtspDecoderMode>(
|
||||
options: RtspDecoderMode.values,
|
||||
labelOf: (m) => m.label,
|
||||
selected: _draft.decoderMode,
|
||||
onChanged: (m) =>
|
||||
setState(() => _draft = _draft.copyWith(decoderMode: m)),
|
||||
),
|
||||
const TuningHint(
|
||||
text: 'Media3 默认硬解,且硬解初始化失败不会自动回退软解;怀疑解码侧问题时,切软解对比同一画面。',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TuningMsField(
|
||||
label: 'targetBufferBytes(字节上限,按 KB 填)',
|
||||
value: _draft.targetBufferBytes ~/ 1024,
|
||||
suffix: 'KB',
|
||||
hint: '0 = 用默认(视频约 2MB)。高码率下 2MB 不到 1 秒就撞上限,会频繁 rebuffer,可试 8192',
|
||||
onChanged: (kb) => setState(
|
||||
() => _draft = _draft.copyWith(targetBufferBytes: kb < 0 ? 0 : kb * 1024),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummary() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1E1E1E),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFF3D3D3D)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'预计稳态积压 ≈ ${_draft.estimatedBacklogMs}ms',
|
||||
style: const TextStyle(color: Color(0xFF94BFFF), fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'注意:这只是播放器内部水位,不等于肉眼端到端延迟——后端的大头通常在摄像头 GOP / '
|
||||
'图传编码,而不是这里。',
|
||||
style: TextStyle(color: Color(0xFF9AA0A6), fontSize: 11, height: 1.4),
|
||||
),
|
||||
if (_nativeEcho.isNotEmpty) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
_nativeEcho,
|
||||
style: const TextStyle(color: Color(0xFFB8B8B8), fontSize: 11),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 底部两个按钮必须用同一套尺寸:主题只给 elevatedButtonTheme 设了
|
||||
// padding(vertical:16, horizontal:24) 与 radius 12,outlinedButton 没被覆盖,
|
||||
// 两个按钮默认内间距/圆角完全不同 → 一高一矮,看着就别扭。这里显式对齐。
|
||||
static const EdgeInsets _actionPadding = EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 12,
|
||||
);
|
||||
static const Size _actionMinSize = Size(0, 44);
|
||||
static const TextStyle _actionText = TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
static const OutlinedBorder _actionShape = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
);
|
||||
|
||||
Widget _buildActions() {
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => _apply(replay: false),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFFCCCCCC),
|
||||
backgroundColor: Colors.transparent,
|
||||
side: const BorderSide(color: Color(0xFF4A4A4A)),
|
||||
padding: _actionPadding,
|
||||
minimumSize: _actionMinSize,
|
||||
textStyle: _actionText,
|
||||
shape: _actionShape,
|
||||
),
|
||||
child: const Text('仅保存 · 下次拉流生效'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _apply(replay: true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF165DFF),
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: _actionPadding,
|
||||
minimumSize: _actionMinSize,
|
||||
textStyle: _actionText,
|
||||
shape: _actionShape,
|
||||
),
|
||||
child: const Text('保存 · 立即重拉流'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SheetHandle extends StatelessWidget {
|
||||
const _SheetHandle();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user