OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / libhb / enclame.c
index 24e9542..a3f4a38 100644 (file)
@@ -28,6 +28,7 @@ struct hb_work_private_s
     /* LAME handle */
     lame_global_flags * lame;
 
+    int             done;
     unsigned long   input_samples;
     unsigned long   output_bytes;
     uint8_t       * buf;
@@ -47,10 +48,19 @@ int enclameInit( hb_work_object_t * w, hb_job_t * job )
     hb_log( "enclame: opening libmp3lame" );
 
     pv->lame = lame_init();
-    lame_set_brate( pv->lame, audio->config.out.bitrate );
+    // use ABR
+    lame_set_VBR( pv->lame, vbr_abr );
+    lame_set_VBR_mean_bitrate_kbps( pv->lame, audio->config.out.bitrate );
     lame_set_in_samplerate( pv->lame, audio->config.out.samplerate );
     lame_set_out_samplerate( pv->lame, audio->config.out.samplerate );
     lame_init_params( pv->lame );
+    // Lame's default encoding mode is JOINT_STEREO.  This subtracts signal
+    // that is "common" to left and right (within some threshold) and encodes
+    // it separately.  This improves quality at low bitrates, but hurts 
+    // imaging (channel separation) at higher bitrates.  So if the bitrate
+    // is suffeciently high, use regular STEREO mode.
+    if ( audio->config.out.bitrate >= 128 )
+        lame_set_mode( pv->lame, STEREO );
 
     pv->input_samples = 1152 * 2;
     pv->output_bytes = LAME_MAXMP3BUFFER;
@@ -138,8 +148,35 @@ int enclameWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
                  hb_buffer_t ** buf_out )
 {
     hb_work_private_t * pv = w->private_data;
+    hb_buffer_t * in = *buf_in;
     hb_buffer_t * buf;
 
+    if ( (*buf_in)->size <= 0 )
+    {
+        /* EOF on input - send it downstream & say we're done */
+        if ( pv->done )
+        {
+            *buf_out = *buf_in;
+            *buf_in = NULL;
+            return HB_WORK_DONE;
+        }
+        else
+        {
+            pv->done = 1;
+            hb_fifo_push( w->fifo_in, in);
+            *buf_in = NULL;
+
+            buf = hb_buffer_init( pv->output_bytes );
+            buf->size = lame_encode_flush( pv->lame, buf->data, LAME_MAXMP3BUFFER );
+            if( buf->size <= 0 )
+            {
+                hb_buffer_close( &buf );
+            }
+            *buf_out = buf;
+            return HB_WORK_OK;
+        }
+    }
+
     hb_list_add( pv->list, *buf_in );
     *buf_in = NULL;