Пример #1
0
        /// <summary>
        /// Method, called during [Render] to bring forward all the necessary resources, necessary action for maximum abstraction from the user.
        /// </summary>
        /// <param name="command">The command chain the current filter belongs to.</param>
        /// <param name="filterchain">The filterchain that the filter belongs to</param>
        public void Setup(FFmpegCommand command, Filterchain filterchain)
        {
            InputCount = filterchain.Resources.Count;

            if (InputCount == 0)
            {
                throw new InvalidOperationException("Cannot setup filter with a resource count of zero.");
            }
            if (InputCount > MaxInputs)
            {
                throw new InvalidOperationException("The filter has exceeded the maximum allowed number of inputs.");
            }
        }
Пример #2
0
        private FilterchainOutput(Filterchain owner, IStream resource)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            Owner  = owner;
            Stream = resource;
            Id     = Guid.NewGuid().ToString();
        }
Пример #3
0
        public List <StreamIdentifier> AddToEach(Filterchain filterchain, params StreamIdentifier[] streamIds)
        {
            if (filterchain == null)
            {
                throw new ArgumentNullException("filterchain");
            }
            if (streamIds == null || streamIds.Length == 0)
            {
                throw new ArgumentException("Cannot apply filters to null or empty objects.", "streamIds");
            }

            var resourceList = new List <StreamIdentifier>(streamIds);

            return(resourceList.SelectMany(r => Add(filterchain, r)).ToList());
        }
Пример #4
0
        /// <summary>
        /// merges the given Filterchain to the Filtergraph
        /// </summary>
        /// <param name="filterchain">the filterchain to be added to the filtergraph</param>
        /// <param name="optionType">the option specifying how the merge should declare a winner</param>
        public Filtergraph Merge(Filterchain filterchain, FFmpegMergeOptionType optionType)
        {
            var indexOfItem = IndexOf(filterchain);

            if (indexOfItem != -1 && optionType == FFmpegMergeOptionType.NewWins)
            {
                FilterchainList.RemoveAt(indexOfItem);
                filterchain.Owner = this;
                FilterchainList.Insert(indexOfItem, filterchain);
            }
            else if (indexOfItem == -1)
            {
                Add(filterchain);
            }

            return(this);
        }
Пример #5
0
        public void PrepCommands(FFmpegCommand command, Filterchain filterchain)
        {
            if (filterchain.OutputList.Count == 0)
            {
                throw new InvalidOperationException("A split cannot happen without a demo output to split on.");
            }

            if (filterchain.OutputList.Count > NumberOfStreams)
            {
                throw new InvalidOperationException("A split cannot happen when the supplied filterchain has to many demo outputs.");
            }

            if (filterchain.OutputList.Count == NumberOfStreams)
            {
                return;
            }

            for (var i = filterchain.OutputList.Count; i < NumberOfStreams; i++)
            {
                filterchain.OutputList.Add(filterchain.OutputList
                                           .First()
                                           .Copy());
            }
        }
Пример #6
0
 /// <summary>
 /// adds the given Filterchain to the Filtergraph
 /// </summary>
 /// <param name="filterchain">the filterchain to be added to the filtergraph</param>
 public Filtergraph Add(Filterchain filterchain)
 {
     filterchain.Owner = this;
     FilterchainList.Add(filterchain);
     return(this);
 }
Пример #7
0
 public int IndexOf(Filterchain filterchain)
 {
     return(FilterchainList.FindIndex(f => f.Id == filterchain.Id));
 }
Пример #8
0
 public bool Contains(Filterchain filterchain)
 {
     return(FilterchainList.Any(f => f.Id == filterchain.Id));
 }
Пример #9
0
 internal static FilterchainOutput Create(Filterchain owner, IStream resource)
 {
     return(new FilterchainOutput(owner, resource));
 }
Пример #10
0
        public List <StreamIdentifier> Add(Filterchain filterchain, params StreamIdentifier[] streamIds)
        {
            if (filterchain == null)
            {
                throw new ArgumentNullException("filterchain");
            }

            var streamIdList = new List <StreamIdentifier>();
            var hasStreams   = (streamIds != null && streamIds.Length > 0);

            if (hasStreams)
            {
                streamIdList.AddRange(streamIds);

                if (!streamIdList.TrueForAll(streamId => Owner.Objects.ContainsInput(streamId) || Owner.Objects.ContainsStream(streamId)))
                {
                    throw new ArgumentException("Cannot apply filters to inputs or streams that do not exist in the command.", "streamIds");
                }
            }

            var finalFilter = filterchain.Filters.LastOrDefault();

            if (finalFilter == null)
            {
                throw new ArgumentException("Filterchain must contain at least one filter.", "filterchain");
            }


            if (!Utilities.ValidateFiltersMaxMin(filterchain, streamIdList))
            {
                throw new InvalidOperationException(
                          "Filterchain is invalid, not withing range of calculated allowable resources.");
            }

            if (!Utilities.ValidateFilters(Owner, filterchain, streamIdList))
            {
                throw new InvalidOperationException(
                          "Filterchain is invalid, failed to comply with child filter requirements.");
            }

            var maximumInputs = Utilities.GetFilterInputMax(filterchain);

            Filterchain finalFilterchain = null;

            if (hasStreams)
            {
                var segmentsList = Helpers.BreakStreamIdentifiers(maximumInputs, streamIds);
                segmentsList.ForEach(segment =>
                {
                    var segmentList = new List <StreamIdentifier>(segment);
                    if (finalFilterchain != null)
                    {
                        finalFilterchain.GetStreamIdentifiers().ForEach(r => segmentList.Insert(0, r));
                    }

                    finalFilterchain = filterchain.Copy();

                    finalFilterchain.Owner = Owner.Objects.Filtergraph;

                    finalFilterchain.SetResources(segmentList);

                    Utilities.ProcessFilters(Owner, finalFilterchain);

                    Owner.Objects.Filtergraph.Add(finalFilterchain);
                });
            }
            else
            {
                finalFilterchain = filterchain.Copy();

                finalFilterchain.Owner = Owner.Objects.Filtergraph;

                Utilities.ProcessFilters(Owner, finalFilterchain);

                Owner.Objects.Filtergraph.Add(finalFilterchain);
            }

            if (finalFilterchain == null)
            {
                throw new InvalidOperationException(
                          "Filterchain is invalid, segemented filters caused an unrecoverable issue.");
            }

            return(finalFilterchain.GetStreamIdentifiers());
        }
Пример #11
0
 public bool Validate(FFmpegCommand command, Filterchain filterchain, List <StreamIdentifier> streamIds)
 {
     return(filterchain.Filters.Count == 1);
 }