Esempio n. 1
0
        /// <summary>
        /// Checks the status of the ongoing encode.
        /// </summary>
        /// <summary>
        /// Checks the status of the ongoing encode.
        /// </summary>
        private void PollEncodeProgress()
        {
            IntPtr    json       = HBFunctions.hb_get_state_json(this.hbHandle);
            string    statusJson = Marshal.PtrToStringAnsi(json);
            JsonState state      = JsonConvert.DeserializeObject <JsonState>(statusJson);

            if (state.State == NativeConstants.HB_STATE_WORKING)
            {
                if (this.EncodeProgress != null)
                {
                    var progressEventArgs = new EncodeProgressEventArgs
                    {
                        FractionComplete  = state.Working.Progress,
                        CurrentFrameRate  = state.Working.Rate,
                        AverageFrameRate  = state.Working.RateAvg,
                        EstimatedTimeLeft = new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds),
                        Pass = 1, // TODO
                    };

                    this.EncodeProgress(this, progressEventArgs);
                }
            }
            else if (state.State == NativeConstants.HB_STATE_WORKDONE)
            {
                this.encodePollTimer.Stop();

                if (this.EncodeCompleted != null)
                {
                    this.EncodeCompleted(this, new EncodeCompletedEventArgs
                    {
                        Error = state.WorkDone.Error != (int)hb_error_code.HB_ERROR_NONE
                    });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks the status of the ongoing encode.
        /// </summary>
        private void PollEncodeProgress()
        {
            hb_state_s state = new hb_state_s();
            HBFunctions.hb_get_state(this.hbHandle, ref state);

            if (state.state == NativeConstants.HB_STATE_WORKING)
            {
                if (this.EncodeProgress != null)
                {
                    int pass = 1;
                    int rawJobNumber = state.param.working.job_cur;

                    if (this.currentJob.EncodingProfile.TwoPass)
                    {
                        if (this.subtitleScan)
                        {
                            switch (rawJobNumber)
                            {
                                case 1:
                                    pass = -1;
                                    break;
                                case 2:
                                    pass = 1;
                                    break;
                                case 3:
                                    pass = 2;
                                    break;
                                default:
                                    break;
                            }
                        }
                        else
                        {
                            switch (rawJobNumber)
                            {
                                case 1:
                                    pass = 1;
                                    break;
                                case 2:
                                    pass = 2;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    else
                    {
                        if (this.subtitleScan)
                        {
                            switch (rawJobNumber)
                            {
                                case 1:
                                    pass = -1;
                                    break;
                                case 2:
                                    pass = 1;
                                    break;
                                default:
                                    break;
                            }
                        }
                        else
                        {
                            pass = 1;
                        }
                    }

                    var progressEventArgs = new EncodeProgressEventArgs
                    {
                        FractionComplete = state.param.working.progress,
                        CurrentFrameRate = state.param.working.rate_cur,
                        AverageFrameRate = state.param.working.rate_avg,
                        EstimatedTimeLeft = new TimeSpan(state.param.working.hours, state.param.working.minutes, state.param.working.seconds),
                        Pass = pass
                    };

                    this.EncodeProgress(this, progressEventArgs);
                }
            }
            else if (state.state == NativeConstants.HB_STATE_WORKDONE)
            {
                InteropUtilities.FreeMemory(this.encodeAllocatedMemory);
                this.encodePollTimer.Stop();

                if (this.EncodeCompleted != null)
                {
                    this.EncodeCompleted(this, new EncodeCompletedEventArgs { Error = state.param.workdone.error > 0 });
                }
            }
        }