Esempio n. 1
0
gint
ghb_selected_subtitle_row(signal_user_data_t *ud)
{
    GtkTreeView *tv;
    GtkTreePath *tp;
    GtkTreeSelection *ts;
    GtkTreeModel *tm;
    GtkTreeIter iter;
    gint *indices;
    gint row = -1;

    g_debug("ghb_selected_subtitle_row ()");
    tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "subtitle_list"));
    ts = gtk_tree_view_get_selection(tv);
    if (gtk_tree_selection_get_selected(ts, &tm, &iter))
    {
        // Get the row number
        tp = gtk_tree_model_get_path(tm, &iter);
        indices = gtk_tree_path_get_indices(tp);
        row = indices[0];
        gtk_tree_path_free(tp);
    }
    return row;
}
Esempio n. 2
0
void
ghb_preview_set_visible(signal_user_data_t *ud, gboolean visible)
{
    GtkWidget *widget;
#if 0
    gint title_id, titleindex;
    const hb_title_t *title;

    title_id = ghb_dict_get_int(ud->settings, "title");
    title = ghb_lookup_title(title_id, &titleindex);
    visible &= title != NULL;
#endif
    widget = GHB_WIDGET(ud->builder, "preview_window");
    if (visible)
    {
        gint x, y;
        x = ghb_dict_get_int(ud->prefs, "preview_x");
        y = ghb_dict_get_int(ud->prefs, "preview_y");
        if (x >= 0 && y >= 0)
            gtk_window_move(GTK_WINDOW(widget), x, y);
        gtk_window_deiconify(GTK_WINDOW(widget));
    }
    gtk_widget_set_visible(widget, visible);
}
Esempio n. 3
0
static void
update_adv_settings_tooltip(signal_user_data_t *ud)
{
    if (video_option_tooltip == NULL)
    {
        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "VideoOptionExtra"));
        video_option_tooltip = gtk_widget_get_tooltip_text(eo);
    }

    int encoder = ghb_get_video_encoder(ud->settings);
    if (!ghb_dict_get_bool(ud->settings, "x264UseAdvancedOptions") &&
        (encoder & HB_VCODEC_X264_MASK))
    {
        GString *str = g_string_new("");
        const char *preset;
        const char *tune;
        const char *profile;
        const char *level;
        const char *opts;
        char *tunes;

        preset  = ghb_dict_get_string(ud->settings, "VideoPreset");
        tune    = ghb_dict_get_string(ud->settings, "VideoTune");
        profile = ghb_dict_get_string(ud->settings, "VideoProfile");
        level   = ghb_dict_get_string(ud->settings, "VideoLevel");
        opts    = ghb_dict_get_string(ud->settings, "VideoOptionExtra");

        if (tune[0] && strcmp(tune, "none"))
        {
            g_string_append_printf(str, "%s", tune);
        }
        if (ghb_dict_get_bool(ud->settings, "x264FastDecode"))
        {
            g_string_append_printf(str, "%s%s", str->str[0] ? "," : "", "fastdecode");
        }
        if (ghb_dict_get_bool(ud->settings, "x264ZeroLatency"))
        {
            g_string_append_printf(str, "%s%s", str->str[0] ? "," : "", "zerolatency");
        }
        tunes = g_string_free(str, FALSE);

        char * new_opts;

        int w = ghb_dict_get_int(ud->settings, "scale_width");
        int h = ghb_dict_get_int(ud->settings, "scale_height");

        if (w == 0 || h == 0)
        {
            if (!ghb_dict_get_bool(ud->settings, "autoscale"))
            {
                w = ghb_dict_get_int(ud->settings, "PictureWidth");
                h = ghb_dict_get_int(ud->settings, "PictureHeight");

                if (h == 0 && w != 0)
                {
                    h = w * 9 / 16;
                }
                if (w == 0 && h != 0)
                {
                    w = h * 16 / 9;
                }
            }
            if (w == 0 || h == 0)
            {
                w = 1280;
                h = 720;
            }
        }

        if (!strcasecmp(profile, "auto"))
        {
            profile = "";
        }
        if (!strcasecmp(level, "auto"))
        {
            level = "";
        }
        new_opts = hb_x264_param_unparse(hb_video_encoder_get_depth(encoder),
                        preset, tunes, opts, profile, level, w, h);
        if (new_opts)
            ghb_update_x264Option(ud, new_opts);
        else
            ghb_update_x264Option(ud, "");

        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "VideoOptionExtra"));

        char * tt;
        if (new_opts)
            tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
                                 video_option_tooltip, new_opts);
        else
            tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
                                 video_option_tooltip);
        gtk_widget_set_tooltip_text(eo, tt);

        g_free(tt);
        g_free(new_opts);

        g_free(tunes);
    }
    else if (ghb_dict_get_bool(ud->settings, "x264UseAdvancedOptions"))
    {
        const char *opts = ghb_dict_get_string(ud->settings, "x264Option");

        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "VideoOptionExtra"));
        char * tt;
        if (opts)
            tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
                                 video_option_tooltip, opts);
        else
            tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
                                 video_option_tooltip);
        gtk_widget_set_tooltip_text(eo, tt);
        g_free(tt);
    }
}
Esempio n. 4
0
void
ghb_queue_buttons_grey(signal_user_data_t *ud)
{
    GtkWidget *widget;
    GtkAction *action;
    gint queue_count;
    gint titleindex;
    gint queue_state, scan_state;
    gboolean show_start, show_stop, paused;

    queue_count = ghb_array_len(ud->queue);
    titleindex = ghb_settings_combo_int(ud->settings, "title");

    queue_state = ghb_get_queue_state();
    scan_state = ghb_get_scan_state();

    show_stop = queue_state & 
                (GHB_STATE_WORKING | GHB_STATE_SEARCHING | 
                 GHB_STATE_SCANNING | GHB_STATE_MUXING);
    show_start = !(scan_state & GHB_STATE_SCANNING) && 
                    (titleindex >= 0 || queue_count > 0);


    paused = queue_state & GHB_STATE_PAUSED;

    widget = GHB_WIDGET(ud->builder, "queue_add");
    gtk_widget_set_sensitive(widget, show_start);
    action = GHB_ACTION(ud->builder, "queue_add_menu");
    gtk_action_set_sensitive(action, show_start);
    action = GHB_ACTION(ud->builder, "queue_add_all_menu");
    gtk_action_set_sensitive(action, show_start);

    widget = GHB_WIDGET (ud->builder, "queue_start1");
    if (show_stop)
    {
        gtk_widget_set_sensitive (widget, TRUE);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
    }
    else
    {
        gtk_widget_set_sensitive (widget, show_start);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-start");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
    }
    widget = GHB_WIDGET (ud->builder, "queue_start2");
    if (show_stop)
    {
        gtk_widget_set_sensitive (widget, TRUE);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
    }
    else
    {
        gtk_widget_set_sensitive (widget, show_start);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-start");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
    }
    widget = GHB_WIDGET (ud->builder, "queue_pause1");
    if (paused)
    {
        gtk_widget_set_sensitive (widget, show_stop);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-start");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
    }
    else
    {
        gtk_widget_set_sensitive (widget, show_stop);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
    }
    widget = GHB_WIDGET (ud->builder, "queue_pause2");
    if (paused)
    {
        gtk_widget_set_sensitive (widget, show_stop);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-start");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
    }
    else
    {
        gtk_widget_set_sensitive (widget, show_stop);
        gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
        gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
        gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
    }

    action = GHB_ACTION (ud->builder, "queue_start_menu");
    if (show_stop)
    {
        gtk_action_set_sensitive (action, TRUE);
#if GTK_CHECK_VERSION(2, 16, 0)
        gtk_action_set_icon_name(action, "hb-stop");
        gtk_action_set_label(action, "S_top Queue");
        gtk_action_set_tooltip(action, "Stop Encoding");
#else
        g_object_set_property(G_OBJECT(action), "icon-name", 
                                            ghb_string_value("hb-stop"));
        g_object_set_property(G_OBJECT(action), "label",
                                            ghb_string_value("S_top Queue"));
        g_object_set_property(G_OBJECT(action), "tooltip",
                                            ghb_string_value("Stop Encoding"));
#endif
    }
    else
    {
        gtk_action_set_sensitive (action, show_start);
#if GTK_CHECK_VERSION(2, 16, 0)
        gtk_action_set_icon_name(action, "hb-start");
        gtk_action_set_label(action, "_Start Queue");
        gtk_action_set_tooltip(action, "Start Encoding");
#else
        g_object_set_property(G_OBJECT(action), "icon-name", 
                                            ghb_string_value("hb-start"));
        g_object_set_property(G_OBJECT(action), "label",
                                            ghb_string_value("_Start Queue"));
        g_object_set_property(G_OBJECT(action), "tooltip",
                                            ghb_string_value("Start Encoding"));
#endif
    }
    action = GHB_ACTION (ud->builder, "queue_pause_menu");
    if (paused)
    {
        gtk_action_set_sensitive (action, show_start);
#if GTK_CHECK_VERSION(2, 16, 0)
        gtk_action_set_icon_name(action, "hb-start");
        gtk_action_set_label(action, "_Resume Queue");
        gtk_action_set_tooltip(action, "Resume Encoding");
#else
        g_object_set_property(G_OBJECT(action), "icon-name", 
                                        ghb_string_value("hb-start"));
        g_object_set_property(G_OBJECT(action), "label",
                                        ghb_string_value("_Resume Queue"));
        g_object_set_property(G_OBJECT(action), "tooltip",
                                        ghb_string_value("Resume Encoding"));
#endif
    }
    else
    {
        gtk_action_set_sensitive (action, show_stop);
#if GTK_CHECK_VERSION(2, 16, 0)
        gtk_action_set_icon_name(action, "hb-pause");
        gtk_action_set_label(action, "_Pause Queue");
        gtk_action_set_tooltip(action, "Pause Encoding");
#else
        g_object_set_property(G_OBJECT(action), "icon-name", 
                                        ghb_string_value("hb-pause"));
        g_object_set_property(G_OBJECT(action), "label",
                                        ghb_string_value("_Pause Queue"));
        g_object_set_property(G_OBJECT(action), "tooltip",
                                        ghb_string_value("Pause Encoding"));
#endif
    }
}
Esempio n. 5
0
static void
add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter)
{
    GtkTreeView *treeview;
    GtkTreeIter iter;
    GtkTreeStore *store;
    gchar *info;
    gint status;
    GtkTreeIter citer;
    gchar *dest, *preset, *vol_name, *basename;
    const gchar *vcodec, *container;
    gchar *fps, *vcodec_abbr;
    gint title, start_point, end_point, width, height;
    gint source_width, source_height;
    gboolean pass2 = FALSE, keep_aspect, vqtype, turbo;
    gint pic_par;
    gchar *escape, *escape2;
    
    g_debug("update_queue_list ()");
    if (settings == NULL) return;
    treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
    store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
        
    title = ghb_settings_get_int(settings, "titlenum");
    start_point = ghb_settings_get_int(settings, "start_point");
    end_point = ghb_settings_get_int(settings, "end_point");
    vol_name = ghb_settings_get_string(settings, "volume_label");
    dest = ghb_settings_get_string(settings, "destination");
    basename = g_path_get_basename(dest);
    escape = g_markup_escape_text(basename, -1);
    escape2 = g_markup_escape_text(vol_name, -1);

    vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
    if (!vqtype)
        pass2 = ghb_settings_get_boolean(settings, "VideoTwoPass");
    const gchar *points = "Chapters";
    if (ghb_settings_combo_int(settings, "PtoPType") == 0)
        points = "Chapters";
    else if (ghb_settings_combo_int(settings, "PtoPType") == 1)
        points = "Seconds";
    else if (ghb_settings_combo_int(settings, "PtoPType") == 2)
        points = "Frames";
    info = g_strdup_printf 
    (
        "<big><b>%s</b></big> "
        "<small>(Title %d, %s %d through %d, %d Video %s)"
        " --> %s</small>",
         escape2, title, points, start_point, end_point, 
         pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
    );
    g_free(basename);
    g_free(escape);
    g_free(escape2);

    if (piter)
        iter = *piter;
    else
        gtk_tree_store_append(store, &iter, NULL);

    gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
    g_free(info);
    status = ghb_settings_get_int(settings, "job_status");
    switch (status)
    {
        case GHB_QUEUE_PENDING:
            gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
            break;
        case GHB_QUEUE_CANCELED:
            gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
            break;
        case GHB_QUEUE_RUNNING:
            gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
            break;
        case GHB_QUEUE_DONE:
            gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
            break;
        default:
            gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
            break;
    }

    GString *str = g_string_new("");
    gboolean markers;
    gboolean preset_modified;
    gint mux;
    const GValue *path;

    container = ghb_settings_combo_option(settings, "FileFormat");
    mux = ghb_settings_combo_int(settings, "FileFormat");
    preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
    path = ghb_settings_get_value(settings, "preset");
    preset = ghb_preset_path_string(path);
    markers = ghb_settings_get_boolean(settings, "ChapterMarkers");

    if (preset_modified)
        g_string_append_printf(str, 
            "<b>Modified Preset Based On:</b> <small>%s</small>\n", 
            preset);
    else
        g_string_append_printf(str, 
            "<b>Preset:</b> <small>%s</small>\n", 
            preset);

    if (markers)
    {
        g_string_append_printf(str, 
            "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n", 
            container);
    }
    else
    {
        g_string_append_printf(str, 
            "<b>Format:</b> <small>%s Container</small>\n", container);
    }
    if (mux == HB_MUX_MP4)
    {
        gboolean ipod, http, large;

        ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
        http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
        large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
        if (http || ipod || large)
        {
            g_string_append_printf(str, "<b>MP4 Options:</b><small>");
            if (ipod)
                g_string_append_printf(str, " - iPod 5G Support");
            if (http)
                g_string_append_printf(str, " - Web Optimized");
            if (large)
                g_string_append_printf(str, " - Large File Size (>4GB)");
            g_string_append_printf(str, "</small>\n");
        }
    }
    escape = g_markup_escape_text(dest, -1);
    g_string_append_printf(str, 
        "<b>Destination:</b> <small>%s</small>\n", escape);

    width = ghb_settings_get_int(settings, "scale_width");
    height = ghb_settings_get_int(settings, "scale_height");
    pic_par = ghb_settings_combo_int(settings, "PicturePAR");
    keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");

    gchar *aspect_desc;
    switch (pic_par)
    {
    case 0:
    {
        if (keep_aspect)
        {
            aspect_desc = "(Aspect Preserved)";
        }
        else
        {
            aspect_desc = "(Aspect Lost)";
        }
    } break;

    case 1:
    {
        aspect_desc = "(Strict Anamorphic)";
    } break;

    case 2:
    {
        aspect_desc = "(Loose Anamorphic)";
    } break;

    case 3:
    {
        aspect_desc = "(Custom Anamorphic)";
    } break;

    default:
    {
        aspect_desc = "(Unknown)";
    } break;
    }
    vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
    vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
    vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");

    gchar *vq_desc = "Error";
    gchar *vq_units = "";
    gchar *vqstr;
    gdouble vqvalue;
    if (!vqtype)
    {
        // Has to be bitrate
        vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
        vq_desc = "Bitrate:";
        vq_units = "kbps";
        vqstr = g_strdup_printf("%d", (gint)vqvalue);
    }
    else
    {
        // Constant quality
        vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
        vq_desc = "Constant Quality:";
        vqstr = g_strdup_printf("%d", (gint)vqvalue);
        if (strcmp(vcodec_abbr, "x264") == 0)
        {
            vq_units = "(RF)";
        }
        else
        {
            vq_units = "(QP)";
        }
    }
    fps = ghb_settings_get_string(settings, "VideoFramerate");
    if (strcmp("source", fps) == 0)
    {
        g_free(fps);
        if (ghb_settings_get_boolean(settings, "VideoFramerateCFR"))
            fps = g_strdup("Same As Source (constant)");
        else
            fps = g_strdup("Same As Source (variable)");
    }
    else
    {
        if (ghb_settings_get_boolean(settings, "VideoFrameratePFR"))
        {
            gchar *tmp;
            tmp = g_strdup_printf("Peak %s (may be lower)", fps);
            g_free(fps);
            fps = tmp;
        }
        else
        {
            gchar *tmp;
            tmp = g_strdup_printf("%s (constant frame rate)", fps);
            g_free(fps);
            fps = tmp;
        }
    }
    source_width = ghb_settings_get_int(settings, "source_width");
    source_height = ghb_settings_get_int(settings, "source_height");
    g_string_append_printf(str,
        "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
         source_width, source_height, width, height, aspect_desc);

    gint decomb, detel;
    gboolean decomb_deint;
    gboolean filters = FALSE;

    decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
    decomb = ghb_settings_combo_int(settings, "PictureDecomb");
    g_string_append_printf(str, "<b>Filters:</b><small>");
    detel = ghb_settings_combo_int(settings, "PictureDetelecine");
    if (detel)
    {
        g_string_append_printf(str, " - Detelecine");
        if (detel == 1)
        {
            gchar *cust;
            cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
            g_string_append_printf(str, ": %s", cust);
            g_free(cust);
        }
        filters = TRUE;
    }
    if (decomb_deint && decomb)
    {
        g_string_append_printf(str, " - Decomb");
        if (decomb == 1)
        {
            gchar *cust;
            cust = ghb_settings_get_string(settings, "PictureDecombCustom");
            g_string_append_printf(str, ": %s", cust);
            g_free(cust);
        }
        filters = TRUE;
    }
    else if (!decomb_deint)
    {
        gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
        if (deint)
        {
            if (deint == 1)
            {
                gchar *cust = ghb_settings_get_string(settings,
                                                "PictureDeinterlaceCustom");
                g_string_append_printf(str, " - Deinterlace: %s", cust);
                g_free(cust);
            }
            else
            {
                const gchar *opt = ghb_settings_combo_option(settings,
                                                    "PictureDeinterlace");
                g_string_append_printf(str, " - Deinterlace: %s", opt);
            }
            filters = TRUE;
        }
    }
    gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
    if (denoise)
    {
        if (denoise == 1)
        {
            gchar *cust = ghb_settings_get_string(settings,
                                                    "PictureDenoiseCustom");
            g_string_append_printf(str, " - Denoise: %s", cust);
            g_free(cust);
        }
        else
        {
            const gchar *opt = ghb_settings_combo_option(settings,
                                                    "PictureDenoise");
            g_string_append_printf(str, " - Denoise: %s", opt);
        }
        filters = TRUE;
    }
    gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
    if (deblock >= 5)
    {
        g_string_append_printf(str, " - Deblock (%d)", deblock);
        filters = TRUE;
    }
    if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
    {
        g_string_append_printf(str, " - Grayscale");
        filters = TRUE;
    }
    if (!filters)
        g_string_append_printf(str, " None");
    g_string_append_printf(str, "</small>\n");

    g_string_append_printf(str,
        "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
         vcodec, fps, vq_desc, vqstr, vq_units);

    turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
    if (turbo)
    {
        g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
    }
    if (strcmp(vcodec_abbr, "x264") == 0 ||
        strcmp(vcodec_abbr, "ffmpeg") == 0)
    {
        gchar *opts = ghb_build_advanced_opts_string(settings);
        g_string_append_printf(str, 
            "<b>Advanced Options:</b> <small>%s</small>\n", opts);
        g_free(opts);
    }
    // Add the audios
    gint count, ii;
    const GValue *audio_list;

    audio_list = ghb_settings_get_value(settings, "audio_list");
    count = ghb_array_len(audio_list);
    for (ii = 0; ii < count; ii++)
    {
        gchar *quality = NULL, *samplerate, *track;
        const gchar *acodec, *mix;
        GValue *asettings;
        gdouble sr;

        asettings = ghb_array_get_nth(audio_list, ii);

        acodec = ghb_settings_combo_option(asettings, "AudioEncoderActual");
        double q = ghb_settings_get_double(asettings, "AudioTrackQuality");
        if (ghb_settings_get_boolean(asettings, "AudioTrackQualityEnable") &&
            q != HB_INVALID_AUDIO_QUALITY)
        {
            int codec = ghb_settings_combo_int(asettings, "AudioEncoderActual");
            quality = ghb_format_quality("Quality: ", codec, q);
        }
        else
        {
            const char *br;
            br = ghb_settings_get_string(asettings, "AudioBitrate");
            quality = g_strdup_printf("Bitrate: %s", br);
        }
        sr = ghb_settings_get_double(asettings, "AudioSamplerate");
        samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
        if ((int)sr == 0)
        {
            samplerate = g_strdup("Same As Source");
        }
        else
        {
            samplerate = g_strdup_printf("%.4g", sr);
        }
        track = ghb_settings_get_string(asettings, "AudioTrackDescription");
        mix = ghb_settings_combo_option(asettings, "AudioMixdown");
        if (count == 1)
            g_string_append_printf(str, "<b>Audio:</b>");
        else if (ii == 0)
            g_string_append_printf(str, "<b>Audio:</b>\n");
        if (count != 1)
            g_string_append_printf(str, "\t");

        g_string_append_printf(str,
            "<small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, %s</small>\n",
             track, acodec, mix, samplerate, quality);
        g_free(track);
        g_free(quality);
        g_free(samplerate);
    }

    // Add the audios
    const GValue *sub_list;

    sub_list = ghb_settings_get_value(settings, "subtitle_list");
    count = ghb_array_len(sub_list);
    for (ii = 0; ii < count; ii++)
    {
        GValue *settings;
        gchar *track;
        gboolean force, burn, def;
        gint source;

        settings = ghb_array_get_nth(sub_list, ii);
        track = ghb_settings_get_string(settings, "SubtitleTrackDescription");
        source = ghb_settings_get_int(settings, "SubtitleSource");
        force = ghb_settings_get_boolean(settings, "SubtitleForced");
        burn = ghb_settings_get_boolean(settings, "SubtitleBurned");
        def = ghb_settings_get_boolean(settings, "SubtitleDefaultTrack");
        if (count == 1)
            g_string_append_printf(str, "<b>Subtitle:</b>");
        else if (ii == 0)
            g_string_append_printf(str, "<b>Subtitles:</b>\n");
        if (count != 1)
            g_string_append_printf(str, "\t");

        if (source != SRTSUB)
        {
            g_string_append_printf(str,
                "<small> %s%s%s%s</small>",
                track, 
                force ? " (Force)":"",
                burn  ? " (Burn)":"",
                def   ? " (Default)":""
            );
        }
        else
        {
            gint offset;
            gchar *filename, *basename, *code;

            offset = ghb_settings_get_int(settings, "SrtOffset");
            filename = ghb_settings_get_string(settings, "SrtFile");
            basename = g_path_get_basename(filename);
            code = ghb_settings_get_string(settings, "SrtCodeset");
            g_string_append_printf(str,
                "<small> %s (%s), %s, Offset (ms) %d%s</small>",
                track, code, basename, offset,
                def   ? " (Default)":""
            );
            g_free(filename);
            g_free(basename);
            g_free(code);
        }
        if (ii < count-1)
            g_string_append_printf(str, "\n");
        g_free(track);
    }

    info = g_string_free(str, FALSE);
    gtk_tree_store_append(store, &citer, &iter);
    gtk_tree_store_set(store, &citer, 1, info, -1);
    g_free(info);
    g_free(fps);
    g_free(vcodec_abbr);
    g_free(vol_name);
    g_free(dest);
    g_free(preset);
}
Esempio n. 6
0
gboolean
ghb_reload_queue(signal_user_data_t *ud)
{
    GValue *queue;
    gint unfinished = 0;
    gint count, ii;
    gint pid;
    gint status;
    GValue *settings;
    gchar *message;

    g_debug("ghb_reload_queue");

find_pid:
    pid = ghb_find_pid_file();
    if (pid < 0)
        return FALSE;

    queue = ghb_load_old_queue(pid);
    ghb_remove_old_queue_file(pid);
    // Look for unfinished entries
    count = ghb_array_len(queue);
    for (ii = 0; ii < count; ii++)
    {
        settings = ghb_array_get_nth(queue, ii);
        status = ghb_settings_get_int(settings, "job_status");
        if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
        {
            unfinished++;
        }
    }
    if (!unfinished)
        goto find_pid;

    if (unfinished)
    {
        message = g_strdup_printf(
                    "You have %d unfinished job%s in a saved queue.\n\n"
                    "Would you like to reload %s?",
                    unfinished, 
                    (unfinished > 1) ? "s" : "",
                    (unfinished > 1) ? "them" : "it");
        if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
        {
            GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
            gtk_widget_show (widget);
            widget = GHB_WIDGET (ud->builder, "show_queue");
            gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE);

            ud->queue = queue;
            // First get rid of any old items we don't want
            for (ii = count-1; ii >= 0; ii--)
            {
                settings = ghb_array_get_nth(queue, ii);
                status = ghb_settings_get_int(settings, "job_status");
                if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
                {
                    GValue *old = ghb_array_get_nth(queue, ii);
                    ghb_value_free(old);
                    ghb_array_remove(queue, ii);
                }
            }
            count = ghb_array_len(queue);
            for (ii = 0; ii < count; ii++)
            {
                settings = ghb_array_get_nth(queue, ii);
                ghb_settings_set_int(settings, "job_unique_id", 0);
                ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
                add_to_queue_list(ud, settings, NULL);
            }
            ghb_queue_buttons_grey(ud);
            ghb_save_queue(ud->queue);
        }
        else
        {
            ghb_value_free(queue);
        }
        g_free(message);
    }
    return FALSE;
}
Esempio n. 7
0
void
ghb_adjust_audio_rate_combos(signal_user_data_t *ud)
{
    gint titleindex, track, acodec, select_acodec, mix;
    hb_audio_config_t *aconfig;
    GtkWidget *widget;
    GValue *gval;
    gint mux;
    gint bitrate;
    gint sr = 48000;
    
    g_debug("ghb_adjust_audio_rate_combos ()");
    mux = ghb_settings_combo_int(ud->settings, "FileFormat");
    titleindex = ghb_settings_combo_int(ud->settings, "title");

    widget = GHB_WIDGET(ud->builder, "AudioTrack");
    gval = ghb_widget_value(widget);
    track = ghb_lookup_combo_int("AudioTrack", gval);
    ghb_value_free(gval);

    widget = GHB_WIDGET(ud->builder, "AudioEncoder");
    gval = ghb_widget_value(widget);
    acodec = ghb_lookup_combo_int("AudioEncoder", gval);
    ghb_value_free(gval);
    widget = GHB_WIDGET(ud->builder, "AudioMixdown");
    gval = ghb_widget_value(widget);
    mix = ghb_lookup_combo_int("AudioMixdown", gval);
    ghb_value_free(gval);

    widget = GHB_WIDGET(ud->builder, "AudioBitrate");
    gval = ghb_widget_value(widget);
    bitrate = ghb_lookup_combo_int("AudioBitrate", gval);

    widget = GHB_WIDGET(ud->builder, "AudioSamplerate");
    gval = ghb_widget_value(widget);
    sr = ghb_lookup_combo_int("AudioSamplerate", gval);


    aconfig = ghb_get_scan_audio_info(titleindex, track);
    if (sr == 0)
    {
        sr = aconfig ? aconfig->in.samplerate : 48000;
    }
    gint fallback = ghb_select_fallback( ud->settings, mux, acodec );
    gint copy_mask = ghb_get_copy_mask(ud->settings);
    select_acodec = ghb_select_audio_codec(mux, aconfig, acodec, fallback, copy_mask);
    gboolean codec_defined_bitrate = FALSE;
    if (ghb_audio_is_passthru (select_acodec))
    {
        if (aconfig)
        {
            bitrate = aconfig->in.bitrate / 1000;

            // Set the values for bitrate and samplerate to the input rates
            ghb_set_bitrate_opts (ud->builder, bitrate, bitrate, bitrate);
            mix = 0;
            ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix));
            select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG;
            codec_defined_bitrate = TRUE;
            ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0));
        }
        else
        {
            ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0));
            mix = 0;
            ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix));
            bitrate = 448;
        }
        ghb_ui_update(ud, "AudioTrackDRCSlider", ghb_double_value(0));
    }
    else
    {
        if (mix == 0)
            mix = ghb_get_best_mix( aconfig, select_acodec, 0);
        bitrate = hb_audio_bitrate_get_best(select_acodec, bitrate, sr, mix);
        ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix));
    }
    if (!codec_defined_bitrate)
    {
        int low, high;
        mix = ghb_get_best_mix( aconfig, select_acodec, mix);
        hb_audio_bitrate_get_limits(select_acodec, sr, mix, &low, &high);
        ghb_set_bitrate_opts (ud->builder, low, high, -1);
    }
    ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate));

    ghb_settings_take_value(ud->settings, "AudioEncoderActual", 
                            ghb_lookup_audio_encoder_value(select_acodec));
    GValue *asettings = get_selected_asettings(ud);
    if (asettings)
    {
        ghb_settings_take_value(asettings, "AudioEncoderActual", 
                            ghb_lookup_audio_encoder_value(select_acodec));
    }
    ghb_audio_list_refresh_selected(ud);
    ghb_check_dependency(ud, NULL, "AudioEncoderActual");
}
Esempio n. 8
0
G_MODULE_EXPORT gboolean
live_preview_cb(GstBus *bus, GstMessage *msg, gpointer data)
{
    signal_user_data_t *ud = (signal_user_data_t*)data;

    switch (GST_MESSAGE_TYPE(msg))
    {
    case GST_MESSAGE_UNKNOWN:
    {
        //printf("unknown");
    } break;

    case GST_MESSAGE_EOS:
    {
        // Done
        GtkImage *img;

        //printf("eos");
        img = GTK_IMAGE(GHB_WIDGET(ud->builder, "live_preview_play_image"));
        gtk_image_set_from_icon_name(img, GHB_PLAY_ICON, GTK_ICON_SIZE_BUTTON);
        gst_element_set_state(ud->preview->play, GST_STATE_PAUSED);
        ud->preview->pause = TRUE;
        gst_element_seek(ud->preview->play, 1.0,
            GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
            GST_SEEK_TYPE_SET, 0,
            GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
    } break;

    case GST_MESSAGE_ERROR:
    {
        //printf("error\n");
        GError *err;
        gchar *debug;

        gst_message_parse_error(msg, &err, &debug);
        g_warning("Gstreamer Error: %s", err->message);
        g_error_free(err);
        g_free(debug);
    } break;

    case GST_MESSAGE_WARNING:
    case GST_MESSAGE_INFO:
    case GST_MESSAGE_TAG:
    case GST_MESSAGE_BUFFERING:
    case GST_MESSAGE_STATE_CHANGED:
    {
        GstState state, pending;
        gst_element_get_state(ud->preview->play, &state, &pending, 0);
        //printf("state change %x\n", state);
        if (state == GST_STATE_PAUSED || state == GST_STATE_PLAYING)
        {
            update_stream_info(ud);
        }
    } break;

    case GST_MESSAGE_STATE_DIRTY:
    {
        //printf("state dirty\n");
    } break;

    case GST_MESSAGE_STEP_DONE:
    {
        //printf("step done\n");
    } break;

    case GST_MESSAGE_CLOCK_PROVIDE:
    {
        //printf("clock provide\n");
    } break;

    case GST_MESSAGE_CLOCK_LOST:
    {
        //printf("clock lost\n");
    } break;

    case GST_MESSAGE_NEW_CLOCK:
    {
        //printf("new clock\n");
    } break;

    case GST_MESSAGE_STRUCTURE_CHANGE:
    {
        //printf("structure change\n");
    } break;

    case GST_MESSAGE_STREAM_STATUS:
    {
        //printf("stream status\n");
    } break;

    case GST_MESSAGE_APPLICATION:
    {
        //printf("application\n");
    } break;

    case GST_MESSAGE_ELEMENT:
    {
        //printf("element\n");
        if (gst_is_missing_plugin_message(msg))
        {
            GtkWindow *hb_window;
            hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
            gst_element_set_state(ud->preview->play, GST_STATE_PAUSED);
            gchar *message, *desc;
            desc = gst_missing_plugin_message_get_description(msg);
            message = g_strdup_printf(
                        _("Missing GStreamer plugin\n"
                        "Audio or Video may not play as expected\n\n%s"),
                        desc);
            ghb_message_dialog(hb_window, GTK_MESSAGE_WARNING,
                               message, "Ok", NULL);
            g_free(message);
            gst_element_set_state(ud->preview->play, GST_STATE_PLAYING);
        }
    } break;

    case GST_MESSAGE_SEGMENT_START:
    {
        //printf("segment start\n");
    } break;

    case GST_MESSAGE_SEGMENT_DONE:
    {
        //printf("segment done\n");
    } break;

#if GST_CHECK_VERSION(1, 0, 0)
    case GST_MESSAGE_DURATION_CHANGED:
    {
        //printf("duration change\n");
    };
#endif

    case GST_MESSAGE_LATENCY:
    {
        //printf("latency\n");
    };

    case GST_MESSAGE_ASYNC_START:
    {
        //printf("async start\n");
    } break;

    case GST_MESSAGE_ASYNC_DONE:
    {
        //printf("async done\n");
    } break;

    case GST_MESSAGE_REQUEST_STATE:
    {
        //printf("request state\n");
    } break;

    case GST_MESSAGE_STEP_START:
    {
        //printf("step start\n");
    } break;

    case GST_MESSAGE_QOS:
    {
        //printf("qos\n");
    } break;

#if GST_CHECK_VERSION(1, 0, 0)
    case GST_MESSAGE_PROGRESS:
    {
        //printf("progress\n");
    } break;

    case GST_MESSAGE_TOC:
    {
        //printf("toc\n");
    } break;

    case GST_MESSAGE_RESET_TIME:
    {
        //printf("reset time\n");
    } break;

    case GST_MESSAGE_STREAM_START:
    {
        //printf("stream start\n");
    };
#endif

    case GST_MESSAGE_ANY:
    {
        //printf("any\n");
    } break;


    default:
    {
        // Ignore
        //printf("?msg? %x\n", GST_MESSAGE_TYPE(msg));
    }
    }
    return TRUE;
}
Esempio n. 9
0
void
ghb_set_preview_image(signal_user_data_t *ud)
{
    GtkWidget *widget;
    gint preview_width, preview_height, target_height, width, height;

    g_debug("set_preview_button_image ()");
    gint title_id, titleindex;
    const hb_title_t *title;

    live_preview_stop(ud);

    title_id = ghb_dict_get_int(ud->settings, "title");
    title = ghb_lookup_title(title_id, &titleindex);
    if (title == NULL) return;
    widget = GHB_WIDGET (ud->builder, "preview_frame");
    ud->preview->frame = ghb_widget_int(widget) - 1;
    if (ud->preview->encoded[ud->preview->frame])
    {
        widget = GHB_WIDGET(ud->builder, "live_progress_box");
        gtk_widget_hide (widget);
        widget = GHB_WIDGET(ud->builder, "live_preview_progress");
        gtk_widget_show (widget);
    }
    else
    {
        widget = GHB_WIDGET(ud->builder, "live_preview_progress");
        gtk_widget_hide (widget);
        widget = GHB_WIDGET(ud->builder, "live_progress_box");
        gtk_widget_show (widget);
        widget = GHB_WIDGET(ud->builder, "live_encode_progress");
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(widget), "");
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(widget), 0);
    }
    if (ud->preview->pix != NULL)
        g_object_unref(ud->preview->pix);

    ud->preview->pix =
        ghb_get_preview_image(title, ud->preview->frame, ud, &width, &height);
    if (ud->preview->pix == NULL) return;
    preview_width = gdk_pixbuf_get_width(ud->preview->pix);
    preview_height = gdk_pixbuf_get_height(ud->preview->pix);
    widget = GHB_WIDGET (ud->builder, "preview_image");
    if (preview_width != ud->preview->width ||
        preview_height != ud->preview->height)
    {
        preview_set_size(ud, preview_width, preview_height);
    }
    gtk_widget_queue_draw(widget);

    gchar *text = g_strdup_printf("%d x %d", width, height);
    widget = GHB_WIDGET (ud->builder, "preview_dims");
    gtk_label_set_text(GTK_LABEL(widget), text);
    g_free(text);

    g_debug("preview %d x %d", preview_width, preview_height);
    target_height = MIN(ud->preview->button_height, 200);
    height = target_height;
    width = preview_width * height / preview_height;
    if (width > 400)
    {
        width = 400;
        height = preview_height * width / preview_width;
    }

    if ((height >= 16) && (width >= 16))
    {
        GdkPixbuf *scaled_preview;
        scaled_preview = gdk_pixbuf_scale_simple (ud->preview->pix, width,
                                                height, GDK_INTERP_NEAREST);
        if (scaled_preview != NULL)
        {
            widget = GHB_WIDGET (ud->builder, "preview_button_image");
            gtk_image_set_from_pixbuf(GTK_IMAGE(widget), scaled_preview);
            g_object_unref(scaled_preview);
        }
    }
}
Esempio n. 10
0
G_MODULE_EXPORT void
x264_setting_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
    static char *tt = NULL;


    if (tt == NULL)
    {
        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "x264OptionExtra"));
        tt = gtk_widget_get_tooltip_text(eo);
    }

    ghb_widget_to_setting(ud->settings, widget);

    int x264Preset = ghb_settings_get_int(ud->settings, "x264PresetSlider");
    const char *preset;
    preset = hb_video_encoder_get_presets(HB_VCODEC_X264)[x264Preset];
    ghb_settings_set_string(ud->settings, "x264Preset", preset);

    if (!ghb_settings_get_boolean(ud->settings, "x264UseAdvancedOptions"))
    {
        GString *str = g_string_new("");
        char *preset;
        char *tune;
        char *profile;
        char *level;
        char *opts;
        char *tunes;

        preset = ghb_settings_get_string(ud->settings, "x264Preset");
        tune = ghb_settings_get_string(ud->settings, "x264Tune");
        profile = ghb_settings_get_string(ud->settings, "h264Profile");
        level = ghb_settings_get_string(ud->settings, "h264Level");
        opts = ghb_settings_get_string(ud->settings, "x264OptionExtra");

        if (tune[0] && strcmp(tune, "none"))
        {
            g_string_append_printf(str, "%s", tune);
        }
        if (ghb_settings_get_boolean(ud->settings, "x264FastDecode"))
        {
            g_string_append_printf(str, "%s%s", str->str[0] ? "," : "", "fastdecode");
        }
        if (ghb_settings_get_boolean(ud->settings, "x264ZeroLatency"))
        {
            g_string_append_printf(str, "%s%s", str->str[0] ? "," : "", "zerolatency");
        }
        tunes = g_string_free(str, FALSE);

        char * new_opts;

        int w = ghb_settings_get_int(ud->settings, "scale_width");
        int h = ghb_settings_get_int(ud->settings, "scale_height");

        if (w == 0 || h == 0)
        {
            if (!ghb_settings_get_boolean(ud->settings, "autoscale"))
            {
                w = ghb_settings_get_int(ud->settings, "PictureWidth");
                h = ghb_settings_get_int(ud->settings, "PictureHeight");

                if (h == 0 && w != 0)
                {
                    h = w * 9 / 16;
                }
                if (w == 0 && h != 0)
                {
                    w = h * 16 / 9;
                }
            }
            if (w == 0 || h == 0)
            {
                w = 1280;
                h = 720;
            }
        }

        if (!strcasecmp(profile, "auto"))
        {
            profile[0] = 0;
        }
        if (!strcasecmp(level, "auto"))
        {
            level[0] = 0;
        }
        new_opts = hb_x264_param_unparse(
                        preset, tunes, opts, profile, level, w, h);
        if (new_opts)
            ghb_ui_update(ud, "x264Option", ghb_string_value(new_opts));
        else
            ghb_ui_update(ud, "x264Option", ghb_string_value(""));

        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "x264OptionExtra"));

        char * new_tt;
        if (new_opts)
            new_tt = g_strdup_printf("%s\n\nExpanded Options:\n\"%s\"", tt, new_opts);
        else
            new_tt = g_strdup_printf("%s\n\nExpanded Options:\n\"\"", tt);
        gtk_widget_set_tooltip_text(eo, new_tt);

        g_free(new_tt);
        g_free(new_opts);

        g_free(preset);
        g_free(tune);
        g_free(profile);
        g_free(level);
        g_free(opts);
        g_free(tunes);
    }
    else
    {
        char *opts = ghb_settings_get_string(ud->settings, "x264Option");

        GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "x264OptionExtra"));
        char * new_tt;
        if (opts)
            new_tt = g_strdup_printf("%s\n\nExpanded Options:\n\"%s\"", tt, opts);
        else
            new_tt = g_strdup_printf("%s\n\nExpanded Options:\n\"\"", tt);
        gtk_widget_set_tooltip_text(eo, new_tt);
        g_free(new_tt);

        g_free(opts);
    }

    ghb_check_dependency(ud, widget, NULL);
    ghb_clear_presets_selection(ud);
}
Esempio n. 11
0
void
ghb_preview_init(signal_user_data_t *ud)
{
    GtkWidget *widget;

    ud->preview = g_malloc0(sizeof(preview_t));
    ud->preview->view = GHB_WIDGET(ud->builder, "preview_image");
    gtk_widget_realize(ud->preview->view);

    ud->preview->pause = TRUE;
    ud->preview->encode_frame = -1;
    ud->preview->live_id = -1;
    widget = GHB_WIDGET(ud->builder, "preview_button_image");
    gtk_widget_get_size_request(widget, &ud->preview->button_width, &ud->preview->button_height);

    widget = GHB_WIDGET(ud->builder, "preview_hud");
    gtk_widget_realize(widget);
    // Use a native window for the HUD.  Client side windows don't get
    // updated properly as video changes benieth them.
    // This also seems to be required to make the preview hud visible
    // on win32.  otherwise it is transparent for some reason.
    if (!gdk_window_ensure_native(gtk_widget_get_window(widget)))
    {
        g_message("Couldn't create native window for HUD.");
    }

#if defined(_ENABLE_GST)
    GstBus *bus;
    GstElement *xover;

    if (!gdk_window_ensure_native(preview_window(ud->preview->view)))
    {
        g_message("Couldn't create native window for GstXOverlay. Disabling live preview.");
        GtkWidget *widget = GHB_WIDGET(ud->builder, "live_preview_box");
        gtk_widget_hide (widget);
        widget = GHB_WIDGET(ud->builder, "live_preview_duration_box");
        gtk_widget_hide (widget);
        return;
    }

#if !defined(_WIN32)
    ud->preview->xid = GDK_WINDOW_XID(preview_window(ud->preview->view));
#else
    ud->preview->xid = GDK_WINDOW_HWND(preview_window(ud->preview->view));
#endif
    ud->preview->play = gst_element_factory_make("playbin", "play");
    xover = gst_element_factory_make("gconfvideosink", "xover");
    if (xover == NULL)
    {
        xover = gst_element_factory_make("xvimagesink", "xover");
    }
    if (xover == NULL)
    {
        xover = gst_element_factory_make("ximagesink", "xover");
    }
    if (xover == NULL)
    {
        xover = gst_element_factory_make("autovideosink", "xover");
    }
    if (ud->preview->play == NULL || xover == NULL)
    {
        g_message("Couldn't initialize gstreamer. Disabling live preview.");
        GtkWidget *widget = GHB_WIDGET(ud->builder, "live_preview_box");
        gtk_widget_hide (widget);
        widget = GHB_WIDGET(ud->builder, "live_preview_duration_box");
        gtk_widget_hide (widget);
        return;
    }
    else
    {

        g_object_set(G_OBJECT(ud->preview->play), "video-sink", xover, NULL);
        g_object_set(ud->preview->play, "subtitle-font-desc",
                    "sans bold 20", NULL);

        bus = gst_pipeline_get_bus(GST_PIPELINE(ud->preview->play));
        gst_bus_add_watch(bus, live_preview_cb, ud);
#if GST_CHECK_VERSION(1, 0, 0)
        gst_bus_set_sync_handler(bus, create_window, ud->preview, NULL);
#else
        gst_bus_set_sync_handler(bus, create_window, ud->preview);
#endif
        gst_object_unref(bus);
        ud->preview->live_enabled = 1;
    }
#else
    widget = GHB_WIDGET(ud->builder, "live_preview_box");
    gtk_widget_hide (widget);
    widget = GHB_WIDGET(ud->builder, "live_preview_duration_box");
    gtk_widget_hide (widget);
#endif
}
Esempio n. 12
0
G_MODULE_EXPORT void
audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
    static gint prev_acodec = 0;
    gint acodec_code;
    GValue *asettings, *gval;
    
    g_debug("audio_codec_changed_cb ()");
    gval = ghb_widget_value(widget);
    acodec_code = ghb_lookup_combo_int("AudioEncoder", gval);
    ghb_value_free(gval);

    if (block_updates)
    {
        prev_acodec = acodec_code;
        ghb_grey_combo_options (ud);
        ghb_check_dependency(ud, widget, NULL);
        return;
    }

    asettings = get_selected_asettings(ud);
    if (ghb_audio_is_passthru (prev_acodec) && 
        !ghb_audio_is_passthru (acodec_code))
    {
        // Transition from passthru to not, put some audio settings back to 
        // pref settings
        gint titleindex;
        gint track;
        gint br, sr, mix_code;

        if (asettings != NULL)
        {
            br = ghb_settings_get_int(asettings, "AudioBitrate");
            sr = ghb_settings_combo_int(asettings, "AudioSamplerate");
            mix_code = ghb_settings_combo_int(asettings, "AudioMixdown");
        }
        else
        {
            br = 160;
            sr = 0;
            mix_code = 0;
        }

        titleindex = ghb_settings_combo_int(ud->settings, "title");
        track = ghb_settings_combo_int(ud->settings, "AudioTrack");
        if (sr)
        {
            sr = ghb_find_closest_audio_samplerate(sr);
        }
        ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(sr));

        hb_audio_config_t *aconfig;
        aconfig = ghb_get_scan_audio_info(titleindex, track);
        if (sr == 0)
        {
            sr = aconfig ? aconfig->in.samplerate : 48000;
        }
        mix_code = ghb_get_best_mix( aconfig, acodec_code, mix_code);
        br = hb_audio_bitrate_get_best(acodec_code, br, sr, mix_code);
        ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br));

        ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix_code));
    }
    ghb_adjust_audio_rate_combos(ud);
    ghb_grey_combo_options (ud);
    ghb_check_dependency(ud, widget, NULL);
    prev_acodec = acodec_code;
    if (asettings != NULL)
    {
        ghb_widget_to_setting(asettings, widget);
        ghb_settings_set_value(asettings, "AudioEncoderActual", ghb_settings_get_value(ud->settings, "AudioEncoderActual"));
        ghb_audio_list_refresh_selected(ud);
    }
    ghb_live_reset(ud);

    float low, high, gran, defval;
    int dir;
    hb_audio_quality_get_limits(acodec_code, &low, &high, &gran, &dir);
    defval = hb_audio_quality_get_default(acodec_code);
    GtkScaleButton *sb;
    GtkAdjustment *adj;
    sb = GTK_SCALE_BUTTON(GHB_WIDGET(ud->builder, "AudioTrackQuality"));
    adj = gtk_scale_button_get_adjustment(sb);
    if (dir)
    {
        // Quality values are inverted
        defval = high - defval + low;
    }
    gtk_adjustment_configure (adj, defval, low, high, gran, gran * 10, 0);
}
Esempio n. 13
0
void
ghb_audio_list_refresh(signal_user_data_t *ud)
{
    GtkTreeView *treeview;
    GtkTreeIter iter;
    GtkListStore *store;
    gboolean done;
    gint row = 0;
    const GValue *audio_list;

    g_debug("ghb_audio_list_refresh ()");
    treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
    store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
    if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
    {
        do
        {
            const gchar *track, *codec, *br = NULL, *sr, *mix;
            gchar *s_drc, *s_gain, *s_quality = NULL;
            gdouble drc, gain;
            GValue *asettings;

            audio_list = ghb_settings_get_value(ud->settings, "audio_list");
            if (row >= ghb_array_len(audio_list))
                return;
            asettings = ghb_array_get_nth(audio_list, row);

            track = ghb_settings_combo_option(asettings, "AudioTrack");
            codec = ghb_settings_combo_option(asettings, "AudioEncoderActual");
            double quality = ghb_settings_get_double(asettings, "AudioTrackQuality");
            if (ghb_settings_get_boolean(asettings, "AudioTrackQualityEnable") &&
                quality != HB_INVALID_AUDIO_QUALITY)
            {
                int codec = ghb_settings_combo_int(asettings, "AudioEncoderActual");
                s_quality = ghb_format_quality("Q/", codec, quality);
            }
            else
            {
                br = ghb_settings_get_string(asettings, "AudioBitrate");
            }
            sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
            mix = ghb_settings_combo_option(asettings, "AudioMixdown");
            gain = ghb_settings_get_double(asettings, "AudioTrackGain");
            s_gain = g_strdup_printf("%.fdB", gain);

            drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
            if (drc < 1.0)
                s_drc = g_strdup("Off");
            else
                s_drc = g_strdup_printf("%.1f", drc);

            gtk_list_store_set(GTK_LIST_STORE(store), &iter, 
                // These are displayed in list
                0, track,
                1, codec,
                2, s_quality ? s_quality : br,
                3, sr,
                4, mix,
                5, s_gain,
                6, s_drc,
                -1);
            g_free(s_drc);
            g_free(s_gain);
            done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
            row++;
        } while (!done);
    }
}
Esempio n. 14
0
void
ghb_audio_list_refresh_selected(signal_user_data_t *ud)
{
    GtkTreeView *treeview;
    GtkTreePath *treepath;
    GtkTreeSelection *selection;
    GtkTreeModel *store;
    GtkTreeIter iter;
    gint *indices;
    gint row;
    GValue *asettings = NULL;
    const GValue *audio_list;
    
    g_debug("ghb_audio_list_refresh_selected ()");
    treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
    selection = gtk_tree_view_get_selection (treeview);
    if (gtk_tree_selection_get_selected(selection, &store, &iter))
    {
        const gchar *track, *codec, *br = NULL, *sr, *mix;
        gchar *s_drc, *s_gain, *s_quality = NULL;
        gdouble drc, gain;
        // Get the row number
        treepath = gtk_tree_model_get_path (store, &iter);
        indices = gtk_tree_path_get_indices (treepath);
        row = indices[0];
        gtk_tree_path_free(treepath);
        // find audio settings
        if (row < 0) return;
        audio_list = ghb_settings_get_value(ud->settings, "audio_list");
        if (row >= ghb_array_len(audio_list))
            return;
        asettings = ghb_array_get_nth(audio_list, row);

        track = ghb_settings_combo_option(asettings, "AudioTrack");
        codec = ghb_settings_combo_option(asettings, "AudioEncoderActual");
        double quality = ghb_settings_get_double(asettings, "AudioTrackQuality");
        if (ghb_settings_get_boolean(asettings, "AudioTrackQualityEnable") &&
            quality != HB_INVALID_AUDIO_QUALITY)
        {
            int codec = ghb_settings_combo_int(asettings, "AudioEncoderActual");
            s_quality = ghb_format_quality("Q/", codec, quality);
        }
        else
        {
            br = ghb_settings_combo_option(asettings, "AudioBitrate");
        }
        sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
        mix = ghb_settings_combo_option(asettings, "AudioMixdown");
        gain = ghb_settings_get_double(asettings, "AudioTrackGain");
        s_gain = g_strdup_printf("%ddB", (int)gain);

        drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
        if (drc < 1.0)
            s_drc = g_strdup("Off");
        else
            s_drc = g_strdup_printf("%.1f", drc);

        gtk_list_store_set(GTK_LIST_STORE(store), &iter, 
            // These are displayed in list
            0, track,
            1, codec,
            2, s_quality ? s_quality : br,
            3, sr,
            4, mix,
            5, s_gain,
            6, s_drc,
            -1);
        g_free(s_drc);
        g_free(s_gain);
        g_free(s_quality);
    }
}
Esempio n. 15
0
int
main(int argc, char *argv[])
{
    signal_user_data_t *ud;
    GError *error = NULL;
    GOptionContext *context;

#if defined(_WIN32)
    // Tell gdk pixbuf where it's loader config file is.
    _putenv_s("GDK_PIXBUF_MODULE_FILE", "ghb.exe.local/loaders.cache");
    _putenv_s("GST_PLUGIN_PATH", "lib/gstreamer-1.0");
#endif

    hb_global_init();

#ifdef ENABLE_NLS
    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);
