public async Task <StreamTask> AddTask(RtspIdentity rtspIdentity, Size convertResolution, RtspAuthentication authentication) { if (StreamTasks.TryGetValue(rtspIdentity, out var streamTask)) { if (streamTask.IsRunning) { return(streamTask); } } else { streamTask = new StreamTask(rtspIdentity, this); while (!StreamTasks.TryAdd(rtspIdentity, streamTask)) { } } if (!streamTask.IsRunning) { try { await streamTask.RunAsync(DefaultUsername ?? authentication.Credential.UserName, DefaultPassword ?? authentication.Credential.Password, convertResolution); } catch (Exception ex) { StreamTasks.TryRemove(rtspIdentity, out _); throw; } streamTask.ProcessExit += StreamTask_ProcessExit; } return(streamTask); }
public async Task <StreamTask> AddTaskWithHeartBeat(RtspIdentity rtspIdentity, Size convertResolution, RtspAuthentication authentication = null) { var task = await base.AddTask(rtspIdentity, convertResolution, authentication); if (_heartBeatDictionary.TryAdd(rtspIdentity, DateTime.Now)) { task.ProcessExit += StreamTask_ProcessExit; } else { if (!_heartBeatDictionary.ContainsKey(rtspIdentity)) { ConsoleHelper.WriteWarn("Add auto dispose task failed", "auto_management"); } } return(task); }