Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSegment"/> class.
        /// Allow specifying an absolutely aligned (to the nearest minute) file segment.
        /// Implies `FileDateBehavior.Required`.
        /// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
        /// </summary>
        public FileSegment(
            FileInfo source,
            TimeAlignment alignment,
            IAudioUtility utility         = null,
            FileDateBehavior dateBehavior = FileDateBehavior.Try)
        {
            Contract.Requires(source != null);
            if (alignment != TimeAlignment.None)
            {
                Contract.Requires(
                    dateBehavior == FileDateBehavior.Required,
                    "If TimeAlignment is required, a date must be required in the filename");
            }

            this.dateBehavior = dateBehavior;
            this.Source       = source;
            this.Alignment    = alignment;

            var fileDate = this.ParseDate(null);

            var info = (utility ?? DefaultMasterAudioUtility).Info(source);

            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);

            this.SourceMetadata = new SourceMetadata(info.Duration.Value, info.SampleRate.Value, basename, fileDate);

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new <see cref="TaskProcessor"/> based on a <see cref="Task"/>
        /// </summary>
        /// <param name="task"> The <see cref="Task"/></param>
        /// <returns></returns>
        public TaskProcessor(AdaptTask task)
        {
            SignalWritter.CleanAppData();
            CreateSourceInstance(task.DataSource);
            List <AdaptSignal> inputSignals = m_Source.GetSignals().Where(s => task.InputSignalIds.Contains(s.ID)).ToList();

            m_sourceQueue       = Channel.CreateUnbounded <IFrame>();
            m_start             = task.Start;
            m_end               = task.End;
            m_sourceSignals     = inputSignals;
            m_cancelationSource = new CancellationTokenSource();
            m_sectionQueue      = task.Sections.Select(sec => Channel.CreateUnbounded <IFrame>()).ToList();
            Dictionary <string, int> framesPerSecond = new Dictionary <string, int>(inputSignals.Select(item => new KeyValuePair <string, int>(item.ID, (int)item.FramesPerSecond)));

            m_processors = task.Sections.Select((sec, i) => {
                if (i == 0)
                {
                    return(new SignalProcessor(m_sourceQueue, m_sectionQueue[0], sec, framesPerSecond));
                }
                return(new SignalProcessor(m_sectionQueue[i - 1], m_sectionQueue[i], sec, framesPerSecond));
            }).ToList();

            task.OutputSignals.ForEach(s => s.FramesPerSecond = framesPerSecond[s.ID]);
            m_writers = new ConcurrentDictionary <string, SignalWritter>(task.OutputSignals.ToDictionary(signal => signal.ID, signal => new SignalWritter(signal, task.VariableReplacements)));

            m_commonFrameRate = TimeAlignment.Combine(m_processors.Select(item => item.FramesPerSecond).Where(fps => fps > 0).ToArray());
        }
 public SignalProcessor(Channel <IFrame> input, Channel <IFrame> output, TaskSection section, Dictionary <string, int> framesPerSecond)
 {
     m_queueInput            = input;
     m_queueOutput           = output;
     m_analyticProcesors     = section.Analytics.Select(item => new AnalyticProcessor(item, framesPerSecond)).ToList();
     m_futureFrameBufferSize = m_analyticProcesors.Max(a => a.NFutureFrames);
     m_futureFrameBuffer     = new Queue <IFrame>(m_futureFrameBufferSize);
     FramesPerSecond         = TimeAlignment.Combine(m_analyticProcesors.Select(item => item.FramesPerSecond).Where(fps => fps > 0).ToArray());
     m_lastProcessedTS       = Ticks.MinValue;
 }
Beispiel #4
0
 /// <summary>
 /// Create as new <see cref="TaskProcessor"/> that only grabs the data from the <see cref="IDataSource"/> and saves it.
 /// No Processing is done in between.
 /// </summary>
 /// <param name="Signals"> A list of <see cref="AdaptSignal"/> to grab.</param>
 /// <param name="Source"> The <see cref="DataSource"/> used to get the Data</param>
 public TaskProcessor(List <AdaptSignal> Signals, DataSource Source, DateTime start, DateTime end)
 {
     SignalWritter.CleanAppData();
     CreateSourceInstance(Source);
     m_writers           = new ConcurrentDictionary <string, SignalWritter>(Signals.ToDictionary(signal => signal.ID, signal => new SignalWritter(signal)));
     m_processors        = new List <SignalProcessor>();
     m_sourceQueue       = Channel.CreateUnbounded <IFrame>();
     m_sectionQueue      = new List <Channel <IFrame> >();
     m_start             = start;
     m_end               = end;
     m_sourceSignals     = Signals;
     m_cancelationSource = new CancellationTokenSource();
     m_commonFrameRate   = TimeAlignment.Combine(Signals.Select(item => item.FramesPerSecond).ToArray());
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSegment"/> class.
 /// Allow specifying an absolutely aligned (to the nearest minute) file segment.
 /// Implies `FileDateBehavior.Required`.
 /// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
 /// </summary>
 public FileSegment(FileInfo source, TimeAlignment alignment)
     : this(source, alignment, null, FileDateBehavior.Required)
 {
 }