#endif

    context = g_option_context_new(_("- Transcode media formats"));
    g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));
#if defined(_ENABLE_GST)
    g_option_context_add_group(context, gst_init_get_option_group());
#endif
    g_option_context_parse(context, &argc, &argv, &error);
    if (error != NULL)
    {
        g_warning("%s: %s", G_STRFUNC, error->message);
        g_clear_error(&error);
    }
    g_option_context_free(context);

#if defined(_WIN32)
    if (win32_console)
    {
        // Enable console logging
        if(AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()){
            close(STDOUT_FILENO);
            freopen("CONOUT$", "w", stdout);
            close(STDERR_FILENO);
            freopen("CONOUT$", "w", stderr);
        }
    }
    else
    {
        // Non-console windows apps do not have a stderr->_file
        // assigned properly
        stderr->_file = STDERR_FILENO;
        stdout->_file = STDOUT_FILENO;
    }
#endif

    if (argc > 1 && dvd_device == NULL && argv[1][0] != '-')
    {
        dvd_device = argv[1];
    }

    gtk_init(&argc, &argv);

    GtkCssProvider *css = gtk_css_provider_new();
    error = NULL;
    gtk_css_provider_load_from_data(css, MyCSS, -1, &error);
    if (error == NULL)
    {
        GdkScreen *ss = gdk_screen_get_default();
        gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css),
                                    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    }
    else
    {
        g_warning("%s: %s", G_STRFUNC, error->message);
        g_clear_error(&error);
    }

