Beispiel #1
0
 public CCTV2VideoSource(CCTVServerInfo curServer, CCTVServerInfo preferServer, string videoId, string url)
 {
     Url     = url;
     VideoId = videoId;
     initDecoder();
     //生成StreamPipe
     createStreamPipe(curServer, preferServer, url);
 }
        private void classifyInfo(VideoParser.Node node, string serverId)
        {
            //在线标识。
            var nodeId = getNodeId(node.Id);

            _onlineStatus[nodeId] = new CCTVOnlineStatus()
            {
                VideoId = nodeId, Online = node.Online
            };

            VideoParser.Server server = node as VideoParser.Server;
            if (server != null)
            {
                CCTVServerInfo si = new CCTVServerInfo()
                {
                    ServerId          = getNodeId(node.Id),
                    Name              = node.Name,
                    InfoServiceIp     = node.Host,
                    InfoServicePort   = 27010,
                    StreamServerIp    = node.Host,
                    StreamServerPort  = 37010,
                    ControlServerIp   = node.Host,
                    ControlServerPort = 47010
                };
                _servers[si.ServerId] = si;
                if (server.Childs != null)
                {
                    foreach (VideoParser.Node child in server.Childs)
                    {
                        classifyInfo(child, si.ServerId);
                    }
                }
            }
            else
            {
                VideoParser.Front front = node as VideoParser.Front;
                if (front != null)
                {
                    if (front.Childs != null)
                    {
                        int channel = 1;
                        foreach (VideoParser.Video child in front.Childs)
                        {
                            classifyInfo(front, child, channel, serverId);
                            if (front.Type == 1 || front.Type == 11)
                            {
                                channel += 4;
                            }
                            else
                            {
                                channel++;
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void createStreamPipe(CCTVServerInfo curServer, CCTVServerInfo preferServer, string url)
        {
            _streamPipe = new CCTV2StreamPipe(new Uri(url), curServer.StreamServerIp, curServer.StreamServerPort,
                                              preferServer.StreamServerIp, preferServer.StreamServerPort);

            _streamPipe.StreamHeaderReceived += streamPipe_StreamHeaderReceived;
            _streamPipe.StreamDataReceived   += streamPipe_StreamDataReceived;
            _streamPipe.ErrorOccurred        += streamPipe_ErrorOccurred;
        }
Beispiel #4
0
        private CCTVServerInfo getPreferServer(string videoId)
        {
            CCTVServerInfo preferServer = _currentServer;
            CCTVDeviceInfo di           = _clientHub.GetDeviceInfo(videoId);

            if (di != null && !string.IsNullOrWhiteSpace(di.PreferredServerId))
            {
                CCTVServerInfo temp = _clientHub.GetServerInfo(di.PreferredServerId);
                if (temp != null && !string.IsNullOrWhiteSpace(temp.StreamServerIp))
                {
                    preferServer = temp;
                }
            }
            return(preferServer);
        }
Beispiel #5
0
        private bool isNameExist(CCTVServerInfo server)
        {
            var servers = ServerPersistence.Instance.GetAllInfos();

            if (servers != null && servers.Count() > 0)
            {
                foreach (CCTVServerInfo si in servers)
                {
                    if (si.ServerId != server.ServerId && server.Name.Equals(si.Name))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #6
0
 // POST: api/Server
 public IHttpActionResult Post([FromBody] CCTVServerInfo server)
 {
     if (server == null)
     {
         return(BadRequest("提交的节点信息数据是一个空值"));
     }
     if (string.IsNullOrWhiteSpace(server.ServerId))
     {
         server.ServerId = Guid.NewGuid().ToString();
     }
     if (isNameExist(server))
     {
         return(BadRequest("已存在同名的节点服务器"));
     }
     ServerPersistence.Instance.Put(server.ServerId, server);
     return(Ok("添加节点信息成功"));
 }
Beispiel #7
0
 //Put:api/server/5
 public IHttpActionResult Put(string id, [FromBody] CCTVServerInfo server)
 {
     if (id == null)
     {
         return(BadRequest("无效的ServerId标识"));
     }
     if (server == null)
     {
         return(BadRequest("提交的节点信息数据是一个空值"));
     }
     server.ServerId = id;
     if (isNameExist(server))
     {
         return(BadRequest("已存在同名的节点服务器"));
     }
     ServerPersistence.Instance.Put(id, server);
     return(Ok("修改节点信息成功"));
 }
Beispiel #8
0
        /// <summary>
        /// 获取一个视频流数据源。
        /// </summary>
        /// <param name="videoId">视频ID,如:CCTV1_50BAD15900010302</param>
        /// <param name="url">
        /// 视频URL,如:cctv1://192.168.9.222/5817192048884777730?stream=1
        /// </param>
        /// <returns></returns>
        public VideoSource GetVideoSource(string videoId, string url)
        {
            Uri uri = new Uri(url);

            if (uri.Scheme.ToLower() == "cctv1")
            {
                if (_videoSourceDict.ContainsKey(url))
                {
                    VideoSource vs = _videoSourceDict[url];
                    if (vs.IsDisposed)
                    {
                        vs = new CCTV1VideoSource(_clientHub, getCCTVInfo(), videoId, url);
                        _videoSourceDict[url] = vs;
                    }
                    return(vs);
                }
                else
                {
                    VideoSource vs = new CCTV1VideoSource(_clientHub, getCCTVInfo(), videoId, url);
                    _videoSourceDict[url] = vs;
                    return(vs);
                }
            }
            else
            {
                CCTVServerInfo preferServer = getPreferServer(videoId);
                if (_videoSourceDict.ContainsKey(url))
                {
                    VideoSource vs = _videoSourceDict[url];
                    if (vs.IsDisposed)
                    {
                        vs = new CCTV2VideoSource(_currentServer, preferServer, videoId, url);
                        _videoSourceDict[url] = vs;
                    }
                    return(vs);
                }
                else
                {
                    VideoSource vs = new CCTV2VideoSource(_currentServer, preferServer, videoId, url);
                    _videoSourceDict[url] = vs;
                    return(vs);
                }
            }
        }
Beispiel #9
0
        private void findCurrentServer()
        {
            //使用Infoservice的IP和端口来
            Uri    uri  = new Uri(_clientHub.BaseAddress);
            string ip   = IpCorrector.CorrectIp(uri.Host);
            int    port = uri.Port;

            CCTVServerInfo[] sis = _clientHub.GetAllServerInfo();
            foreach (CCTVServerInfo si in sis)
            {
                if (ip.Equals(si.InfoServiceIp) && port == si.InfoServicePort)
                {
                    _currentServer = new CCTVServerInfo()
                    {
                        ServerId          = si.ServerId,
                        Name              = si.Name,
                        InfoServiceIp     = si.InfoServiceIp,
                        InfoServicePort   = si.InfoServicePort,
                        StreamServerIp    = si.StreamServerIp,
                        StreamServerPort  = si.StreamServerPort,
                        ControlServerIp   = si.ControlServerIp,
                        ControlServerPort = si.ControlServerPort
                    };
                    break;
                }
            }
            if (_currentServer == null)
            {
                _currentServer = new CCTVServerInfo()
                {
                    ServerId          = Guid.NewGuid().ToString(),
                    Name              = "独立信息服务",
                    InfoServiceIp     = ip,
                    InfoServicePort   = port,
                    StreamServerIp    = ip,
                    StreamServerPort  = 37010,
                    ControlServerIp   = ip,
                    ControlServerPort = 47010
                };
            }
        }
 public void PutServerInfo(CCTVServerInfo info, bool isDeleted)
 {
     PutDefaultInfo(CCTVInfoType.ServerInfo, info.ServerId, info, isDeleted);
 }