Esempio n. 1
0
 private void InfoTimerTick(object source, ElapsedEventArgs args)
 {
     while (true)
     {
         try
         {
             // let's ignore the time here, for reasons detailed in VLCWrapperParsingUnit.cs around line 115
             float position = transcoder.GetPosition();
             StreamLog.Trace(context.Identifier, "VLCManagedInfo: calling NewPercentage with position {0}", position);
             calculator.NewPercentage(position);
             calculator.SaveStats(infoReference);
         }
         catch (Exception ex)
         {
             StreamLog.Warn(context.Identifier, "Failed to get VLC data", ex);
         }
     }
 }
        private void ParseOutputStream(Stream stdoutStream, Reference <WebTranscodingInfo> data, int startPosition, bool logProgress)
        {
            StreamReader reader = new StreamReader(stdoutStream);
            TranscodingInfoCalculator calculator = new TranscodingInfoCalculator(position, 25, 500, info.Duration); //VLCWrapper prints twice a second

            bool   aborted = false;
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                try
                {
                    Log.Trace("VLCWrapperParsing: read line {0}", line);

                    // just for debugging of the wrapper tool
                    if (line.StartsWith("A") || line == "S started" || line == "S null")
                    {
                        continue;
                    }

                    // propagate start event to Start() method
                    if (line == "S playing")
                    {
                        vlcIsStarted = true;
                        continue;
                    }

                    // events
                    if (line == "S error")
                    {
                        vlcIsStarted        = true;
                        data.Value.Finished = true;
                        data.Value.Failed   = true;
                        break;
                    }

                    if (line == "S finished")
                    {
                        data.Value.Failed   = false;
                        data.Value.Finished = true;
                        continue;
                    }

                    // the actual progress parsing
                    if (line.StartsWith("P"))
                    {
                        // the format is 'P [time in microseconds] [percentage of file]'. Sadly we can't use the way more detailed time in microseconds
                        // because the VLC guys decided it would be a good idea to convert it to a 32-bit integer before returning it, as opposed to
                        // returning libvlc_time_t or a int64_t. And since it's in microseconds it gets big very fast, so it's absolutely useless.
                        double percentage = Double.Parse(line.Substring(line.IndexOf(",") + 2), CultureInfo.InvariantCulture);
                        calculator.NewPercentage(percentage);
                        calculator.SetStats(data);
                        continue;
                    }

                    Log.Warn("VLCWrapperParsing: encountered unknown line {0}", line);
                }
                catch (ThreadAbortException)
                {
                    aborted = true;
                    break;
                }
                catch (Exception e)
                {
                    Log.Error("Failure during parsing of VLC output", e);
                }
            }

            data.Value.Failed   = aborted;
            data.Value.Finished = true;
            reader.Close();
            return;
        }