#if !defined(_WIN32)
    notify_init("HandBrake");
#endif
    ghb_resource_init();
    ghb_load_icons();

#if !defined(_WIN32)
    dbus_g_thread_init();
#endif
    ghb_udev_init();

    ghb_write_pid_file();
    ud = g_malloc0(sizeof(signal_user_data_t));
    ud->debug = ghb_debug;
    g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud);
    g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud);
    //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud);

    ud->globals = ghb_dict_new();
    ud->prefs = ghb_dict_new();
    ud->settings_array = ghb_array_new();
    ud->settings = ghb_dict_new();
    ghb_array_append(ud->settings_array, ud->settings);

    ud->builder = create_builder_or_die(BUILDER_NAME);
    // Enable events that alert us to media change events
    watch_volumes(ud);

    //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom");
    //gtk_entry_set_inner_border(widget, 2);

    // Since GtkBuilder no longer assigns object ids to widget names
    // Assign a few that are necessary for style overrides to work
#if defined(_NO_UPDATE_CHECK)
    GtkWidget *widget;
    widget = GHB_WIDGET(ud->builder, "check_updates_box");
    gtk_widget_hide(widget);
#endif

    // Must set the names of the widgets that I want to modify
    // style for.
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_hud"), "preview_hud");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "activity_view"), "activity_view");

    // Redirect stderr to the activity window
    ghb_preview_init(ud);
    IoRedirect(ud);
    ghb_log( "%s - %s - %s",
        HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE );
    ghb_init_dep_map();

    // Need to connect x264_options textview buffer to the changed signal
    // since it can't be done automatically
    GtkTextView *textview;
    GtkTextBuffer *buffer;
    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option"));
    buffer = gtk_text_view_get_buffer(textview);
    g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud);

    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "VideoOptionExtra"));
    buffer = gtk_text_view_get_buffer(textview);
    g_signal_connect(buffer, "changed", (GCallback)video_option_changed_cb, ud);

    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "MetaLongDescription"));
    buffer = gtk_text_view_get_buffer(textview);
    g_signal_connect(buffer, "changed", (GCallback)plot_changed_cb, ud);

    ghb_combo_init(ud);

    g_debug("ud %p\n", ud);
    g_debug("ud->builder %p\n", ud->builder);

    bind_audio_tree_model(ud);
    bind_subtitle_tree_model(ud);
    bind_presets_tree_model(ud);
    bind_queue_tree_model(ud);
    bind_chapter_tree_model(ud);
    // Connect up the signals to their callbacks
    // I wrote my own connector so that I could pass user data
    // to the callbacks.  Builder's standard autoconnect doesn't all this.
    gtk_builder_connect_signals_full(ud->builder, MyConnect, ud);

    ghb_init_audio_defaults_ui(ud);
    ghb_init_subtitle_defaults_ui(ud);

    // Parsing x264 options "" initializes x264 widgets to proper defaults
    ghb_x264_init(ud);

    // Load prefs before presets.  Some preset defaults may depend
    // on preference settings.
    // First load default values
    ghb_settings_init(ud->prefs, "Preferences");
    ghb_settings_init(ud->globals, "Globals");
    ghb_settings_init(ud->settings, "Initialization");
    ghb_settings_init(ud->settings, "OneTimeInitialization");
    // Load user preferences file
    ghb_prefs_load(ud);
    // Store user preferences into ud->prefs
    ghb_prefs_to_settings(ud->prefs);

    int logLevel = ghb_dict_get_int(ud->prefs, "LoggingLevel");
    ghb_backend_init(logLevel);

    // Load the presets files
    ghb_presets_load(ud);
    // Note that ghb_preset_to_settings(ud->settings) is called when
    // the default preset is selected.

    ghb_settings_to_ui(ud, ud->globals);
    ghb_settings_to_ui(ud, ud->prefs);
    // Note that ghb_settings_to_ui(ud->settings) happens when initial
    // empty title is initialized.


    if (ghb_dict_get_bool(ud->prefs, "hbfd"))
    {
        ghb_hbfd(ud, TRUE);
    }
    const gchar *source = ghb_dict_get_string(ud->prefs, "default_source");
    ghb_dvd_set_current(source, ud);

    // Populate the presets tree view
    ghb_presets_list_init(ud, NULL);
    // Get the first preset name
    if (arg_preset != NULL)
    {
        ghb_select_preset(ud->builder, arg_preset);
    }
    else
    {
        ghb_select_default_preset(ud->builder);
    }

    // Grey out widgets that are dependent on a disabled feature
    ghb_check_all_depencencies(ud);

    if (dvd_device != NULL)
    {
        // Source overridden from command line option
        ghb_dict_set_string(ud->globals, "scan_source", dvd_device);
        g_idle_add((GSourceFunc)ghb_idle_scan, ud);
    }
    else
    {
        GhbValue *gval = ghb_dict_get_value(ud->prefs, "default_source");
        ghb_dict_set(ud->globals, "scan_source", ghb_value_dup(gval));
    }
    // Reload and check status of the last saved queue
    g_idle_add((GSourceFunc)ghb_reload_queue, ud);

    // Start timer for monitoring libhb status, 500ms
    g_timeout_add(200, ghb_timer_cb, (gpointer)ud);

    // Add dvd devices to File menu
    ghb_volname_cache_init();
    GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud);

    GtkWidget *ghb_window = GHB_WIDGET(ud->builder, "hb_window");

    gint window_width, window_height;
    GdkGeometry geo = {
        -1, -1, 1920, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST
    };
    GdkWindowHints geo_mask;
    geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE;
    gtk_window_set_geometry_hints(GTK_WINDOW(ghb_window), ghb_window,
                                  &geo, geo_mask);
    window_width = ghb_dict_get_int(ud->prefs, "window_width");
    window_height = ghb_dict_get_int(ud->prefs, "window_height");

    /*
     * Filter objects in GtkBuilder xml
     * Unfortunately, GtkFilter is poorly supported by GtkBuilder,
     * so a lot of the setup must happen in code.
        SourceFilterAll
        SourceFilterVideo
        SourceFilterTS
        SourceFilterMPG
        SourceFilterEVO
        SourceFilterVOB
        SourceFilterMKV
        SourceFilterMP4
        SourceFilterAVI
        SourceFilterMOV
        SourceFilterOGG
        SourceFilterFLV
        SourceFilterWMV
    */
    // Add filters to source chooser
    GtkFileFilter *filter;
    GtkFileChooser *chooser;
    chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog"));
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
    gtk_file_filter_set_name(filter, _("All"));
    gtk_file_filter_add_pattern(filter, "*");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo"));
    gtk_file_filter_set_name(filter, _("Video"));
    gtk_file_filter_add_mime_type(filter, "video/*");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS"));
    gtk_file_filter_set_name(filter, "TS");
    gtk_file_filter_add_pattern(filter, "*.ts");
    gtk_file_filter_add_pattern(filter, "*.TS");
    gtk_file_filter_add_pattern(filter, "*.m2ts");
    gtk_file_filter_add_pattern(filter, "*.M2TS");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG"));
    gtk_file_filter_set_name(filter, "MPG");
    gtk_file_filter_add_pattern(filter, "*.mpg");
    gtk_file_filter_add_pattern(filter, "*.MPG");
    gtk_file_filter_add_pattern(filter, "*.mepg");
    gtk_file_filter_add_pattern(filter, "*.MEPG");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO"));
    gtk_file_filter_set_name(filter, "EVO");
    gtk_file_filter_add_pattern(filter, "*.evo");
    gtk_file_filter_add_pattern(filter, "*.EVO");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB"));
    gtk_file_filter_set_name(filter, "VOB");
    gtk_file_filter_add_pattern(filter, "*.vob");
    gtk_file_filter_add_pattern(filter, "*.VOB");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV"));
    gtk_file_filter_set_name(filter, "MKV");
    gtk_file_filter_add_pattern(filter, "*.mkv");
    gtk_file_filter_add_pattern(filter, "*.MKV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4"));
    gtk_file_filter_set_name(filter, "MP4");
    gtk_file_filter_add_pattern(filter, "*.mp4");
    gtk_file_filter_add_pattern(filter, "*.MP4");
    gtk_file_filter_add_pattern(filter, "*.m4v");
    gtk_file_filter_add_pattern(filter, "*.M4V");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV"));
    gtk_file_filter_set_name(filter, "MOV");
    gtk_file_filter_add_pattern(filter, "*.mov");
    gtk_file_filter_add_pattern(filter, "*.MOV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI"));
    gtk_file_filter_set_name(filter, "AVI");
    gtk_file_filter_add_pattern(filter, "*.avi");
    gtk_file_filter_add_pattern(filter, "*.AVI");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG"));
    gtk_file_filter_set_name(filter, "OGG");
    gtk_file_filter_add_pattern(filter, "*.ogg");
    gtk_file_filter_add_pattern(filter, "*.OGG");
    gtk_file_filter_add_pattern(filter, "*.ogv");
    gtk_file_filter_add_pattern(filter, "*.OGV");
    gtk_file_filter_add_pattern(filter, "*.ogm");
    gtk_file_filter_add_pattern(filter, "*.OGM");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV"));
    gtk_file_filter_set_name(filter, "FLV");
    gtk_file_filter_add_pattern(filter, "*.flv");
    gtk_file_filter_add_pattern(filter, "*.FLV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV"));
    gtk_file_filter_set_name(filter, "WMV");
    gtk_file_filter_add_pattern(filter, "*.wmv");
    gtk_file_filter_add_pattern(filter, "*.WMV");
    gtk_file_chooser_add_filter(chooser, filter);

    // Gtk has a really stupid bug.  If the file chooser is showing
    // hidden files AND there is no filter set, it will not select
    // the filename when gtk_file_chooser_set_filename is called.
    // So add a completely unnessary filter to prevent this behavior.
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
    gtk_file_chooser_set_filter(chooser, filter);

