Skip to content

Commit

Permalink
WinGui: Updates to handle changes to the JSON API. HandBrake#964
Browse files Browse the repository at this point in the history
  • Loading branch information
sr55 committed Nov 6, 2017
1 parent 8a68af4 commit 84ae324
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
<Compile Include="Interop\Json\Presets\PresetCategory.cs" />
<Compile Include="Interop\Json\Presets\PresetTransportContainer.cs" />
<Compile Include="Interop\Json\Queue\Task.cs" />
<Compile Include="Interop\Json\Scan\AudioAttributes.cs" />
<Compile Include="Interop\Json\Scan\SubtitleAttributes.cs" />
<Compile Include="Interop\Json\Shared\PAR.cs" />
<Compile Include="Interop\Json\Encode\Audio.cs" />
<Compile Include="Interop\Json\Encode\AudioTrack.cs" />
Expand All @@ -125,6 +127,7 @@
<Compile Include="Interop\Json\Encode\SubtitleTrack.cs" />
<Compile Include="Interop\Json\Encode\Video.cs" />
<Compile Include="Interop\Factories\AnamorphicFactory.cs" />
<Compile Include="Interop\Json\State\TaskState.cs" />
<Compile Include="Interop\Model\Encoding\CombDetect.cs" />
<Compile Include="Interop\Model\Encoding\DeinterlaceFilter.cs" />
<Compile Include="Interop\Model\Encoding\HBPresetTune.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,16 @@ private void PollScanProgress()
state = JsonConvert.DeserializeObject<JsonState>(statusJson);
}

if (state != null && (state.State == NativeConstants.HB_STATE_SCANNING || state.State == NativeConstants.HB_STATE_SEARCHING))
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 (state != null && state.State == NativeConstants.HB_STATE_SCANDONE)
else if (taskState != null && taskState == TaskState.ScanDone)
{
this.scanPollTimer.Stop();

Expand Down Expand Up @@ -531,17 +533,19 @@ private void PollEncodeProgress()

JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);

if (state != null && (state.State == NativeConstants.HB_STATE_WORKING || state.State == NativeConstants.HB_STATE_MUXING || state.State == NativeConstants.HB_STATE_SEARCHING))
TaskState taskState = state != null ? TaskState.FromRepositoryValue(state.State) : null;

if (taskState != null && (taskState == TaskState.Working || taskState == TaskState.Muxing || taskState == TaskState.Searching))
{
if (this.EncodeProgress != null)
{
var progressEventArgs = new EncodeProgressEventArgs(state.Working.Progress, state.Working.Rate, state.Working.RateAvg, new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds),
state.Working.PassID, state.Working.Pass, state.Working.PassCount, state.State == NativeConstants.HB_STATE_MUXING, state.State == NativeConstants.HB_STATE_SEARCHING);
state.Working.PassID, state.Working.Pass, state.Working.PassCount, taskState == TaskState.Muxing, taskState == TaskState.Searching);

