完善契约与客户端、服务端的收发代码
This commit is contained in:
84
SHH.CameraDashboard/Pages/CameraWall/VideoWallViewModel.cs
Normal file
84
SHH.CameraDashboard/Pages/CameraWall/VideoWallViewModel.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using SHH.Contracts;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SHH.CameraDashboard
|
||||
{
|
||||
public class VideoWallViewModel : ViewModelBase
|
||||
{
|
||||
// 引用推流接收服务
|
||||
private readonly VideoPushServer _pushServer;
|
||||
|
||||
// 视频列表
|
||||
public ObservableCollection<VideoTileViewModel> VideoTiles { get; } = new ObservableCollection<VideoTileViewModel>();
|
||||
|
||||
// 控制 UniformGrid 的列数 (决定是 2x2 还是 3x3)
|
||||
private int _columns = 2;
|
||||
public int Columns
|
||||
{
|
||||
get => _columns;
|
||||
set => SetProperty(ref _columns, value);
|
||||
}
|
||||
|
||||
// 切换布局命令
|
||||
public ICommand SetLayoutCommand { get; }
|
||||
|
||||
public VideoWallViewModel()
|
||||
{
|
||||
SetLayoutCommand = new RelayCommand<string>(ExecuteSetLayout);
|
||||
|
||||
// 1. 初始化并启动接收服务
|
||||
_pushServer = new VideoPushServer();
|
||||
_pushServer.OnFrameReceived += OnGlobalFrameReceived;
|
||||
|
||||
// 2. 启动监听端口 (比如 6000)
|
||||
// 之后你的采集端 ForwarderClient 需要 Connect("tcp://你的IP:6000")
|
||||
_pushServer.Start(6000);
|
||||
|
||||
// 3. 初始化格子 (不再需要传入 IP/Port 去主动连接了)
|
||||
// 我们用 CameraId 或 Name 来作为匹配标识
|
||||
InitVideoTiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局接收回调:收到任何一路视频都会进这里
|
||||
/// </summary>
|
||||
private void OnGlobalFrameReceived(VideoPayload payload)
|
||||
{
|
||||
// 1. 在 VideoTiles 集合中找到对应的格子
|
||||
// 假设 payload.CameraId 与我们 VideoTileViewModel 中的 ID 对应
|
||||
//var targetTile = VideoTiles.FirstOrDefault(t => t.id == payload.CameraId);
|
||||
|
||||
//if (targetTile != null)
|
||||
//{
|
||||
// // 2. 将数据交给格子去渲染
|
||||
// targetTile.UpdateFrame(payload);
|
||||
//}
|
||||
}
|
||||
|
||||
private void InitVideoTiles()
|
||||
{
|
||||
// 假设我们预设 4 个格子,分别对应不同的摄像头 ID
|
||||
// 这里 ID 必须和采集端发送的 VideoPayload.CameraId 一致
|
||||
//VideoTiles.Add(new VideoTileViewModel("1004", "仓库通道"));
|
||||
}
|
||||
|
||||
public void AddCamera(string ip, int port, string name)
|
||||
{
|
||||
var tile = new VideoTileViewModel(ip, port, name);
|
||||
VideoTiles.Add(tile);
|
||||
}
|
||||
|
||||
private void ExecuteSetLayout(string layoutType)
|
||||
{
|
||||
switch (layoutType)
|
||||
{
|
||||
case "1x1": Columns = 1; break;
|
||||
case "2x2": Columns = 2; break;
|
||||
case "3x3": Columns = 3; break;
|
||||
case "4x4": Columns = 4; break;
|
||||
default: Columns = 2; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user