#if !GTK_CHECK_VERSION(3, 16, 0)
    PangoFontDescription *font_desc;
    font_desc = pango_font_description_from_string("monospace 10");
    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view"));
    gtk_widget_override_font(GTK_WIDGET(textview), font_desc);
    pango_font_description_free(font_desc);
#endif

    // Grrrr!  Gtk developers !!!hard coded!!! the width of the
    // radio buttons in GtkStackSwitcher to 100!!!
    //
    // Thankfully, GtkStackSwitcher is a regular container object
    // and we can access the buttons to change their width.
    GList *stack_switcher_children, *link;
    GtkContainer * stack_switcher = GTK_CONTAINER(
                            GHB_WIDGET(ud->builder, "SettingsStackSwitcher"));
    link = stack_switcher_children = gtk_container_get_children(stack_switcher);
    while (link != NULL)
    {
        GtkWidget *widget = link->data;
        gtk_widget_set_size_request(widget, -1, -1);
        gtk_widget_set_hexpand(widget, TRUE);
        gtk_widget_set_halign(widget, GTK_ALIGN_FILL);
        link = link->next;
    }
    g_list_free(stack_switcher_children);

    gtk_window_resize(GTK_WINDOW(ghb_window), window_width, window_height);
    gtk_widget_show(ghb_window);

    // Everything should be go-to-go.  Lets rock!

    gtk_main();
    ghb_backend_close();

    ghb_value_free(&ud->queue);
    ghb_value_free(&ud->settings_array);
    ghb_value_free(&ud->prefs);
    ghb_value_free(&ud->globals);
    ghb_value_free(&ud->x264_priv);

    g_io_channel_unref(ud->activity_log);
    ghb_settings_close();
    ghb_resource_free();
