private SmcErr SyncChannelConfAccessCode(string channelLabel, string confAccessCode, ChannelControlType controlType)
{
SmcErr err = new SmcErr();
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
string oldConfAccessCode = string.Empty;
logEx.Trace("SyncChannelConfAccessCode Start. input channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType);
if ((this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType == ChannelControlType.Add)
|| (!this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType != ChannelControlType.Add))
{
err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR);
logEx.Trace("SyncChannelConfAccessCode input error channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType);
return err;
}
// 判断是否需要添加通道
if (ChannelControlType.Add == controlType)
{
// 通道关系字典添加一个通道
this.monitorChannelRelationDic.Add(channelLabel, new MonitorChannelRelation(channelLabel));
// 通道字典添加一个新通道
this.monitorChannelManager.AddChannel(channelLabel);
// 判断需要切换的会议号是否为空
if (!string.IsNullOrEmpty(confAccessCode))
{
// 添加通道到软终端
this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode);
this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode;
}
logEx.Trace("SyncChannelConfAccessCode add channel:{0} successfully.", channelLabel);
}
else if (ChannelControlType.None == controlType)
{
oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode;
if (string.IsNullOrEmpty(oldConfAccessCode)) // 判断本地通道号码是否入会
{
// 判断需要切换的会议号是否为空
if (!string.IsNullOrEmpty(confAccessCode))
{
// 添加通道到软终端
this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode);
this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode;
}
}
else
{
// 判断需要切换的会议号是否为空
if (!string.IsNullOrEmpty(confAccessCode))
{
if (confAccessCode == oldConfAccessCode)
{
logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] is same.", oldConfAccessCode, confAccessCode);
return err;
}
// 关闭视频码流
//err = this.SwitchChannelVideo(channelLabel, string.Empty);
err = this.StopCameraRtpAudio(channelLabel);
if (!err.IsSuccess())
{
logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode);
return err;
}
// 软终端删除该通道
this.monitorChannelManager.RemoveSotChannel(channelLabel);
// 软终端重新添加该通道
this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode);
}
else
{
// 关闭视频码流
//err = this.SwitchChannelVideo(channelLabel, string.Empty);
err = this.StopCameraRtpAudio(channelLabel);
if (!err.IsSuccess())
{
logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode);
return err;
}
// 软终端删除该通道
this.monitorChannelManager.RemoveSotChannel(channelLabel);
}
this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode;
}
}
else
{
oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode;
if (!string.IsNullOrEmpty(oldConfAccessCode))
{
// 关闭视频码流
//err = this.SwitchChannelVideo(channelLabel, string.Empty);
err = this.StopCameraRtpAudio(channelLabel);
if (!err.IsSuccess())
{
logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode);
return err;
}
// 软终端删除该通道
this.monitorChannelManager.RemoveSotChannel(channelLabel);
this.monitorChannelRelationDic[channelLabel].ConfAccessCode = string.Empty;
}
// 通道关系字典删除该通道
if (this.monitorChannelRelationDic.ContainsKey(channelLabel))
{
this.monitorChannelRelationDic.Remove(channelLabel);
}
// 通道字典删除该通道
this.monitorChannelManager.RemoveChannel(channelLabel);
logEx.Trace("SyncChannelConfAccessCode remove channel:{0} successfully.", channelLabel);
}
logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] successfully.", oldConfAccessCode, confAccessCode);
return err;
}