OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[handbrake-jp/handbrake-jp-git.git] / libhb / work.c
index 70ca36a..72d12d7 100644 (file)
@@ -22,7 +22,7 @@ static void work_func();
 static void do_job( hb_job_t *, int cpu_count );
 static void work_loop( void * );
 
-#define FIFO_SIZE 32
+#define FIFO_CPU_MULT 8
 
 /**
  * Allocates work object and launches work thread with work_func.
@@ -128,76 +128,6 @@ static void do_job( hb_job_t * job, int cpu_count )
        job->height=title->height-job->crop[0]-job->crop[1];
        job->width=title->width-job->crop[2]-job->crop[3];
     }
-    else if ( job->pixel_ratio == 2 )
-    {
-        /* "Loose" anamorphic.
-            - Uses mod16-compliant dimensions,
-            - Allows users to set the width
-            - Handles ITU pixel aspects
-        */
-        /* Use mod16 values for better compression */
-        job->width   = MULTIPLE_16( job->width );
-        job->height  = MULTIPLE_16( job->height );
-        job->width   = MAX( 16, job->width );
-        job->height  = MAX( 16, job->height );
-
-        /* Set up some variables to make the math easier to follow. */
-        int cropped_width = title->width - job->crop[2] - job->crop[3] ;
-        int cropped_height = title->height - job->crop[0] - job->crop[1] ;
-        int storage_aspect = cropped_width * HB_ASPECT_BASE / cropped_height;
-        int pixels = job->width * (job->width / storage_aspect * HB_ASPECT_BASE);
-
-        /* While keeping the DVD storage aspect, resize the job width and height
-            so they fit into the user's specified dimensions. */
-        hb_set_size(job, -1, pixels, 1);
-
-        if (cropped_width <= 706)
-        {
-            /* Handle ITU PARs */
-            if (title->height == 480)
-            {
-                /* It's NTSC */
-                if (title->aspect == 16)
-                {
-                    /* It's widescreen */
-                    job->pixel_aspect_width = 40;
-                    job->pixel_aspect_height = 33;
-                }
-                else
-                {
-                    /*It's 4:3 */
-                    job->pixel_aspect_width = 10;
-                    job->pixel_aspect_height = 11;
-                }
-            }
-            else if (title->height == 576)
-            {
-                /* It's PAL */
-                if(title->aspect == 16)
-                {
-                    /* It's widescreen */
-                    job->pixel_aspect_width = 16;
-                    job->pixel_aspect_height = 11;
-                }
-                else
-                {
-                    /* It's 4:3 */
-                    job->pixel_aspect_width = 12;
-                    job->pixel_aspect_height = 11;
-                }
-            }
-        }
-
-        /* Figure out what dimensions the source would display at. */
-        int source_display_width = cropped_width * ((float)job->pixel_aspect_width / (float)job->pixel_aspect_height) ;
-
-        /* The film AR is the source's display width / cropped source height.
-           The output display width is the output height * film AR.
-           The output PAR is the output display width / output storage width. */
-        job->pixel_aspect_width = job->height * source_display_width / cropped_height;
-        job->pixel_aspect_height = job->width;
-
-    }
 
        /* Keep width and height within these boundaries */
        if (job->maxHeight && (job->height > job->maxHeight) )
@@ -246,10 +176,10 @@ static void do_job( hb_job_t * job, int cpu_count )
     }
        hb_log (" + PixelRatio: %d, width:%d, height: %d",job->pixel_ratio,job->width, job->height);
     job->fifo_mpeg2  = hb_fifo_init( 2048 );
-    job->fifo_raw    = hb_fifo_init( FIFO_SIZE );
-    job->fifo_sync   = hb_fifo_init( FIFO_SIZE );
-    job->fifo_render = hb_fifo_init( FIFO_SIZE );
-    job->fifo_mpeg4  = hb_fifo_init( FIFO_SIZE );
+    job->fifo_raw    = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+    job->fifo_sync   = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+    job->fifo_render = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+    job->fifo_mpeg4  = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
 
     /* Synchronization */
     hb_list_add( job->list_work, ( w = getWork( WORK_SYNC ) ) );
@@ -309,8 +239,8 @@ static void do_job( hb_job_t * job, int cpu_count )
         {
             hb_log( " + subtitle %x, %s", subtitle->id, subtitle->lang );
             
-            subtitle->fifo_in  = hb_fifo_init( FIFO_SIZE );
-            subtitle->fifo_raw = hb_fifo_init( FIFO_SIZE );
+            subtitle->fifo_in  = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+            subtitle->fifo_raw = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
             
             /*
              * Disable forced subtitles if we didn't find any in the scan
@@ -396,9 +326,9 @@ static void do_job( hb_job_t * job, int cpu_count )
         /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
            but this may change in the future, so they are separated for flexibility */
         int audioCodecsSupportMono = ((audio->codec == HB_ACODEC_AC3 ||
-            audio->codec == HB_ACODEC_DCA) && job->acodec == HB_ACODEC_FAAC);
+            audio->codec == HB_ACODEC_DCA) && (job->acodec == HB_ACODEC_FAAC || job->acodec == HB_ACODEC_VORBIS));
         int audioCodecsSupport6Ch =  ((audio->codec == HB_ACODEC_AC3 ||
-            audio->codec == HB_ACODEC_DCA) && job->acodec == HB_ACODEC_FAAC);
+            audio->codec == HB_ACODEC_DCA) && (job->acodec == HB_ACODEC_FAAC || job->acodec == HB_ACODEC_VORBIS));
 
         /* find out what the format of our source audio is */
         switch (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK) {
@@ -509,9 +439,9 @@ static void do_job( hb_job_t * job, int cpu_count )
 
                /* set up the audio work structures */
         audio->fifo_in   = hb_fifo_init( 2048 );
-        audio->fifo_raw  = hb_fifo_init( FIFO_SIZE );
-        audio->fifo_sync = hb_fifo_init( FIFO_SIZE );
-        audio->fifo_out  = hb_fifo_init( FIFO_SIZE );
+        audio->fifo_raw  = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+        audio->fifo_sync = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+        audio->fifo_out  = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
 
         switch( audio->codec )
         {
@@ -646,8 +576,6 @@ static void do_job( hb_job_t * job, int cpu_count )
     hb_fifo_close( &job->fifo_render );
     hb_fifo_close( &job->fifo_mpeg4 );
 
-    hb_buffer_pool_free();
-
     for (i=0; i < hb_list_count(title->list_subtitle); i++) {
         subtitle =  hb_list_item( title->list_subtitle, i);
         if( subtitle )
@@ -689,9 +617,12 @@ static void do_job( hb_job_t * job, int cpu_count )
                 subtitle_lowest_id = subtitle->id;
             }
 
-            if ( subtitle->forced_hits > 0 )
+            if( subtitle->forced_hits > 0 )
             {
-                subtitle_forced_id = subtitle->id;
+                if( subtitle_forced_id == 0 )
+                {
+                    subtitle_forced_id = subtitle->id;
+                }
             }
         }
         
@@ -759,6 +690,8 @@ static void do_job( hb_job_t * job, int cpu_count )
         }
     }
 
+    hb_buffer_pool_free();
+
     hb_title_close( &job->title );
     free( job );
 }