#if !defined(_WIN32)
    notify_uninit();
#endif

    g_object_unref(ud->builder);

    g_free(ud->current_dvd_device);
    g_free(ud);

    return 0;
}
Esempio n. 16
0
// Create and bind the tree model to the tree view for the audio track list
// Also, connect up the signal that lets us know the selection has changed
static void
bind_audio_tree_model (signal_user_data_t *ud)
{
	GtkCellRenderer *cell;
	GtkTreeViewColumn *column;
	GtkListStore *treestore;
	GtkTreeView  *treeview;
	GtkTreeSelection *selection;
	GtkWidget *widget;

	g_debug("bind_audio_tree_model ()\n");
	treeview = GTK_TREE_VIEW(GHB_WIDGET (ud->builder, "audio_list"));
	selection = gtk_tree_view_get_selection (treeview);
	// 12 columns in model.  6 are visible, the other 6 are for storing
	// values that I need
	treestore = gtk_list_store_new(7, G_TYPE_STRING, G_TYPE_STRING, 
								   G_TYPE_STRING, G_TYPE_STRING, 
								   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
	gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(treestore));

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Track"), cell, "text", 0, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 200);
	gtk_tree_view_column_set_max_width (column, 200);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Codec"), cell, "text", 1, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 110);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Bitrate"), cell, "text", 2, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 50);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Sample Rate"), cell, "text", 3, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 100);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Mix"), cell, "text", 4, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 115);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Gain"), cell, "text", 5, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("DRC"), cell, "text", 6, NULL);
    gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));

	g_signal_connect(selection, "changed", audio_list_selection_changed_cb, ud);
	// Need to disable remove and update buttons since there are initially
	// no selections
	widget = GHB_WIDGET (ud->builder, "audio_remove");
	gtk_widget_set_sensitive(widget, FALSE);
	g_debug("Done\n");
}
Esempio n. 17
0
G_MODULE_EXPORT void
subtitle_add_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
{
    // Add the current subtitle settings to the list.
    GValue *subsettings, *backup;
    gboolean one_burned;
    gint track;

    int title_id, titleindex;
    const hb_title_t *title;

    title_id = ghb_settings_get_int(ud->settings, "title");
    title = ghb_lookup_title(title_id, &titleindex);
    if (title == NULL)
    {
        return;
    }

    // Back up settings in case we need to revert.
    backup = ghb_value_dup(
                ghb_settings_get_value(ud->settings, "subtitle_list"));

    one_burned = subtitle_is_one_burned(ud->settings);

    const char *mux_id;
    const hb_container_t *mux;

    mux_id = ghb_settings_get_const_string(ud->settings, "FileFormat");
    mux = ghb_lookup_container_by_name(mux_id);

    int count = hb_list_count(title->list_subtitle);
    for (subsettings = NULL, track = 0;
         subsettings == NULL && track < count; track++)
    {
        subsettings = subtitle_add_track(ud, ud->settings, title, track,
                                mux->format, FALSE, FALSE, &one_burned);
    }
    if (subsettings == NULL)
    {
        subsettings = subtitle_add_track(ud, ud->settings, title, 0,
                                mux->format, FALSE, TRUE, &one_burned);
    }
    ghb_add_subtitle_to_ui(ud, subsettings);

    if (subsettings != NULL)
    {
        // Pop up the edit dialog
        GtkResponseType response;
        GtkWidget *dialog = GHB_WIDGET(ud->builder, "subtitle_dialog");
        response = gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_hide(dialog);
        if (response != GTK_RESPONSE_OK)
        {
            ghb_settings_take_value(ud->settings, "subtitle_list", backup);
            subsettings = subtitle_get_selected_settings(ud, NULL);
            if (subsettings != NULL)
            {
                subtitle_update_dialog_widgets(ud, subsettings);
            }
            subtitle_refresh_list_ui(ud);
        }
        else
        {
            ghb_value_free(backup);
        }
    }
}
Esempio n. 18
0
// Create and bind the tree model to the tree view for the subtitle track list
// Also, connect up the signal that lets us know the selection has changed
static void
bind_subtitle_tree_model (signal_user_data_t *ud)
{
	GtkCellRenderer *cell;
	GtkTreeViewColumn *column;
	GtkListStore *treestore;
	GtkTreeView  *treeview;
	GtkTreeSelection *selection;
	GtkWidget *widget;

	g_debug("bind_subtitle_tree_model ()\n");
	treeview = GTK_TREE_VIEW(GHB_WIDGET (ud->builder, "subtitle_list"));
	selection = gtk_tree_view_get_selection (treeview);
	// 6 columns in model.  5 are visible, the other 1 is for storing
	// values that I need
	// Track, force, burn, default, type, srt offset, track short, source
	// force visible, burn visible, offset visible
	treestore = gtk_list_store_new(10, 
									G_TYPE_STRING,
									G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
									G_TYPE_BOOLEAN,
									G_TYPE_INT,     G_TYPE_STRING,
									G_TYPE_INT,
									G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
									G_TYPE_BOOLEAN);
	gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(treestore));

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
									_("Track"), cell, "text", 0, NULL);
	gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	gtk_tree_view_column_set_min_width (column, 350);
	gtk_tree_view_column_set_max_width (column, 350);

	cell = gtk_cell_renderer_toggle_new();
	column = gtk_tree_view_column_new_with_attributes(
			_("Forced Only"), cell, "active", 1, "visible", 7, NULL);
	gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	g_signal_connect(cell, "toggled", subtitle_forced_toggled_cb, ud);

	cell = gtk_cell_renderer_toggle_new();
	gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(cell), TRUE);
	column = gtk_tree_view_column_new_with_attributes(
			_("Burned In"), cell, "active", 2, "visible", 8, NULL);
	gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	g_signal_connect(cell, "toggled", subtitle_burned_toggled_cb, ud);

	cell = gtk_cell_renderer_toggle_new();
	gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(cell), TRUE);
	column = gtk_tree_view_column_new_with_attributes(
				_("Default"), cell, "active", 3, NULL);
	gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));
	g_signal_connect(cell, "toggled", subtitle_default_toggled_cb, ud);

	cell = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes(
			_("Srt Offset"), cell, "text", 4, "visible", 9, NULL);
	gtk_tree_view_append_column(treeview, GTK_TREE_VIEW_COLUMN(column));


	g_signal_connect(selection, "changed", subtitle_list_selection_changed_cb, ud);
	// Need to disable remove and update buttons since there are initially
	// no selections
	widget = GHB_WIDGET (ud->builder, "subtitle_remove");
	gtk_widget_set_sensitive(widget, FALSE);
	g_debug("Done\n");
}
Esempio n. 19
0
static void
subtitle_update_dialog_widgets(signal_user_data_t *ud, GValue *subsettings)
{
    GtkWidget *widget;

    if (subsettings != NULL)
    {
        // Update widgets with subsettings
        gboolean burn, force, def;

        const char *mux_id;
        const hb_container_t *mux;

        mux_id = ghb_settings_get_const_string(ud->settings, "FileFormat");
        mux = ghb_lookup_container_by_name(mux_id);

        int source = ghb_settings_get_int(subsettings, "SubtitleSource");

        ghb_ui_update_from_settings(ud, "SubtitleTrack", subsettings);
        ghb_ui_update_from_settings(ud, "SrtLanguage", subsettings);
        ghb_ui_update_from_settings(ud, "SrtCodeset", subsettings);
        ghb_ui_update_from_settings(ud, "SrtFile", subsettings);
        ghb_ui_update_from_settings(ud, "SrtOffset", subsettings);

        if (source == SRTSUB)
        {
            ghb_ui_update(ud, "SubtitleSrtEnable", ghb_boolean_value(TRUE));
        }
        else
        {
            ghb_ui_update(ud, "SubtitleSrtDisable", ghb_boolean_value(TRUE));
        }

        widget = GHB_WIDGET(ud->builder, "SubtitleBurned");
        gtk_widget_set_sensitive(widget, hb_subtitle_can_burn(source) &&
                                    hb_subtitle_can_pass(source, mux->format));
        widget = GHB_WIDGET(ud->builder, "SubtitleForced");
        gtk_widget_set_sensitive(widget, hb_subtitle_can_force(source));
        widget = GHB_WIDGET(ud->builder, "SubtitleDefaultTrack");
        gtk_widget_set_sensitive(widget,
                                    hb_subtitle_can_pass(source, mux->format));

        burn = ghb_settings_get_int(subsettings, "SubtitleBurned");
        force = ghb_settings_get_int(subsettings, "SubtitleForced");
        def = ghb_settings_get_int(subsettings, "SubtitleDefaultTrack");

        if (!hb_subtitle_can_burn(source))
        {
            burn = FALSE;
        }
        if (!hb_subtitle_can_force(source))
        {
            force = FALSE;
        }
        if (!hb_subtitle_can_pass(source, mux->format))
        {
            def = FALSE;
            burn = TRUE;
        }
        ghb_settings_set_boolean(subsettings, "SubtitleBurned", burn);
        ghb_ui_update(ud, "SubtitleBurned", ghb_boolean_value(burn));
        ghb_settings_set_boolean(subsettings, "SubtitleForced", force);
        ghb_ui_update(ud, "SubtitleForced", ghb_boolean_value(force));
        ghb_settings_set_boolean(subsettings, "SubtitleDefaultTrack", def);
        ghb_ui_update(ud, "SubtitleDefaultTrack", ghb_boolean_value(def));

        // Hide regular subtitle widgets
        widget = GHB_WIDGET(ud->builder, "subtitle_track_box");
        gtk_widget_set_visible(widget, source != SRTSUB);

        // Show SRT subitle widgets
        widget = GHB_WIDGET(ud->builder, "subtitle_srt_grid");
        gtk_widget_set_visible(widget, source == SRTSUB);
    }
    else
    {
        // Hide SRT subitle widgets
        widget = GHB_WIDGET(ud->builder, "subtitle_srt_grid");
        gtk_widget_set_visible(widget, FALSE);

        // Show regular subtitle widgets
        widget = GHB_WIDGET(ud->builder, "subtitle_track_box");
        gtk_widget_set_visible(widget, TRUE);
    }
}
Esempio n. 20
0
int
main (int argc, char *argv[])
{
	signal_user_data_t *ud;
	GValue *preset;
	GError *error = NULL;
	GOptionContext *context;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	if (!g_thread_supported())
		g_thread_init(NULL);
	context = g_option_context_new ("- Transcode media formats");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
#if defined(_ENABLE_GST)
	g_option_context_add_group (context, gst_init_get_option_group ());
#endif
	g_option_context_parse (context, &argc, &argv, &error);
	g_option_context_free(context);

	if (argc > 1 && dvd_device == NULL && argv[1][0] != '-')
	{
		dvd_device = argv[1];
	}
	
	gtk_init (&argc, &argv);
	gtk_rc_parse_string(hud_rcstyle);
	g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON));
	g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL);
