OSDN Git Service

Allow mac gui to select AC-3 + AAC at the same time, still needs CLI work for the...
[handbrake-jp/handbrake-jp-git.git] / libhb / common.c
index 45d207c..dab7fb4 100644 (file)
@@ -36,12 +36,17 @@ int hb_audio_bitrates_count = sizeof( hb_audio_bitrates ) /
                               sizeof( hb_rate_t );
 int hb_audio_bitrates_default = 8; /* 128 kbps */
 
+static hb_error_handler_t *error_handler = NULL;
+
 hb_mixdown_t hb_audio_mixdowns[] =
 { { "Mono",               "HB_AMIXDOWN_MONO",      "mono",   HB_AMIXDOWN_MONO      },
   { "Stereo",             "HB_AMIXDOWN_STEREO",    "stereo", HB_AMIXDOWN_STEREO    },
   { "Dolby Surround",     "HB_AMIXDOWN_DOLBY",     "dpl1",   HB_AMIXDOWN_DOLBY     },
   { "Dolby Pro Logic II", "HB_AMIXDOWN_DOLBYPLII", "dpl2",   HB_AMIXDOWN_DOLBYPLII },
-  { "6-channel discrete", "HB_AMIXDOWN_6CH",       "6ch",    HB_AMIXDOWN_6CH       } };
+  { "6-channel discrete", "HB_AMIXDOWN_6CH",       "6ch",    HB_AMIXDOWN_6CH       },
+  { "AC-3 Pass-through",  "HB_AMIXDOWN_AC3",       "ac-3",   HB_AMIXDOWN_AC3       },
+  { "Dolby PLII + AC-3",  "HB_AMIXDOWN_DOLBYPLII_AC3", "dpl2+ac3", HB_AMIXDOWN_DOLBYPLII_AC3 },
+};
 int hb_audio_mixdowns_count = sizeof( hb_audio_mixdowns ) /
                               sizeof( hb_mixdown_t );
 
@@ -175,6 +180,7 @@ int hb_calc_bitrate( hb_job_t * job, int size )
        case HB_MUX_MP4:
        case HB_MUX_PSP:
                case HB_MUX_IPOD:
+               case HB_MUX_MKV:
             overhead = 6;
             break; 
         case HB_MUX_AVI:
@@ -221,13 +227,22 @@ int hb_calc_bitrate( hb_job_t * job, int size )
     {
         /* Audio data */
         int abitrate;
-        if( job->acodec & HB_ACODEC_AC3 )
+        if( job->acodec & HB_ACODEC_AC3 ||
+            job->audio_mixdowns[i] == HB_AMIXDOWN_AC3)
         {
+            /*
+             * For AC-3 we take the bitrate from the input audio
+             * bitrate as we are simply passing it through.
+             */
             audio = hb_list_item( title->list_audio, job->audios[i] );
             abitrate = audio->bitrate / 8;
         }
         else
         {
+            /*
+             * Where we are transcoding the audio we use the destination
+             * bitrate.
+             */
             abitrate = job->abitrate * 1000 / 8;
         }
         avail -= length * abitrate;
@@ -493,7 +508,7 @@ void hb_list_close( hb_list_t ** _l )
  *********************************************************************/
 void hb_log( char * log, ... )
 {
-    char        string[182]; /* 180 chars + \n + \0 */
+    char        string[362]; /* 360 chars + \n + \0 */
     time_t      _now;
     struct tm * now;
     va_list     args;
@@ -530,12 +545,8 @@ void hb_log( char * log, ... )
 void hb_error( char * log, ... )
 {
     char        string[181]; /* 180 chars + \0 */
-    time_t      _now;
-    struct tm * now;
     va_list     args;
 
-    extern void hb_error_handler(const char *errmsg);
-
     /* Convert the message to a string */
     va_start( args, log );
     vsnprintf( string, 180, log, args );
@@ -544,7 +555,17 @@ void hb_error( char * log, ... )
     /*
      * Got the error in a single string, send it off to be dispatched.
      */
-    hb_error_handler(string);
+    if( error_handler )
+    {
+        error_handler( string );
+    } else {
+        hb_log( string );
+    }
+}
+
+void hb_register_error_handler( hb_error_handler_t * handler )
+{
+    error_handler = handler;
 }
 
 /**********************************************************************
@@ -604,3 +625,23 @@ void hb_title_close( hb_title_t ** _t )
     *_t = NULL;
 }
 
+/**********************************************************************
+ * hb_filter_close
+ **********************************************************************
+ * 
+ *********************************************************************/
+void hb_filter_close( hb_filter_object_t ** _f )
+{
+    hb_filter_object_t * f = *_f;
+
+    f->close( f->private_data );
+
+    if( f->name )
+        free( f->name );
+    if( f->settings )
+        free( f->settings );
+
+    free( f );
+    *_f = NULL;
+}
+