OSDN Git Service

x264 bump to r1338-19977e9
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.m
index cd0ef73..8fcd1ba 100644 (file)
@@ -1098,6 +1098,11 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     if (fHandle)
     {
         hb_state_t s;
+        
+        hb_get_state( fHandle, &s );
+        if (s.state == HB_STATE_SCANNING && ([ident isEqualToString: StartEncodingIdentifier] || [ident isEqualToString: AddToQueueIdentifier]))
+            return NO;
+        
         hb_get_state2( fQueueEncodeLibhb, &s );
         
         if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
@@ -2149,6 +2154,8 @@ fWorkingCount = 0;
     /* if we are custom anamorphic, store the exact storage, par and display dims */
     if (fTitle->job->anamorphic.mode == 3)
     {
+        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.modulus] forKey:@"PicturePARModulus"];
+        
         [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
         [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
         
@@ -2865,12 +2872,6 @@ fWorkingCount = 0;
     
        if( job->vcodec & HB_VCODEC_X264 )
     {
-               /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
-         Currently only used with Constant Quality setting*/
-               if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
-               {
-               job->crf = 1;
-               }
                
                /* Below Sends x264 options to the core library if x264 is selected*/
                /* Lets use this as per Nyx, Thanks Nyx!*/
@@ -3364,12 +3365,7 @@ bool one_burned = FALSE;
             job->ipod_atom = 0;
         }
                
-               /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
-         Currently only used with Constant Quality setting*/
-               if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
-               {
-               job->crf = 1;
-               }
+               
                /* Below Sends x264 options to the core library if x264 is selected*/
                /* Lets use this as per Nyx, Thanks Nyx!*/
                job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
@@ -3403,6 +3399,8 @@ bool one_burned = FALSE;
         job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"]  intValue];
         job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"]  intValue];
         
+        job->anamorphic.modulus = [[queueToApply objectForKey:@"PicturePARModulus"] intValue];
+        
         job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"]  intValue];
         job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"]  intValue];
         
@@ -4578,10 +4576,7 @@ the user is using "Custom" settings by determining the sender*/
         /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
         int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
         [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
-        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0)
-        {
-            qpRFLabelString = @"RF:";
-        }
+        qpRFLabelString = @"RF:";
     }
     /* ffmpeg  1-31 */
     if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
@@ -4992,7 +4987,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack1MixPopUp removeAllItems];
         [fAudTrack1RatePopUp removeAllItems];
         [fAudTrack1BitratePopUp removeAllItems];
-        [fAudTrack1DrcSlider setFloatValue: 1.00];
+        [fAudTrack1DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack1DrcSlider];
     }
     else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5016,7 +5011,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack2MixPopUp removeAllItems];
         [fAudTrack2RatePopUp removeAllItems];
         [fAudTrack2BitratePopUp removeAllItems];
-        [fAudTrack2DrcSlider setFloatValue: 1.00];
+        [fAudTrack2DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack2DrcSlider];
     }
     else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5040,7 +5035,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack3MixPopUp removeAllItems];
         [fAudTrack3RatePopUp removeAllItems];
         [fAudTrack3BitratePopUp removeAllItems];
-        [fAudTrack3DrcSlider setFloatValue: 1.00];
+        [fAudTrack3DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack3DrcSlider];
     }
     else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5064,7 +5059,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack4MixPopUp removeAllItems];
         [fAudTrack4RatePopUp removeAllItems];
         [fAudTrack4BitratePopUp removeAllItems];
-        [fAudTrack4DrcSlider setFloatValue: 1.00];
+        [fAudTrack4DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack4DrcSlider];
     }
     else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5740,7 +5735,7 @@ the user is using "Custom" settings by determining the sender*/
         [bitratePopUp setEnabled: NO];
         [sampleratePopUp setEnabled: NO];
         
-        [drcSlider setFloatValue: 1.00];
+        [drcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: drcSlider];
         [drcSlider setEnabled: NO];
         [drcField setEnabled: NO];
