private void ProcessInputs(List <StatisticItem> stat,
                                   Dictionary <string, RebuildInfo> rebuild,
                                   string trunkPrefix,
                                   Dictionary <string, IssueCache> cache,
                                   InputIssue[] model,
                                   Action <InputIssue[]> setter)
        {
            List <InputIssue> vi = new List <InputIssue>();
            var now = DateTime.UtcNow;

            foreach (var item in rebuild)
            {
                InputIssueDesc result = InputIssueDesc.None;
                string         id     = item.Key;
                if (item.Value.Issue != InputIssueDesc.None)
                {
                    result = item.Value.Issue;
                }
                else if (item.Value.Video?.Image == null)
                {
                    // runtime issue
                    var st = stat.FirstOrDefault(s => s.Name.Trunk == id && s.Name.Name == "I" && s.Name.TrunkPrefix == trunkPrefix);
                    if (st?.Data is StatisticDataOfInputOutput iostat)
                    {
                        if (!cache.ContainsKey(id))
                        {
                            cache[id] = new IssueCache {
                                Created = now
                            }
                        }
                        ;

                        if (iostat.Errors > 0)
                        {
                            if (iostat.ErrorType == InputErrorType.InUse)
                            {
                                result = InputIssueDesc.InUse;
                            }
                            else
                            {
                                result = InputIssueDesc.Failed;
                            }

                            cache[id].FailedTime = DateTime.UtcNow;
                            cache[id].Failure    = result;
                        }
                        else if (iostat.Frames == 0)
                        {
                            var cacheEntry = cache[id];
                            if (now - cacheEntry.FailedTime < TimeSpan.FromSeconds(10))
                            {
                                result = cacheEntry.Failure;
                            }
                            else if (now - cacheEntry.Created > TimeSpan.FromSeconds(3))
                            {
                                cacheEntry.NoFramesCount++;
                                if (cacheEntry.NoFramesCount >= 2) // two consequtive seconds
                                {
                                    result = InputIssueDesc.NoFrames;
                                }
                            }
                        }
                        else if (iostat.Frames > 250)
                        {
                            result = InputIssueDesc.TooManyFrames;
                        }
                        else
                        {
                            cache[id].NoFramesCount = 0;
                        }
                    }
                    //else
                    //    result = InputIssueDesc.UnknownState;
                }

                if (result != InputIssueDesc.None)
                {
                    vi.Add(new InputIssue {
                        Id = id, Desc = result
                    });
                }
            }

            if (vi.Count == 0)
            {
                if (model != null)
                {
                    setter(null);
                }
            }
            else
            {
                var sorted = vi.OrderBy(s => s.Id).ToArray();

                if (model == null || !model.SequenceEqual(sorted))
                {
                    setter(sorted);
                }
            }
        }
    }
Ejemplo n.º 2
0
 public static string GetIssueString(InputIssueDesc desc) => desc switch
 {
Ejemplo n.º 3
0
 internal void AddVideo(string id, InputIssueDesc reason) => Videos[id].Issue = reason;
Ejemplo n.º 4
0
 internal void AddAudio(string id, InputIssueDesc reason) => Audios[id].Issue = reason;
Ejemplo n.º 5
0
 private VideoInputConfigSingleFrame GetFailedInputSource(string id, StreamerRebuildContext rebuildContext, InputIssueDesc reason, string log)
 {
     Log.Error($"Bad input source in model: {log}");
     rebuildContext.AddVideo(id, reason);
     return(new VideoInputConfigSingleFrame(new FixedFrameData(nameof(StaticResources.BadSource), StaticResources.BadSource, SingleFrameType.Png)));
 }