// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Defines the HandBrakeFilterHelpers type.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrake.ApplicationServices.Interop
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using HandBrake.ApplicationServices.Interop.HbLib;
using HandBrake.ApplicationServices.Interop.Helpers;
using HandBrake.ApplicationServices.Interop.Json.Filters;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
using Newtonsoft.Json;
///
/// The hand brake filter helpers.
///
public class HandBrakeFilterHelpers
{
///
/// The get filter presets.
///
///
/// The filter.
///
///
/// The .
///
public static List GetFilterPresets(int filter)
{
IntPtr ptr = HBFunctions.hb_filter_get_presets_json(filter);
string result = Marshal.PtrToStringAnsi(ptr);
List list = JsonConvert.DeserializeObject>(result);
return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList();
}
///
/// The get filter tunes.
///
///
/// The filter.
///
///
/// The .
///
public static List GetFilterTunes(int filter)
{
IntPtr ptr = HBFunctions.hb_filter_get_tunes_json(filter);
string result = Marshal.PtrToStringAnsi(ptr);
List list = JsonConvert.DeserializeObject>(result);
return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList();
}
///
/// Gets a list of keys for custom settings for the filter.
///
/// The filter to look up.
/// The list of keys for custom settings for the filter.
public static List GetFilterKeys(int filter)
{
IntPtr ptr = HBFunctions.hb_filter_get_keys(filter);
return InteropUtilities.ToStringListFromArrayPtr(ptr);
}
///
/// Gets the default settings for the filter.
///
/// The filter to look up.
/// The default settings for that filter.
public static IDictionary GetDefaultCustomSettings(int filter)
{
string presetName;
List presets = GetFilterPresets(filter);
if (presets.Any(p => p.ShortName == "default"))
{
presetName = "default";
}
else if (presets.Any(p => p.ShortName == "medium"))
{
presetName = "medium";
}
else
{
return new Dictionary();
}
IntPtr ptr = HBFunctions.hb_generate_filter_settings_json(filter, presetName, null, null);
string result = Marshal.PtrToStringAnsi(ptr);
return JsonConvert.DeserializeObject>(result);
}
}
}