blob: 914d7916f18066b226b536477390e50e0898aa80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HandBrakeInstanceManager.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 hand brake instance manager.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Instance
{
using System;
using System.Runtime.CompilerServices;
using HandBrake.Interop.Interop;
using HandBrake.Interop.Interop.Interfaces;
using HandBrake.Interop.Model;
using HandBrakeWPF.Factories;
/// <summary>
/// The HandBrake Instance manager.
/// Only supports scanning right now.
/// </summary>
public static class HandBrakeInstanceManager
{
private static IEncodeInstance encodeInstance;
private static HandBrakeInstance scanInstance;
private static HandBrakeInstance previewInstance;
private static bool noHardware;
public static void Init(bool noHardwareMode)
{
noHardware = noHardwareMode;
HandBrakeUtils.RegisterLogger();
HandBrakeUtils.EnsureGlobalInit(noHardwareMode);
}
/// <summary>
/// The get encode instance.
/// </summary>
/// <param name="verbosity">
/// The verbosity.
/// </param>
/// <param name="configuration">
/// The configuration.
/// </param>
/// <returns>
/// The <see cref="IHandBrakeInstance"/>.
/// </returns>
public static IEncodeInstance GetEncodeInstance(int verbosity, HBConfiguration configuration)
{
if (!HandBrakeUtils.IsInitialised())
{
throw new Exception("Please call Init before Using!");
}
if (encodeInstance != null)
{
encodeInstance.Dispose();
encodeInstance = null;
}
IEncodeInstance newInstance;
if (configuration.RemoteServiceEnabled)
{
newInstance = new RemoteInstance(configuration.RemoteServicePort);
}
else
{
newInstance = new HandBrakeInstance();
}
newInstance.Initialize(verbosity, noHardware);
encodeInstance = newInstance;
HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);
return encodeInstance;
}
/// <summary>
/// Gets the scanInstance.
/// </summary>
/// <param name="verbosity">
/// The verbosity.
/// </param>
/// <param name="configuration">
/// HandBrakes config
/// </param>
/// <returns>
/// The <see cref="IHandBrakeInstance"/>.
/// </returns>
public static IHandBrakeInstance GetScanInstance(int verbosity, HBConfiguration configuration)
{
if (!HandBrakeUtils.IsInitialised())
{
throw new Exception("Please call Init before Using!");
}
if (scanInstance != null)
{
scanInstance.Dispose();
scanInstance = null;
}
HandBrakeInstance newInstance = new HandBrakeInstance();
newInstance.Initialize(verbosity, noHardware);
scanInstance = newInstance;
return scanInstance;
}
/// <summary>
/// The get encode instance.
/// </summary>
/// <param name="verbosity">
/// The verbosity.
/// </param>
/// <param name="configuration">
/// The configuration.
/// </param>
/// <returns>
/// The <see cref="IHandBrakeInstance"/>.
/// </returns>
public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration)
{
if (!HandBrakeUtils.IsInitialised())
{
throw new Exception("Please call Init before Using!");
}
if (previewInstance != null)
{
previewInstance.Dispose();
previewInstance = null;
}
HandBrakeInstance newInstance = new HandBrakeInstance();
newInstance.Initialize(verbosity, noHardware);
previewInstance = newInstance;
HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);
return previewInstance;
}
}
}
|