OSDN Git Service

Fix hb_log to truncate the message at the correct point, fixes 1244.
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.mm
index 62a7327..1492a02 100644 (file)
@@ -21,7 +21,9 @@
 static int FormatSettings[4][10] =
   { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
          HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
-         0,
+      HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
+      HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_AC3,
+      0,
          0 },
     { HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
          HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
@@ -93,16 +95,15 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 
 - (void) applicationDidFinishLaunching: (NSNotification *) notification
 {
-    int    build;
-    char * version;
+    /* Variables from legacy update system, leave but commented out until Sparkle is compeletely vetted */
+    //int    build;
+    //char * version;
     
     // Init libhb
-       int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
-    /* Old update method using hb_init, commented out but code left for a few revs til new sparkle updater is vetted */
+       /* Old update method using hb_init, commented out but code left for a few revs til new sparkle updater is vetted */
     //fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
     /* New Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
-    fHandle = hb_init(debugLevel, 0);
-    
+    fHandle = hb_init(HB_DEBUG_ALL, 0);
     
        // Set the Growl Delegate
     [GrowlApplicationBridge setGrowlDelegate: self];    
@@ -1550,6 +1551,38 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         job->audios[0] = -1;
     }
 
+    /*
+     * Where one or more of the audio tracks has a mixdown of DPLII+AC3 we need to create an extra
+     * track for each.
+     */
+    if (job->audio_mixdowns[0] == HB_AMIXDOWN_DOLBYPLII_AC3)
+    {
+        /*
+         * Make space for the AC3 track by moving 1 to 2
+         */
+        job->audios[2] = job->audios[1];
+        job->audio_mixdowns[2] = job->audio_mixdowns[1];
+        job->audios[1] = job->audios[0];
+        job->audio_mixdowns[0] = HB_AMIXDOWN_DOLBYPLII;
+        job->audio_mixdowns[1] = HB_AMIXDOWN_AC3;
+    }
+
+    if (job->audio_mixdowns[1] == HB_AMIXDOWN_DOLBYPLII_AC3)
+    {
+        job->audios[2] = job->audios[1];
+        job->audio_mixdowns[1] = HB_AMIXDOWN_DOLBYPLII;
+        job->audio_mixdowns[2] = HB_AMIXDOWN_AC3;
+        job->audios[3] = -1;
+    }
+
+    if (job->audio_mixdowns[2] == HB_AMIXDOWN_DOLBYPLII_AC3)
+    {
+        job->audios[3] = job->audios[2];
+        job->audio_mixdowns[2] = HB_AMIXDOWN_DOLBYPLII;
+        job->audio_mixdowns[3] = HB_AMIXDOWN_AC3;
+        job->audios[4] = -1;
+    }
+
     /* Audio settings */
     job->arate = hb_audio_rates[[fAudRatePopUp
                      indexOfSelectedItem]].rate;
@@ -1580,26 +1613,20 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     /* Deinterlace */
     if ([fPictureController deinterlace] == 1)
     {
-        /* Run old deinterlacer by default */
+        /* Run old deinterlacer fd by default */
         hb_filter_deinterlace.settings = "-1"; 
         hb_list_add( job->filters, &hb_filter_deinterlace );
     }
     else if ([fPictureController deinterlace] == 2)
     {
-        /* Yadif mode 0 (1-pass with spatial deinterlacing.) */
-        hb_filter_deinterlace.settings = "0"; 
+        /* Yadif mode 0 (without spatial deinterlacing.) */
+        hb_filter_deinterlace.settings = "2"; 
         hb_list_add( job->filters, &hb_filter_deinterlace );            
     }
     else if ([fPictureController deinterlace] == 3)
     {
-        /* Yadif (1-pass w/o spatial deinterlacing) and Mcdeint */
-        hb_filter_deinterlace.settings = "2:-1:1"; 
-        hb_list_add( job->filters, &hb_filter_deinterlace );            
-    }
-    else if ([fPictureController deinterlace] == 4)
-    {
-        /* Yadif (2-pass w/ spatial deinterlacing) and Mcdeint*/
-        hb_filter_deinterlace.settings = "1:-1:1"; 
+        /* Yadif (with spatial deinterlacing) */
+        hb_filter_deinterlace.settings = "0"; 
         hb_list_add( job->filters, &hb_filter_deinterlace );            
     }
        
@@ -2071,10 +2098,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
        AutoCropLeft = job->crop[2];
        AutoCropRight = job->crop[3];
 
-       /* we run the picture size values through
-       calculatePictureSizing to get all picture size
-       information*/
-       [self calculatePictureSizing: NULL];
        /* Run Through encoderPopUpChanged to see if there
                needs to be any pic value modifications based on encoder settings */
        //[self encoderPopUpChanged: NULL];
@@ -2159,6 +2182,9 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     }   
     [fVidRatePopUp selectItemAtIndex: 0];
     
+    /* we run the picture size values through calculatePictureSizing to get all picture setting        information*/
+       [self calculatePictureSizing: NULL];
+    
    /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
        [self selectPreset:NULL]; 
        
@@ -2224,7 +2250,9 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             
             [fDstCodecsPopUp addItemWithTitle:_( @"MPEG-4 Video / AAC Audio" )];
             [fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / AAC Audio" )];
-            
+            /* We add a new codecs entry which will allow the new aac/ ac3 hybrid */
+            [fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / AAC + AC3 Audio" )];
+            [fDstCodecsPopUp addItemWithTitle:_( @"AVC/H.264 Video / AC3 Audio" )];
                        /* We enable the create chapters checkbox here since we are .mp4*/
                        [fCreateChapterMarkers setEnabled: YES];
                        /* We show the Large File (64 bit formatting) checkbox since we are .mp4 
@@ -2643,10 +2671,6 @@ the user is using "Custom" settings by determining the sender*/
        {
                [fPicSettingDeinterlace setStringValue: @"Slower"];
        }
-       else if ([fPictureController deinterlace] ==4)
-       {
-               [fPicSettingDeinterlace setStringValue: @"Slowest"];
-       }
        /* Denoise */
        if ([fPictureController denoise] == 0)
        {
@@ -2787,6 +2811,7 @@ the user is using "Custom" settings by determining the sender*/
     /* get the index of the selected audio */
     int thisAudioIndex = [sender indexOfSelectedItem] - 1;
 
+#if 0
     /* Handbrake can't currently cope with ripping the same source track twice */
     /* So, if this audio is also selected in the other audio track popup, set that popup's selection to "none" */
     /* get a reference to the two audio track popups */
@@ -2798,6 +2823,7 @@ the user is using "Custom" settings by determining the sender*/
         [otherAudioPopUp selectItemAtIndex: 0];
         [self audioTrackPopUpChanged: otherAudioPopUp];
     }
+#endif
 
     /* pointer for the hb_audio_s struct we will use later on */
     hb_audio_t * audio;
@@ -2806,6 +2832,17 @@ the user is using "Custom" settings by determining the sender*/
     int format = [fDstFormatPopUp indexOfSelectedItem];
     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
     int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
+    
+    /*HACK: Lets setup a convenience variable to decide whether or not to allow aac hybrid (aac + ac3 passthru )*/
+    bool mp4AacAc3;
+    if (format == 0 && codecs == 2) // if mp4 and aac + ac3
+    {
+    mp4AacAc3 = 1;
+    }
+    else
+    {
+    mp4AacAc3 = 0;
+    }
 
     /* pointer to this track's mixdown NSPopUpButton */
     NSTextField   * mixdownTextField;
@@ -2851,6 +2888,7 @@ the user is using "Custom" settings by determining the sender*/
             /* check for AC-3 passthru */
             if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
             {
+            
                     [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: "AC3 Passthru"]
                         action: NULL keyEquivalent: @""];
@@ -2870,7 +2908,7 @@ the user is using "Custom" settings by determining the sender*/
                 int layout = audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
 
                 /* do we want to add a mono option? */
-                if (audioCodecsSupportMono == 1) {
+                if (!mp4AacAc3 && audioCodecsSupportMono == 1) {
                     NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
                         action: NULL keyEquivalent: @""];
@@ -2882,7 +2920,7 @@ the user is using "Custom" settings by determining the sender*/
                 /* do we want to add a stereo option? */
                 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
                 /* also offer stereo if we have a stereo-or-better source */
-                if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO) {
+                if ((!mp4AacAc3 && ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO))) {
                     NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
                         action: NULL keyEquivalent: @""];
@@ -2892,7 +2930,7 @@ the user is using "Custom" settings by determining the sender*/
                 }
 
                 /* do we want to add a dolby surround (DPL1) option? */
-                if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY) {
+                if (!mp4AacAc3 && (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)) {
                     NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
                         action: NULL keyEquivalent: @""];
@@ -2902,7 +2940,7 @@ the user is using "Custom" settings by determining the sender*/
                 }
 
                 /* do we want to add a dolby pro logic 2 (DPL2) option? */
-                if (layout == HB_INPUT_CH_LAYOUT_3F2R) {
+                if ((!mp4AacAc3 || audio->codec == HB_ACODEC_DCA) && layout == HB_INPUT_CH_LAYOUT_3F2R) {
                     NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
                         action: NULL keyEquivalent: @""];
@@ -2912,7 +2950,7 @@ the user is using "Custom" settings by determining the sender*/
                 }
 
                 /* do we want to add a 6-channel discrete option? */
-                if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE)) {
+                if (!mp4AacAc3 && (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))) {
                     NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
                         [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
                         action: NULL keyEquivalent: @""];
@@ -2921,6 +2959,25 @@ the user is using "Custom" settings by determining the sender*/
                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
                 }
 
