// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The hand brake instance manager.
//
// --------------------------------------------------------------------------------------------------------------------
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;
///
/// The HandBrake Instance manager.
/// Only supports scanning right now.
///
public static class HandBrakeInstanceManager
{
private static IEncodeInstance encodeInstance;
private static HandBrakeInstance scanInstance;
private static HandBrakeInstance previewInstance;
private static bool noHardware;
///
/// The init.
///
public static void Init(bool noHardwareMode)
{
noHardware = noHardwareMode;
HandBrakeUtils.RegisterLogger();
HandBrakeUtils.EnsureGlobalInit(noHardwareMode);
}
///
/// The get encode instance.
///
///
/// The verbosity.
///
///
/// The configuratio.
///
///
/// The .
///
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;
}
///
/// Gets the scanInstance.
///
///
/// The verbosity.
///
///
/// HandBrakes config
///
///
/// The .
///
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;
}
///
/// The get encode instance.
///
///
/// The verbosity.
///
///
/// The configuration.
///
///
/// The .
///
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;
}
}
}