Ejemplo n.º 1
0
        public void CopyTo(ProcessWriter writer, CancellationToken cancellationToken)
        {
            Logger.Write(this.GetType(), LogLevel.Debug, "Begin reading data from channel {0} with {1} byte buffer.", this.Stream.ChannelHandle, BUFFER_SIZE);
            var length = default(int);
            var buffer = new byte[BUFFER_SIZE];

            while ((length = Bass.ChannelGetData(this.Stream.ChannelHandle, buffer, BUFFER_SIZE)) > 0)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
                writer.Write(buffer, length);
                this.Update();
            }
            Logger.Write(this.GetType(), LogLevel.Debug, "Finished reading data from channel {0}, closing process input.", this.Stream.ChannelHandle);
            writer.Close();
        }
Ejemplo n.º 2
0
        protected virtual void Encode(EncoderItem encoderItem, IBassStream stream, Process encoderProcess)
        {
            var channelReader = new ChannelReader(encoderItem, stream);
            var encoderWriter = new ProcessWriter(encoderProcess);
            var thread        = new Thread(() =>
            {
                this.Try(() => channelReader.CopyTo(encoderWriter, this.CancellationToken), this.GetErrorHandler(encoderItem));
            })
            {
                Name         = string.Format("ChannelReader(\"{0}\", {1})", encoderItem.InputFileName, stream.ChannelHandle),
                IsBackground = true
            };

            Logger.Write(this, LogLevel.Debug, "Starting background thread for file \"{0}\".", encoderItem.InputFileName);
            thread.Start();
            Logger.Write(this, LogLevel.Debug, "Completing background thread for file \"{0}\".", encoderItem.InputFileName);
            this.Join(thread);
            encoderWriter.Close();
        }
Ejemplo n.º 3
0
        public void CopyTo(ProcessWriter writer, CancellationToken cancellationToken)
        {
            Logger.Write(this.GetType(), LogLevel.Debug, "Begin reading data from process {0} with {1} byte buffer.", this.Process.Id, BUFFER_SIZE);
            var length = default(int);
            var buffer = new byte[BUFFER_SIZE];

            while (!this.Process.HasExited)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
                while ((length = this.Process.StandardOutput.BaseStream.Read(buffer, 0, BUFFER_SIZE)) > 0)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                    writer.Write(buffer, length);
                }
            }
            Logger.Write(this.GetType(), LogLevel.Debug, "Finished reading data from process {0}, closing process input.", this.Process.Id);
            writer.Close();
        }