Ejemplo n.º 1
0
 public static void PreventSleep()
 {
     DispatchUtilities.BeginInvoke(() =>
     {
         SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
     });
 }
Ejemplo n.º 2
0
 public static void AllowSleep()
 {
     DispatchUtilities.BeginInvoke(() =>
     {
         SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
     });
 }
Ejemplo n.º 3
0
        public void OnEncodeProgress(float averageFrameRate, float currentFrameRate, TimeSpan estimatedTimeLeft, float fractionComplete, int passId, int pass, int passCount, string stateCode)
        {
            // Dispatch to avoid deadlocks on callbacks
            DispatchUtilities.BeginInvoke(() =>
            {
                lock (this.ProcessLock)
                {
                    this.LastWorkerCommunication = DateTimeOffset.UtcNow;

                    if (this.Running && this.EncodeProgress != null)
                    {
                        this.EncodeProgress(
                            this,
                            new EncodeProgressEventArgs(fractionComplete, currentFrameRate, averageFrameRate, estimatedTimeLeft, passId, pass, passCount, stateCode));
                    }
                }
            });
        }
Ejemplo n.º 4
0
        private void StartEncodeInternal(string scanPath, int titleNumber, Func <JsonScanObject, string> jsonFunc)
        {
            this.logger.Log("Starting encode in-process");

            this.encoding = true;

            this.encodeStartEvent = new ManualResetEventSlim(false);
            this.encodeEndEvent   = new ManualResetEventSlim(false);

            this.instance = new HandBrakeInstance();
            this.instance.Initialize(Config.LogVerbosity, noHardware: false);

            this.instance.ScanCompleted += (o, e) =>
            {
                try
                {
                    string encodeJson = jsonFunc(this.instance.Titles);
                    if (encodeJson != null)
                    {
                        lock (this.encoderLock)
                        {
                            this.instance.StartEncode(encodeJson);
                            this.EncodeStarted?.Invoke(this, EventArgs.Empty);

                            this.encodeStartEvent.Set();
                        }
                    }
                    else
                    {
                        this.EncodeCompleted?.Invoke(this, new EncodeCompletedEventArgs(error: true));

                        this.encodeStartEvent.Set();
                        this.encodeEndEvent.Set();
                    }
                }
                catch (Exception exception)
                {
                    this.logger.LogError("Encoding failed. Please report this error so it can be fixed in the future:" + Environment.NewLine + exception);
                }
            };

            this.instance.EncodeProgress += (o, e) =>
            {
                // Dispatch to avoid deadlocks on callbacks
                DispatchUtilities.BeginInvoke(() =>
                {
                    lock (this.encoderLock)
                    {
                        if (this.encoding)
                        {
                            this.EncodeProgress?.Invoke(this, e);
                        }
                    }
                });
            };

            this.instance.EncodeCompleted += (o, e) =>
            {
                if (this.encoding)
                {
                    this.EncodeCompleted?.Invoke(this, e);

                    this.encoding = false;
                }

                this.encodeEndEvent.Set();
                this.instance.Dispose();
            };

            this.instance.StartScan(scanPath, Config.PreviewCount, TimeSpan.FromSeconds(Config.MinimumTitleLengthSeconds), titleNumber);

            this.encoding = true;
        }