private static void Sc_ConnectCompleted(object sender, EventArgs e) { Console.WriteLine("连接成功!"); //_hik = new CCTVStreamCmd.Hikvision.HikStream("192.168.9.155", 8000, "admin", "admin12345", 1, false, hwnd); string HikvUrl = "hikv://{0}:{1}@{2}:{3}/stream?channel={4}&profile={5}"; string url = string.Format(HikvUrl, new object[] { "admin", "admin12345", "192.168.9.155", 8000, 1, "main" }); StreamAddress sa = new StreamAddress(url, "127.0.0.1", 37010); SocketClient client = sender as SocketClient; client.Send(sa.Serialize()); }
public IStreamLinker GetStreamLinker(StreamAddress addr) { if (!string.IsNullOrWhiteSpace(addr.Url)) { string key = createKey(addr); //如果已创建码流数据通道,则使用现有通道,否则,新建一个通道。 if (_dictLinkers.ContainsKey(key)) { return(_dictLinkers[key]); } else { clearLinker(); //清除不再使用的linker try { bool isRemote = !string.IsNullOrWhiteSpace(addr.PreferredServerIp) && (!LocalIPHost.Instance.IsLocalIp(addr.PreferredServerIp)); IStreamLinker sl; if (isRemote) { Console.WriteLine($"路由至远程流媒体服务:{addr.PreferredServerIp}:{addr.PreferredServerPort}"); sl = new RemoteStreamLinker(new Uri(addr.Url), addr.PreferredServerIp, addr.PreferredServerPort); } else { Console.WriteLine("本地视频直连!"); sl = new DirectStreamLinker(new Uri(addr.Url)); } _dictLinkers[key] = sl; return(sl); } catch (Exception e) { Logger.Default.Error(e.Message); } } } return(null); }
private void _adapter_ReceiveCompleted(object sender, SocketHelper.Events.ReceiveEventArgs args) { if (args.ByteLenght >= 4) { int code = BitConverter.ToInt32(args.ReceivedBytes, 0); switch (code) { case StreamEntityCode.StreamAddress: { StreamAddress sa = StreamAddress.DeserializeTo(args.ReceivedBytes); destoryLinker(); Console.WriteLine("Uri:" + sa.Url); _linker = StreamLinkerManager.Instance.GetStreamLinker(sa); if (_linker != null) { _linker.StreamHeaderReceived += linker_StreamHeaderReceived; _linker.StreamDataReceived += linker_StreamDataReceived; _linker.ErrorOccurred += linker_ErrorOccurred; } } break; } } }
private string createKey(StreamAddress addr) { return(string.Format(_template, addr.Url, addr.PreferredServerIp)); }