@@ -6354,6 +6349,16 @@ return YES;
         /* First we check to see if we are using the current audio track layout based on AudioList array */
         if ([chosenPreset objectForKey:@"AudioList"])
         {
+            
+            /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
+            NSPopUpButton * trackLangPopUp = nil;
+            NSPopUpButton * mixdownPopUp = nil;
+            NSPopUpButton * audiocodecPopUp = nil;
+            NSPopUpButton * sampleratePopUp = nil;
+            NSPopUpButton * bitratePopUp = nil;
+            NSSlider      * drcSlider = nil;
+            
+            
             /* Populate the audio widgets based on the contents of the AudioList array */
             int i = 0;
             NSEnumerator *enumerator = [[chosenPreset objectForKey:@"AudioList"] objectEnumerator];
@@ -6363,74 +6368,105 @@ return YES;
                 i++;
                 if( i == 1 )
                 {
-                    if ([fAudLang1PopUp indexOfSelectedItem] == 0)
-                    {
-                        [fAudLang1PopUp selectItemAtIndex: 1];
-                    }
-                    [self audioTrackPopUpChanged: fAudLang1PopUp];
-                    [fAudTrack1CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
-                    /* check our pref for core audio and use it in place of faac if applicable */
-                    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
-                        [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
-                    {
-                        [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
-                    }                    
-                    
-                    [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
-                    [fAudTrack1MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
-                    /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-                     * mixdown*/
-                    if  ([fAudTrack1MixPopUp selectedItem] == nil)
-                    {
-                        [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
-                    }
-                    [fAudTrack1RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
-                    /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-                    if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
-                    {
-                        [fAudTrack1BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
-                    }
-                    [fAudTrack1DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
-                    [self audioDRCSliderChanged: fAudTrack1DrcSlider];
+                    trackLangPopUp = fAudLang1PopUp;
+                    mixdownPopUp = fAudTrack1MixPopUp;
+                    audiocodecPopUp = fAudTrack1CodecPopUp;
+                    sampleratePopUp = fAudTrack1RatePopUp;
+                    bitratePopUp = fAudTrack1BitratePopUp;
+                    drcSlider = fAudTrack1DrcSlider;
                 }
-                
                 if( i == 2 )
                 {
-                    
-                    if ([fAudLang2PopUp indexOfSelectedItem] == 0)
-                    {
-                        [fAudLang2PopUp selectItemAtIndex: 1];
-                    }
-                    [self audioTrackPopUpChanged: fAudLang2PopUp];
-                    [fAudTrack2CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
-                    /* check our pref for core audio and use it in place of faac if applicable */
-                    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
-                        [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
-                    {
-                        [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
-                    }
-                    [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
-                    [fAudTrack2MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
-                    /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-                     * mixdown*/
-                    if  ([fAudTrack2MixPopUp selectedItem] == nil)
-                    {
-                        [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
-                    }
-                    [fAudTrack2RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
-                    /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-                    if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
+                    trackLangPopUp = fAudLang2PopUp;
+                    mixdownPopUp = fAudTrack2MixPopUp;
+                    audiocodecPopUp = fAudTrack2CodecPopUp;
+                    sampleratePopUp = fAudTrack2RatePopUp;
+                    bitratePopUp = fAudTrack2BitratePopUp;
+                    drcSlider = fAudTrack2DrcSlider;
+                }
+                if( i == 3 )
+                {
+                    trackLangPopUp = fAudLang3PopUp;
+                    mixdownPopUp = fAudTrack3MixPopUp;
+                    audiocodecPopUp = fAudTrack3CodecPopUp;
+                    sampleratePopUp = fAudTrack3RatePopUp;
+                    bitratePopUp = fAudTrack3BitratePopUp;
+                    drcSlider = fAudTrack3DrcSlider;
+                }
+                if( i == 4 )
+                {
+                    trackLangPopUp = fAudLang4PopUp;
+                    mixdownPopUp = fAudTrack4MixPopUp;
+                    audiocodecPopUp = fAudTrack4CodecPopUp;
+                    sampleratePopUp = fAudTrack4RatePopUp;
+                    bitratePopUp = fAudTrack4BitratePopUp;
+                    drcSlider = fAudTrack4DrcSlider;
+                }
+                
+                
+                if ([trackLangPopUp indexOfSelectedItem] == 0)
+                {
+                    [trackLangPopUp selectItemAtIndex: 1];
+                }
+                [self audioTrackPopUpChanged: trackLangPopUp];
+                [audiocodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
+                /* check our pref for core audio and use it in place of faac if applicable */
+                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                    [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
+                {
+                    [audiocodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
+                }                    
+                
+                [self audioTrackPopUpChanged: audiocodecPopUp];
+                [mixdownPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
+                /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
+                 * mixdown*/
+                if  ([mixdownPopUp selectedItem] == nil)
+                {
+                    [self audioTrackPopUpChanged: audiocodecPopUp];
+                }
+                [sampleratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
+                /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
+                if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
+                {
+                    [bitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
+                }
+                [drcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
+                [self audioDRCSliderChanged: drcSlider];
+                
+                
+                /* If we are any track greater than 1 check to make sure we have a matching source codec is using ac3 passthru or dts passthru,
+                 * if not we will set the track to "None". Track 1 is allowed to mixdown to a suitable DPL2 mix if we cannot passthru */
+                
+                if( i > 1 )
+                {
+                    /* Check to see if the preset asks for a passhthru track (AC3 or DTS) and verify there is a matching source track if not, set the track to "None". */
+                    if (([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] || [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"])  && [trackLangPopUp indexOfSelectedItem] != 0)
                     {
-                        [fAudTrack2BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
+                        hb_audio_config_t * audio;
+                        /* get the audio source audio codec */
+                        audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [trackLangPopUp indexOfSelectedItem] - 1 );
+                        if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] && audio->in.codec != HB_ACODEC_AC3 ||
+                            [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"] && audio->in.codec != HB_ACODEC_DCA )
+                        {
+                            /* We have a preset using ac3 passthru but no ac3 source audio, so set the track to "None" and bail */
+                            if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
+                            {
+                                [self writeToActivityLog: "Preset calls for AC3 Pass thru ..."];
+                            }
+                            if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"])
+                            {
+                                [self writeToActivityLog: "Preset calls for DTS Pass thru ..."];
+                            }
+                            [self writeToActivityLog: "No matching source codec, setting track  %d to None", i];
+                            [trackLangPopUp selectItemAtIndex: 0];
+                            [self audioTrackPopUpChanged: trackLangPopUp]; 
+                        }   
                     }
-                    [fAudTrack2DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
-                    [self audioDRCSliderChanged: fAudTrack2DrcSlider];
-                    
                 }
-                
             }
             
-             /* We now cleanup any extra audio tracks that may have been previously set if we need to */
+            /* We now cleanup any extra audio tracks that may have been previously set if we need to */
             
             if (i < 4)
             {
@@ -6484,6 +6520,7 @@ return YES;
                 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
                 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
             }
+            
             if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
             {
                 if ([fAudLang2PopUp indexOfSelectedItem] == 0)