Exemplo n.º 1
0
        private void PollScanProgress()
        {
            IntPtr json       = HBFunctions.hb_get_state_json(this.hbHandle);
            string statusJson = Marshal.PtrToStringAnsi(json);

            this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace);
            JsonState state = JsonConvert.DeserializeObject <JsonState>(statusJson);

            if (state != null && state.State == NativeConstants.HB_STATE_SCANNING)
            {
                if (this.ScanProgress != null)
                {
                    this.ScanProgress(this, new ScanProgressEventArgs(state.Scanning.Progress, state.Scanning.Preview, state.Scanning.PreviewCount, state.Scanning.Title, state.Scanning.TitleCount));
                }
            }
            else if (state != null && state.State == NativeConstants.HB_STATE_SCANDONE)
            {
                var    jsonMsg  = HBFunctions.hb_get_title_set_json(this.hbHandle);
                string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
                this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Trace);
                this.titles       = JsonConvert.DeserializeObject <JsonScanObject>(scanJson);
                this.featureTitle = this.titles.MainFeature;

                this.scanPollTimer.Stop();

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new System.EventArgs());
                }
            }
        }
Exemplo n.º 2
0
        private void ScanNextJob()
        {
            SourcePath path = this.pathsToScan[this.currentJobIndex];

            IScanProxy scanProxy = Utilities.CreateScanProxy();

            scanProxy.ScanProgress += (sender, args) =>
            {
                lock (this.currentJobIndexLock)
                {
                    this.currentJobProgress = args.Value;
                    this.RaisePropertyChanged(nameof(this.Progress));
                }
            };

            scanProxy.ScanCompleted += (sender, args) =>
            {
                if (args.Value != null)
                {
                    JsonScanObject scanObject = JsonConvert.DeserializeObject <JsonScanObject>(args.Value);
                    this.ScanResults.Add(new ScanResult {
                        SourcePath = path, VideoSource = scanObject.ToVideoSource()
                    });
                }
                else
                {
                    this.ScanResults.Add(new ScanResult {
                        SourcePath = path
                    });
                }

                lock (this.currentJobIndexLock)
                {
                    this.currentJobIndex++;
                    this.currentJobProgress = 0;
                    this.RaisePropertyChanged(nameof(this.Progress));

                    if (this.ScanFinished)
                    {
                        DispatchUtilities.BeginInvoke(() =>
                        {
                            this.Cancel.Execute(null);
                        });
                    }
                    else
                    {
                        this.ScanNextJob();
                    }
                }
            };

            var scanLogger = StaticResolver.Resolve <AppLoggerFactory>().ResolveRemoteScanLogger(path.Path);

            scanProxy.StartScan(path.Path, scanLogger);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert Interop Title objects to App Services Title object
        /// </summary>
        /// <param name="titles">
        /// The titles.
        /// </param>
        /// <returns>
        /// The convert titles.
        /// </returns>
        private List <Title> ConvertTitles(JsonScanObject titles)
        {
            List <Title> titleList = new List <Title>();

            foreach (SourceTitle title in titles.TitleList)
            {
                Title converted = this.titleFactory.CreateTitle(title, titles.MainFeature);
                titleList.Add(converted);
            }

            return(titleList);
        }
        private void PollScanProgress()
        {
            IntPtr json       = HBFunctions.hb_get_state_json(this.hbHandle);
            string statusJson = Marshal.PtrToStringAnsi(json);

            this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace);
            JsonState state = null;

            if (!string.IsNullOrEmpty(statusJson))
            {
                state = JsonConvert.DeserializeObject <JsonState>(statusJson);
            }

            TaskState taskState = state != null?TaskState.FromRepositoryValue(state.State) : null;

            if (taskState != null && (taskState == TaskState.Scanning || taskState == TaskState.Searching))
            {
                if (this.ScanProgress != null && state.Scanning != null)
                {
                    this.ScanProgress(this, new ScanProgressEventArgs(state.Scanning.Progress, state.Scanning.Preview, state.Scanning.PreviewCount, state.Scanning.Title, state.Scanning.TitleCount));
                }
            }
            else if (taskState != null && taskState == TaskState.ScanDone)
            {
                this.scanPollTimer.Stop();

                var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);
                this.titlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
                this.log.LogMessage(this.titlesJson, LogMessageType.Progress, LogLevel.Trace);

                if (string.IsNullOrEmpty(this.titlesJson))
                {
                    this.log.LogMessage("Scan Error: No Scan Data Returned.", LogMessageType.API, LogLevel.Error);
                }
                else
                {
                    this.titles = JsonConvert.DeserializeObject <JsonScanObject>(this.titlesJson);
                    if (this.titles != null)
                    {
                        this.featureTitle = this.titles.MainFeature;
                    }
                }

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new System.EventArgs());
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks the status of the ongoing scan.
        /// </summary>
        private void PollScanProgress()
        {
            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_SCANNING)
            {
                if (this.ScanProgress != null)
                {
                    this.ScanProgress(this, new ScanProgressEventArgs
                    {
                        Progress       = state.Scanning.Progress,
                        CurrentPreview = state.Scanning.Preview,
                        Previews       = state.Scanning.PreviewCount,
                        CurrentTitle   = state.Scanning.Title,
                        Titles         = state.Scanning.TitleCount
                    });
                }
            }
            else if (state.State == NativeConstants.HB_STATE_SCANDONE)
            {
                this.titles = new List <Title>();

                var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);

                string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);

                JsonScanObject scanObject = JsonConvert.DeserializeObject <JsonScanObject>(scanJson);

                foreach (Title title in ScanFactory.CreateTitleSet(scanObject))
                {
                    // Set the Main Title.
                    this.featureTitle = title.IsMainFeature ? title.TitleNumber : 0;

                    this.titles.Add(title);
                }

                this.scanPollTimer.Stop();

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new System.EventArgs());
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// The create title set.
        /// </summary>
        /// <param name="scan">
        /// The scan.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable"/>.
        /// </returns>
        internal static IEnumerable <Title> CreateTitleSet(JsonScanObject scan)
        {
            List <Title> titles = new List <Title>();

            if (scan != null)
            {
                foreach (TitleList item in scan.TitleList)
                {
                    Title title = CreateTitle(item);

                    if (title.TitleNumber == scan.MainFeature)
                    {
                        title.IsMainFeature = true;
                    }

                    titles.Add(title);
                }
            }

            return(titles);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Convert Interop Title objects to App Services Title object
        /// </summary>
        /// <param name="titles">
        /// The titles.
        /// </param>
        /// <returns>
        /// The convert titles.
        /// </returns>
        private static List <Title> ConvertTitles(JsonScanObject titles)
        {
            List <Title> titleList = new List <Title>();

            foreach (SourceTitle title in titles.TitleList)
            {
                Title converted = new Title
                {
                    TitleNumber        = title.Index,
                    Duration           = new TimeSpan(0, title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
                    Resolution         = new Size(title.Geometry.Width, title.Geometry.Height),
                    AngleCount         = title.AngleCount,
                    ParVal             = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
                    AutoCropDimensions = new Cropping
                    {
                        Top    = title.Crop[0],
                        Bottom = title.Crop[1],
                        Left   = title.Crop[2],
                        Right  = title.Crop[3]
                    },
                    Fps                  = ((double)title.FrameRate.Num) / title.FrameRate.Den,
                    SourceName           = title.Path,
                    MainTitle            = titles.MainFeature == title.Index,
                    Playlist             = title.Type == 1 ? string.Format(" {0:d5}.MPLS", title.Playlist).Trim() : null,
                    FramerateNumerator   = title.FrameRate.Num,
                    FramerateDenominator = title.FrameRate.Den,
                    Type                 = title.Type
                };

                int currentTrack = 1;
                foreach (SourceChapter chapter in title.ChapterList)
                {
                    string chapterName = !string.IsNullOrEmpty(chapter.Name) ? chapter.Name : string.Empty;
                    converted.Chapters.Add(new Chapter(currentTrack, chapterName, new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)));
                    currentTrack++;
                }

                int currentAudioTrack = 1;
                foreach (SourceAudioTrack track in title.AudioList)
                {
                    converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, track.Codec, track.SampleRate, track.BitRate, track.ChannelLayout));
                    currentAudioTrack++;
                }

                int currentSubtitleTrack = 1;
                foreach (SourceSubtitleTrack track in title.SubtitleList)
                {
                    SubtitleType convertedType = new SubtitleType();

                    switch (track.Source)
                    {
                    case 0:
                        convertedType = SubtitleType.VobSub;
                        break;

                    case 4:
                        convertedType = SubtitleType.UTF8Sub;
                        break;

                    case 5:
                        convertedType = SubtitleType.TX3G;
                        break;

                    case 6:
                        convertedType = SubtitleType.SSA;
                        break;

                    case 1:
                        convertedType = SubtitleType.SRT;
                        break;

                    case 2:
                        convertedType = SubtitleType.CC;
                        break;

                    case 3:
                        convertedType = SubtitleType.CC;
                        break;

                    case 7:
                        convertedType = SubtitleType.PGS;
                        break;
                    }

                    bool canBurn          = HBFunctions.hb_subtitle_can_burn(track.Source) > 0;
                    bool canSetForcedOnly = HBFunctions.hb_subtitle_can_force(track.Source) > 0;

                    converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly));
                    currentSubtitleTrack++;
                }

                titleList.Add(converted);
            }

            return(titleList);
        }
Exemplo n.º 8
0
 public static VideoSource ToVideoSource(this JsonScanObject scanObject)
 {
     return(new VideoSource {
         FeatureTitle = scanObject.MainFeature, Titles = scanObject.TitleList
     });
 }