#if !defined(_WIN32)
	notify_init("HandBrake");
#endif
	ghb_register_transforms();
	ghb_resource_init();
	ghb_load_icons();

#if !defined(_WIN32)
	dbus_g_thread_init();
#endif
	ghb_udev_init();

	ghb_write_pid_file();
	ud = g_malloc0(sizeof(signal_user_data_t));
	ud->debug = ghb_debug;
	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud);
	g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud);
	//g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud);
	ud->settings = ghb_settings_new();
	ud->builder = create_builder_or_die (BUILDER_NAME);
	// Enable events that alert us to media change events
	watch_volumes (ud);

	//GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom");
	//gtk_entry_set_inner_border(widget, 2);

	// Since GtkBuilder no longer assigns object ids to widget names
	// Assign a few that are necessary for style overrides to work
	GtkWidget *widget;
#if defined(_NO_UPDATE_CHECK)
	widget = GHB_WIDGET(ud->builder, "check_updates_box");
	gtk_widget_hide(widget);
#endif

	widget = GHB_WIDGET(ud->builder, "preview_hud");
	gtk_widget_set_name(widget, "preview_hud");
	widget = GHB_WIDGET(ud->builder, "preview_window");
	gtk_widget_set_name(widget, "preview_window");

	// Set up the "hud" control overlay for the preview window
	GtkWidget *draw, *hud, *blender, *align;

	align = GHB_WIDGET(ud->builder, "preview_window_alignment");
	draw = GHB_WIDGET(ud->builder, "preview_image_align");
	hud = GHB_WIDGET(ud->builder, "preview_hud");

	// Set up compositing for hud
	blender = ghb_compositor_new();

	gtk_container_add(GTK_CONTAINER(align), blender);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85);
	gtk_widget_show(blender);

	// Redirect stderr to the activity window
	ghb_preview_init(ud);
	IoRedirect(ud);
	ghb_log( "%s - %s - %s",
		HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE );
	ghb_init_dep_map();

	// Need to connect x264_options textview buffer to the changed signal
	// since it can't be done automatically
	GtkTextView *textview;
	GtkTextBuffer *buffer;
	textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "x264Option"));
	buffer = gtk_text_view_get_buffer (textview);
	g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud);

	ghb_combo_init(ud);

	g_debug("ud %p\n", ud);
	g_debug("ud->builder %p\n", ud->builder);

	bind_audio_tree_model(ud);
	bind_subtitle_tree_model(ud);
	bind_presets_tree_model(ud);
	bind_queue_tree_model(ud);
	bind_chapter_tree_model(ud);
	// Connect up the signals to their callbacks
	// I wrote my own connector so that I could pass user data
	// to the callbacks.  Builder's standard autoconnect doesn't all this.
	gtk_builder_connect_signals_full (ud->builder, MyConnect, ud);

	// Load all internal settings
	ghb_settings_init(ud);
	// Load the presets files
	ghb_presets_load(ud);
	ghb_prefs_load(ud);

	ghb_prefs_to_ui(ud);

	gint logLevel;
	logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel");
	ghb_backend_init(logLevel);

	if (ghb_settings_get_boolean(ud->settings, "hbfd"))
	{
		ghb_hbfd(ud, TRUE);
	}
	gchar *source = ghb_settings_get_string(ud->settings, "default_source");
	ghb_dvd_set_current(source, ud);
	g_free(source);

	// Parsing x264 options "" initializes x264 widgets to proper defaults
	ghb_x264_parse_options(ud, "");

	// Populate the presets tree view
	ghb_presets_list_init(ud, NULL, 0);
	// Get the first preset name
	if (arg_preset != NULL)
	{
		preset = ghb_parse_preset_path(arg_preset);
		if (preset)
		{
			ghb_select_preset(ud->builder, preset);
			ghb_value_free(preset);
		}
	}
	else
	{
		ghb_select_default_preset(ud->builder);
	}

	// Grey out widgets that are dependent on a disabled feature
	ghb_check_all_depencencies (ud);

	if (dvd_device != NULL)
	{
		// Source overridden from command line option
		ghb_settings_set_string(ud->settings, "scan_source", dvd_device);
		g_idle_add((GSourceFunc)ghb_idle_scan, ud);
	}
	// Reload and check status of the last saved queue
	g_idle_add((GSourceFunc)ghb_reload_queue, ud);

	// Start timer for monitoring libhb status, 500ms
	g_timeout_add (500, ghb_timer_cb, (gpointer)ud);

	// Add dvd devices to File menu
	ghb_volname_cache_init();
	g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);

