Exemple #1
0
        public void SetUpWorker(
            int verbosity,
            int previewCount,
            bool useDvdNav,
            double minTitleDurationSeconds,
            double cpuThrottlingFraction,
            string tempFolder)
        {
#if DEBUG_REMOTE
            Debugger.Launch();
#endif

            this.passedVerbosity               = verbosity;
            this.passedPreviewCount            = previewCount;
            this.passedMinTitleDurationSeconds = minTitleDurationSeconds;
            this.passedCpuThrottlingFraction   = cpuThrottlingFraction;

            CurrentWorker = this;
            this.callback = OperationContext.Current.GetCallbackChannel <IHandBrakeWorkerCallback>();

            this.logger = new WorkerLogger(this.callback);

            try
            {
                if (!string.IsNullOrEmpty(tempFolder))
                {
                    Environment.SetEnvironmentVariable("TMP", tempFolder, EnvironmentVariableTarget.Process);
                }

                if (this.callback == null)
                {
                    throw new ArgumentException("Could not get callback channel.");
                }

                this.ApplyCpuThrottling();

                HandBrakeUtils.MessageLogged += (o, e) =>
                {
                    this.StopOnException(() =>
                    {
                        this.callback.OnMessageLogged(e.Message);
                    });
                };

                HandBrakeUtils.ErrorLogged += (o, e) =>
                {
                    this.StopOnException(() =>
                    {
                        this.callback.OnErrorLogged(e.Message);
                    });
                };

                HandBrakeUtils.SetDvdNav(useDvdNav);
            }
            catch (Exception exception)
            {
                this.callback.OnException(exception.ToString());
                throw;
            }
        }
Exemple #2
0
        public void SetUpWorker(
            int verbosity,
            int previewCount,
            bool useDvdNav,
            double minTitleDurationSeconds,
            double cpuThrottlingFraction,
            string tempFolder)
        {
#if DEBUG_REMOTE
            Debugger.Launch();
#endif

            this.passedVerbosity               = verbosity;
            this.passedPreviewCount            = previewCount;
            this.passedMinTitleDurationSeconds = minTitleDurationSeconds;

            CurrentWorker = this;
            this.callback = OperationContext.Current.GetCallbackChannel <IHandBrakeWorkerCallback>();

            Ioc.Container.RegisterInstance <ILogger>(new WorkerLogger(this.callback));

            try
            {
                if (!string.IsNullOrEmpty(tempFolder))
                {
                    Environment.SetEnvironmentVariable("TMP", tempFolder, EnvironmentVariableTarget.Process);
                }

                if (cpuThrottlingFraction < 1.0)
                {
                    int coresToUse = (int)Math.Round(Environment.ProcessorCount * cpuThrottlingFraction);
                    if (coresToUse < 1)
                    {
                        coresToUse = 1;
                    }

                    if (coresToUse > Environment.ProcessorCount)
                    {
                        coresToUse = Environment.ProcessorCount;
                    }

                    Process process      = Process.GetCurrentProcess();
                    long    affinityMask = 0x0;
                    for (int i = 0; i < coresToUse; i++)
                    {
                        affinityMask |= (uint)(1 << i);
                    }

                    process.ProcessorAffinity = (IntPtr)affinityMask;
                }

                if (this.callback == null)
                {
                    throw new ArgumentException("Could not get callback channel.");
                }


                HandBrakeUtils.MessageLogged += (o, e) =>
                {
                    this.StopOnException(() =>
                    {
                        this.callback.OnMessageLogged(e.Message);
                    });
                };

                HandBrakeUtils.ErrorLogged += (o, e) =>
                {
                    this.StopOnException(() =>
                    {
                        this.callback.OnErrorLogged(e.Message);
                    });
                };

                HandBrakeUtils.SetDvdNav(useDvdNav);
            }
            catch (Exception exception)
            {
                this.callback.OnException(exception.ToString());
                throw;
            }
        }
Exemple #3
0
 public WorkerLogger(IHandBrakeWorkerCallback callback)
 {
     this.callback = callback;
 }