+ * hb_dvd_is_break
+ ***********************************************************************
+ * Returns 1 if the current block is a new chapter start
+ **********************************************************************/
+int hb_dvd_is_break( hb_dvd_t * d )
+{
+ int i, j;
+ int pgc_id, pgn;
+ int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
+ pgc_t * pgc;
+ int cell, chapter_length, cell_end;
+
+ for( i = nr_of_ptts - 1;
+ i > 0;
+ i-- )
+ {
+ /* Get pgc for chapter (i+1) */
+ pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
+ pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
+ pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
+ cell = pgc->program_map[pgn-1] - 1;
+
+ if( cell <= d->cell_start )
+ break;
+
+ // This must not match against the start cell.
+ if( pgc->cell_playback[cell].first_sector == d->block && cell != d->cell_start )
+ {
+ /* Check to see if we merged this chapter into the previous one... */
+ /* As a note, merging chapters is probably bad practice for this very reason */
+ chapter_length = 0;
+
+ if( i == nr_of_ptts - 1 )
+ {
+ cell_end = d->pgc->nr_of_cells;
+ }
+ else
+ {
+ cell_end = pgc->program_map[pgn] - 1;
+ }
+
+ for( j = cell; j < cell_end; j++ )
+ {
+ chapter_length += pgc->cell_playback[j].last_sector + 1 -
+ pgc->cell_playback[j].first_sector;
+ }
+
+ if( chapter_length >= 2048 )
+ {
+ hb_log("DVD: Chapter Break Cell Found");
+ /* We have a chapter break */
+ return 1;
+ }
+ else
+ {
+ hb_log("DVD: Cell Found (%d)", chapter_length);
+ }
+ }
+ }
+
+ return 0;
+}
+
+/***********************************************************************