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

Audio

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  * x264_encode_status_window.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. #if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __DragonFly__
  21. #  include <inttypes.h>
  22. #else
  23. #  include <stdint.h>
  24. #endif
  25. #include <gtk/gtk.h>
  26. #include "../x264.h"
  27. #include "x264_gtk_i18n.h"
  28. #include "x264_gtk_encode_private.h"
  29. /* Callbacks */
  30. static gboolean x264_delete_window_cb    (GtkWidget *widget,
  31.                                       GdkEvent  *event,
  32.                                       gpointer   user_data);
  33. static void     x264_response_window_cb  (GtkDialog *dialog,
  34.                                       gint       res,
  35.                                       gpointer   user_data);
  36. GtkWidget *
  37. x264_gtk_encode_status_window (X264_Thread_Data *thread_data)
  38. {
  39.   GtkWidget *win_status;
  40.   GtkWidget *table;
  41.   GtkWidget *label;
  42.   if (!thread_data) return NULL;
  43.   win_status = thread_data->dialog = gtk_dialog_new ();
  44.   gtk_window_set_title  (GTK_WINDOW (win_status), _("Encoding status"));
  45.   thread_data->button = gtk_dialog_add_button (GTK_DIALOG (win_status),
  46.                                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
  47.   thread_data->end_button = gtk_dialog_add_button (GTK_DIALOG (thread_data->dialog),
  48.                                                    GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
  49.   gtk_widget_set_sensitive (thread_data->end_button, FALSE);
  50.   g_signal_connect (G_OBJECT (win_status),
  51.                     "delete-event",
  52.                     G_CALLBACK (x264_delete_window_cb),
  53.                     thread_data);
  54.   g_signal_connect (G_OBJECT (win_status),
  55.                     "response",
  56.                     G_CALLBACK (x264_response_window_cb),
  57.                     thread_data);
  58.   table = gtk_table_new (5, 2, FALSE);
  59.   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  60.   gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  61.   gtk_container_set_border_width (GTK_CONTAINER (table), 6);
  62.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (win_status)->vbox), table,
  63.                       FALSE, FALSE, 0);
  64.   gtk_widget_show (table);
  65.   label = gtk_label_new (_("Current video frame:"));
  66.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  67.   gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
  68.   gtk_widget_show (label);
  69.   thread_data->current_video_frame = gtk_entry_new ();
  70.   gtk_editable_set_editable (GTK_EDITABLE (thread_data->current_video_frame), FALSE);
  71.   gtk_table_attach_defaults (GTK_TABLE (table),
  72.                              thread_data->current_video_frame,
  73.                              1, 2, 0, 1);
  74.   gtk_widget_show (thread_data->current_video_frame);
  75.   label = gtk_label_new (_("Video data:"));
  76.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  77.   gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
  78.   gtk_widget_show (label);
  79.   thread_data->video_data = gtk_entry_new ();
  80.   gtk_entry_set_text (GTK_ENTRY (thread_data->video_data), _("0KB"));
  81.   gtk_editable_set_editable (GTK_EDITABLE (thread_data->video_data), FALSE);
  82.   gtk_table_attach_defaults (GTK_TABLE (table), thread_data->video_data,
  83.                              1, 2, 1, 2);
  84.   gtk_widget_show (thread_data->video_data);
  85.   label = gtk_label_new (_("Video rendering rate:"));
  86.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  87.   gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
  88.   gtk_widget_show (label);
  89.   thread_data->video_rendering_rate = gtk_entry_new ();
  90.   gtk_editable_set_editable (GTK_EDITABLE (thread_data->video_rendering_rate), FALSE);
  91.   gtk_table_attach_defaults (GTK_TABLE (table),
  92.                              thread_data->video_rendering_rate,
  93.                              1, 2, 2, 3);
  94.   gtk_widget_show (thread_data->video_rendering_rate);
  95.   label = gtk_label_new (_("Time elapsed:"));
  96.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  97.   gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4);
  98.   gtk_widget_show (label);
  99.   thread_data->time_elapsed = gtk_entry_new ();
  100.   gtk_editable_set_editable (GTK_EDITABLE (thread_data->time_elapsed), FALSE);
  101.   gtk_table_attach_defaults (GTK_TABLE (table), thread_data->time_elapsed,
  102.                              1, 2, 3, 4);
  103.   gtk_widget_show (thread_data->time_elapsed);
  104.   label = gtk_label_new (_("Time remaining (estimated):"));
  105.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  106.   gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5);
  107.   gtk_widget_show (label);
  108.   thread_data->time_remaining = gtk_entry_new ();
  109.   gtk_editable_set_editable (GTK_EDITABLE (thread_data->time_remaining), FALSE);
  110.   gtk_table_attach_defaults (GTK_TABLE (table), thread_data->time_remaining,
  111.                              1, 2, 4, 5);
  112.   gtk_widget_show (thread_data->time_remaining);
  113.   table = gtk_table_new (1, 2, FALSE);
  114.   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  115.   gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  116.   gtk_container_set_border_width (GTK_CONTAINER (table), 6);
  117.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (win_status)->vbox), table,
  118.                       FALSE, FALSE, 0);
  119.   gtk_widget_show (table);
  120.   label = gtk_label_new (_("Progress:"));
  121.   gtk_misc_set_alignment (GTK_MISC (label),
  122.                           0.0, 0.5);
  123.   gtk_table_attach_defaults (GTK_TABLE (table),
  124.                              label,
  125.                              0, 1,
  126.                              0, 1);
  127.   gtk_widget_show (label);
  128.   thread_data->progress = gtk_progress_bar_new ();
  129.   gtk_table_attach_defaults (GTK_TABLE (table), thread_data->progress,
  130.                              1, 2, 0, 1);
  131.   gtk_widget_show (thread_data->progress);
  132.   return win_status;
  133. }
  134. static void
  135. x264_thread_data_free (X264_Thread_Data *thread_data)
  136. {
  137.   g_free (thread_data->param);
  138.   g_free (thread_data->file_input);
  139.   g_free (thread_data->file_output);
  140.   g_io_channel_unref (thread_data->io_read);
  141.   g_io_channel_unref (thread_data->io_write);
  142.   g_free (thread_data);
  143. }
  144. static gboolean
  145. x264_delete_window_cb (GtkWidget *widget,
  146.                    GdkEvent  *event UNUSED,
  147.                    gpointer   user_data)
  148. {
  149.   gtk_widget_destroy (widget);
  150.   x264_thread_data_free ((X264_Thread_Data *)user_data);
  151.   return TRUE;
  152. }
  153. static void
  154. x264_response_window_cb (GtkDialog *dialog,
  155.                      gint       res,
  156.                      gpointer   user_data)
  157. {
  158.   switch (res) {
  159.   case GTK_RESPONSE_CANCEL:
  160.   default:
  161.     gtk_widget_destroy (GTK_WIDGET (dialog));
  162.     x264_thread_data_free ((X264_Thread_Data *)user_data);
  163.   }
  164. }