OSDN Git Service

LinGui: force button images to be always enabled
[handbrake-jp/handbrake-jp-git.git] / gtk / src / hb-backend.c
index dca551a..7ac7172 100644 (file)
@@ -226,8 +226,8 @@ combo_opts_t denoise_opts =
 static options_map_t d_vcodec_opts[] =
 {
        {"H.264 (x264)",    "x264",   HB_VCODEC_X264, ""},
-       {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
-       {"Theora",          "theora", HB_VCODEC_THEORA, ""},
+       {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
+       {"VP3 (Theora)",    "theora", HB_VCODEC_THEORA, ""},
 };
 combo_opts_t vcodec_opts =
 {
@@ -1354,11 +1354,12 @@ ghb_grey_combo_options(GtkBuilder *builder)
        gboolean allow_dolby = TRUE;
        gboolean allow_dpl2 = TRUE;
        gboolean allow_6ch = TRUE;
+       allow_mono = acodec & ~HB_ACODEC_LAME;
+       allow_6ch = acodec & ~HB_ACODEC_LAME;
        if (audio)
        {
-               allow_mono =
-                       (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
-                       (acodec & ~HB_ACODEC_LAME);
+               allow_mono = allow_mono &&
+                       (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA));
                gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
                allow_stereo =
                        ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
@@ -1367,9 +1368,8 @@ ghb_grey_combo_options(GtkBuilder *builder)
                        (layout == HB_INPUT_CH_LAYOUT_3F2R) || 
                        (layout == HB_INPUT_CH_LAYOUT_DOLBY);
                allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
-               allow_6ch =
+               allow_6ch = allow_6ch &&
                        (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
-                       (acodec & ~HB_ACODEC_LAME) &&
                        (layout == HB_INPUT_CH_LAYOUT_3F2R) && 
                        (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
        }
@@ -1381,10 +1381,14 @@ ghb_grey_combo_options(GtkBuilder *builder)
 }
 
 gint
-ghb_get_best_audio_bitrate(gint acodec, gint br)
+ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
 {
-       if ((acodec & HB_ACODEC_FAAC) && br > 160)
-               br = 160;
+       if (acodec & HB_ACODEC_FAAC)
+       {
+       int maxbr = channels * 80;
+               if (br > maxbr)
+                       br = maxbr;
+       }
        return br;
 }
 
@@ -1490,7 +1494,7 @@ init_combo_box(GtkBuilder *builder, const gchar *name)
        cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
-               "text", 0, "sensitive", 1, NULL);
+               "markup", 0, "sensitive", 1, NULL);
        }
        else
        { // Combo box entry
@@ -1504,6 +1508,7 @@ audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rat
        GtkTreeIter iter;
        GtkListStore *store;
        gint ii;
+       gchar *str;
        
        g_debug("audio_samplerate_opts_set ()\n");
        store = get_combo_box_store(builder, name);
@@ -1511,7 +1516,7 @@ audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rat
        // Add an item for "Same As Source"
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, 
-                                          0, "Same as source", 
+                                          0, "<small>Same as source</small>", 
                                           1, TRUE, 
                                           2, "source", 
                                           3, 0.0, 
@@ -1520,13 +1525,15 @@ audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rat
        for (ii = 0; ii < count; ii++)
        {
                gtk_list_store_append(store, &iter);
+               str = g_strdup_printf("<small>%s</small>", rates[ii].string);
                gtk_list_store_set(store, &iter, 
-                                                  0, rates[ii].string, 
+                                                  0, str,
                                                   1, TRUE, 
                                                   2, rates[ii].string, 
                                                   3, (gdouble)rates[ii].rate, 
                                                   4, rates[ii].string, 
                                                   -1);
+               g_free(str);
        }
 }
 
@@ -1584,13 +1591,14 @@ mix_opts_set(GtkBuilder *builder, const gchar *name)
        GtkTreeIter iter;
        GtkListStore *store;
        gint ii;
+       gchar *str;
        
        g_debug("mix_opts_set ()\n");
        store = get_combo_box_store(builder, name);
        gtk_list_store_clear(store);
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, 
-                                          0, "None", 
+                                          0, "<small>None</small>", 
                                           1, TRUE, 
                                           2, "none", 
                                           3, 0.0, 
@@ -1599,13 +1607,16 @@ mix_opts_set(GtkBuilder *builder, const gchar *name)
        for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
        {
                gtk_list_store_append(store, &iter);
+               str = g_strdup_printf("<small>%s</small>",
+                       hb_audio_mixdowns[ii].human_readable_name);
                gtk_list_store_set(store, &iter, 
-                                                  0, hb_audio_mixdowns[ii].human_readable_name, 
+                                                  0, str,
                                                   1, TRUE, 
                                                   2, hb_audio_mixdowns[ii].short_name, 
                                                   3, (gdouble)hb_audio_mixdowns[ii].amixdown, 
                                                   4, hb_audio_mixdowns[ii].internal_name, 
                                                   -1);
+               g_free(str);
        }
 }
 