#if defined(_USE_APP_IND)
	GtkUIManager * uim = GTK_UI_MANAGER(GHB_OBJECT(ud->builder, "uimanager1"));

	GtkMenu *ai_menu = GTK_MENU(gtk_ui_manager_get_widget(uim, "/ui/tray_menu"));
	ud->ai = app_indicator_new("HandBrake", "hb-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
	app_indicator_set_menu( ud->ai, ai_menu );
	app_indicator_set_label( ud->ai, "", "99.99%");
	if (ghb_settings_get_boolean(ud->settings, "show_status"))
	{
		app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE );
	}
	else
	{
		app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE );
	}
	GtkStatusIcon *si;
	si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

	gtk_status_icon_set_visible(si, FALSE );
#else
	GtkStatusIcon *si;
	si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

	gtk_status_icon_set_visible(si,
			ghb_settings_get_boolean(ud->settings, "show_status"));

#if GTK_CHECK_VERSION(2, 16, 0)
	gtk_status_icon_set_has_tooltip(si, TRUE);
	g_signal_connect(si, "query-tooltip", 
					status_icon_query_tooltip_cb, ud);
#else
	gtk_status_icon_set_tooltip(si, "HandBrake");
#endif
#endif

	// Ugly hack to keep subtitle table from bouncing around as I change
	// which set of controls are visible
	GtkRequisition req;
	gint width, height;
	
	widget = GHB_WIDGET(ud->builder, "SrtCodeset");
	gtk_widget_size_request( widget, &req );
	height = req.height;
	widget = GHB_WIDGET(ud->builder, "srt_code_label");
	gtk_widget_size_request( widget, &req );
	height += req.height;
	widget = GHB_WIDGET(ud->builder, "subtitle_table");
	gtk_widget_set_size_request(widget, -1, height);
	
	widget = GHB_WIDGET (ud->builder, "hb_window");

	GdkGeometry geo = { 
		-1, -1, 1024, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST
	};
	GdkWindowHints geo_mask;
	geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE;
	gtk_window_set_geometry_hints( GTK_WINDOW(widget), widget, &geo, geo_mask);
	width = ghb_settings_get_int(ud->settings, "window_width");
	height = ghb_settings_get_int(ud->settings, "window_height");
	gtk_window_resize(GTK_WINDOW(widget), width, height);
	gtk_widget_show(widget);

	/*
 	 * Filter objects in GtkBuilder xml
 	 * Unfortunately, GtkFilter is poorly supported by GtkBuilder,
 	 * so a lot of the setup must happen in code.
		SourceFilterAll
		SourceFilterVideo
		SourceFilterTS
		SourceFilterMPG
		SourceFilterEVO
		SourceFilterVOB
		SourceFilterMKV
		SourceFilterMP4
		SourceFilterAVI
		SourceFilterMOV
		SourceFilterOGG
		SourceFilterFLV
		SourceFilterWMV
	*/
	// Add filters to source chooser
	GtkFileFilter *filter;
	GtkFileChooser *chooser;
	chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog"));
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
	gtk_file_filter_set_name(filter, "All");
	gtk_file_filter_add_pattern(filter, "*");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo"));
	gtk_file_filter_set_name(filter, "Video");
	gtk_file_filter_add_mime_type(filter, "video/*");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS"));
	gtk_file_filter_set_name(filter, "TS");
	gtk_file_filter_add_pattern(filter, "*.ts");
	gtk_file_filter_add_pattern(filter, "*.TS");
	gtk_file_filter_add_pattern(filter, "*.m2ts");
	gtk_file_filter_add_pattern(filter, "*.M2TS");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG"));
	gtk_file_filter_set_name(filter, "MPG");
	gtk_file_filter_add_pattern(filter, "*.mpg");
	gtk_file_filter_add_pattern(filter, "*.MPG");
	gtk_file_filter_add_pattern(filter, "*.mepg");
	gtk_file_filter_add_pattern(filter, "*.MEPG");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO"));
	gtk_file_filter_set_name(filter, "EVO");
	gtk_file_filter_add_pattern(filter, "*.evo");
	gtk_file_filter_add_pattern(filter, "*.EVO");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB"));
	gtk_file_filter_set_name(filter, "VOB");
	gtk_file_filter_add_pattern(filter, "*.vob");
	gtk_file_filter_add_pattern(filter, "*.VOB");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV"));
	gtk_file_filter_set_name(filter, "MKV");
	gtk_file_filter_add_pattern(filter, "*.mkv");
	gtk_file_filter_add_pattern(filter, "*.MKV");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4"));
	gtk_file_filter_set_name(filter, "MP4");
	gtk_file_filter_add_pattern(filter, "*.mp4");
	gtk_file_filter_add_pattern(filter, "*.MP4");
	gtk_file_filter_add_pattern(filter, "*.m4v");
	gtk_file_filter_add_pattern(filter, "*.M4V");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV"));
	gtk_file_filter_set_name(filter, "MOV");
	gtk_file_filter_add_pattern(filter, "*.mov");
	gtk_file_filter_add_pattern(filter, "*.MOV");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI"));
	gtk_file_filter_set_name(filter, "AVI");
	gtk_file_filter_add_pattern(filter, "*.avi");
	gtk_file_filter_add_pattern(filter, "*.AVI");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG"));
	gtk_file_filter_set_name(filter, "OGG");
	gtk_file_filter_add_pattern(filter, "*.ogg");
	gtk_file_filter_add_pattern(filter, "*.OGG");
	gtk_file_filter_add_pattern(filter, "*.ogv");
	gtk_file_filter_add_pattern(filter, "*.OGV");
	gtk_file_filter_add_pattern(filter, "*.ogm");
	gtk_file_filter_add_pattern(filter, "*.OGM");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV"));
	gtk_file_filter_set_name(filter, "FLV");
	gtk_file_filter_add_pattern(filter, "*.flv");
	gtk_file_filter_add_pattern(filter, "*.FLV");
	gtk_file_chooser_add_filter(chooser, filter);
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV"));
	gtk_file_filter_set_name(filter, "WMV");
	gtk_file_filter_add_pattern(filter, "*.wmv");
	gtk_file_filter_add_pattern(filter, "*.WMV");
	gtk_file_chooser_add_filter(chooser, filter);

	// Gtk has a really stupid bug.  If the file chooser is showing
	// hidden files AND there is no filter set, it will not select
	// the filename when gtk_file_chooser_set_filename is called.
	// So add a completely unnessary filter to prevent this behavior.
	filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
	gtk_file_chooser_set_filter(chooser, filter);

	PangoFontDescription *font_desc;
	font_desc = pango_font_description_from_string ("monospace 10");
	textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "activity_view"));
	gtk_widget_modify_font(GTK_WIDGET(textview), font_desc);      
	pango_font_description_free (font_desc);      

	// Everything should be go-to-go.  Lets rock!

	gtk_main ();
	gtk_status_icon_set_visible(si, FALSE);
	ghb_backend_close();
	if (ud->queue)
		ghb_value_free(ud->queue);
	ghb_value_free(ud->settings);
	g_io_channel_unref(ud->activity_log);
	ghb_settings_close();
#if !defined(_WIN32)
	notify_uninit();
