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> RemoveTask(RtspIdentity rtspIdentity) { if (StreamTasks.TryGetValue(rtspIdentity, out var task)) { await task.StopAsync(); return(task); } else { ConsoleHelper.WriteWarn("No available task found.", "management"); return(null); } }
public void HeartBeat(RtspIdentity rtspIdentity) { if (_heartBeatDictionary.TryGetValue(rtspIdentity, out var old)) { var now = DateTime.Now; _heartBeatDictionary[rtspIdentity] = now; //ConsoleHelper.WriteInfo( // "Update task `" + rtspIdentity + "` expire time from " + old.ToLongTimeString() + " to " + // now.ToLongTimeString(), "auto_management"); } else { ConsoleHelper.WriteWarn("HeartBeat error: cannot find task `" + rtspIdentity + "`", "auto_management"); } }
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); }
public StreamTask(RtspIdentity rtspIdentity, StreamManagement management) { Identity = rtspIdentity; _management = management; }