+ hb_bd_close( &r->bd );
+ hb_buffer_close( &ps );
+ return;
+ }
+ if ( r->job->start_at_preview )
+ {
+ // XXX code from DecodePreviews - should go into its own routine
+ hb_bd_seek( r->bd, (float)r->job->start_at_preview /
+ ( r->job->seek_points ? ( r->job->seek_points + 1.0 ) : 11.0 ) );
+ }
+ else if ( r->job->pts_to_start )
+ {
+ hb_bd_seek_pts( r->bd, r->job->pts_to_start );
+ }
+ else
+ {
+ hb_bd_seek_chapter( r->bd, r->job->chapter_start );
+ }
+ if (r->job->angle > 1)
+ {
+ hb_bd_set_angle( r->bd, r->job->angle - 1 );
+ }
+ }
+ else if (r->dvd)
+ {
+ /*
+ * 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, start ) )
+ {
+ hb_dvd_close( &r->dvd );
+ hb_buffer_close( &ps );
+ return;
+ }
+ if (r->job->angle)
+ {
+ hb_dvd_set_angle( r->dvd, r->job->angle );
+ }
+
+ if ( r->job->start_at_preview )
+ {
+ // XXX code from DecodePreviews - should go into its own routine
+ hb_dvd_seek( r->dvd, (float)r->job->start_at_preview /
+ ( r->job->seek_points ? ( r->job->seek_points + 1.0 ) : 11.0 ) );