diff options
author | sr55 <[email protected]> | 2015-03-05 21:05:26 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2015-03-05 21:05:26 +0000 |
commit | f6bf7d75908d718ea620ac2e6f691627d0a9e7c2 (patch) | |
tree | d4345230a9fb991e1dd4d4248c263aa46f2e4899 /win/CS/HandBrake.ApplicationServices/Interop/Factories | |
parent | 5c7597d9de68e920ea6f06b6086df148d7225739 (diff) |
WinGui: Moving some more namespaces.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6967 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Interop/Factories')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Interop/Factories/AnamorphicFactory.cs | 111 | ||||
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Interop/Factories/ScanFactory.cs | 221 |
2 files changed, 332 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Factories/AnamorphicFactory.cs b/win/CS/HandBrake.ApplicationServices/Interop/Factories/AnamorphicFactory.cs new file mode 100644 index 000000000..2618fc4a8 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Factories/AnamorphicFactory.cs @@ -0,0 +1,111 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AnamorphicFactory.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The Anamorphic factory.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Interop.Factories
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+
+ using HandBrake.ApplicationServices.Interop.HbLib;
+ using HandBrake.ApplicationServices.Interop.Json.Anamorphic;
+ using HandBrake.ApplicationServices.Interop.Model;
+ using HandBrake.ApplicationServices.Interop.Model.Encoding;
+ using HandBrake.ApplicationServices.Services.Encode.Model;
+
+ using Newtonsoft.Json;
+
+ /// <summary>
+ /// The anamorphic factory.
+ /// </summary>
+ public class AnamorphicFactory
+ {
+ /// <summary>
+ /// The keep setting.
+ /// </summary>
+ public enum KeepSetting
+ {
+ HB_KEEP_WIDTH = 0x01,
+ HB_KEEP_HEIGHT = 0x02,
+ HB_KEEP_DISPLAY_ASPECT = 0x04
+ }
+
+ /// <summary>
+ /// The create geometry.
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="title">
+ /// The current title.
+ /// </param>
+ /// <param name="keepWidthOrHeight">
+ /// Keep Width or Height. (Not Display Aspect)
+ /// </param>
+ /// <returns>
+ /// The <see cref="HandBrake.ApplicationServices.Interop.Json.Scan.Geometry"/>.
+ /// </returns>
+ public static Geometry CreateGeometry(EncodeTask job, SourceVideoInfo title, KeepSetting keepWidthOrHeight) // Todo remove the need for these objects. Should use simpler objects.
+ {
+ int settingMode = (int)keepWidthOrHeight + (job.KeepDisplayAspect ? 0x04 : 0);
+
+ // Sanatise the Geometry First.
+ AnamorphicGeometry anamorphicGeometry = new AnamorphicGeometry
+ {
+ SourceGeometry = new SourceGeometry
+ {
+ Width = title.Resolution.Width,
+ Height = title.Resolution.Height,
+ PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height }
+ },
+ DestSettings = new DestSettings
+ {
+ AnamorphicMode = (int)job.Anamorphic,
+ Geometry = {
+ Width = job.Width ?? 0, Height = job.Height ?? 0,
+ PAR = new PAR
+ {
+ Num = job.Anamorphic != Anamorphic.Custom ? title.ParVal.Width : job.PixelAspectX,
+ Den = job.Anamorphic != Anamorphic.Custom ? title.ParVal.Height : job.PixelAspectY,
+ }
+ },
+ Keep = settingMode,
+ Crop = new List<int> { job.Cropping.Top, job.Cropping.Bottom, job.Cropping.Left, job.Cropping.Right },
+ Modulus = job.Modulus ?? 16,
+ MaxWidth = job.MaxWidth ?? 0,
+ MaxHeight = job.MaxHeight ?? 0,
+ ItuPAR = false
+ }
+ };
+
+ if (job.Anamorphic == Anamorphic.Custom)
+ {
+ anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = job.PixelAspectX, Den = job.PixelAspectY };
+ }
+ else
+ {
+ anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height };
+ }
+
+ string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
+ IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));
+ string result = Marshal.PtrToStringAnsi(json);
+ AnamorphicResult resultGeometry = JsonConvert.DeserializeObject<AnamorphicResult>(result);
+
+ // Setup the Destination Gemotry.
+ Geometry geometry = new Geometry
+ {
+ Width = resultGeometry.Width,
+ Height = resultGeometry.Height,
+ PAR = resultGeometry.PAR
+ };
+ return geometry;
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Factories/ScanFactory.cs b/win/CS/HandBrake.ApplicationServices/Interop/Factories/ScanFactory.cs new file mode 100644 index 000000000..e2ac0f3cb --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Factories/ScanFactory.cs @@ -0,0 +1,221 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="ScanFactory.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The scan factory.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Interop.Factories
+{
+ using System;
+ using System.Collections.Generic;
+
+ using HandBrake.ApplicationServices.Interop.Json.Scan;
+ using HandBrake.ApplicationServices.Interop.Model;
+ using HandBrake.ApplicationServices.Interop.Model.Scan;
+
+ /// <summary>
+ /// This factory takes the JSON objects deserialized from libhb for the scan information
+ /// and converts them into the internal Title objects.
+ /// </summary>
+ internal class ScanFactory
+ {
+ /// <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;
+ }
+
+ /// <summary>
+ /// The create title.
+ /// </summary>
+ /// <param name="title">
+ /// The title.
+ /// </param>
+ /// <returns>
+ /// The <see cref="Title"/>.
+ /// </returns>
+ private static Title CreateTitle(TitleList title)
+ {
+ Title newTitle = new Title
+ {
+ TitleNumber = title.Index,
+ Playlist = title.Playlist,
+ Resolution = new Size(title.Geometry.Width, title.Geometry.Height),
+ ParVal = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
+ Duration = new TimeSpan(title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
+ AutoCropDimensions = new Cropping
+ {
+ Top = title.Crop[0],
+ Bottom = title.Crop[1],
+ Left = title.Crop[2],
+ Right = title.Crop[3]
+ },
+ AngleCount = title.AngleCount,
+ VideoCodecName = title.VideoCodec,
+ Framerate = ((double)title.FrameRate.Num) / title.FrameRate.Den,
+ FramerateNumerator = title.FrameRate.Num,
+ FramerateDenominator = title.FrameRate.Den,
+ Path = title.Path
+ };
+
+ switch (title.Type)
+ {
+ case 2:
+ newTitle.InputType = InputType.Stream;
+ break;
+ case 0:
+ newTitle.InputType = InputType.Dvd;
+ break;
+ case 1:
+ newTitle.InputType = InputType.Bluray;
+ break;
+ case 3:
+ newTitle.InputType = InputType.FFStream;
+ break;
+ }
+
+ foreach (Subtitle subtitleTrack in CreateSubtitleTracks(title.SubtitleList))
+ {
+ newTitle.Subtitles.Add(subtitleTrack);
+ }
+
+ foreach (AudioTrack audioTrack in CreateAudioTracks(title.AudioList))
+ {
+ newTitle.AudioTracks.Add(audioTrack);
+ }
+
+ foreach (Chapter chapter in CreateChapters(title.ChapterList))
+ {
+ newTitle.Chapters.Add(chapter);
+ }
+
+ return newTitle;
+ }
+
+ /// <summary>
+ /// The create subtitle tracks.
+ /// </summary>
+ /// <param name="subtitles">
+ /// The subtitles.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IEnumerable"/>.
+ /// </returns>
+ private static IEnumerable<Subtitle> CreateSubtitleTracks(IEnumerable<SubtitleList> subtitles)
+ {
+ List<Subtitle> subtiles = new List<Subtitle>();
+
+ int currentSubtitleTrack = 1;
+ foreach (SubtitleList subtitle in subtitles)
+ {
+ Subtitle newSubtitle = new Subtitle
+ {
+ TrackNumber = currentSubtitleTrack,
+ Language = subtitle.Language,
+ LanguageCode = subtitle.LanguageCode,
+ SubtitleSourceInt = subtitle.Source,
+ SubtitleSource = (SubtitleSource)subtitle.Source // TODO Check correct
+ };
+
+ subtiles.Add(newSubtitle);
+
+ currentSubtitleTrack++;
+ }
+
+ return subtiles;
+ }
+
+ /// <summary>
+ /// The create audio tracks.
+ /// </summary>
+ /// <param name="audioTracks">
+ /// The audio tracks.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IEnumerable"/>.
+ /// </returns>
+ private static IEnumerable<AudioTrack> CreateAudioTracks(IEnumerable<AudioList> audioTracks)
+ {
+ List<AudioTrack> tracks = new List<AudioTrack>();
+
+ int currentAudioTrack = 1;
+ foreach (AudioList track in audioTracks)
+ {
+ AudioTrack newAudio = new AudioTrack
+ {
+ TrackNumber = currentAudioTrack,
+ CodecId = Convert.ToUInt32(track.Codec),
+ Language = track.Language,
+ LanguageCode = track.LanguageCode,
+ Description = track.Description,
+ ChannelLayout = (ulong)track.ChannelLayout,
+ SampleRate = track.SampleRate,
+ Bitrate = track.BitRate
+ };
+
+ tracks.Add(newAudio);
+
+ currentAudioTrack++;
+ }
+ return tracks;
+ }
+
+ /// <summary>
+ /// The create chapters.
+ /// </summary>
+ /// <param name="chapters">
+ /// The chapters.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IEnumerable"/>.
+ /// </returns>
+ private static IEnumerable<Chapter> CreateChapters(IEnumerable<ChapterList> chapters)
+ {
+ List<Chapter> tracks = new List<Chapter>();
+
+ int currentTrack = 1;
+ foreach (ChapterList chapter in chapters)
+ {
+ Chapter newChapter = new Chapter
+ {
+ Name = chapter.Name,
+ ChapterNumber = currentTrack,
+ Duration = new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)
+ };
+
+ tracks.Add(newChapter);
+ currentTrack++;
+ }
+
+ return tracks;
+ }
+ }
+}
|