+ghb_save_queue(GValue *queue)
+{
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ store_plist(queue, path);
+ g_free(path);
+}
+
+GValue*
+ghb_load_queue()
+{
+ GValue *queue;
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ queue = load_plist(path);
+ g_free(path);
+ return queue;
+}
+
+GValue*
+ghb_load_old_queue(int pid)
+{
+ GValue *queue;
+ char *path;
+
+ path = g_strdup_printf ("queue.%d", pid);
+ queue = load_plist(path);
+ g_free(path);
+ return queue;
+}
+
+void
+ghb_remove_old_queue_file(int pid)
+{
+ char *path;
+
+ path = g_strdup_printf ("queue.%d", pid);
+ remove_plist(path);
+ g_free(path);
+}
+
+void
+ghb_remove_queue_file()
+{
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ remove_plist(path);
+ g_free(path);
+}
+
+typedef struct
+{
+ gchar *mac_val;
+ gchar *lin_val;
+} value_map_t;
+
+static value_map_t vcodec_xlat[] =
+{
+ {"MPEG-4 (FFmpeg)", "ffmpeg"},
+ {"MPEG-4 (XviD)", "ffmpeg"},
+ {"H.264 (x264)", "x264"},
+ {"VP3 (Theora)", "theora"},
+ {NULL,NULL}
+};
+
+static value_map_t acodec_xlat[] =
+{
+ {"AAC (faac)", "faac"},
+ {"AAC (CoreAudio)", "faac"},
+ {"AC3 Passthru", "ac3"},
+ {"MP3 (lame)", "lame"},
+ {"Vorbis (vorbis)", "vorbis"},
+ {NULL,NULL}
+};
+
+value_map_t container_xlat[] =
+{
+ {"MP4 file", "mp4"},
+ {"M4V file", "mp4"},
+ {"MKV file", "mkv"},
+ {"AVI file", "mkv"},
+ {"OGM file", "mkv"},
+ {NULL, NULL}
+};
+
+value_map_t framerate_xlat[] =
+{
+ {"Same as source", "source"},
+ {"5", "5"},
+ {"10", "10"},
+ {"12", "12"},
+ {"15", "15"},
+ {"23.976", "23.976"},
+ {"24", "24"},
+ {"25", "25"},
+ {"29.97", "29.97"},
+ {NULL, NULL}
+};
+
+value_map_t samplerate_xlat[] =
+{
+ {"Auto", "source"},
+ {"22.05", "22.05"},
+ {"24", "24"},
+ {"32", "32"},
+ {"44.1", "44.1"},
+ {"48", "48"},
+ {NULL, NULL}
+};
+
+value_map_t mix_xlat[] =
+{
+ {"Mono", "mono"},
+ {"Stereo", "stereo"},
+ {"Dolby Surround", "dpl1"},
+ {"Dolby Pro Logic II", "dpl2"},
+ {"6-channel discrete", "6ch"},
+ {"AC3 Passthru", "none"},
+ {NULL, NULL}
+};
+
+value_map_t deint_xlat[] =
+{
+ {"0", "off"},
+ {"1", "custom"},
+ {"2", "fast"},
+ {"3", "slow"},
+ {"4", "slower"},
+ {NULL, NULL}
+};
+
+value_map_t denoise_xlat[] =
+{
+ {"0", "off"},
+ {"1", "custom"},
+ {"2", "weak"},
+ {"3", "medium"},
+ {"4", "strong"},
+ {NULL, NULL}
+};
+
+value_map_t detel_xlat[] =
+{
+ {"0", "off"},
+ {"1", "custom"},
+ {"2", "default"},
+ {NULL, NULL}
+};
+
+value_map_t decomb_xlat[] =
+{
+ {"0", "off"},
+ {"1", "custom"},
+ {"2", "default"},
+ {NULL, NULL}
+};
+
+extern iso639_lang_t ghb_language_table[];
+
+static GValue*
+export_lang_xlat2(GValue *lin_val)
+{
+ GValue *gval;
+
+ if (lin_val == NULL) return NULL;
+ gint ii;
+ gchar *str;
+
+ str = ghb_value_string(lin_val);
+ for (ii = 0; ghb_language_table[ii].eng_name; ii++)
+ {
+ if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
+ {
+ const gchar *lang;
+
+ if (ghb_language_table[ii].native_name[0] != 0)
+ lang = ghb_language_table[ii].native_name;
+ else
+ lang = ghb_language_table[ii].eng_name;
+
+ gval = ghb_string_value_new(lang);
+ g_free(str);
+ return gval;
+ }
+ }
+ g_debug("Can't map language value: (%s)", str);
+ g_free(str);
+ return NULL;
+}
+
+static GValue*
+export_subtitle_xlat2(GValue *lin_val)
+{
+ gchar *str;
+ GValue *gval;
+
+ if (lin_val == NULL) return NULL;
+ str = ghb_value_string(lin_val);
+ if (strcmp(str, "none") == 0)
+ {
+ gval = ghb_string_value_new("None");
+ }
+ else if (strcmp(str, "auto") == 0)
+ {
+ gval = ghb_string_value_new("Autoselect");
+ }
+ else
+ {
+ gval = export_lang_xlat2(lin_val);
+ }
+ g_free(str);
+ return gval;
+}
+
+static GValue*
+import_lang_xlat2(GValue *mac_val)
+{
+ GValue *gval;
+
+ if (mac_val == NULL) return NULL;
+ gint ii;
+ gchar *str;
+
+ str = ghb_value_string(mac_val);
+ for (ii = 0; ghb_language_table[ii].eng_name; ii++)
+ {
+ if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
+ (strcmp(str, ghb_language_table[ii].native_name) == 0))
+ {
+ gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
+ g_free(str);
+ return gval;
+ }
+ }
+ g_debug("Can't map language value: (%s)", str);
+ g_free(str);
+ return NULL;
+}
+
+static GValue*
+import_subtitle_xlat2(GValue *mac_val)
+{
+ gchar *str;
+ GValue *gval;
+
+ if (mac_val == NULL) return NULL;
+ str = ghb_value_string(mac_val);
+ if (strcmp(str, "None") == 0)
+ {
+ gval = ghb_string_value_new("none");
+ }
+ else if (strcmp(str, "Autoselect") == 0)
+ {
+ gval = ghb_string_value_new("auto");
+ }
+ else
+ {
+ gval = import_lang_xlat2(mac_val);
+ }
+ g_free(str);
+ return gval;
+}
+
+static GValue*
+export_audio_track_xlat2(GValue *lin_val)
+{
+ gchar *str;
+ GValue *gval = NULL;
+
+ if (lin_val == NULL) return NULL;
+ str = ghb_value_string(lin_val);
+ if (strcmp(str, "none") == 0)
+ {
+ gval = ghb_int_value_new(1);
+ }
+ else
+ {
+ gint val = ghb_value_int(lin_val) + 1;
+ gval = ghb_int_value_new(val);
+ }
+ g_free(str);
+ return gval;
+}
+
+static GValue*
+import_audio_track_xlat2(GValue *mac_val)
+{
+ gint val;
+ gchar *str;
+ GValue *gval;
+
+ if (mac_val == NULL) return NULL;
+ val = ghb_value_int(mac_val);
+ if (val <= 0)
+ {
+ val = 0;
+ }
+ else
+ {
+ val--;
+ }
+ str = g_strdup_printf("%d", val);
+ gval = ghb_string_value_new(str);
+ g_free(str);
+ return gval;
+}
+
+static GValue*
+export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
+{
+ GValue *gval;
+
+ if (lin_val == NULL) return NULL;
+ gint ii;
+ gchar *str;
+ GValue *sval;
+
+ str = ghb_value_string(lin_val);
+ for (ii = 0; value_map[ii].mac_val; ii++)
+ {
+ if (strcmp(str, value_map[ii].lin_val) == 0)
+ {
+ sval = ghb_string_value_new(value_map[ii].mac_val);
+ g_free(str);
+ gval = ghb_value_new(mac_type);
+ if (!g_value_transform(sval, gval))
+ {
+ g_warning("can't transform");
+ ghb_value_free(gval);
+ ghb_value_free(sval);
+ return NULL;
+ }
+ ghb_value_free(sval);
+ return gval;
+ }
+ }
+ g_debug("Can't map value: (%s)", str);
+ g_free(str);
+ return NULL;
+}
+
+static void
+export_value_xlat(GValue *dict)
+{
+ GValue *lin_val, *gval;
+ const gchar *key;
+
+ key = "VideoEncoder";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "FileFormat";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "VideoFramerate";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDetelecine";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDecomb";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDeinterlace";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDenoise";
+ lin_val = ghb_dict_lookup(dict, key);
+ gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+
+ GValue *slist;
+ GValue *sdict;
+ gint count, ii;
+
+ slist = ghb_dict_lookup(dict, "SubtitleList");
+ count = ghb_array_len(slist);
+ for (ii = 0; ii < count; ii++)
+ {
+ sdict = ghb_array_get_nth(slist, ii);
+ key = "SubtitleLanguage";
+ lin_val = ghb_dict_lookup(sdict, key);
+ gval = export_subtitle_xlat2(lin_val);
+ if (gval)
+ ghb_dict_insert(sdict, g_strdup(key), gval);
+ }
+
+ GValue *alist;
+ GValue *adict;
+
+ alist = ghb_dict_lookup(dict, "AudioList");
+ count = ghb_array_len(alist);
+ for (ii = 0; ii < count; ii++)
+ {
+ adict = ghb_array_get_nth(alist, ii);
+ key = "AudioTrack";
+ lin_val = ghb_dict_lookup(adict, key);
+ gval = export_audio_track_xlat2(lin_val);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioEncoder";
+ lin_val = ghb_dict_lookup(adict, key);
+ gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioSamplerate";
+ lin_val = ghb_dict_lookup(adict, key);
+ gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioMixdown";
+ lin_val = ghb_dict_lookup(adict, key);
+ gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ }
+}
+
+
+static GValue*
+import_value_xlat2(
+ GValue *defaults,
+ value_map_t *value_map,
+ const gchar *key,
+ GValue *mac_val)
+{
+ GValue *gval, *def_val;
+
+ if (mac_val == NULL) return NULL;
+ def_val = ghb_dict_lookup(defaults, key);
+ if (def_val)
+ {
+ gint ii;
+ gchar *str;
+ GValue *sval;
+
+ str = ghb_value_string(mac_val);
+ for (ii = 0; value_map[ii].mac_val; ii++)
+ {
+ if (strcmp(str, value_map[ii].mac_val) == 0)
+ {
+ sval = ghb_string_value_new(value_map[ii].lin_val);
+ g_free(str);
+ gval = ghb_value_new(G_VALUE_TYPE(def_val));
+ if (!g_value_transform(sval, gval))
+ {
+ g_warning("can't transform");
+ ghb_value_free(gval);
+ ghb_value_free(sval);
+ return NULL;
+ }
+ ghb_value_free(sval);
+ return gval;
+ }
+ }
+ g_free(str);
+ }
+ else
+ {
+ gint ii;
+ gchar *str;
+ GValue *sval;
+
+ str = ghb_value_string(mac_val);
+ for (ii = 0; value_map[ii].mac_val; ii++)
+ {
+ if (strcmp(str, value_map[ii].mac_val) == 0)
+ {
+ sval = ghb_string_value_new(value_map[ii].lin_val);
+ g_free(str);
+ gval = ghb_value_new(G_VALUE_TYPE(mac_val));
+ if (!g_value_transform(sval, gval))
+ {
+ g_warning("can't transform");
+ ghb_value_free(gval);
+ ghb_value_free(sval);
+ return NULL;
+ }
+ ghb_value_free(sval);
+ return gval;
+ }
+ }
+ g_free(str);
+ }
+ return NULL;
+}
+
+static void
+import_value_xlat(GValue *dict)
+{
+ GValue *defaults, *mac_val, *gval;
+ const gchar *key;
+
+ defaults = plist_get_dict(internalPlist, "Presets");
+ key = "VideoEncoder";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "FileFormat";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "VideoFramerate";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDetelecine";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDecomb";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDeinterlace";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+ key = "PictureDenoise";
+ mac_val = ghb_dict_lookup(dict, key);
+ gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(dict, g_strdup(key), gval);
+
+
+ GValue *sdeflist;
+ GValue *sdefaults;
+ GValue *slist;
+ GValue *sdict;
+ gint count, ii;
+
+ sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
+ if (sdeflist)
+ {
+ slist = ghb_dict_lookup(dict, "SubtitleList");
+ if (slist)
+ {
+ sdefaults = ghb_array_get_nth(sdeflist, 0);
+ count = ghb_array_len(slist);
+ for (ii = 0; ii < count; ii++)
+ {
+ sdict = ghb_array_get_nth(slist, ii);
+ key = "SubtitleLanguage";
+ mac_val = ghb_dict_lookup(sdict, key);
+ gval = import_subtitle_xlat2(mac_val);
+ if (gval)
+ ghb_dict_insert(sdict, g_strdup(key), gval);
+ }
+
+ }
+ else
+ {
+ key = "Subtitles";
+ mac_val = ghb_dict_lookup(dict, key);
+ slist = ghb_array_value_new(8);
+ ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
+ if (mac_val)
+ {
+ gchar *lang;
+
+ gval = import_subtitle_xlat2(mac_val);
+ lang = ghb_value_string(gval);
+ if (lang && strcasecmp(lang, "none") != 0 && !slist)
+ {
+ sdict = ghb_dict_value_new();
+ ghb_array_append(slist, sdict);
+ ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
+ gval = ghb_dict_lookup(dict, "SubtitlesForced");
+ if (gval != NULL)
+ {
+ ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
+ ghb_value_dup(gval));
+ }
+ else
+ {
+ ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
+ ghb_boolean_value_new(FALSE));
+ }
+ ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
+ ghb_boolean_value_new(FALSE));
+ }
+ else
+ {
+ ghb_value_free(gval);
+ }
+ if (lang)
+ g_free(lang);
+ }
+ }
+ }
+ ghb_dict_remove(dict, "Subtitles");
+ ghb_dict_remove(dict, "SubtitlesForced");
+
+
+ GValue *alist;
+ GValue *adict;
+ GValue *adefaults;
+ GValue *adeflist;
+
+ adeflist = ghb_dict_lookup(defaults, "AudioList");
+ if (adeflist)
+ {
+ adefaults = ghb_array_get_nth(adeflist, 0);
+ alist = ghb_dict_lookup(dict, "AudioList");
+ count = ghb_array_len(alist);
+ for (ii = 0; ii < count; ii++)
+ {
+ adict = ghb_array_get_nth(alist, ii);
+ key = "AudioTrack";
+ mac_val = ghb_dict_lookup(adict, key);
+ gval = import_audio_track_xlat2(mac_val);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioEncoder";
+ mac_val = ghb_dict_lookup(adict, key);
+ gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioSamplerate";
+ mac_val = ghb_dict_lookup(adict, key);
+ gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+ key = "AudioMixdown";
+ mac_val = ghb_dict_lookup(adict, key);
+ gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
+ if (gval)
+ ghb_dict_insert(adict, g_strdup(key), gval);
+
+ mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
+ if (mac_val != NULL)
+ {
+ gdouble drc;
+ drc = ghb_value_double(mac_val);
+ if (drc < 1.0 && drc > 0.0)
+ {
+ ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
+ ghb_double_value_new(0.0));
+ }
+ }
+ }
+ }
+}
+
+static void
+import_xlat_preset(GValue *dict)
+{
+ gboolean uses_max;
+ gint uses_pic;
+ gint par;
+ gint vqtype;
+
+ g_debug("import_xlat_preset ()");
+ uses_max = ghb_value_boolean(
+ preset_dict_get_value(dict, "UsesMaxPictureSettings"));
+ uses_pic = ghb_value_int(
+ preset_dict_get_value(dict, "UsesPictureSettings"));
+ par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
+ vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
+
+ if (uses_max || uses_pic == 2)
+ {
+ ghb_dict_insert(dict, g_strdup("autoscale"),
+ ghb_boolean_value_new(TRUE));
+ }
+ switch (par)
+ {
+ case 0:
+ {
+ if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
+ ghb_dict_insert(dict, g_strdup("PictureModulus"),
+ ghb_int_value_new(16));
+ } break;
+ case 1:
+ {
+ ghb_dict_insert(dict, g_strdup("PictureModulus"),
+ ghb_int_value_new(1));
+ } break;
+ case 2:
+ {
+ if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
+ ghb_dict_insert(dict, g_strdup("PictureModulus"),
+ ghb_int_value_new(16));
+ } break;
+ default:
+ {
+ if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
+ ghb_dict_insert(dict, g_strdup("PictureModulus"),
+ ghb_int_value_new(16));
+ } break;
+ }
+ // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
+ switch (vqtype)
+ {
+ case 0:
+ {
+ ghb_dict_insert(dict, g_strdup("vquality_type_target"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
+ ghb_boolean_value_new(FALSE));
+ } break;
+ case 1:
+ {
+ ghb_dict_insert(dict, g_strdup("vquality_type_target"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
+ ghb_boolean_value_new(FALSE));
+ } break;
+ case 2:
+ {
+ ghb_dict_insert(dict, g_strdup("vquality_type_target"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
+ ghb_boolean_value_new(TRUE));
+ } break;
+ default:
+ {
+ ghb_dict_insert(dict, g_strdup("vquality_type_target"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
+ ghb_boolean_value_new(TRUE));
+ } break;
+ }
+ import_value_xlat(dict);
+
+ gdouble vquality;
+ const GValue *gval;
+
+ vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
+ if (vquality > 0.0 && vquality < 1.0)
+ {
+ gint vcodec;
+
+ gval = preset_dict_get_value(dict, "VideoEncoder");
+ vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
+ switch (vcodec)
+ {
+ case HB_VCODEC_X264:
+ {
+ vquality = 51. - vquality * 51.;
+ } break;
+
+ case HB_VCODEC_FFMPEG:
+ {
+ vquality = 31. - vquality * 30.;
+ } break;
+
+ case HB_VCODEC_THEORA:
+ {
+ vquality = vquality * 63.;
+ } break;
+
+ default:
+ {
+ vquality = 0.;
+ } break;
+ }
+ ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
+ ghb_double_value_new(vquality));
+ }
+}
+
+static void
+import_xlat_presets(GValue *presets)
+{
+ gint count, ii;
+ GValue *dict;
+ gboolean folder;
+
+ g_debug("import_xlat_presets ()");
+ if (presets == NULL) return;
+ count = ghb_array_len(presets);
+ for (ii = 0; ii < count; ii++)
+ {
+ dict = ghb_array_get_nth(presets, ii);
+ folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
+ if (folder)
+ {
+ GValue *nested;
+
+ nested = ghb_dict_lookup(dict, "ChildrenArray");
+ import_xlat_presets(nested);
+ }
+ else
+ {
+ import_xlat_preset(dict);
+ }
+ }
+}
+
+static void
+export_xlat_preset(GValue *dict)
+{
+ gboolean autoscale, target, br, constant;
+
+ g_debug("export_xlat_prest ()");
+ autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
+ target = ghb_value_boolean(
+ preset_dict_get_value(dict, "vquality_type_target"));
+ br = ghb_value_boolean(
+ preset_dict_get_value(dict, "vquality_type_bitrate"));
+ constant = ghb_value_boolean(
+ preset_dict_get_value(dict, "vquality_type_constant"));
+
+ if (autoscale)
+ ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
+ ghb_int_value_new(2));
+ else
+ ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
+ ghb_int_value_new(1));
+
+ // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
+ if (target)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoQualityType"),
+ ghb_int_value_new(0));
+ }
+ else if (br)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoQualityType"),
+ ghb_int_value_new(1));
+ }
+ else if (constant)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoQualityType"),
+ ghb_int_value_new(2));
+ }
+
+ GValue *alist, *adict;
+ gint count, ii;
+
+ alist = ghb_dict_lookup(dict, "AudioList");
+ count = ghb_array_len(alist);
+ for (ii = 0; ii < count; ii++)
+ {
+ gdouble drc;
+
+ adict = ghb_array_get_nth(alist, ii);
+ drc = ghb_value_double(
+ preset_dict_get_value(adict, "AudioTrackDRCSlider"));
+ if (drc < 1.0 && drc > 0.0)
+ {
+ ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
+ ghb_double_value_new(0.0));
+ }
+ }
+
+ ghb_dict_remove(dict, "UsesMaxPictureSettings");
+ ghb_dict_remove(dict, "autoscale");
+ ghb_dict_remove(dict, "vquality_type_target");
+ ghb_dict_remove(dict, "vquality_type_bitrate");
+ ghb_dict_remove(dict, "vquality_type_constant");
+ export_value_xlat(dict);
+}
+
+static void
+export_xlat_presets(GValue *presets)
+{
+ gint count, ii;
+ GValue *dict;
+ gboolean folder;
+
+ if (presets == NULL) return;
+ count = ghb_array_len(presets);
+ for (ii = 0; ii < count; ii++)
+ {
+ dict = ghb_array_get_nth(presets, ii);
+ folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
+ if (folder)
+ {
+ GValue *nested;
+
+ nested = ghb_dict_lookup(dict, "ChildrenArray");
+ export_xlat_presets(nested);
+ }
+ else
+ {
+ export_xlat_preset(dict);
+ }
+ }
+}
+
+static guint prefs_timeout_id = 0;
+
+static gboolean
+delayed_store_prefs(gpointer data)
+{
+ store_plist(prefsPlist, "preferences");
+ prefs_timeout_id = 0;
+ return FALSE;
+}
+
+static void
+store_presets()
+{
+ GValue *export;
+
+ export = ghb_value_dup(presetsPlist);
+ export_xlat_presets(export);
+ store_plist(export, "presets");
+ ghb_value_free(export);
+}
+
+static void
+store_prefs(void)
+{
+ if (prefs_timeout_id != 0)
+ {
+ GMainContext *mc;
+ GSource *source;
+
+ mc = g_main_context_default();
+ source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
+ if (source != NULL)
+ g_source_destroy(source);
+ }
+ prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
+}
+
+void
+ghb_presets_reload(signal_user_data_t *ud)
+{
+ GValue *std_presets;
+ gint count, ii;
+ int *indices, len;
+
+ g_debug("ghb_presets_reload()\n");
+ std_presets = ghb_resource_get("standard-presets");
+ if (std_presets == NULL) return;
+
+ remove_std_presets(ud);
+ indices = presets_find_default(presetsPlist, &len);
+ if (indices)
+ {
+ presets_clear_default(std_presets);
+ g_free(indices);
+ }
+ // Merge the keyfile contents into our presets
+ count = ghb_array_len(std_presets);
+ for (ii = count-1; ii >= 0; ii--)
+ {
+ GValue *std_dict;
+ GValue *copy_dict;
+ gint indices = 0;
+
+ std_dict = ghb_array_get_nth(std_presets, ii);
+ copy_dict = ghb_value_dup(std_dict);
+ ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
+ ghb_int64_value_new(hb_get_build(NULL)));
+ ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
+ presets_list_insert(ud, &indices, 1);
+ }
+ import_xlat_presets(presetsPlist);
+ store_presets();
+}
+
+static gboolean
+check_old_presets()
+{
+ gint count, ii;
+
+ count = ghb_array_len(presetsPlist);
+ for (ii = count-1; ii >= 0; ii--)
+ {
+ GValue *dict;
+ GValue *type;
+
+ dict = ghb_array_get_nth(presetsPlist, ii);
+ type = ghb_dict_lookup(dict, "Type");
+ if (type == NULL)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+replace_standard_presets()
+{
+ GValue *std_presets;
+ int *indices, len;
+ gint count, ii;
+
+ count = ghb_array_len(presetsPlist);
+ for (ii = count-1; ii >= 0; ii--)
+ {
+ GValue *dict;
+ gint ptype;
+
+ dict = ghb_array_get_nth(presetsPlist, ii);
+ ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
+ if (ptype == PRESETS_BUILTIN)
+ {
+ gint indices = 0;
+ ghb_presets_remove(presetsPlist, &indices, 1);
+ }
+ }
+
+ std_presets = ghb_resource_get("standard-presets");
+ if (std_presets == NULL) return;
+
+ indices = presets_find_default(presetsPlist, &len);
+ if (indices)
+ {
+ presets_clear_default(std_presets);
+ g_free(indices);
+ }
+ // Merge the keyfile contents into our presets
+ count = ghb_array_len(std_presets);
+ for (ii = count-1; ii >= 0; ii--)
+ {
+ GValue *std_dict;
+ GValue *copy_dict;
+ gint indices = 0;
+
+ std_dict = ghb_array_get_nth(std_presets, ii);
+ copy_dict = ghb_value_dup(std_dict);
+ ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
+ ghb_int64_value_new(hb_get_build(NULL)));
+ ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
+ }
+ import_xlat_presets(presetsPlist);
+ store_presets();
+}
+
+static void
+update_standard_presets(signal_user_data_t *ud)
+{
+ gint count, ii;
+
+ count = ghb_array_len(presetsPlist);
+ for (ii = count-1; ii >= 0; ii--)
+ {
+ GValue *dict;
+ const GValue *gval;
+ gint64 build;
+ gint type;
+
+ dict = ghb_array_get_nth(presetsPlist, ii);
+ gval = ghb_dict_lookup(dict, "Type");
+ if (gval == NULL)
+ {
+ // Old preset that doesn't have a Type
+ replace_standard_presets();
+ return;
+ }
+
+ type = ghb_value_int(gval);
+ if (type == 0)
+ {
+ gval = ghb_dict_lookup(dict, "PresetBuildNumber");
+ if (gval == NULL)
+ {
+ // Old preset that doesn't have a build number
+ replace_standard_presets();
+ return;
+ }
+
+ build = ghb_value_int64(gval);
+ if (build != hb_get_build(NULL))
+ {
+ // Build number does not match
+ replace_standard_presets();
+ return;
+ }
+ }
+ }
+ return;
+}
+
+void
+ghb_presets_load(signal_user_data_t *ud)
+{
+ presetsPlist = load_plist("presets");
+ if (presetsPlist == NULL)
+ {
+ presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
+ import_xlat_presets(presetsPlist);
+ store_presets();
+ }
+ else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
+ { // Presets is older dictionary format. Convert to array
+ ghb_value_free(presetsPlist);
+ presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
+ import_xlat_presets(presetsPlist);
+ store_presets();
+ }
+ else if (check_old_presets())
+ {
+ ghb_value_free(presetsPlist);
+ presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
+ import_xlat_presets(presetsPlist);
+ store_presets();
+ }
+ update_standard_presets(ud);
+ import_xlat_presets(presetsPlist);
+}
+
+static void
+settings_save(signal_user_data_t *ud, const GValue *path)