OSDN Git Service

Change subtitle position to prevent displaying within a 2% margin of the height of...
[handbrake-jp/handbrake-jp-git.git] / libhb / reader.c
index 5067745..1d89c4f 100644 (file)
@@ -15,6 +15,8 @@ typedef struct
     hb_dvd_t     * dvd;
     hb_buffer_t  * ps;
     hb_stream_t  * stream;
+    
+    uint           sequence;
 
 } hb_reader_t;
 
@@ -38,6 +40,7 @@ hb_thread_t * hb_reader_init( hb_job_t * job )
     r->job   = job;
     r->title = job->title;
     r->die   = job->die;
+    r->sequence = 0;
     
     return hb_thread_init( "reader", ReaderFunc, r,
                            HB_NORMAL_PRIORITY );
@@ -55,6 +58,7 @@ static void ReaderFunc( void * _r )
     hb_buffer_t  * buf;
     hb_list_t    * list;
     int            chapter = -1;
+    int            chapter_end = r->job->chapter_end;
 
     if( !( r->dvd = hb_dvd_init( r->title->dvd ) ) )
     {
@@ -66,21 +70,32 @@ static void ReaderFunc( void * _r )
 
     if (r->dvd)
     {
-      if( !hb_dvd_start( r->dvd, r->title->index, r->job->chapter_start ) )
+      /*
+       * XXX this code is a temporary hack that should go away if/when
+       *     chapter merging goes away in libhb/dvd.c
+       * map the start and end chapter numbers to on-media chapter
+       * numbers since chapter merging could cause the handbrake numbers
+       * to diverge from the media numbers and, if our chapter_end is after
+       * a media chapter that got merged, we'll stop ripping too early.
+       */
+      int start = r->job->chapter_start;
+      hb_chapter_t * chap = hb_list_item( r->title->list_chapter, chapter_end - 1 );
+
+      chapter_end = chap->index;
+      if (start > 1)
+      {
+         chap = hb_list_item( r->title->list_chapter, start - 1 );
+         start = chap->index;
+      }
+      /* end chapter mapping XXX */
+
+      if( !hb_dvd_start( r->dvd, r->title->index, start ) )
       {
           hb_dvd_close( &r->dvd );
           return;
       }
     }
     
-       if (r->stream)
-       {
-               // At this point r->audios[0] gives us the index of the selected audio track for output track 0
-               // we cannot effectively demux multiple PID's into the seperate output tracks unfortunately
-               // so we'll just specifiy things here for a single track.
-               hb_stream_set_selected_audio_pid_index(r->stream, r->job->audios[0]);
-       }
-       
     list  = hb_list_init();
     r->ps = hb_buffer_init( HB_DVD_READ_BUFFER_SIZE );
 
@@ -96,10 +111,10 @@ static void ReaderFunc( void * _r )
             hb_log( "reader: end of the title reached" );
             break;
         }
-        if( chapter > r->job->chapter_end )
+        if( chapter > chapter_end )
         {
-            hb_log( "reader: end of chapter %d reached (%d)",
-                    r->job->chapter_end, chapter );
+            hb_log( "reader: end of chapter %d (media %d) reached at media chapter %d",
+                    r->job->chapter_end, chapter_end, chapter );
             break;
         }
 
@@ -118,7 +133,7 @@ static void ReaderFunc( void * _r )
           }
         }
 
-        if( r->job->subtitle_scan )
+        if( r->job->indepth_scan )
         {
             /*
              * Need to update the progress during a subtitle scan
@@ -139,7 +154,7 @@ static void ReaderFunc( void * _r )
             p.seconds  = -1;
             hb_set_state( r->job->h, &state );
         }
-        
+
         hb_demux_ps( r->ps, list );
 
         while( ( buf = hb_list_item( list, 0 ) ) )
@@ -153,6 +168,7 @@ static void ReaderFunc( void * _r )
                 {
                     hb_snooze( 50 );
                 }
+                buf->sequence = r->sequence++;
                 hb_fifo_push( fifo, buf );
             }
             else
@@ -194,18 +210,21 @@ static hb_fifo_t * GetFifoForId( hb_job_t * job, int id )
 
     if( id == 0xE0 )
     {
-        if( !job->subtitle_scan )
+        if( job->indepth_scan ) 
         {
-            return job->fifo_mpeg2;
-        } else {
             /*
-             * Ditch the mpeg2 video when doing a subtitle scan.
+             * Ditch the video here during the indepth scan until
+             * we can improve the MPEG2 decode performance.
              */
             return NULL;
+        } 
+        else 
+        {
+            return job->fifo_mpeg2;
         }
     }
 
-    if (job->subtitle_scan) {
+    if( job->indepth_scan ) {
         /*
          * Count the occurances of the subtitles, don't actually
          * return any to encode unless we are looking fro forced
@@ -233,12 +252,15 @@ static hb_fifo_t * GetFifoForId( hb_job_t * job, int id )
             return subtitle->fifo_in;
         }
     }
-    for( i = 0; i < hb_list_count( title->list_audio ); i++ )
+    if( !job->indepth_scan ) 
     {
-        audio = hb_list_item( title->list_audio, i );
-        if( id == audio->id )
+        for( i = 0; i < hb_list_count( title->list_audio ); i++ )
         {
-            return audio->fifo_in;
+            audio = hb_list_item( title->list_audio, i );
+            if( id == audio->id )
+            {
+                return audio->fifo_in;
+            }
         }
     }