private DecodeChannel FindOneFreeDecodeChannel()
        {
            //找得到就找

            foreach (var VARIABLE in _listDecodeChannel)
            {
                if (VARIABLE.Value.IsUsed() == false)
                {
                    return VARIABLE.Value;
                }
            }
            //找不到就释放以前的解码通道

            foreach (var VARIABLE in _listDecodeChannel)
            {
                if ((VARIABLE.Value.CurrentCardOutType!=CurrentCardOutType)||(VARIABLE.Value.CurrentCardOutId!=CurrentCardOutId))
                {
                    foreach (var VARIABLE2 in _listDecodeChannel)
                    {
                        if ((VARIABLE2.Value.CurrentCardOutType == VARIABLE.Value.CurrentCardOutType) && (VARIABLE2.Value.CurrentCardOutId == VARIABLE.Value.CurrentCardOutId))
                        {
                            CloseHandle(VARIABLE2.Value.Handle);
                            DecodeChannel decodeChannel = new DecodeChannel();
                            decodeChannel.Id = VARIABLE2.Key;
                            _listDecodeChannel[decodeChannel.Id] = decodeChannel;
                            return decodeChannel;
                        }
                    }
                }
            }
            //再找不到就从编号0的通道开始循环使用
            DecodeChannel dc = new DecodeChannel();
            dc.Id = CurrentDecodeChannel++;
            _listDecodeChannel[dc.Id] = dc;
            if (CurrentDecodeChannel >= TotalDecodeChannels)
            {
                CurrentDecodeChannel = 0;
            }
            return _listDecodeChannel[dc.Id];
        }
 public static void InitDecodeCard()
 {
     TotalDecodeChannels = (int)HikVisionSDK.GetDecodeChannelCount();
     TotalDisplayChannels = (int)HikVisionSDK.GetDisplayChannelCount();
     CurrentDecodeChannelCount = 0;
     CurrentDisplayChannelCount = 0;
     _listDecodeChannel = new Dictionary<int, DecodeChannel>(TotalDecodeChannels);
     for (int i = 0; i < TotalDecodeChannels; i++)
     {
         DecodeChannel dc = new DecodeChannel();
         dc.Id = i;
         _listDecodeChannel.Add(i, dc);
     }
 }
 public void ReleaseUsedScreen(UsedDisplayChannelInfo udci)
 {
     //
     for(int i=0;i<AlUsedDisplayChannelInfo.Count;i++)
     {
         UsedDisplayChannelInfo tempudci = (UsedDisplayChannelInfo)(AlUsedDisplayChannelInfo[i]);
         if ((tempudci.DefaultDisplayCameraId == udci.DefaultDisplayCameraId)&&(tempudci.SynGroupId == udci.SynGroupId)&&
             (tempudci.GroupSwitchId == udci.GroupSwitchId) && (tempudci.ProgSwitchId == udci.ProgSwitchId))
         {
             //先释放相应的DecodeChannel
             for (int j = 0; j < _listDecodeChannel.Count; j++)
             {
                 DecodeChannel sc = _listDecodeChannel[i];
                 if ((sc.Handle == tempudci.Handle))
                 {
                     int tempid = sc.Id;
                     DecodeChannel newDC = new DecodeChannel();
                     newDC.Id = tempid;
                     _listDecodeChannel[newDC.Id] = newDC;
                 }
             }
             CloseHandle(tempudci.Handle);
             AlUsedDisplayChannelInfo.RemoveAt(i--);
         }
     }
 }