+                /* do we want to add an AC-3 passthrough option? */
+                if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3) {
+                    NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
+                        [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
+                        action: NULL keyEquivalent: @""];
+                    [menuItem setTag: hb_audio_mixdowns[5].amixdown];
+                    if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
+                    maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
+                }
+
+                /* do we want to add the DPLII+AC3 passthrough option? */
+                if (mp4AacAc3 && audio->codec == HB_ACODEC_AC3) {
+                    NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
+                        [NSString stringWithCString: hb_audio_mixdowns[6].human_readable_name]
+                        action: NULL keyEquivalent: @""];
+                    [menuItem setTag: hb_audio_mixdowns[6].amixdown];
+                    if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[6].amixdown;
+                    maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[6].amixdown);
+                }
                 /* auto-select the best mixdown based on our saved mixdown preference */
                 
                 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
@@ -2974,7 +3031,10 @@ the user is using "Custom" settings by determining the sender*/
     {
         case HB_ACODEC_FAAC:
             /* check if we have a 6ch discrete conversion in either audio track */
-            if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
+            if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || 
+                [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || 
+                [[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_AC3 || 
+                [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_AC3)
             {
                 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
                 minbitrate = 32;
@@ -3040,7 +3100,10 @@ the user is using "Custom" settings by determining the sender*/
     }
 
     /* select the default bitrate (but use 384 for 6-ch AAC) */
-    if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
+    if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || 
+        [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH ||
+        [[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_AC3 || 
+        [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_AC3)
     {
         [fAudBitratePopUp selectItemWithTag: 384];
     }
@@ -3383,6 +3446,9 @@ if (item == nil)
         [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
         /*Subtitles*/
         [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
+        /* Forced Subtitles */
+        [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
+           
         /* Dynamic Range Control Slider */
         [fAudDrcSlider setFloatValue: [[chosenPreset valueForKey:@"AudioDRCSlider"] floatValue]];
         [self audioDRCSliderChanged: NULL];
@@ -3419,8 +3485,19 @@ if (item == nil)
             }
             else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
             {
-                job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
-                job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
+                /* we check to make sure the presets width/height does not exceed the sources width/height */
+                if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"]  intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"]  intValue])
+                {
+                    /* if so, then we use the sources height and width to avoid scaling up */
+                    job->width = fTitle->width;
+                    job->height = fTitle->height;
+                }
+                else // source width/height is >= the preset height/width
+                {
+                    /* we can go ahead and use the presets values for height and width */
+                    job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
+                    job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
+                }
                 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
                 if (job->keep_ratio == 1)
                 {
@@ -3468,7 +3545,17 @@ if (item == nil)
                     /* Deinterlace */
                     if ([chosenPreset objectForKey:@"PictureDeinterlace"])
                     {
-                        [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
+                        /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
+                        * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
+                        if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
+                        {
+                            [fPictureController setDeinterlace:3];
+                        }
+                        else
+                        {
+
+                            [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
+                        }
                     }
                     else
                     {
@@ -3526,7 +3613,16 @@ if (item == nil)
             /* Deinterlace */
             if ([chosenPreset objectForKey:@"PictureDeinterlace"])
             {
-                [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
+                /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
+                 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
+                if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
+                {
+                    [fPictureController setDeinterlace:3];
+                }
+                else
+                {
+                    [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
+                }
             }
             else
             {
@@ -3755,6 +3851,8 @@ if (item == nil)
        [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
        /* Subtitles*/
        [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
+    /* Forced Subtitles */
+       [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
     /* Dynamic Range Control Slider */
     [preset setObject:[NSNumber numberWithFloat:[fAudDrcSlider floatValue]] forKey:@"AudioDRCSlider"];