public BalancedPriorityGroupMonitor(int priority, BalancedHeuristicsSettings settings)
 {
     Priority          = priority;
     _stableBufferSize = TimeSpan.FromMilliseconds(StableBufferSize);
     _avoidProblematicBitrateDuration = TimeSpan.FromMilliseconds(AvoidProblematicBitrateDurationMillis);
     _registeredPlugins        = new List <IAdaptiveMediaPlugin>();
     _problematicTransitions   = new List <ProblematicTransitionRecord>();
     _dispatcherTimer          = new DispatcherTimer();
     _dispatcherTimer.Tick    += (s, e) => MonitorPlugins();
     _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(MonitorFrequencyMillis);
 }
 public BalancedPriorityGroupMonitor(int priority, BalancedHeuristicsSettings settings)
 {
     Priority = priority;
     _stableBufferSize = TimeSpan.FromMilliseconds(StableBufferSize);
     _avoidProblematicBitrateDuration = TimeSpan.FromMilliseconds(AvoidProblematicBitrateDurationMillis);
     _registeredPlugins = new List<IAdaptiveMediaPlugin>();
     _problematicTransitions = new List<ProblematicTransitionRecord>();
     _dispatcherTimer = new DispatcherTimer();
     _dispatcherTimer.Tick += (s, e) => MonitorPlugins();
     _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(MonitorFrequencyMillis);
 }
        /// <summary>
        /// Registers the plugin so that it can be managed.
        /// </summary>
        /// <param name="plugin">The plugin to register.</param>
        /// <param name="priority">The priority of the specified plugin.</param>
        public void RegisterPlugin(IAdaptiveMediaPlugin plugin, int priority)
        {
            if (_settings == null)
            {
                _settings = ReadSettings();
            }

            BalancedPriorityGroupMonitor priorityGroup = _priorityGroups.Where(i => i.Priority == priority)
                .FirstOrDefault();

            if (priorityGroup == null)
            {
                priorityGroup = new BalancedPriorityGroupMonitor(priority, _settings);
                priorityGroup.AllowBitrateIncreases = true;
                _priorityGroups.Add(priorityGroup);
            }

            priorityGroup.RegisterPlugin(plugin);
        }
        /// <summary>
        /// Registers the plugin so that it can be managed.
        /// </summary>
        /// <param name="plugin">The plugin to register.</param>
        /// <param name="priority">The priority of the specified plugin.</param>
        public void RegisterPlugin(IAdaptiveMediaPlugin plugin, int priority)
        {
            if (_settings == null)
            {
                _settings = ReadSettings();
            }

            BalancedPriorityGroupMonitor priorityGroup = _priorityGroups.Where(i => i.Priority == priority)
                                                         .FirstOrDefault();

            if (priorityGroup == null)
            {
                priorityGroup = new BalancedPriorityGroupMonitor(priority, _settings);
                priorityGroup.AllowBitrateIncreases = true;
                _priorityGroups.Add(priorityGroup);
            }

            priorityGroup.RegisterPlugin(plugin);
        }
        private static BalancedHeuristicsSettings ReadSettings()
        {
            var result = new BalancedHeuristicsSettings();

            try
            {
                XDocument document = XDocument.Load(HeuristicsSettingsFileName);
                result.PollingFrequencyMillis = document.Root.Descendants(PollingFrequencySettingName)
                    .First()
                    .GetValueAsLong().Value;

                result.TolerableProblematicPlugins = document.Root.Descendants(TolerableProblematicPluginsSettingName)
                    .First()
                    .GetValueAsInt().Value;

                result.TolerableSubOptimalTrackDifferences =
                    document.Root.Descendants(TolerableSubOptimalTrackDifferencesSettingName)
                        .First()
                        .GetValueAsInt().Value;

                result.BitrateBlackListDuration = document.Root.Descendants(BitrateBlackListDurationSettingName)
                    .First()
                    .GetValueAsLong().Value;

                result.StableBufferSize = document.Root.Descendants(StableBufferSizeSettingName)
                    .First()
                    .GetValueAsLong().Value;

                result.TolerableDroppedFramesPercentage =
                    document.Root.Descendants(TolerableDroppedFramesPercentageSettingName)
                        .First()
                        .GetValueAsDouble().Value;
            }
            catch (Exception)
            {
                result = new BalancedHeuristicsSettings();
            }


            return result;
        }
        private static BalancedHeuristicsSettings ReadSettings()
        {
            var result = new BalancedHeuristicsSettings();

            try
            {
                XDocument document = XDocument.Load(HeuristicsSettingsFileName);
                result.PollingFrequencyMillis = document.Root.Descendants(PollingFrequencySettingName)
                                                .First()
                                                .GetValueAsLong().Value;

                result.TolerableProblematicPlugins = document.Root.Descendants(TolerableProblematicPluginsSettingName)
                                                     .First()
                                                     .GetValueAsInt().Value;

                result.TolerableSubOptimalTrackDifferences =
                    document.Root.Descendants(TolerableSubOptimalTrackDifferencesSettingName)
                    .First()
                    .GetValueAsInt().Value;

                result.BitrateBlackListDuration = document.Root.Descendants(BitrateBlackListDurationSettingName)
                                                  .First()
                                                  .GetValueAsLong().Value;

                result.StableBufferSize = document.Root.Descendants(StableBufferSizeSettingName)
                                          .First()
                                          .GetValueAsLong().Value;

                result.TolerableDroppedFramesPercentage =
                    document.Root.Descendants(TolerableDroppedFramesPercentageSettingName)
                    .First()
                    .GetValueAsDouble().Value;
            }
            catch (Exception)
            {
                result = new BalancedHeuristicsSettings();
            }


            return(result);
        }