/// <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."); } }
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(); }
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()); }
/// <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); }
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()); } }
/// <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); }
public int IndexOf(Filterchain filterchain) { return(FilterchainList.FindIndex(f => f.Id == filterchain.Id)); }
public bool Contains(Filterchain filterchain) { return(FilterchainList.Any(f => f.Id == filterchain.Id)); }
internal static FilterchainOutput Create(Filterchain owner, IStream resource) { return(new FilterchainOutput(owner, resource)); }
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()); }
public bool Validate(FFmpegCommand command, Filterchain filterchain, List <StreamIdentifier> streamIds) { return(filterchain.Filters.Count == 1); }