this.EncodeProgress(this, progressEventArgs);
}
}
else if (state != null && state.State == NativeConstants.HB_STATE_WORKDONE)
else if (taskState != null && taskState == TaskState.WorkDone)
{
this.encodePollTimer.Stop();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AudioAttributes.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 color.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrake.ApplicationServices.Interop.Json.Scan
{
public class AudioAttributes
{
public bool AltCommentary { get; set; }
public bool Commentary { get; set; }
public bool Default { get; set; }
public bool Normal { get; set; }
public bool Secondary { get; set; }
public bool VisuallyImpaired { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SourceAudioTrack
/// <summary>
/// Gets or sets the channel layout.
/// </summary>
public long ChannelLayout { get; set; }
public int ChannelLayout { get; set; }

/// <summary>
/// Gets or sets the description.
Expand All @@ -48,5 +48,15 @@ public class SourceAudioTrack
/// Gets or sets the codec.
/// </summary>
public int Codec { get; set; }

public string CodecName { get; set; }

public long LFECount { get; set; }

public string ChannelLayoutName { get; set; }

public int ChannelCount { get; set; }

public AudioAttributes Attributes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
// <summary>
// The a chapter from a video source.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrake.ApplicationServices.Interop.Json.Scan
{
/// <summary>
/// The a chapter from a video source.
/// </summary>
public class SourceChapter
{
/// <summary>
/// Gets or sets the duration.
/// </summary>
public Duration Duration { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
public string Name { get; set; }
}
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrake.ApplicationServices.Interop.Json.Scan
{
/// <summary>
/// The a chapter from a video source.
/// </summary>
public class SourceChapter
{
/// <summary>
/// Gets or sets the duration.
/// </summary>
public Duration Duration { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ namespace HandBrake.ApplicationServices.Interop.Json.Scan
/// </summary>
public class SourceMetadata
{
public string Artist { get; set; }
public string Description { get; set; }
public string Genre { get; set; }
public string LongDescription { get; set; }
public string Name { get; set; }
public string ReleaseDate { get; set; }
public string Composer { get; set; }
public string AlbumArtist { get; set; }
public string Comment { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SourceSubtitleTrack
/// <summary>
/// Gets or sets the format.
/// </summary>
public int Format { get; set; }
public string Format { get; set; }

/// <summary>
/// Gets or sets the language.
Expand All @@ -33,5 +33,12 @@ public class SourceSubtitleTrack
/// Gets or sets the source.
/// </summary>
public int Source { get; set; }

public string SourceName { get; set; }

/// <summary>
/// Gets or sets subtitle attribute information.
/// </summary>
public SubtitleAttributes Attributes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class SourceTitle
/// </summary>
public Color Color { get; set; }

/// <summary>
/// Gets or sets the input file container.
/// </summary>
public string Container { get; set; }

/// <summary>
/// Gets or sets the cropping values
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SubtitleAttributes.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 color.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrake.ApplicationServices.Interop.Json.Scan
{
using Newtonsoft.Json;

public class SubtitleAttributes
{
[JsonProperty(PropertyName = "4By3")]
public bool FourByThree { get; set; }
public bool Children { get; set; }
public bool ClosedCaption { get; set; }
public bool Commentary { get; set; }
public bool Default { get; set; }
public bool Forced { get; set; }
public bool Large { get; set; }
public bool Letterbox { get; set; }
public bool Normal { get; set; }
public bool PanScan { get; set; }
public bool Wide { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public class JsonState
/// <summary>
/// Gets or sets the state.
/// </summary>
public int State { get; set; }
public string State { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TaskState.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 status of the current task being processed.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrake.ApplicationServices.Interop.Json.State
{
using System.Collections.Generic;

public class TaskState
{
public static TaskState Idle = new TaskState("IDLE");
public static TaskState Scanning = new TaskState("SCANNING");
public static TaskState ScanDone = new TaskState("SCANDONE");
public static TaskState Working = new TaskState("WORKING");
public static TaskState Paused = new TaskState("PAUSED");
public static TaskState Searching = new TaskState("SEARCHING");
public static TaskState WorkDone = new TaskState("WORKDONE");
public static TaskState Muxing = new TaskState("MUXING");
public static TaskState Unknown = new TaskState("UNKNOWN");

private static readonly Dictionary<string, TaskState> taskStates = new Dictionary<string, TaskState>();

static TaskState()
{
taskStates.Add("IDLE", Idle);
taskStates.Add("SCANNING", Scanning);
taskStates.Add("SCANDONE", ScanDone);
taskStates.Add("WORKING", Working);
taskStates.Add("PAUSED", Paused);
taskStates.Add("SEARCHING", Searching);
taskStates.Add("WORKDONE", WorkDone);
taskStates.Add("MUXING", Muxing);
taskStates.Add("UNKNOWN", Unknown);
}

public TaskState(string code)
{
this.Code = code;
}

public string Code { get; }

public static TaskState FromRepositoryValue(string code)
{
TaskState state = null;
if (taskStates.TryGetValue(code, out state))
{
return state;
}

return null;
}
}
}

0 comments on commit 84ae324

Please sign in to comment.