/// <summary> /// The scan completed. /// </summary> /// <param name="job"> /// The job. /// </param> /// <param name="instance"> /// The instance. /// </param> private void ScanCompleted(QueueTask job, IHandBrakeInstance instance) { // Get an EncodeJob object for the Interop Library EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job); // Start the Encode instance.StartEncode(encodeJob); // Fire the Encode Started Event this.InvokeEncodeStarted(EventArgs.Empty); // Set the Process Priority switch (job.Configuration.ProcessPriority) { case "Realtime": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; break; case "High": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; break; case "Above Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; break; case "Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; break; case "Low": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; break; default: Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; break; } }
/// <summary> /// Get a Preview image for the current job and preview number. /// </summary> /// <param name="job"> /// The job. /// </param> /// <param name="preview"> /// The preview. /// </param> /// <returns> /// The <see cref="BitmapImage"/>. /// </returns> public BitmapImage GetPreview(EncodeTask job, int preview) { if (this.instance == null) { return(null); } EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job); BitmapImage bitmapImage = null; try { bitmapImage = this.instance.GetPreview(encodeJob, preview); } catch (AccessViolationException e) { Console.WriteLine(e); } return(bitmapImage); }
/// <summary> /// The scan completed. /// </summary> /// <param name="job"> /// The job. /// </param> /// <param name="instance"> /// The instance. /// </param> private void ScanCompleted(QueueTask job, IHandBrakeInstance instance) { ServiceLogMessage("Scan Completed. Setting up the job for encoding ..."); // Get an EncodeJob object for the Interop Library EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job); // Start the Encode Title title = this.scannedSource.Titles.FirstOrDefault(t => t.TitleNumber == job.Task.Title); if (title == null) { ServiceLogMessage("Title not found."); throw new Exception("Unable to get title for encoding. Encode Failed."); } Interop.Model.Scan.Title scannedTitle = new Interop.Model.Scan.Title { Resolution = new Size(title.Resolution.Width, title.Resolution.Height), ParVal = new Size(title.ParVal.Width, title.ParVal.Height), FramerateDenominator = title.FramerateDenominator, FramerateNumerator = title.FramerateNumerator, }; // TODO fix this tempory hack to pass in the required title information into the factory. try { ServiceLogMessage("Starting Encode ..."); instance.StartEncode(encodeJob, scannedTitle); } catch (Exception exc) { ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", job.Task.Source)); } // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); // Set the Process Priority switch (job.Configuration.ProcessPriority) { case "Realtime": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; break; case "High": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; break; case "Above Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; break; case "Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; break; case "Low": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; break; default: Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; break; } }
/// <summary> /// Start with a LibHb EncodeJob Object /// </summary> /// <param name="job"> /// The job. /// </param> /// <param name="enableLogging"> /// The enable Logging. /// </param> public void Start(QueueTask job, bool enableLogging) { this.startTime = DateTime.Now; this.loggingEnabled = enableLogging; try { // Sanity Checking and Setup if (this.IsEncoding) { throw new Exception("HandBrake is already encoding."); } this.IsEncoding = true; // Get an EncodeJob object for the Interop Library EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job); // Enable logging if required. if (enableLogging) { try { this.SetupLogging(job); } catch (Exception) { this.IsEncoding = false; throw; } } // Prvent the system from sleeping if the user asks if (this.userSettingService.GetUserSetting <bool>(ASUserSettingConstants.PreventSleep)) { Win32.PreventSleep(); } // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(job); // Start the Encode this.instance.StartEncode(encodeJob); // Set the Process Priority switch (this.userSettingService.GetUserSetting <string>(ASUserSettingConstants.ProcessPriority)) { case "Realtime": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; break; case "High": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; break; case "Above Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; break; case "Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; break; case "Low": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; break; default: Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; break; } // Fire the Encode Started Event this.Invoke_encodeStarted(EventArgs.Empty); } catch (Exception exc) { this.Invoke_encodeCompleted(new EncodeCompletedEventArgs(false, exc, "An Error has occured in EncodeService.Run()")); } }