@@ -1777,6 +1788,7 @@ audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
     hb_audio_config_t * audio;
        gint ii;
        gint count = 0;
+       gchar *str;
        
        g_debug("audio_track_opts_set ()\n");
        store = get_combo_box_store(builder, name);
@@ -1807,7 +1819,7 @@ audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
                // No audio. set some default
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter, 
-                                                  0, "No Audio", 
+                                                  0, "<small>No Audio</small>", 
                                                   1, TRUE, 
                                                   2, "none", 
                                                   3, -1.0, 
@@ -1824,13 +1836,15 @@ audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
        {
         audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
                gtk_list_store_append(store, &iter);
+               str = g_strdup_printf("<small>%s</small>", audio->lang.description);
                gtk_list_store_set(store, &iter, 
-                                                  0, audio->lang.description, 
+                                                  0, str,
                                                   1, TRUE, 
                                                   2, index_str[ii], 
                                                   3, (gdouble)ii, 
                                                   4, index_str[ii], 
                                                   -1);
+               g_free(str);
                audio_track_opts.map[ii].option = audio->lang.description,
                audio_track_opts.map[ii].shortOpt = index_str[ii];
                audio_track_opts.map[ii].ivalue = ii;
@@ -2193,9 +2207,12 @@ ghb_find_cc_track(gint titleindex)
 
 gint
 ghb_find_subtitle_track(
-       gint titleindex, 
-       const gchar *lang, 
-       GHashTable *track_indices)
+       gint          titleindex, 
+       const gchar * lang, 
+       gboolean      burn,
+       gboolean      force,
+       gint          source,
+       GHashTable  * track_indices)
 {
        hb_list_t  * list;
        hb_title_t * title;
@@ -2218,6 +2235,21 @@ ghb_find_subtitle_track(
                        used = g_malloc0(count * sizeof(gboolean));
                        g_hash_table_insert(track_indices, g_strdup(lang), used);
                }
+               // Try to find an item that matches the preferred language and source
+               for (ii = 0; ii < count; ii++)
+               {
+                       if (used[ii])
+                               continue;
+
+                       subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
+                       if (source == subtitle->source &&
+                               ((strcmp(lang, subtitle->iso639_2) == 0) ||
+                                (strcmp(lang, "und") == 0)))
+                       {
+                               used[ii] = TRUE;
+                               return ii;
+                       }
+               }
                // Try to find an item that matches the preferred language
                for (ii = 0; ii < count; ii++)
                {
@@ -2225,8 +2257,9 @@ ghb_find_subtitle_track(
                                continue;
 
                        subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
-                       if ((strcmp(lang, subtitle->iso639_2) == 0) ||
-                               (strcmp(lang, "und") == 0))
+                       if (((burn || force) && (subtitle->source == VOBSUB)) &&
+                               ((strcmp(lang, subtitle->iso639_2) == 0) ||
+                                (strcmp(lang, "und") == 0)))
                        {
                                used[ii] = TRUE;
                                return ii;
@@ -2260,6 +2293,33 @@ generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
        }
 }
 
+static void
+small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
+{
+       GtkTreeIter iter;
+       GtkListStore *store;
+       gint ii;
+       gchar *str;
+       
+       g_debug("generic_opts_set ()\n");
+       if (name == NULL || opts == NULL) return;
+       store = get_combo_box_store(builder, name);
+       gtk_list_store_clear(store);
+       for (ii = 0; ii < opts->count; ii++)
+       {
+               gtk_list_store_append(store, &iter);
+               str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
+               gtk_list_store_set(store, &iter, 
+                                                  0, str,
+                                                  1, TRUE, 
+                                                  2, opts->map[ii].shortOpt, 
+                                                  3, opts->map[ii].ivalue, 
+                                                  4, opts->map[ii].svalue, 
+                                                  -1);
+               g_free(str);
+       }
+}
+
 combo_opts_t*
 find_combo_table(const gchar *name)
 {
@@ -2431,7 +2491,7 @@ ghb_update_ui_combo_box(
                generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
                generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
                generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
-               generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
+               small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
                generic_opts_set(ud->builder, "x264_direct", &direct_opts);
                generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
                generic_opts_set(ud->builder, "x264_me", &me_opts);
@@ -2596,14 +2656,14 @@ audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
        GtkListStore *store;
        gchar *str;
        
-       g_debug("audio_rate_opts_add ()\n");
+       g_debug("audio_bitrate_opts_add ()\n");
 
        if (rate < 8) return;
 
        store = get_combo_box_store(builder, name);
        if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
        {
-               str = g_strdup_printf ("%d", rate);
+               str = g_strdup_printf ("<small>%d</small>", rate);
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter, 
                                                   0, str, 
@@ -2617,7 +2677,11 @@ audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
 }
 
 static void
-audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
+audio_bitrate_opts_clean(
+       GtkBuilder *builder, 
+       const gchar *name, 
+       gint first_rate, 
+       gint last_rate)
 {
        GtkTreeIter iter;
        GtkListStore *store;
@@ -2625,6 +2689,7 @@ audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
        gboolean done = FALSE;
        gint ii = 0;
        guint last = (guint)last_rate;
+       guint first = (guint)first_rate;
        
        g_debug("audio_bitrate_opts_clean ()\n");
        store = get_combo_box_store(builder, name);
@@ -2638,7 +2703,7 @@ audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
                        {
                                done = !gtk_list_store_remove(store, &iter);
                        }
-                       else if (ivalue > last)
+                       else if (ivalue < first || ivalue > last)
                        {
                                ii++;
                                gtk_list_store_set(store, &iter, 1, FALSE, -1);
@@ -2660,6 +2725,7 @@ audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
        GtkTreeIter iter;
        GtkListStore *store;
        gint ii;
+       gchar *str;
        
        g_debug("audio_bitrate_opts_set ()\n");
        store = get_combo_box_store(builder, name);
@@ -2667,13 +2733,16 @@ audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
        for (ii = 0; ii < hb_audio_bitrates_count; ii++)
        {
                gtk_list_store_append(store, &iter);
+               str = g_strdup_printf ("<small>%s</small>", 
+                       hb_audio_bitrates[ii].string);
                gtk_list_store_set(store, &iter, 
-                                                  0, hb_audio_bitrates[ii].string, 
+                                                  0, str,
                                                   1, TRUE, 
                                                   2, hb_audio_bitrates[ii].string, 
                                                   3, (gdouble)hb_audio_bitrates[ii].rate, 
                                                   4, hb_audio_bitrates[ii].string, 
                                                   -1);
+               g_free(str);
        }
 }
 
@@ -2684,9 +2753,12 @@ ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
 }
 
 void
-ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
+ghb_set_default_bitrate_opts(
+       GtkBuilder *builder, 
+       gint first_rate, 
+       gint last_rate)
 {
-       audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
+       audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
 }
 
 static ghb_status_t hb_status;
@@ -3091,7 +3163,12 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
        if (busy) return;
        busy = TRUE;
 
-       
+       if (!ud->dont_clear_presets && (keep_width || keep_height))
+       {
+               ghb_settings_set_int(ud->settings, "PictureWidth", 0);
+               ghb_settings_set_int(ud->settings, "PictureHeight", 0);
+       }
+
        // First configure widgets
        mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
        pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
@@ -3227,7 +3304,7 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
                job->anamorphic.dar_height = 0;
 
                if (keep_height && pic_par == 2)
-                       width = ((double)height * crop_width / crop_height) + 0.5;
+                       width = ((double)height * crop_width / crop_height) + mod / 2;
                job->width = width;
                job->height = height;
                job->maxWidth = max_width;
@@ -3478,7 +3555,7 @@ ghb_validate_filters(signal_user_data_t *ud)
        if (!decomb_deint && index == 1)
        {
                str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
-               if (!ghb_validate_filter_string(str, 4))
+               if (!ghb_validate_filter_string(str, -1))
                {
                        message = g_strdup_printf(
                                                "Invalid Deinterlace Settings:\n\n%s\n",
@@ -3495,7 +3572,7 @@ ghb_validate_filters(signal_user_data_t *ud)
        if (index == 1)
        {
                str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
-               if (!ghb_validate_filter_string(str, 6))
+               if (!ghb_validate_filter_string(str, -1))
                {
                        message = g_strdup_printf(
                                                "Invalid Detelecine Settings:\n\n%s\n",
@@ -3512,7 +3589,7 @@ ghb_validate_filters(signal_user_data_t *ud)
        if (decomb_deint && index == 1)
        {
                str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
-               if (!ghb_validate_filter_string(str, 15))
+               if (!ghb_validate_filter_string(str, -1))
                {
                        message = g_strdup_printf(
                                                "Invalid Decomb Settings:\n\n%s\n",
@@ -3529,7 +3606,7 @@ ghb_validate_filters(signal_user_data_t *ud)
        if (index == 1)
        {
                str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
-               if (!ghb_validate_filter_string(str, 4))
+               if (!ghb_validate_filter_string(str, -1))
                {
                        message = g_strdup_printf(
                                                "Invalid Denoise Settings:\n\n%s\n",
@@ -3667,6 +3744,63 @@ ghb_validate_subtitles(signal_user_data_t *ud)
        return TRUE;
 }
 
+gint
+ghb_select_audio_codec(signal_user_data_t *ud, gint track)
+{
+       hb_list_t  * list;
+       hb_title_t * title;
+       hb_audio_config_t *audio;
+
+       if (h_scan == NULL) return -1;
+       list = hb_get_titles( h_scan );
+       if( !hb_list_count( list ) )
+       {
+               return -1;
+       }
+
+       gint titleindex;
+
+       titleindex = ghb_settings_combo_int(ud->settings, "title");
+    title = hb_list_item( list, titleindex );
+       if (title == NULL) return -1;
+
+       gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
+
+       if (track < 0 || track >= hb_list_count(title->list_audio))
+               return -1;
+
+       audio = (hb_audio_config_t *) hb_list_audio_config_item(
+                                                                       title->list_audio, track );
+       if (mux == HB_MUX_MP4)
+       {
+               if (audio->in.codec == HB_ACODEC_AC3)
+                       return audio->in.codec;
+               else
+                       return HB_ACODEC_FAAC;
+       }
+       else
+       {
+               if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
+                       return audio->in.codec;
+               else
+                       return HB_ACODEC_LAME;
+       }
+}
+
+const gchar*
+ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
+{
+       gint acodec, ii;
+
+       acodec = ghb_select_audio_codec(ud, track);
+       for (ii = 0; ii < acodec_opts.count; ii++)
+       {
+               if (acodec_opts.map[ii].ivalue == acodec)
+                       return acodec_opts.map[ii].option;
+       }
+       return "Unknown";
+}
+
 gboolean
 ghb_validate_audio(signal_user_data_t *ud)
 {
@@ -4168,9 +4302,10 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
                }
                if ((job->mux == HB_MUX_MP4) && 
                        ((audio.out.codec & HB_ACODEC_LAME) ||
+                       (audio.out.codec & HB_ACODEC_DCA) ||
                        (audio.out.codec & HB_ACODEC_VORBIS)))
                {
-                       // mp4/mp3|vorbis combination is not supported.
+                       // mp4/mp3|dts|vorbis combination is not supported.
                        audio.out.codec = HB_ACODEC_FAAC;
                }
         audio.out.dynamic_range_compression = 
@@ -4185,19 +4320,29 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
                }
                else
                {
+                       int channels;
+
                        audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
+                       if (audio.out.mixdown == HB_AMIXDOWN_MONO)
+                               channels = 1;
+                       else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
+                               channels = 6;
+                       else
+                               channels = 2;
+
                        // Make sure the mixdown is valid and pick a new one if not.
                        audio.out.mixdown = ghb_get_best_mix(titleindex, 
                                audio.in.track, audio.out.codec, audio.out.mixdown);
                        audio.out.bitrate = 
                                ghb_settings_combo_int(asettings, "AudioBitrate");
-                       audio.out.bitrate = ghb_get_best_audio_bitrate(
-                               audio.out.codec, audio.out.bitrate);
                        gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
                        if (srate == 0) // 0 is same as source
                                audio.out.samplerate = taudio->in.samplerate;
                        else
                                audio.out.samplerate = srate;
+
+                       audio.out.bitrate = ghb_get_best_audio_bitrate(
+                               audio.out.codec, audio.out.bitrate, channels);
                }
 
                // Add it to the jobs audio list
@@ -4218,7 +4363,6 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
 
        dest_str = ghb_settings_get_string(js, "destination");
        job->file = dest_str;
-       job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
 
        const GValue *subtitle_list;
        gint subtitle;