Esempio n. 1
0
        public UserDefinedWriter(string path, Stream IO, UserDefinedEncoderSettings settings)
        {
            m_settings  = settings;
            _path       = path;
            useTempFile = m_settings.Parameters.Contains("%I");
            tempFile    = path + ".tmp.wav";

            _encoderProcess = new Process();
            _encoderProcess.StartInfo.FileName       = m_settings.Path;
            _encoderProcess.StartInfo.Arguments      = m_settings.Parameters.Replace("%O", "\"" + path + "\"").Replace("%M", m_settings.EncoderMode).Replace("%P", m_settings.Padding.ToString()).Replace("%I", "\"" + tempFile + "\"");
            _encoderProcess.StartInfo.CreateNoWindow = true;
            if (!useTempFile)
            {
                _encoderProcess.StartInfo.RedirectStandardInput = true;
            }
            _encoderProcess.StartInfo.UseShellExecute = false;
            if (!m_settings.Parameters.Contains("%O"))
            {
                _encoderProcess.StartInfo.RedirectStandardOutput = true;
            }
            if (useTempFile)
            {
                wrt = new WAVWriter(tempFile, null, new WAVWriterSettings(settings.PCM));
                return;
            }
            bool      started = false;
            Exception ex      = null;

            try
            {
                started = _encoderProcess.Start();
                if (started)
                {
                    _encoderProcess.PriorityClass = Process.GetCurrentProcess().PriorityClass;
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }
            if (!started)
            {
                throw new Exception(m_settings.Path + ": " + (ex == null ? "please check the path" : ex.Message));
            }
            if (_encoderProcess.StartInfo.RedirectStandardOutput)
            {
                Stream outputStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
                outputBuffer = new CyclicBuffer(2 * 1024 * 1024, _encoderProcess.StandardOutput.BaseStream, outputStream);
            }
            Stream inputStream = new CyclicBufferOutputStream(_encoderProcess.StandardInput.BaseStream, 128 * 1024);

            wrt = new WAVWriter(path, inputStream, new WAVWriterSettings(settings.PCM));
        }
Esempio n. 2
0
 public UserDefinedWriter(string path, UserDefinedEncoderSettings settings)
     : this(path, null, settings)
 {
 }