x264_gtk.c
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:47k
源码类别:

Audio

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  * x264_gtk.c: h264 gtk encoder frontend
  3.  *****************************************************************************
  4.  * Copyright (C) 2006 Vincent Torri
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
  19.  *****************************************************************************/
  20. #include <string.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <errno.h>
  24. #include <math.h>
  25. #if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __DragonFly__
  26. #  include <inttypes.h>
  27. #else
  28. #  include <stdint.h>
  29. #endif
  30. #ifdef _WIN32
  31. #  define _WIN32_IE   0x400
  32. #  include <unistd.h>        /* for mkdir */
  33. #  include <shlobj.h>        /* for SHGetSpecialFolderPath */
  34. #endif
  35. #include "../x264.h"
  36. #include <gtk/gtk.h>
  37. #include "x264_gtk.h"
  38. #include "x264_gtk_i18n.h"
  39. #include "x264_gtk_private.h"
  40. #include "x264_gtk_enum.h"
  41. #include "x264_gtk_bitrate.h"
  42. #include "x264_gtk_rc.h"
  43. #include "x264_gtk_mb.h"
  44. #include "x264_gtk_more.h"
  45. #include "x264_gtk_cqm.h"
  46. #define CHECK_FLAG(a,flag) ((a) & (flag)) == (flag)
  47. #define round(a) ( ((a)<0.0) ? (gint)(floor((a) - 0.5)) : (gint)(floor((a) + 0.5)) )
  48. #define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )
  49. #define X264_MIN(a,b) ( (a)<(b) ? (a) : (b) )
  50. /* Callbacks */
  51. static void x264_dialog_run (GtkDialog       *dialog,
  52.                          gint             response,
  53.                          X264_Gui_Config *gconfig,
  54.                          X264_Gtk        *x264_gtk);
  55. /* x264 config management */
  56. static void x264_default_load (GtkButton *button, gpointer user_data);
  57. static void x264_current_get (X264_Gui_Config *gconfig, X264_Gtk *x264_gtk);
  58. static void x264_current_set (X264_Gui_Config *gconfig, X264_Gtk *x264_gtk);
  59. static void x264_default_set (X264_Gtk *x264_gtk);
  60. /* Result must be freed */
  61. x264_param_t *x264_gtk_param_get (X264_Gtk *x264_gtk)
  62. {
  63.   x264_param_t *param;
  64.   if (!x264_gtk)
  65.     return NULL;
  66.   param = (x264_param_t *)g_malloc (sizeof (x264_param_t));
  67.   if (!param)
  68.     return NULL;
  69.   x264_param_default (param);
  70.   /* rate control */
  71.   param->rc.f_ip_factor = 1.0 + (double)x264_gtk->keyframe_boost / 100.0;
  72.   param->rc.f_pb_factor = 1.0 + (double)x264_gtk->bframes_reduction / 100.0;
  73.   param->rc.f_qcompress = (double)x264_gtk->bitrate_variability / 100.0;
  74.   param->rc.i_qp_min = x264_gtk->min_qp;
  75.   param->rc.i_qp_max = x264_gtk->max_qp;
  76.   param->rc.i_qp_step = x264_gtk->max_qp_step;
  77.   param->i_scenecut_threshold = x264_gtk->scene_cut_threshold;
  78.   param->i_keyint_min = x264_gtk->min_idr_frame_interval;
  79.   param->i_keyint_max = x264_gtk->max_idr_frame_interval;
  80.   param->rc.i_vbv_max_bitrate = x264_gtk->vbv_max_bitrate;
  81.   param->rc.i_vbv_buffer_size = x264_gtk->vbv_buffer_size;
  82.   param->rc.f_vbv_buffer_init = x264_gtk->vbv_buffer_init;
  83.   /* mb */
  84.   param->analyse.b_transform_8x8 = x264_gtk->transform_8x8;
  85.   param->analyse.inter = 0;
  86.   if (x264_gtk->pframe_search_8)
  87.     param->analyse.inter |= X264_ANALYSE_PSUB16x16;
  88.   if (x264_gtk->bframe_search_8)
  89.     param->analyse.inter |= X264_ANALYSE_BSUB16x16;
  90.   if (x264_gtk->pframe_search_4)
  91.     param->analyse.inter |= X264_ANALYSE_PSUB8x8;
  92.   if (x264_gtk->inter_search_8)
  93.     param->analyse.inter |= X264_ANALYSE_I8x8;
  94.   if (x264_gtk->inter_search_4)
  95.     param->analyse.inter |= X264_ANALYSE_I4x4;
  96.   param->b_bframe_pyramid = x264_gtk->bframe_pyramid && x264_gtk->bframe;
  97.   param->analyse.b_bidir_me = x264_gtk->bidir_me;
  98.   param->b_bframe_adaptive = x264_gtk->bframe_adaptive;
  99.   param->analyse.b_weighted_bipred = x264_gtk->weighted_bipred;
  100.   param->i_bframe = x264_gtk->bframe;
  101.   param->i_bframe_bias = x264_gtk->bframe_bias;
  102.   param->analyse.i_direct_mv_pred = x264_gtk->direct_mode;
  103. /*   param->b_bframe_pyramid = param->b_bframe_pyramid && (param->i_bframe > 1); */
  104.   /* more */
  105.   param->analyse.i_subpel_refine = x264_gtk->partition_decision + 1;
  106.   param->analyse.b_bframe_rdo = x264_gtk->bframe_rdo;
  107.   param->analyse.i_me_method = x264_gtk->me_method;
  108.   param->analyse.i_me_range = x264_gtk->range;
  109.   param->analyse.b_chroma_me = x264_gtk->chroma_me;
  110.   param->analyse.i_trellis = x264_gtk->trellis;
  111.   param->analyse.i_noise_reduction = x264_gtk->noise_reduction;
  112.   param->i_frame_reference = x264_gtk->max_ref_frames;
  113.   param->analyse.b_mixed_references = x264_gtk->mixed_refs;
  114.   param->analyse.b_fast_pskip = x264_gtk->fast_pskip;
  115.   param->analyse.b_dct_decimate = x264_gtk->dct_decimate;
  116.   /* rdo : RD based mode decision for B-frames. Requires subme 6 */
  117.   param->vui.i_sar_width = x264_gtk->sample_ar_x;
  118.   param->vui.i_sar_height = x264_gtk->sample_ar_y;
  119.   param->i_threads = x264_gtk->threads;
  120.   param->b_cabac = x264_gtk->cabac;
  121.   param->b_deblocking_filter = x264_gtk->deblocking_filter;
  122.   param->i_deblocking_filter_alphac0 = x264_gtk->strength;
  123.   param->i_deblocking_filter_beta = x264_gtk->threshold;
  124.   param->i_log_level = x264_gtk->debug_method - 1;
  125.   /* cqm */
  126.   param->i_cqm_preset = x264_gtk->cqm_preset;
  127.   if (x264_gtk->cqm_file && (x264_gtk->cqm_file[0] != ''))
  128.     param->psz_cqm_file = x264_gtk->cqm_file;
  129.   memcpy( param->cqm_4iy, x264_gtk->cqm_4iy, 16 );
  130.   memcpy( param->cqm_4ic, x264_gtk->cqm_4ic, 16 );
  131.   memcpy( param->cqm_4py, x264_gtk->cqm_4py, 16 );
  132.   memcpy( param->cqm_4pc, x264_gtk->cqm_4pc, 16 );
  133.   memcpy( param->cqm_8iy, x264_gtk->cqm_8iy, 64 );
  134.   memcpy( param->cqm_8py, x264_gtk->cqm_8py, 64 );
  135.   /* bitrate */
  136.   switch (x264_gtk->pass) {
  137.   case X264_PASS_SINGLE_BITRATE:
  138.     param->rc.i_rc_method = X264_RC_ABR;
  139.     param->rc.i_bitrate  = x264_gtk->average_bitrate;
  140.     break;
  141.   case X264_PASS_SINGLE_QUANTIZER:
  142.     param->rc.i_rc_method = X264_RC_CQP;
  143.     param->rc.i_qp_constant = x264_gtk->quantizer;
  144.     break;
  145.   case X264_PASS_MULTIPASS_1ST_FAST:
  146.     param->analyse.i_subpel_refine = X264_MAX( X264_MIN( 3, param->analyse.i_subpel_refine - 1 ), 1 );
  147.     param->i_frame_reference = ( param->i_frame_reference + 1 ) >> 1;
  148.     param->analyse.inter &= ( ~X264_ANALYSE_PSUB8x8 );
  149.     param->analyse.inter &= ( ~X264_ANALYSE_BSUB16x16 );
  150.   case X264_PASS_MULTIPASS_1ST:
  151.     param->rc.i_rc_method = X264_RC_ABR;
  152.     param->rc.i_bitrate  = x264_gtk->average_bitrate;
  153.     param->rc.f_rate_tolerance = 4.0;
  154.     break;
  155.   case X264_PASS_MULTIPASS_NTH:
  156.     param->rc.i_rc_method = X264_RC_ABR;
  157.     param->rc.i_bitrate  = x264_gtk->average_bitrate;
  158.     param->rc.f_rate_tolerance = 1.0;
  159.     break;
  160.   }
  161.   param->rc.b_stat_write = x264_gtk->stat_write;
  162.   param->rc.b_stat_read = x264_gtk->stat_read;
  163.   /* FIXME: potential mem leak... */
  164.   param->rc.psz_stat_out = x264_gtk_path (x264_gtk->statsfile_name);
  165.   return param;
  166. }
  167. /* Result must be freed */
  168. X264_Gtk *
  169. x264_gtk_load (void)
  170. {
  171.   X264_Gtk     *x264_gtk;
  172.   GIOChannel   *file;
  173.   GError       *error = NULL;
  174.   gchar        *filename;
  175.   x264_gtk = (X264_Gtk *)g_malloc0 (sizeof (X264_Gtk));
  176.   if (!x264_gtk)
  177.     return NULL;
  178.   filename = x264_gtk_path ("x264.cfg");
  179.   file = g_io_channel_new_file (filename, "r", &error);
  180.   if (error) {
  181.     g_print (_("x264.cfg: %sn"), error->message);
  182.     g_print (_("Loading default configurationn"));
  183.     x264_default_set (x264_gtk);
  184.   }
  185.   else {
  186.     GIOStatus status;
  187.     gchar    *data = NULL;
  188.     gsize     length;
  189.     g_print (_("Loading configuration from %sn"), filename);
  190.     g_io_channel_set_encoding (file, NULL, NULL);
  191.     status = g_io_channel_read_to_end (file, &data, &length, &error);
  192.     if ((status == G_IO_STATUS_NORMAL) &&
  193.         (length == sizeof (X264_Gtk))) {
  194.       memcpy (x264_gtk, data, length);
  195.     }
  196.     g_io_channel_shutdown (file, TRUE, NULL);
  197.     g_io_channel_unref (file);
  198.   }
  199.   g_free (filename);
  200.   return x264_gtk;
  201. }
  202. GtkWidget *
  203. x264_gtk_window_create (GtkWidget *parent)
  204. {
  205.   GtkWidget       *win_x264_gtk;
  206.   GtkWidget       *notebook;
  207.   GtkWidget       *page;
  208.   GtkWidget       *button;
  209.   GtkWidget       *label;
  210.   X264_Gui_Config *gconfig;
  211.   X264_Gtk        *x264_gtk;
  212.   gint             result;
  213.   GtkDialogFlags   flags = 0;
  214.   gconfig = (X264_Gui_Config *)g_malloc (sizeof (X264_Gui_Config));
  215.   if (!gconfig)
  216.     return NULL;
  217.   x264_gtk = x264_gtk_load ();
  218.   if (parent)
  219.     flags = GTK_DIALOG_MODAL |GTK_DIALOG_DESTROY_WITH_PARENT;
  220.   win_x264_gtk = gtk_dialog_new_with_buttons (_("X264 Configuration"),
  221.                                               GTK_WINDOW (parent),
  222.                                               flags,
  223.                                               NULL);
  224.   button = gtk_button_new_with_label (_("Default"));
  225.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (win_x264_gtk)->action_area), button, FALSE, TRUE, 6);
  226.   g_signal_connect (G_OBJECT (button),
  227.                     "clicked",
  228.                     G_CALLBACK (x264_default_load),
  229.                     gconfig);
  230.   gtk_widget_show (button);
  231.   gtk_dialog_add_buttons (GTK_DIALOG (win_x264_gtk),
  232.                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  233.                           GTK_STOCK_OK, GTK_RESPONSE_OK,
  234.                           NULL);
  235.   g_object_set_data (G_OBJECT (win_x264_gtk), "x264-gui-config", gconfig);
  236.   g_object_set_data (G_OBJECT (win_x264_gtk), "x264-config", x264_gtk);
  237.   gtk_window_set_resizable (GTK_WINDOW (win_x264_gtk), FALSE);
  238.   notebook = gtk_notebook_new ();
  239.   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (win_x264_gtk)->vbox), notebook);
  240.   gtk_widget_show (notebook);
  241.   label = gtk_label_new (_("Bitrate"));
  242.   gtk_widget_show (label);
  243.   page = x264_bitrate_page (gconfig);
  244.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
  245.   gtk_widget_show (page);
  246.   label = gtk_label_new (_("Rate Control"));
  247.   gtk_widget_show (label);
  248.   page = x264_rate_control_page (gconfig);
  249.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
  250.   gtk_widget_show (page);
  251.   label = gtk_label_new (_("MB & Frames"));
  252.   gtk_widget_show (label);
  253.   page = x264_mb_page (gconfig);
  254.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
  255.   gtk_widget_show (page);
  256.   label = gtk_label_new (_("More..."));
  257.   gtk_widget_show (label);
  258.   page = x264_more_page (gconfig);
  259.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
  260.   gtk_widget_show (page);
  261.   label = gtk_label_new (_("Quantization matrices"));
  262.   gtk_widget_show (label);
  263.   page = x264_cqm_page (gconfig);
  264.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
  265.   gtk_widget_show (page);
  266.   x264_current_set (gconfig, x264_gtk);
  267.   result = gtk_dialog_run (GTK_DIALOG (win_x264_gtk));
  268.   x264_dialog_run (GTK_DIALOG (win_x264_gtk), result, gconfig, x264_gtk);
  269.   return win_x264_gtk;
  270. }
  271. void
  272. x264_gtk_shutdown (GtkWidget *dialog)
  273. {
  274.   X264_Gui_Config *gconfig;
  275.   gconfig = g_object_get_data (G_OBJECT (dialog), "x264-gui-config");
  276.   gtk_widget_destroy (dialog);
  277.   if (gconfig)
  278.     g_free (gconfig);
  279. }
  280. void
  281. x264_gtk_free (X264_Gtk *x264_gtk)
  282. {
  283.   if (!x264_gtk)
  284.     return;
  285.   g_free (x264_gtk);
  286. }
  287. /* Notebook pages */
  288. /* Callbacks */
  289. static void
  290. x264_dialog_run (GtkDialog       *dialog UNUSED,
  291.              gint             response,
  292.              X264_Gui_Config *gconfig,
  293.              X264_Gtk        *x264_gtk)
  294. {
  295.   if (response == GTK_RESPONSE_OK)
  296.     {
  297.       GIOChannel *file;
  298.       gchar      *filename;
  299.       gchar      *dir;
  300.       gsize       length;
  301.       gint        res;
  302. #ifndef _WIN32
  303.       mode_t      mode;
  304. #endif
  305.       dir = x264_gtk_path (NULL);
  306. #ifdef _WIN32
  307.       res = mkdir (dir);
  308. #else
  309.       mode =
  310.         S_IRUSR | S_IXUSR | S_IWUSR |
  311.         S_IRGRP | S_IXGRP | S_IWGRP |
  312.         S_IROTH | S_IXOTH | S_IWOTH;
  313.       res = mkdir (dir, mode);
  314. #endif /* _WIN32 */
  315.       if (res != 0 && errno != EEXIST)
  316.         {
  317.           g_free (dir);
  318.           return;
  319.         }
  320.       filename = x264_gtk_path ("x264.cfg");
  321.       g_print (_("Writing configuration to %sn"), filename);
  322.       file = g_io_channel_new_file (filename, "w+", NULL);
  323.       if (file)
  324.         {
  325.           x264_current_get (gconfig, x264_gtk);
  326.           g_io_channel_set_encoding (file, NULL, NULL);
  327.           g_io_channel_write_chars (file, (const gchar *)x264_gtk,
  328.                                     sizeof (X264_Gtk), &length, NULL);
  329.           g_io_channel_unref (file);
  330.         }
  331.       g_free (filename);
  332.       g_free (dir);
  333.     }
  334. }
  335. /* x264 config management */
  336. static void
  337. x264_default_load (GtkButton *button UNUSED, gpointer user_data)
  338. {
  339.   gchar            buf[64];
  340.   X264_Gui_Config *config;
  341.   x264_param_t     param;
  342.   gint             i;
  343.   if (!user_data)
  344.     return;
  345.   config = (X264_Gui_Config *)user_data;
  346.   x264_param_default (&param);
  347.   /* bitrate */
  348.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->bitrate.pass), 1);
  349.   g_snprintf (buf, 64, "%d", param.rc.i_bitrate);
  350.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.w_average_bitrate), buf);
  351.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.w_target_bitrate), buf);
  352.   gtk_range_set_range (GTK_RANGE (config->bitrate.w_quantizer),
  353.                        0.0,
  354.                        51.0);
  355.   gtk_range_set_value (GTK_RANGE (config->bitrate.w_quantizer),
  356.                        (gdouble)param.rc.i_qp_constant);
  357.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->bitrate.update_statfile), FALSE);
  358.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.statsfile_name), "x264.stats");
  359.   gtk_widget_set_sensitive (config->bitrate.statsfile_name, FALSE);
  360.   gtk_widget_set_sensitive (config->bitrate.update_statfile, FALSE);
  361.   /* rate control */
  362.   g_snprintf (buf, 64, "%d", round((param.rc.f_ip_factor - 1.0) * 100));
  363.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.keyframe_boost), buf);
  364.   g_snprintf (buf, 64, "%d", round((param.rc.f_pb_factor - 1.0) * 100));
  365.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.bframes_reduction), buf);
  366.   g_snprintf (buf, 64, "%d", (gint)(param.rc.f_qcompress * 100));
  367.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.bitrate_variability), buf);
  368.   g_snprintf (buf, 64, "%d", param.rc.i_qp_min);
  369.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.min_qp), buf);
  370.   g_snprintf (buf, 64, "%d", param.rc.i_qp_max);
  371.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.max_qp), buf);
  372.   g_snprintf (buf, 64, "%d", param.rc.i_qp_step);
  373.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.max_qp_step), buf);
  374.   g_snprintf (buf, 64, "%d", param.i_scenecut_threshold);
  375.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.scene_cut_threshold), buf);
  376.   g_snprintf (buf, 64, "%d", param.i_keyint_min);
  377.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.min_idr_frame_interval), buf);
  378.   g_snprintf (buf, 64, "%d", param.i_keyint_max);
  379.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.max_idr_frame_interval), buf);
  380.   g_snprintf (buf, 64, "%d", param.rc.i_vbv_max_bitrate);
  381.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_max_bitrate), buf);
  382.   g_snprintf (buf, 64, "%d", param.rc.i_vbv_buffer_size);
  383.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_buffer_size), buf);
  384.   g_snprintf (buf, 64, "%.1f", param.rc.f_vbv_buffer_init);
  385.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_buffer_init), buf);
  386.   /* mb */
  387.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.transform_8x8), param.analyse.b_transform_8x8);
  388.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_8), CHECK_FLAG(param.analyse.inter, X264_ANALYSE_PSUB16x16));
  389.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.bframe_search_8), CHECK_FLAG(param.analyse.inter, X264_ANALYSE_BSUB16x16));
  390.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_4), CHECK_FLAG(param.analyse.inter, X264_ANALYSE_PSUB8x8));
  391.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_8), CHECK_FLAG(param.analyse.inter, X264_ANALYSE_I8x8));
  392.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_4), CHECK_FLAG(param.analyse.inter, X264_ANALYSE_I4x4));
  393.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_pyramid), param.b_bframe_pyramid);
  394.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bidir_me), param.analyse.b_bidir_me);
  395.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_adaptive), param.b_bframe_adaptive);
  396.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.weighted_bipred), param.analyse.b_weighted_bipred);
  397.   g_snprintf (buf, 64, "%d", param.i_bframe);
  398.   gtk_entry_set_text (GTK_ENTRY (config->mb.bframes.bframe), buf);
  399.   gtk_range_set_value (GTK_RANGE (config->mb.bframes.bframe_bias), (gdouble)param.i_bframe_bias);
  400.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->mb.bframes.direct_mode), param.analyse.i_direct_mv_pred);
  401.   /* more */
  402.   if (param.analyse.b_bframe_rdo)
  403.     gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.partition_decision), X264_PD_6b);
  404.   else
  405.     gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.partition_decision), param.analyse.i_subpel_refine - 1);
  406.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.method), param.analyse.i_me_method);
  407.   g_snprintf (buf, 64, "%d", param.analyse.i_me_range);
  408.   gtk_entry_set_text (GTK_ENTRY (config->more.motion_estimation.range), buf);
  409.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.chroma_me), param.analyse.b_chroma_me);
  410.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.mixed_refs), param.analyse.b_mixed_references);
  411.   g_snprintf (buf, 64, "%d", param.i_frame_reference);
  412.   gtk_entry_set_text (GTK_ENTRY (config->more.motion_estimation.max_ref_frames), buf);
  413.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.fast_pskip), param.analyse.b_fast_pskip);
  414.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.dct_decimate), param.analyse.b_dct_decimate);
  415.   g_snprintf (buf, 64, "%d", param.vui.i_sar_width);
  416.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.sample_ar_x), buf);
  417.   g_snprintf (buf, 64, "%d", param.vui.i_sar_height);
  418.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.sample_ar_y), buf);
  419.   gtk_spin_button_set_value (GTK_SPIN_BUTTON (config->more.misc.threads), param.i_threads);
  420.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.cabac), param.b_cabac);
  421.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.misc.trellis), param.analyse.i_trellis);
  422.   g_snprintf (buf, 64, "%d", param.analyse.i_noise_reduction);
  423.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.noise_reduction), buf);
  424.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.df.deblocking_filter), param.b_deblocking_filter);
  425.   gtk_range_set_value (GTK_RANGE (config->more.misc.df.strength), (gdouble)param.i_deblocking_filter_alphac0);
  426.   gtk_range_set_value (GTK_RANGE (config->more.misc.df.threshold), (gdouble)param.i_deblocking_filter_beta);
  427.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.debug.log_level), param.i_log_level + 1);
  428.   gtk_entry_set_text (GTK_ENTRY (config->more.debug.fourcc), "H264");
  429.   /* cqm */
  430.   switch (param.i_cqm_preset) {
  431.   case X264_CQM_FLAT:
  432.     // workaround: gtk fails to update the matrix entries if we activate the button
  433.     // that was already active.
  434.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_jvt), TRUE);
  435.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_flat), TRUE);
  436.     break;
  437.   case X264_CQM_JVT:
  438.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_jvt), TRUE);
  439.     break;
  440.   case X264_CQM_CUSTOM:
  441.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_custom), TRUE);
  442.     break;
  443.   }
  444.   if (param.psz_cqm_file && (param.psz_cqm_file[0] != ''))
  445.     gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (config->cqm.cqm_file), param.psz_cqm_file);
  446.   for (i = 0; i < 16; i++) {
  447.     gchar buf[4];
  448.     g_snprintf (buf, 4, "%d", param.cqm_4iy[i]);
  449.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4iy[i]), buf);
  450.     g_snprintf (buf, 4, "%d", param.cqm_4ic[i]);
  451.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4ic[i]), buf);
  452.     g_snprintf (buf, 4, "%d", param.cqm_4py[i]);
  453.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4py[i]), buf);
  454.     g_snprintf (buf, 4, "%d", param.cqm_4pc[i]);
  455.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4pc[i]), buf);
  456.   }
  457.   for (i = 0; i < 64; i++) {
  458.     gchar buf[4];
  459.     g_snprintf (buf, 4, "%d", param.cqm_8iy[i]);
  460.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_8iy[i]), buf);
  461.     g_snprintf (buf, 4, "%d", param.cqm_8py[i]);
  462.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_8py[i]), buf);
  463.   }
  464. }
  465. static void
  466. x264_default_set (X264_Gtk *x264_gtk)
  467. {
  468.   x264_param_t param;
  469.   x264_param_default (&param);
  470.   /* bitrate */
  471.   x264_gtk->pass = X264_PASS_SINGLE_QUANTIZER;
  472.   x264_gtk->average_bitrate = param.rc.i_bitrate;
  473.   x264_gtk->target_bitrate = param.rc.i_bitrate;
  474.   x264_gtk->quantizer = param.rc.i_qp_constant;
  475.   x264_gtk->stat_write = param.rc.b_stat_write;
  476.   x264_gtk->stat_read = param.rc.b_stat_read;
  477.   x264_gtk->update_statfile = 0;
  478.   x264_gtk->statsfile_length = strlen (param.rc.psz_stat_out);
  479.   memcpy (x264_gtk->statsfile_name, param.rc.psz_stat_out, x264_gtk->statsfile_length + 1);
  480.   /* rate control */
  481.   x264_gtk->keyframe_boost = round((param.rc.f_ip_factor - 1.0) * 100);
  482.   x264_gtk->bframes_reduction = round((param.rc.f_pb_factor - 1.0) * 100);
  483.   x264_gtk->bitrate_variability = round(param.rc.f_qcompress * 100);
  484.   x264_gtk->min_qp = param.rc.i_qp_min;
  485.   x264_gtk->max_qp = param.rc.i_qp_max;
  486.   x264_gtk->max_qp_step = param.rc.i_qp_step;
  487.   x264_gtk->scene_cut_threshold = param.i_scenecut_threshold;
  488.   x264_gtk->min_idr_frame_interval = param.i_keyint_min;
  489.   x264_gtk->max_idr_frame_interval = param.i_keyint_max;
  490.   x264_gtk->vbv_max_bitrate = param.rc.i_vbv_max_bitrate;
  491.   x264_gtk->vbv_buffer_size = param.rc.i_vbv_buffer_size;
  492.   x264_gtk->vbv_buffer_init = param.rc.f_vbv_buffer_init;
  493.   /* mb */
  494.   x264_gtk->transform_8x8 = param.analyse.b_transform_8x8;
  495.   if (CHECK_FLAG(param.analyse.inter, X264_ANALYSE_PSUB16x16))
  496.     x264_gtk->pframe_search_8 = 1;
  497.   else
  498.     x264_gtk->pframe_search_8 = 0;
  499.   if (CHECK_FLAG(param.analyse.inter, X264_ANALYSE_BSUB16x16))
  500.     x264_gtk->bframe_search_8 = 1;
  501.   else
  502.     x264_gtk->bframe_search_8 = 0;
  503.   if (CHECK_FLAG(param.analyse.inter, X264_ANALYSE_PSUB8x8))
  504.     x264_gtk->pframe_search_4 = 1;
  505.   else
  506.     x264_gtk->pframe_search_4 = 0;
  507.   x264_gtk->inter_search_8 = CHECK_FLAG(param.analyse.inter, X264_ANALYSE_I8x8);
  508.   x264_gtk->inter_search_4 = CHECK_FLAG(param.analyse.inter, X264_ANALYSE_I4x4);
  509.   x264_gtk->bframe_pyramid = param.b_bframe_pyramid;
  510.   x264_gtk->bidir_me = param.analyse.b_bidir_me;
  511.   x264_gtk->bframe_adaptive = param.b_bframe_adaptive;
  512.   x264_gtk->weighted_bipred = param.analyse.b_weighted_bipred;
  513.   x264_gtk->bframe = param.i_bframe;
  514.   x264_gtk->bframe_bias = param.i_bframe_bias;
  515.   x264_gtk->direct_mode = param.analyse.i_direct_mv_pred;
  516.   /* more */
  517.   x264_gtk->bframe_rdo = param.analyse.b_bframe_rdo;
  518.   x264_gtk->partition_decision = param.analyse.i_subpel_refine - 1;
  519.   x264_gtk->me_method = param.analyse.i_me_method;
  520.   x264_gtk->range = param.analyse.i_me_range;
  521.   x264_gtk->chroma_me = param.analyse.b_chroma_me;
  522.   x264_gtk->max_ref_frames = param.i_frame_reference;
  523.   x264_gtk->mixed_refs = param.analyse.b_mixed_references;
  524.   x264_gtk->fast_pskip = param.analyse.b_fast_pskip;
  525.   x264_gtk->dct_decimate = param.analyse.b_dct_decimate;
  526.   x264_gtk->sample_ar_x = param.vui.i_sar_width;
  527.   x264_gtk->sample_ar_y = param.vui.i_sar_height;
  528.   x264_gtk->threads = param.i_threads;
  529.   x264_gtk->cabac = param.b_cabac;
  530.   x264_gtk->trellis = param.analyse.i_trellis;
  531.   x264_gtk->noise_reduction = param.analyse.i_noise_reduction;
  532.   x264_gtk->deblocking_filter = param.b_deblocking_filter;
  533.   x264_gtk->strength = param.i_deblocking_filter_alphac0;
  534.   x264_gtk->threshold = param.i_deblocking_filter_beta;
  535.   x264_gtk->debug_method = param.i_log_level + 1;
  536.   memcpy (x264_gtk->fourcc, "H264", 5);
  537.   /* cqm */
  538.   x264_gtk->cqm_preset = param.i_cqm_preset;
  539.   if (param.psz_cqm_file && (param.psz_cqm_file[0] != ''))
  540.     memcpy (x264_gtk->cqm_file, param.psz_cqm_file,  strlen (param.psz_cqm_file) + 1);
  541.   memcpy (x264_gtk->cqm_4iy, param.cqm_4iy, 16);
  542.   memcpy (x264_gtk->cqm_4ic, param.cqm_4ic, 16);
  543.   memcpy (x264_gtk->cqm_4py, param.cqm_4py, 16);
  544.   memcpy (x264_gtk->cqm_4pc, param.cqm_4pc, 16);
  545.   memcpy (x264_gtk->cqm_8iy, param.cqm_8iy, 64);
  546.   memcpy (x264_gtk->cqm_8py, param.cqm_8py, 64);
  547. }
  548. static void
  549. x264_current_set (X264_Gui_Config *config, X264_Gtk *x264_gtk)
  550. {
  551.   gchar buf[4096];
  552.   gint  i;
  553.   if (!config)
  554.     return;
  555.   /* bitrate */
  556.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->bitrate.pass), x264_gtk->pass);
  557.   g_snprintf (buf, 5, "%d", x264_gtk->average_bitrate);
  558.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.w_average_bitrate), buf);
  559.   gtk_range_set_range (GTK_RANGE (config->bitrate.w_quantizer),
  560.                        0.0,
  561.                        51.0);
  562.   gtk_range_set_value (GTK_RANGE (config->bitrate.w_quantizer), x264_gtk->quantizer);
  563.   g_snprintf (buf, 5, "%d", x264_gtk->target_bitrate);
  564.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.w_target_bitrate), buf);
  565.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (config->bitrate.pass)))
  566.   {
  567.   case 0:
  568.   case 1:
  569.     gtk_widget_set_sensitive (config->bitrate.update_statfile, FALSE);
  570.     gtk_widget_set_sensitive (config->bitrate.statsfile_name, FALSE);
  571.     break;
  572.   case 2:
  573.   case 3:
  574.   case 4:
  575.   default:
  576.     gtk_widget_set_sensitive (config->bitrate.update_statfile, TRUE);
  577.     break;
  578.   }
  579.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->bitrate.update_statfile), x264_gtk->update_statfile);
  580.   gtk_entry_set_text (GTK_ENTRY (config->bitrate.statsfile_name), x264_gtk->statsfile_name);
  581.   if (x264_gtk->update_statfile)
  582.     gtk_widget_set_sensitive (config->bitrate.statsfile_name, TRUE);
  583.   else
  584.     gtk_widget_set_sensitive (config->bitrate.statsfile_name, FALSE);
  585.   /* rate control */
  586.   g_snprintf (buf, 5, "%d", x264_gtk->keyframe_boost);
  587.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.keyframe_boost), buf);
  588.   g_snprintf (buf, 5, "%d", x264_gtk->bframes_reduction);
  589.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.bframes_reduction), buf);
  590.   g_snprintf (buf, 5, "%d", x264_gtk->bitrate_variability);
  591.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.bitrate.bitrate_variability), buf);
  592.   g_snprintf (buf, 5, "%d", x264_gtk->min_qp);
  593.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.min_qp), buf);
  594.   g_snprintf (buf, 5, "%d", x264_gtk->max_qp);
  595.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.max_qp), buf);
  596.   g_snprintf (buf, 5, "%d", x264_gtk->max_qp_step);
  597.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.quantization_limits.max_qp_step), buf);
  598.   g_snprintf (buf, 5, "%d", x264_gtk->scene_cut_threshold);
  599.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.scene_cut_threshold), buf);
  600.   g_snprintf (buf, 5, "%d", x264_gtk->min_idr_frame_interval);
  601.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.min_idr_frame_interval), buf);
  602.   g_snprintf (buf, 5, "%d", x264_gtk->max_idr_frame_interval);
  603.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.scene_cuts.max_idr_frame_interval), buf);
  604.   g_snprintf (buf, 5, "%d", x264_gtk->vbv_max_bitrate);
  605.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_max_bitrate), buf);
  606.   g_snprintf (buf, 5, "%d", x264_gtk->vbv_buffer_size);
  607.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_buffer_size), buf);
  608.   g_snprintf (buf, 5, "%.1f", x264_gtk->vbv_buffer_init);
  609.   gtk_entry_set_text (GTK_ENTRY (config->rate_control.vbv.vbv_buffer_init), buf);
  610.   /* mb */
  611.   if (x264_gtk->transform_8x8)
  612.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.transform_8x8), TRUE);
  613.   else
  614.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.transform_8x8), FALSE);
  615.   if (x264_gtk->pframe_search_8)
  616.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_8), TRUE);
  617.   else
  618.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_8), FALSE);
  619.   if (x264_gtk->bframe_search_8)
  620.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.bframe_search_8), TRUE);
  621.   else
  622.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.bframe_search_8), FALSE);
  623.   if (x264_gtk->pframe_search_4)
  624.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_4), TRUE);
  625.   else
  626.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.pframe_search_4), FALSE);
  627.   if (x264_gtk->inter_search_8)
  628.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_8), TRUE);
  629.   else
  630.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_8), FALSE);
  631.   if (x264_gtk->inter_search_4)
  632.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_4), TRUE);
  633.   else
  634.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_4), FALSE);
  635.   /* mb - bframes */
  636.   if (x264_gtk->bframe_pyramid)
  637.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_pyramid), TRUE);
  638.   else
  639.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_pyramid), FALSE);
  640.   if (x264_gtk->bidir_me)
  641.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bidir_me), TRUE);
  642.   else
  643.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bidir_me), FALSE);
  644.   if (x264_gtk->bframe_adaptive)
  645.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_adaptive), TRUE);
  646.   else
  647.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.bframe_adaptive), FALSE);
  648.   if (x264_gtk->weighted_bipred)
  649.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.weighted_bipred), TRUE);
  650.   else
  651.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.bframes.weighted_bipred), FALSE);
  652.   g_snprintf (buf, 5, "%d", x264_gtk->bframe);
  653.   gtk_entry_set_text (GTK_ENTRY (config->mb.bframes.bframe), buf);
  654.   gtk_range_set_value (GTK_RANGE (config->mb.bframes.bframe_bias), (gdouble)x264_gtk->bframe_bias);
  655.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->mb.bframes.direct_mode), x264_gtk->direct_mode);
  656.   /* more */
  657.   if (x264_gtk->bframe_rdo)
  658.     gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.partition_decision), X264_PD_6b);
  659.   else
  660.     gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.partition_decision), x264_gtk->partition_decision);
  661.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.motion_estimation.method), x264_gtk->me_method);
  662.   g_snprintf (buf, 5, "%d", x264_gtk->range);
  663.   gtk_entry_set_text (GTK_ENTRY (config->more.motion_estimation.range), buf);
  664.   if (x264_gtk->chroma_me)
  665.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.chroma_me), TRUE);
  666.   else
  667.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.chroma_me), FALSE);
  668.   g_snprintf (buf, 5, "%d", x264_gtk->max_ref_frames);
  669.   gtk_entry_set_text (GTK_ENTRY (config->more.motion_estimation.max_ref_frames), buf);
  670.   if (x264_gtk->mixed_refs && (x264_gtk->max_ref_frames >= 2))
  671.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.mixed_refs), TRUE);
  672.   else
  673.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.mixed_refs), FALSE);
  674.   if (x264_gtk->fast_pskip)
  675.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.fast_pskip), TRUE);
  676.   else
  677.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.fast_pskip), FALSE);
  678.   if (x264_gtk->dct_decimate)
  679.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.dct_decimate), TRUE);
  680.   else
  681.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.motion_estimation.dct_decimate), FALSE);
  682.   g_snprintf (buf, 5, "%d", x264_gtk->sample_ar_x);
  683.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.sample_ar_x), buf);
  684.   g_snprintf (buf, 5, "%d", x264_gtk->sample_ar_y);
  685.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.sample_ar_y), buf);
  686.   gtk_spin_button_set_value (GTK_SPIN_BUTTON (config->more.misc.threads), x264_gtk->threads);
  687.   if (x264_gtk->cabac)
  688.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.cabac), TRUE);
  689.   else
  690.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.cabac), FALSE);
  691.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.misc.trellis), x264_gtk->trellis);
  692.   g_snprintf (buf, 64, "%d", x264_gtk->noise_reduction);
  693.   gtk_entry_set_text (GTK_ENTRY (config->more.misc.noise_reduction), buf);
  694.   if (x264_gtk->deblocking_filter)
  695.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.df.deblocking_filter), TRUE);
  696.   else
  697.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->more.misc.df.deblocking_filter), FALSE);
  698.   gtk_range_set_value (GTK_RANGE (config->more.misc.df.strength), (gdouble)x264_gtk->strength);
  699.   gtk_range_set_value (GTK_RANGE (config->more.misc.df.threshold), (gdouble)x264_gtk->threshold);
  700.   gtk_combo_box_set_active (GTK_COMBO_BOX (config->more.debug.log_level), x264_gtk->debug_method);
  701.   gtk_entry_set_text (GTK_ENTRY (config->more.debug.fourcc), x264_gtk->fourcc);
  702.   /* cqm */
  703.   switch (x264_gtk->cqm_preset) {
  704.   case X264_CQM_PRESET_FLAT:
  705.     // workaround: gtk fails to update the matrix entries if we activate the button
  706.     // that was already active.
  707.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_jvt), TRUE);
  708.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_flat), TRUE);
  709.     break;
  710.   case X264_CQM_PRESET_JVT:
  711.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_jvt), TRUE);
  712.     break;
  713.   case X264_CQM_PRESET_CUSTOM:
  714.     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->cqm.radio_custom), TRUE);
  715.     break;
  716.   }
  717.   if (x264_gtk->cqm_file && (x264_gtk->cqm_file[0] != ''))
  718.     gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (config->cqm.cqm_file), x264_gtk->cqm_file);
  719.   for (i = 0; i < 16; i++) {
  720.     gchar buf[4];
  721.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_4iy[i]);
  722.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4iy[i]), buf);
  723.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_4ic[i]);
  724.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4ic[i]), buf);
  725.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_4py[i]);
  726.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4py[i]), buf);
  727.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_4pc[i]);
  728.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_4pc[i]), buf);
  729.   }
  730.   for (i = 0; i < 64; i++) {
  731.     gchar buf[4];
  732.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_8iy[i]);
  733.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_8iy[i]), buf);
  734.     g_snprintf (buf, 4, "%d", x264_gtk->cqm_8py[i]);
  735.     gtk_entry_set_text (GTK_ENTRY (config->cqm.cqm_8py[i]), buf);
  736.   }
  737. }
  738. static void
  739. x264_current_get (X264_Gui_Config *gconfig, X264_Gtk *x264_gtk)
  740. {
  741.   const gchar *text;
  742.   gint         i;
  743.   if (!gconfig)
  744.     return;
  745.   if (!x264_gtk)
  746.     g_print (_("problem...n"));
  747.   /* bitrate */
  748.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->bitrate.pass)))
  749.   {
  750.   case 0:
  751.     x264_gtk->pass = X264_PASS_SINGLE_BITRATE;
  752.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->bitrate.w_average_bitrate));
  753.     x264_gtk->average_bitrate = (gint)g_ascii_strtoull (text, NULL, 10);
  754.     x264_gtk->stat_write = 0;
  755.     x264_gtk->stat_read = 0;
  756.     break;
  757.   case 1:
  758.     x264_gtk->pass = X264_PASS_SINGLE_QUANTIZER;
  759.     x264_gtk->quantizer = (gint)gtk_range_get_value (GTK_RANGE (gconfig->bitrate.w_quantizer));
  760.     x264_gtk->stat_write = 0;
  761.     x264_gtk->stat_read = 0;
  762.     break;
  763.   case 2:
  764.     x264_gtk->pass = X264_PASS_MULTIPASS_1ST;
  765.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->bitrate.w_target_bitrate));
  766.     x264_gtk->target_bitrate = (gint)g_ascii_strtoull (text, NULL, 10);
  767.     x264_gtk->stat_write = 1;
  768.     break;
  769.   case 3:
  770.     x264_gtk->pass = X264_PASS_MULTIPASS_1ST_FAST;
  771.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->bitrate.w_target_bitrate));
  772.     x264_gtk->target_bitrate = (gint)g_ascii_strtoull (text, NULL, 10);
  773.     x264_gtk->stat_write = 1;
  774.     break;
  775.   case 4:
  776.   default:
  777.     x264_gtk->pass = X264_PASS_MULTIPASS_NTH;
  778.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->bitrate.w_target_bitrate));
  779.     x264_gtk->target_bitrate = (gint)g_ascii_strtoull (text, NULL, 10);
  780.     x264_gtk->stat_read = 1;
  781.     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->bitrate.update_statfile)))
  782.       x264_gtk->stat_write = 1;
  783.     break;
  784.   }
  785.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->bitrate.update_statfile)))
  786.     x264_gtk->update_statfile = 1;
  787.   else
  788.     x264_gtk->update_statfile = 0;
  789.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->bitrate.statsfile_name));
  790.   x264_gtk->statsfile_length = strlen (text);
  791.   memcpy (x264_gtk->statsfile_name,
  792.           text,
  793.           x264_gtk->statsfile_length + 1);
  794.   /* rate control */
  795.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.bitrate.keyframe_boost));
  796.   x264_gtk->keyframe_boost = (gint)g_ascii_strtoull (text, NULL, 10);
  797.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.bitrate.bframes_reduction));
  798.   x264_gtk->bframes_reduction = (gint)g_ascii_strtoull (text, NULL, 10);
  799.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.bitrate.bitrate_variability));
  800.   x264_gtk->bitrate_variability = (gint)g_ascii_strtoull (text, NULL, 10);
  801.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.quantization_limits.min_qp));
  802.   x264_gtk->min_qp = (gint)g_ascii_strtoull (text, NULL, 10);
  803.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.quantization_limits.max_qp));
  804.   x264_gtk->max_qp = (gint)g_ascii_strtoull (text, NULL, 10);
  805.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.quantization_limits.max_qp_step));
  806.   x264_gtk->max_qp_step = (gint)g_ascii_strtoull (text, NULL, 10);
  807.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.scene_cuts.scene_cut_threshold));
  808.   x264_gtk->scene_cut_threshold = (gint)g_ascii_strtoull (text, NULL, 10);
  809.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.scene_cuts.min_idr_frame_interval));
  810.   x264_gtk->min_idr_frame_interval = (gint)g_ascii_strtoull (text, NULL, 10);
  811.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.scene_cuts.max_idr_frame_interval));
  812.   x264_gtk->max_idr_frame_interval = (gint)g_ascii_strtoull (text, NULL, 10);
  813.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.vbv.vbv_max_bitrate));
  814.   x264_gtk->vbv_max_bitrate = (gint)g_ascii_strtoull (text, NULL, 10);
  815.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.vbv.vbv_buffer_size));
  816.   x264_gtk->vbv_buffer_size = (gint)g_ascii_strtoull (text, NULL, 10);
  817.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->rate_control.vbv.vbv_buffer_init));
  818.   x264_gtk->vbv_buffer_init = (gint)g_ascii_strtoull (text, NULL, 10);
  819.   /* mb */
  820.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.transform_8x8)))
  821.     x264_gtk->transform_8x8 = 1;
  822.   else
  823.     x264_gtk->transform_8x8 = 0;
  824.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.pframe_search_8)))
  825.     x264_gtk->pframe_search_8 = 1;
  826.   else
  827.     x264_gtk->pframe_search_8 = 0;
  828.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.bframe_search_8)))
  829.     x264_gtk->bframe_search_8 = 1;
  830.   else
  831.     x264_gtk->bframe_search_8 = 0;
  832.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.pframe_search_4)))
  833.     x264_gtk->pframe_search_4 = 1;
  834.   else
  835.     x264_gtk->pframe_search_4 = 0;
  836.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.inter_search_8)))
  837.     x264_gtk->inter_search_8 = 1;
  838.   else
  839.     x264_gtk->inter_search_8 = 0;
  840.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.partitions.inter_search_4)))
  841.     x264_gtk->inter_search_4 = 1;
  842.   else
  843.     x264_gtk->inter_search_4 = 0;
  844.   /* mb - bframes */
  845.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.bframes.bframe_pyramid)))
  846.     x264_gtk->bframe_pyramid = 1;
  847.   else
  848.     x264_gtk->bframe_pyramid = 0;
  849.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.bframes.bidir_me)))
  850.     x264_gtk->bidir_me = 1;
  851.   else
  852.     x264_gtk->bidir_me = 0;
  853.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.bframes.bframe_adaptive)))
  854.     x264_gtk->bframe_adaptive = 1;
  855.   else
  856.     x264_gtk->bframe_adaptive = 0;
  857.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->mb.bframes.weighted_bipred)))
  858.     x264_gtk->weighted_bipred = 1;
  859.   else
  860.     x264_gtk->weighted_bipred = 0;
  861.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->mb.bframes.bframe));
  862.   x264_gtk->bframe = (gint)g_ascii_strtoull (text, NULL, 10);
  863.   x264_gtk->bframe_bias = (gint)gtk_range_get_value (GTK_RANGE (gconfig->mb.bframes.bframe_bias));
  864.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->mb.bframes.direct_mode)))
  865.     {
  866.     case 0:
  867.       x264_gtk->direct_mode = X264_NONE;
  868.     case 1:
  869.       x264_gtk->direct_mode = X264_SPATIAL;
  870.       break;
  871.     case 2:
  872.       x264_gtk->direct_mode = X264_TEMPORAL;
  873.       break;
  874.     default:
  875.       x264_gtk->direct_mode = X264_AUTO;
  876.       break;
  877.     }
  878.   /* more */
  879.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->more.motion_estimation.partition_decision)))
  880.     {
  881.     case 0:
  882.       x264_gtk->partition_decision = X264_PD_1;
  883.       break;
  884.     case 1:
  885.       x264_gtk->partition_decision = X264_PD_2;
  886.       break;
  887.     case 2:
  888.       x264_gtk->partition_decision = X264_PD_3;
  889.       break;
  890.     case 3:
  891.       x264_gtk->partition_decision = X264_PD_4;
  892.       break;
  893.     case 4:
  894.       x264_gtk->partition_decision = X264_PD_5;
  895.       break;
  896.     case 5:
  897.       x264_gtk->partition_decision = X264_PD_6;
  898.       break;
  899.     default:
  900.       x264_gtk->partition_decision = X264_PD_6;
  901.       x264_gtk->bframe_rdo = 1;
  902.       break;
  903.     }
  904.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->more.motion_estimation.method)))
  905.     {
  906.     case 0:
  907.       x264_gtk->me_method = X264_ME_METHOD_DIAMOND;
  908.       break;
  909.     case 1:
  910.       x264_gtk->me_method = X264_ME_METHOD_HEXAGONAL;
  911.       break;
  912.     case 2:
  913.       x264_gtk->me_method = X264_ME_METHOD_UNEVEN_MULTIHEXA;
  914.       break;
  915.     default:
  916.       x264_gtk->me_method = X264_ME_METHOD_EXHAUSTIVE;
  917.       break;
  918.     }
  919.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.motion_estimation.range));
  920.   x264_gtk->range = (gint)g_ascii_strtoull (text, NULL, 10);
  921.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.motion_estimation.chroma_me)))
  922.     x264_gtk->chroma_me = 1;
  923.   else
  924.     x264_gtk->chroma_me = 0;
  925.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.motion_estimation.max_ref_frames));
  926.   x264_gtk->max_ref_frames = (gint)g_ascii_strtoull (text, NULL, 10);
  927.   if (x264_gtk->max_ref_frames <= 0)
  928.     x264_gtk->max_ref_frames = 1;
  929.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.motion_estimation.mixed_refs)) &&
  930.       (x264_gtk->max_ref_frames >= 2))
  931.     x264_gtk->mixed_refs = 1;
  932.   else
  933.     x264_gtk->mixed_refs = 0;
  934.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.motion_estimation.fast_pskip)))
  935.     x264_gtk->fast_pskip = 1;
  936.   else
  937.     x264_gtk->fast_pskip = 0;
  938.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.motion_estimation.dct_decimate)))
  939.     x264_gtk->dct_decimate = 1;
  940.   else
  941.     x264_gtk->dct_decimate = 0;
  942.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.misc.sample_ar_x));
  943.   x264_gtk->sample_ar_x = (gint)g_ascii_strtoull (text, NULL, 10);
  944.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.misc.sample_ar_y));
  945.   x264_gtk->sample_ar_y = (gint)g_ascii_strtoull (text, NULL, 10);
  946.   x264_gtk->threads = (gint)gtk_spin_button_get_value (GTK_SPIN_BUTTON (gconfig->more.misc.threads));
  947.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.misc.cabac)))
  948.     x264_gtk->cabac = 1;
  949.   else
  950.     x264_gtk->cabac = 0;
  951.   x264_gtk->trellis = gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->more.misc.trellis));
  952.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.misc.noise_reduction));
  953.   x264_gtk->noise_reduction = (gint)g_ascii_strtoull (text, NULL, 10);
  954.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->more.misc.df.deblocking_filter)))
  955.     x264_gtk->deblocking_filter = 1;
  956.   else
  957.     x264_gtk->deblocking_filter = 0;
  958.   x264_gtk->strength = (gint)gtk_range_get_value (GTK_RANGE (gconfig->more.misc.df.strength));
  959.   x264_gtk->threshold = (gint)gtk_range_get_value (GTK_RANGE (gconfig->more.misc.df.threshold));
  960.   switch (gtk_combo_box_get_active (GTK_COMBO_BOX (gconfig->more.debug.log_level)))
  961.     {
  962.     case 0:
  963.       x264_gtk->debug_method = X264_DEBUG_METHOD_NONE;
  964.       break;
  965.     case 1:
  966.       x264_gtk->debug_method = X264_DEBUG_METHOD_ERROR;
  967.       break;
  968.     case 2:
  969.       x264_gtk->debug_method = X264_DEBUG_METHOD_WARNING;
  970.       break;
  971.     case 3:
  972.       x264_gtk->debug_method = X264_DEBUG_METHOD_INFO;
  973.       break;
  974.     default:
  975.       x264_gtk->debug_method = X264_DEBUG_METHOD_DEBUG;
  976.       break;
  977.     }
  978.   text = gtk_entry_get_text (GTK_ENTRY (gconfig->more.debug.fourcc));
  979.   memcpy (x264_gtk->fourcc, text, strlen (text) + 1);
  980.   /* cqm */
  981.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->cqm.radio_flat)))
  982.     x264_gtk->cqm_preset = X264_CQM_PRESET_FLAT;
  983.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->cqm.radio_jvt)))
  984.     x264_gtk->cqm_preset = X264_CQM_PRESET_JVT;
  985.   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gconfig->cqm.radio_custom)))
  986.     x264_gtk->cqm_preset = X264_CQM_PRESET_CUSTOM;
  987.   text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (gconfig->cqm.cqm_file));
  988.   if (text && (text[0] != ''))
  989.     memcpy (x264_gtk->cqm_file, text, strlen (text) + 1);
  990.   for (i = 0; i < 16; i++) {
  991.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_4iy[i]));
  992.     x264_gtk->cqm_4iy[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  993.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_4ic[i]));
  994.     x264_gtk->cqm_4ic[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  995.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_4py[i]));
  996.     x264_gtk->cqm_4py[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  997.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_4pc[i]));
  998.     x264_gtk->cqm_4pc[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  999.   }
  1000.   for (i = 0; i < 64; i++) {
  1001.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_8iy[i]));
  1002.     x264_gtk->cqm_8iy[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  1003.     text = gtk_entry_get_text (GTK_ENTRY (gconfig->cqm.cqm_8py[i]));
  1004.     x264_gtk->cqm_8py[i] = (gint)g_ascii_strtoull (text, NULL, 10);
  1005.   }
  1006. }
  1007. gchar*
  1008. x264_gtk_path(const char* more)
  1009. {
  1010. #ifdef _WIN32
  1011.   gchar szPath[MAX_PATH];
  1012.   // "Documents and Settingsuser" is CSIDL_PROFILE
  1013.   szPath[0] = 0;
  1014.   SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
  1015.   if (more)
  1016.     return g_build_filename(szPath, "x264", more, NULL);
  1017.   else
  1018.     return g_build_filename(szPath, "x264", NULL);
  1019. #else
  1020.   if (more)
  1021.     return g_build_filename (g_get_home_dir (), ".x264", more, NULL);
  1022.   else
  1023.     return g_build_filename (g_get_home_dir (), ".x264", NULL);
  1024. #endif
  1025. }