Ejemplo n.º 1
0
        /// <summary>
        /// Start with a LibHb EncodeJob Object
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        public void Start(EncodeTask task, HBConfiguration configuration)
        {
            try
            {
                // Sanity Checking and Setup
                if (this.IsEncoding)
                {
                    throw new GeneralApplicationException("HandBrake is already encoding a file.", "Please stop the current encode. If the problem persists, please restart HandBrake.", null);
                }

                // Setup
                this.startTime            = DateTime.Now;
                this.currentTask          = task;
                this.currentConfiguration = configuration;

                // Create a new HandBrake instance
                // Setup the HandBrake Instance
                HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
                HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
                this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity);

                this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
                this.instance.EncodeProgress  += this.InstanceEncodeProgress;

                this.IsEncoding        = true;
                this.isPreviewInstance = task.IsPreviewEncode;
                this.SetupLogging(task.IsPreviewEncode);

                // Verify the Destination Path Exists, and if not, create it.
                this.VerifyEncodeDestinationPath(task);

                this.ServiceLogMessage("Starting Encode ...");

                // Get an EncodeJob object for the Interop Library
                this.instance.StartEncode(EncodeFactory.Create(task, configuration));

                // Fire the Encode Started Event
                this.InvokeEncodeStarted(System.EventArgs.Empty);
            }
            catch (Exception exc)
            {
                this.IsEncoding = false;

                this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc);
                this.InvokeEncodeCompleted(new HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start with a LibHb EncodeJob Object
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        public void Start(EncodeTask task, HBConfiguration configuration)
        {
            try
            {
                // Sanity Checking and Setup
                if (this.IsEncoding)
                {
                    throw new GeneralApplicationException(Resources.Queue_AlreadyEncoding, Resources.Queue_AlreadyEncodingSolution, null);
                }

                // Setup
                this.startTime            = DateTime.Now;
                this.currentTask          = task;
                this.currentConfiguration = configuration;

                // Create a new HandBrake instance
                // Setup the HandBrake Instance
                this.log.Reset(); // Reset so we have a clean log for the start of the encode.
                this.ServiceLogMessage("Starting Encode ...");

                HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);
                this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity);

                this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
                this.instance.EncodeProgress  += this.InstanceEncodeProgress;

                this.IsEncoding        = true;
                this.isPreviewInstance = task.IsPreviewEncode;

                // Verify the Destination Path Exists, and if not, create it.
                this.VerifyEncodeDestinationPath(task);

                // Get an EncodeJob object for the Interop Library
                this.instance.StartEncode(EncodeFactory.Create(task, configuration));

                // Fire the Encode Started Event
                this.InvokeEncodeStarted(System.EventArgs.Empty);
            }
            catch (Exception exc)
            {
                this.IsEncoding = false;

                this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc);
                this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source, null, 0));
            }
        }
Ejemplo n.º 3
0
        public void StartEncode(EncodeJob job, Title title)
        {
            JsonEncodeObject encodeObject = EncodeFactory.Create(job, title);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
            };

            string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);

            HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode));
            HBFunctions.hb_start(this.hbHandle);

            this.encodePollTimer          = new Timer();
            this.encodePollTimer.Interval = EncodePollIntervalMs;

            this.encodePollTimer.Elapsed += (o, e) =>
            {
                this.PollEncodeProgress();
            };
            this.encodePollTimer.Start();
        }
Ejemplo n.º 4
0
        public override string ValueEncoding()
        {
            while (rule.i < length + temp)
            {
                //先判断出Tag的值是否为那三个值;
                string tag = "";
                if (rule.ie == 1)
                {
                    ushort gtag = (ushort)(rule.buff[rule.i] * 256 + rule.buff[rule.i + 1]);
                    ushort etag = (ushort)(rule.buff[rule.i + 2] * 256 + rule.buff[rule.i + 3]);
                    tag = "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")";
                }
                else
                {
                    ushort gtag = (ushort)(rule.buff[rule.i] + rule.buff[rule.i + 1] * 256);
                    ushort etag = (ushort)(rule.buff[rule.i + 2] + rule.buff[rule.i + 3] * 256);
                    tag = "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")";
                }

                if (tag == "(FFFE,E000)" || tag == "(FFFE,E00D)")
                {
                    Rule t_rule = new Rule();
                    t_rule.i    = rule.i;
                    t_rule.buff = rule.buff;

                    t_rule.ie = 0;//隐式VR

                    t_rule.flag = rule.flag;
                    Encode encode = EncodeFactory.CreateEnode(t_rule);
                    Item   item   = encode.encode();
                    list.Add(item);
                    rule.i = t_rule.i;
                }
                else if (tag == "(FFFE,E0DD)")
                {
                    Rule t_rule = new Rule();
                    t_rule.i    = rule.i;
                    t_rule.buff = rule.buff;

                    t_rule.ie = 0;//隐式VR

                    t_rule.flag = rule.flag;
                    Encode encode = EncodeFactory.CreateEnode(t_rule);
                    Item   item   = encode.encode();
                    list.Add(item);
                    rule.i = t_rule.i;
                    break;
                }
                else
                {
                    Encode encode = EncodeFactory.CreateEnode(rule);
                    Item   item   = encode.encode();
                    list.Add(item);
                }
            }
            String str = "";

            for (int i = 0; i < list.Count; i++)
            {
                String temp_s = list[i].Tag + "\t" + list[i].len.ToString() + "\t" + list[i].Value.Replace('\0', ' ') + "\n";
                str += temp_s;
            }

            return(str);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start with a LibHb EncodeJob Object
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        public void Start(EncodeTask task, HBConfiguration configuration)
        {
            try
            {
                // Setup
                this.startTime            = DateTime.Now;
                this.currentTask          = task;
                this.currentConfiguration = configuration;

                // Create a new HandBrake instance
                // Setup the HandBrake Instance
                HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
                HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
                this.instance = HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity);
                this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
                this.instance.EncodeProgress  += this.InstanceEncodeProgress;

                // Sanity Checking and Setup
                if (this.IsEncoding)
                {
                    throw new Exception("HandBrake is already encoding.");
                }

                this.IsEncoding = true;
                this.SetupLogging();

                // Verify the Destination Path Exists, and if not, create it.
                this.VerifyEncodeDestinationPath(task);

                this.ServiceLogMessage("Starting Encode ...");

                // Get an EncodeJob object for the Interop Library
                this.instance.StartEncode(EncodeFactory.Create(task, configuration));

                // Fire the Encode Started Event
                this.InvokeEncodeStarted(System.EventArgs.Empty);

                // Set the Process Priority
                switch (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;
                }
            }
            catch (Exception exc)
            {
                this.IsEncoding = false;

                this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc);
                this.InvokeEncodeCompleted(new HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source));
            }
        }