#endif
	g_free(ud);

	return 0;
}
Esempio n. 21
0
G_MODULE_EXPORT gboolean
live_preview_cb(GstBus *bus, GstMessage *msg, gpointer data)
{
    signal_user_data_t *ud = (signal_user_data_t*)data;

    switch (GST_MESSAGE_TYPE(msg))
    {
        case GST_MESSAGE_UNKNOWN:
        {
            //printf("unknown");
        } break;

        case GST_MESSAGE_EOS:
        {
            // Done
            //printf("eos\n");
            live_preview_stop(ud);
            gst_element_seek(ud->preview->play, 1.0,
                GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
                GST_SEEK_TYPE_SET, 0,
                GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
        } break;

        case GST_MESSAGE_ERROR:
        {
            //printf("error\n");
            GError *err;
            gchar *debug;

            gst_message_parse_error(msg, &err, &debug);
            g_warning("Gstreamer Error: %s", err->message);
            g_error_free(err);
            g_free(debug);
        } break;

        case GST_MESSAGE_WARNING:
        case GST_MESSAGE_INFO:
        case GST_MESSAGE_TAG:
        case GST_MESSAGE_BUFFERING:
        case GST_MESSAGE_STATE_CHANGED:
        {
            //printf("state change %x\n", state);
            GstState state, pending;
            gst_element_get_state(ud->preview->play, &state, &pending, 0);
            if (state == GST_STATE_PAUSED || state == GST_STATE_PLAYING)
            {
                update_stream_info(ud);
            }
        } break;

        case GST_MESSAGE_STATE_DIRTY:
        {
            //printf("state dirty\n");
        } break;

        case GST_MESSAGE_STEP_DONE:
        {
            //printf("step done\n");
        } break;

        case GST_MESSAGE_CLOCK_PROVIDE:
        {
            //printf("clock provide\n");
        } break;

        case GST_MESSAGE_CLOCK_LOST:
        {
            //printf("clock lost\n");
        } break;

        case GST_MESSAGE_NEW_CLOCK:
        {
            //printf("new clock\n");
        } break;

        case GST_MESSAGE_STRUCTURE_CHANGE:
        {
            //printf("structure change\n");
        } break;

        case GST_MESSAGE_STREAM_STATUS:
        {
            //printf("stream status\n");
        } break;

        case GST_MESSAGE_APPLICATION:
        {
            //printf("application\n");
        } break;

        case GST_MESSAGE_ELEMENT:
        {
            //printf("element\n");
            if (gst_is_missing_plugin_message(msg))
            {
                GtkWindow *hb_window;
                hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
                gst_element_set_state(ud->preview->play, GST_STATE_PAUSED);
                gchar *message, *desc;
                desc = gst_missing_plugin_message_get_description(msg);
                message = g_strdup_printf(
                            _("Missing GStreamer plugin\n"
                            "Audio or Video may not play as expected\n\n%s"),
                            desc);
                ghb_message_dialog(hb_window, GTK_MESSAGE_WARNING,
                                   message, "Ok", NULL);
                g_free(message);
                gst_element_set_state(ud->preview->play, GST_STATE_PLAYING);
            }
            else if (msg->src == GST_OBJECT_CAST(ud->preview->vsink))
            {
                const GstStructure *gstStruct;
                const GValue       *val;

                gstStruct = gst_message_get_structure(msg);
                if (gstStruct != NULL &&
                    (gst_structure_has_name(gstStruct, "preroll-pixbuf") ||
                     gst_structure_has_name(gstStruct, "pixbuf")))
                {
                    val = gst_structure_get_value(gstStruct, "pixbuf");
                    if (val != NULL)
                    {
                        GdkPixbuf * pix;
                        GtkWidget *widget;
                        int        width, height;

                        if (ud->preview->pix != NULL)
                            g_object_unref(ud->preview->pix);
                        if (ud->preview->scaled_pix != NULL)
                            g_object_unref(ud->preview->scaled_pix);
                        pix = GDK_PIXBUF(g_value_dup_object(val));
                        width = gdk_pixbuf_get_width(pix);
                        height = gdk_pixbuf_get_height(pix);
                        if (width  != ud->preview->width ||
                            height != ud->preview->height ||
                            width  != ud->preview->render_width ||
                            height != ud->preview->render_height)
                        {
                            double xscale, yscale;

                            xscale = (double)ud->preview->render_width /
                                             ud->preview->width;
                            yscale = (double)ud->preview->render_height /
                                             ud->preview->height;
                            if (xscale <= yscale)
                            {
                                width  = ud->preview->render_width;
                                height = ud->preview->height * xscale;
                            }
                            else
                            {
                                width  = ud->preview->width * yscale;
                                height = ud->preview->render_height;
                            }

                            ud->preview->scaled_pix =
                                gdk_pixbuf_scale_simple(pix,
                                                        width, height,
                                                        GDK_INTERP_BILINEAR);
                            g_object_ref(pix);
                        }
                        else
                        {
                            ud->preview->scaled_pix = pix;
                        }
                        ud->preview->pix = ud->preview->scaled_pix;
                        g_object_ref(ud->preview->pix);
                        widget = GHB_WIDGET (ud->builder, "preview_image");
                        gtk_widget_queue_draw(widget);
                    }
                }
            }
        } break;

        case GST_MESSAGE_SEGMENT_START:
        {
            //printf("segment start\n");
        } break;

        case GST_MESSAGE_SEGMENT_DONE:
        {
            //printf("segment done\n");
        } break;

        case GST_MESSAGE_DURATION_CHANGED:
        {
            //printf("duration change\n");
        };

        case GST_MESSAGE_LATENCY:
        {
            //printf("latency\n");
        };

        case GST_MESSAGE_ASYNC_START:
        {
            //printf("async start\n");
        } break;

        case GST_MESSAGE_ASYNC_DONE:
        {
            //printf("async done\n");
        } break;

        case GST_MESSAGE_REQUEST_STATE:
        {
            //printf("request state\n");
        } break;

        case GST_MESSAGE_STEP_START:
        {
            //printf("step start\n");
        } break;

        case GST_MESSAGE_QOS:
        {
            //printf("qos\n");
        } break;

        case GST_MESSAGE_PROGRESS:
        {
            //printf("progress\n");
        } break;

        case GST_MESSAGE_TOC:
        {
            //printf("toc\n");
        } break;

        case GST_MESSAGE_RESET_TIME:
        {
            //printf("reset time\n");
        } break;

        case GST_MESSAGE_STREAM_START:
        {
            //printf("stream start\n");
        };

        case GST_MESSAGE_ANY:
        {
            //printf("any\n");
        } break;


        default:
        {
            // Ignore
            //printf("?msg? %x\n", GST_MESSAGE_TYPE(msg));
        }
    }
    return TRUE;
}
Esempio n. 22
0
int
main (int argc, char *argv[])
{
	signal_user_data_t *ud;
	GValue *preset;
	GError *error = NULL;
	GOptionContext *context;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	if (!g_thread_supported())
		g_thread_init(NULL);
	context = g_option_context_new ("- Rip and encode DVD or MPEG file");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
#if !defined(_WIN32)
	g_option_context_add_group (context, gst_init_get_option_group ());
#endif
	g_option_context_parse (context, &argc, &argv, &error);
	g_option_context_free(context);

	if (argc > 1 && dvd_device == NULL && argv[1][0] != '-')
	{
		dvd_device = argv[1];
	}
	
	gtk_set_locale ();
	gtk_init (&argc, &argv);
	gtk_rc_parse_string(hud_rcstyle);
	g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON));
	g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL);
#if !defined(_WIN32)
	notify_init("HandBrake");
#endif
	ghb_register_transforms();
	ghb_resource_init();
	ghb_load_icons();

#if !defined(_WIN32)
	dbus_g_thread_init();
#endif
	ghb_udev_init();

	ghb_write_pid_file();
	ud = g_malloc0(sizeof(signal_user_data_t));
	ud->debug = ghb_debug;
	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud);
	g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud);
	//g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud);
	ud->settings = ghb_settings_new();
	ud->builder = create_builder_or_die (BUILDER_NAME);
	// Enable events that alert us to media change events
	watch_volumes (ud);

	//GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom");
	//gtk_entry_set_inner_border(widget, 2);

	// Since GtkBuilder no longer assigns object ids to widget names
	// Assign a few that are necessary for style overrides to work
	GtkWidget *widget;
#if defined(_NO_UPDATE_CHECK)
	widget = GHB_WIDGET(ud->builder, "check_updates_box");
	gtk_widget_hide(widget);
#endif

	widget = GHB_WIDGET(ud->builder, "preview_hud");
	gtk_widget_set_name(widget, "preview_hud");
	widget = GHB_WIDGET(ud->builder, "preview_window");
	gtk_widget_set_name(widget, "preview_window");

	// Set up the "hud" control overlay for the preview window
	GtkWidget *draw, *hud, *blender, *align;

	align = GHB_WIDGET(ud->builder, "preview_window_alignment");
	draw = GHB_WIDGET(ud->builder, "preview_image_align");
	hud = GHB_WIDGET(ud->builder, "preview_hud");

	// Set up compositing for hud
	blender = ghb_compositor_new();

	gtk_container_add(GTK_CONTAINER(align), blender);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85);
	gtk_widget_show(blender);

	// Redirect stderr to the activity window
	ghb_preview_init(ud);
	IoRedirect(ud);
	ghb_log( "%s - %s - %s",
		HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE );
	ghb_init_dep_map();

	// Need to connect x264_options textview buffer to the changed signal
	// since it can't be done automatically
	GtkTextView *textview;
	GtkTextBuffer *buffer;
	textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "x264Option"));
	buffer = gtk_text_view_get_buffer (textview);
	g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud);

	ghb_combo_init(ud);

	g_debug("ud %p\n", ud);
	g_debug("ud->builder %p\n", ud->builder);

	bind_audio_tree_model(ud);
	bind_subtitle_tree_model(ud);
	bind_presets_tree_model(ud);
	bind_queue_tree_model(ud);
	bind_chapter_tree_model(ud);
	// Connect up the signals to their callbacks
	// I wrote my own connector so that I could pass user data
	// to the callbacks.  Builder's standard autoconnect doesn't all this.
	gtk_builder_connect_signals_full (ud->builder, MyConnect, ud);

	// Load all internal settings
	ghb_settings_init(ud);
	// Load the presets files
	ghb_presets_load(ud);
	ghb_prefs_load(ud);

	ghb_prefs_to_ui(ud);

	gint logLevel;
	logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel");
	ghb_backend_init(logLevel);

	if (ghb_settings_get_boolean(ud->settings, "hbfd"))
	{
		ghb_hbfd(ud, TRUE);
	}
	gchar *source = ghb_settings_get_string(ud->settings, "default_source");
	ghb_dvd_set_current(source, ud);
	g_free(source);

	// Parsing x264 options "" initializes x264 widgets to proper defaults
	ghb_x264_parse_options(ud, "");

	// Populate the presets tree view
	ghb_presets_list_init(ud, NULL, 0);
	// Get the first preset name
	if (arg_preset != NULL)
	{
		preset = ghb_parse_preset_path(arg_preset);
		if (preset)
		{
			ghb_select_preset(ud->builder, preset);
			ghb_value_free(preset);
		}
	}
	else
	{
		ghb_select_default_preset(ud->builder);
	}

	// Grey out widgets that are dependent on a disabled feature
	ghb_check_all_depencencies (ud);

	if (dvd_device != NULL)
	{
		// Source overridden from command line option
		ghb_settings_set_string(ud->settings, "scan_source", dvd_device);
		g_idle_add((GSourceFunc)ghb_idle_scan, ud);
	}
	// Reload and check status of the last saved queue
	g_idle_add((GSourceFunc)ghb_reload_queue, ud);

	// Start timer for monitoring libhb status, 500ms
	g_timeout_add (500, ghb_timer_cb, (gpointer)ud);

	// Add dvd devices to File menu
	ghb_volname_cache_init();
	g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);

	GtkStatusIcon *si;
	si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

	gtk_status_icon_set_visible(si,
			ghb_settings_get_boolean(ud->settings, "show_status"));

#if GTK_CHECK_VERSION(2, 16, 0)
	gtk_status_icon_set_has_tooltip(si, TRUE);
	g_signal_connect(si, "query-tooltip", 
					status_icon_query_tooltip_cb, ud);
#else
	gtk_status_icon_set_tooltip(si, "HandBrake");
#endif

	// Ugly hack to keep subtitle table from bouncing around as I change
	// which set of controls are visible
	GtkRequisition req;
	gint height;
	
	widget = GHB_WIDGET(ud->builder, "SrtCodeset");
	gtk_widget_size_request( widget, &req );
	height = req.height;
	widget = GHB_WIDGET(ud->builder, "srt_code_label");
	gtk_widget_size_request( widget, &req );
	height += req.height;
	widget = GHB_WIDGET(ud->builder, "subtitle_table");
	gtk_widget_set_size_request(widget, -1, height);
	
	// Everything should be go-to-go.  Lets rock!

	gtk_main ();
	gtk_status_icon_set_visible(si, FALSE);
	ghb_backend_close();
	if (ud->queue)
		ghb_value_free(ud->queue);
	ghb_value_free(ud->settings);
	g_io_channel_unref(ud->activity_log);
	ghb_settings_close();
#if !defined(_WIN32)
	notify_uninit();
#endif
	g_free(ud);

	return 0;
}