Example #1
0
        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);
        }
Example #2
0
 private void StreamTask_ProcessExit(StreamTask obj)
 {
     while (!StreamTasks.TryRemove(obj.Identity, out _))
     {
     }
 }
Example #3
0
 private void StreamTask_ProcessExit(StreamTask obj)
 {
     _heartBeatDictionary.TryRemove(obj.Identity, out _);
 }