private SmcErr TryStartSendRtpData(string cameraNo, string channelLabel)
{
SmcErr err = new CgwError();
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("TryStartSendRtpData start.cameraNo:{0},channelLabel:{1}", cameraNo, channelLabel);
try
{
//bool successed = this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
//// 申请互斥
//if (successed)
//{
// try
// {
if (!this.cameraVideoRelationDic.ContainsKey(cameraNo))
{
if (this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (startCameraLists.Contains(cameraNo))
{
logEx.Trace("TryStartSendRtpData start.Contains CameraNo:{0}",cameraNo);
err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
return err;
}
else
{
startCameraLists.Add(cameraNo);
logEx.Info("TryStartSendRtpData start.Add CameraNo:{0}",cameraNo);
}
}
finally
{
this.cameraVideoRelationDicLocker.ExitWriteLock();
}
}
string pipeName = "";
logEx.Trace("TryStartSendRtpData Begin StartReceiveVideo cameraNo={0}", cameraNo);
err = CgwMonitorManageAdapter.Instance().StartReceiveVideoByPipe(cameraNo, out pipeName);
//startCameraLists.Remove(cameraNo);
if (!err.IsSuccess())
{
logEx.Error("TryStartSendRtpData StartReceiveVideo cameraNo={0} failed.", cameraNo);
startCameraLists.Remove(cameraNo);
return err;
}
//this.cameraVideoRelationDic.Add(cameraNo, new List<string>());
}
if (this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (!this.cameraVideoRelationDic.ContainsKey(cameraNo))
{
this.cameraVideoRelationDic.Add(cameraNo, new List<string>());
}
if (startCameraLists.Contains(cameraNo))
{
startCameraLists.Remove(cameraNo);
}
// 判断通道是否已经存在
bool isExist = this.cameraVideoRelationDic[cameraNo].Exists(a => { return a == channelLabel; });
if (!isExist)
{
logEx.Trace("TryStartSendRtpData add CameraVideoRelationDic cameraNo={0},channelLabel={1}", cameraNo, channelLabel);
this.cameraVideoRelationDic[cameraNo].Add(channelLabel);
}
}
finally
{
this.cameraVideoRelationDicLocker.ExitWriteLock();
}
}
else
{
err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
logEx.Error("TryStartSendRtpData: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraVideoRelationDicLocker.WaitingReadCount, this.cameraVideoRelationDicLocker.WaitingWriteCount);
}
//}
//finally
//{
// // 释放互斥量
// this.cameraVideoRelationDicLocker.ExitWriteLock();
//}
//}
//else
//{
// // 日志
// err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
// logEx.Error("TryStartSendRtpData: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraVideoRelationDicLocker.WaitingReadCount, this.cameraVideoRelationDicLocker.WaitingWriteCount);
//}
}
catch (Exception ex)
{
// 日志
err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
logEx.Error(ex, "TryStartSendRtpData: Enert Write Lock Exception.");
}
logEx.Trace("TryStartSendRtpData cameraNo={0}, channelLabel={1} successfully.", cameraNo, channelLabel);
return err;
}