OSDN Git Service

Fix to the chapter merging to ensure that when reading from the media we take into...
authoreddyg <eddyg@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 9 Oct 2007 02:23:44 +0000 (02:23 +0000)
committereddyg <eddyg@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 9 Oct 2007 02:23:44 +0000 (02:23 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@1012 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/dvd.c
libhb/reader.c

index 234e55b..6ecaab9 100644 (file)
@@ -386,7 +386,8 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
         pgc_t * pgc_next;
 
         chapter = calloc( sizeof( hb_chapter_t ), 1 );
-        chapter->index = c;
+        /* remember the on-disc chapter number */
+        chapter->index = i + 1;
 
         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
@@ -439,14 +440,13 @@ hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
             d->cell_cur = d->cell_next;
         }
 
-        if( chapter->block_count < 2048 && chapter->index > 1 )
+        if( chapter->block_count < 2048 && c > 1 )
         {
-            hb_log( "scan: chapter %d too short (%d blocks, "
-                    "cells=%d->%d), merging", chapter->index,
+            hb_log( "scan: chapter %d(%d) too short (%d blocks, "
+                    "cells=%d->%d), merging", c, chapter->index,
                     chapter->block_count, chapter->cell_start,
                     chapter->cell_end );
-            chapter_old = hb_list_item( title->list_chapter,
-                                        chapter->index - 2 );
+            chapter_old = hb_list_item( title->list_chapter, c - 2 );
             chapter_old->cell_end    = chapter->cell_end;
             chapter_old->block_end   = chapter->block_end;
             chapter_old->block_count += chapter->block_count;
index 4ced0a6..e53e388 100644 (file)
@@ -58,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 ) ) )
     {
@@ -69,7 +70,26 @@ 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;
@@ -99,10 +119,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;
         }