OSDN Git Service

Implemented audio and subtitle selection
[handbrake-jp/handbrake-jp-git.git] / libhb / dvd.c
1 /* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.m0k.org/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #include "hb.h"
8 #include "lang.h"
9
10 #include "dvdread/ifo_read.h"
11 #include "dvdread/nav_read.h"
12
13 struct hb_dvd_s
14 {
15     char         * path;
16
17     dvd_reader_t * reader;
18     ifo_handle_t * vmg;
19
20     int            vts;
21     int            ttn;
22     ifo_handle_t * ifo;
23     dvd_file_t   * file;
24
25     pgc_t        * pgc;
26     int            cell_start;
27     int            cell_end;
28     int            title_start;
29     int            title_end;
30     int            title_block_count;
31     int            cell_cur;
32     int            cell_next;
33     int            block;
34     int            pack_len;
35     int            next_vobu;
36 };
37
38 /***********************************************************************
39  * Local prototypes
40  **********************************************************************/
41 static void FindNextCell( hb_dvd_t * );
42 static int  dvdtime2msec( dvd_time_t * );
43
44 /***********************************************************************
45  * hb_dvd_init
46  ***********************************************************************
47  *
48  **********************************************************************/
49 hb_dvd_t * hb_dvd_init( char * path )
50 {
51     hb_dvd_t * d;
52
53     d = calloc( sizeof( hb_dvd_t ), 1 );
54
55     /* Open device */
56     if( !( d->reader = DVDOpen( path ) ) )
57     {
58         hb_log( "dvd: DVDOpen failed (%s)", path );
59         goto fail;
60     }
61
62     /* Open main IFO */
63     if( !( d->vmg = ifoOpen( d->reader, 0 ) ) )
64     {
65         hb_log( "dvd: ifoOpen failed" );
66         goto fail;
67     }
68
69     d->path = strdup( path );
70
71     return d;
72
73 fail:
74     if( d->vmg )    ifoClose( d->vmg );
75     if( d->reader ) DVDClose( d->reader );
76     free( d );
77     return NULL;
78 }
79
80 /***********************************************************************
81  * hb_dvd_title_count
82  **********************************************************************/
83 int hb_dvd_title_count( hb_dvd_t * d )
84 {
85     return d->vmg->tt_srpt->nr_of_srpts;
86 }
87
88 /***********************************************************************
89  * hb_dvd_title_scan
90  **********************************************************************/
91 hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
92 {
93
94     hb_title_t   * title;
95     ifo_handle_t * vts = NULL;
96     int            pgc_id, pgn, i;
97     hb_chapter_t * chapter, * chapter_old;
98     int            c;
99     uint64_t       duration;
100     float          duration_correction;
101
102     title = hb_title_init( d->path, t );
103
104     hb_log( "scan: scanning title %d", t );
105
106     /* VTS which our title is in */
107     title->vts = d->vmg->tt_srpt->title[t-1].title_set_nr;
108
109     hb_log( "scan: opening IFO for VTS %d", title->vts );
110     if( !( vts = ifoOpen( d->reader, title->vts ) ) )
111     {
112         hb_log( "scan: ifoOpen failed" );
113         goto fail;
114     }
115
116     /* Position of the title in the VTS */
117     title->ttn = d->vmg->tt_srpt->title[t-1].vts_ttn;
118
119     /* Get pgc */
120     pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
121     pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
122     d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
123
124     /* Start cell */
125     title->cell_start  = d->pgc->program_map[pgn-1] - 1;
126     title->block_start = d->pgc->cell_playback[title->cell_start].first_sector;
127
128     /* End cell */
129     title->cell_end  = d->pgc->nr_of_cells - 1;
130     title->block_end = d->pgc->cell_playback[title->cell_end].last_sector;
131
132     /* Block count */
133     title->block_count = 0;
134     d->cell_cur = title->cell_start;
135     while( d->cell_cur <= title->cell_end )
136     {
137 #define cp d->pgc->cell_playback[d->cell_cur]
138         title->block_count += cp.last_sector + 1 - cp.first_sector;
139 #undef cp
140         FindNextCell( d );
141         d->cell_cur = d->cell_next;
142     }
143
144     hb_log( "scan: vts=%d, ttn=%d, cells=%d->%d, blocks=%d->%d, "
145             "%d blocks", title->vts, title->ttn, title->cell_start,
146             title->cell_end, title->block_start, title->block_end,
147             title->block_count );
148
149     if( title->block_count < 2048 )
150     {
151         hb_log( "scan: title too short (%d blocks), ignoring",
152                 title->block_count );
153         goto fail;
154     }
155
156
157     /* Get duration */
158     title->duration = 90LL * dvdtime2msec( &d->pgc->playback_time );
159     title->hours    = title->duration / 90000 / 3600;
160     title->minutes  = ( ( title->duration / 90000 ) % 3600 ) / 60;
161     title->seconds  = ( title->duration / 90000 ) % 60;
162     hb_log( "scan: duration is %02d:%02d:%02d (%lld ms)",
163             title->hours, title->minutes, title->seconds,
164             title->duration / 90 );
165
166     /* Discard titles under 10 seconds */
167     if( !( title->hours | title->minutes ) && title->seconds < 10 )
168     {
169         hb_log( "scan: ignoring title (too short)" );
170         goto fail;
171     }
172
173     /* Detect languages */
174     for( i = 0; i < vts->vtsi_mat->nr_of_vts_audio_streams; i++ )
175     {
176         hb_audio_t * audio, * audio_tmp;
177         int          audio_format, lang_code, audio_control,
178                      position, j;
179
180         hb_log( "scan: checking audio %d", i + 1 );
181
182         audio = calloc( sizeof( hb_audio_t ), 1 );
183
184         audio_format  = vts->vtsi_mat->vts_audio_attr[i].audio_format;
185         lang_code     = vts->vtsi_mat->vts_audio_attr[i].lang_code;
186         audio_control =
187             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->audio_control[i];
188
189         if( !( audio_control & 0x8000 ) )
190         {
191             hb_log( "scan: audio channel is not active" );
192             free( audio );
193             continue;
194         }
195
196         position = ( audio_control & 0x7F00 ) >> 8;
197
198         switch( audio_format )
199         {
200             case 0x00:
201                 audio->id    = ( ( 0x80 + position ) << 8 ) | 0xbd;
202                 audio->codec = HB_ACODEC_AC3;
203                 break;
204
205             case 0x02:
206             case 0x03:
207                 audio->id    = 0xc0 + position;
208                 audio->codec = HB_ACODEC_MPGA;
209                 break;
210
211             case 0x04:
212                 audio->id    = ( ( 0xa0 + position ) << 8 ) | 0xbd;
213                 audio->codec = HB_ACODEC_LPCM;
214                 break;
215
216             default:
217                 audio->id    = 0;
218                 audio->codec = 0;
219                 hb_log( "scan: unknown audio codec (%x)",
220                         audio_format );
221                 break;
222         }
223         if( !audio->id )
224         {
225             continue;
226         }
227
228         /* Check for duplicate tracks */
229         audio_tmp = NULL;
230         for( j = 0; j < hb_list_count( title->list_audio ); j++ )
231         {
232             audio_tmp = hb_list_item( title->list_audio, j );
233             if( audio->id == audio_tmp->id )
234             {
235                 break;
236             }
237             audio_tmp = NULL;
238         }
239         if( audio_tmp )
240         {
241             hb_log( "scan: duplicate audio track" );
242             free( audio );
243             continue;
244         }
245
246         snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)",
247             lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code ),
248             audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec ==
249                 HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) );
250         snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s",
251                   lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code ) );
252
253         hb_log( "scan: id=%x, lang=%s", audio->id,
254                 audio->lang );
255
256         hb_list_add( title->list_audio, audio );
257     }
258
259     if( !hb_list_count( title->list_audio ) )
260     {
261         hb_log( "scan: ignoring title (no audio track)" );
262         goto fail;
263     }
264
265     memcpy( title->palette,
266             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->palette,
267             16 * sizeof( uint32_t ) );
268
269     /* Check for subtitles */
270     for( i = 0; i < vts->vtsi_mat->nr_of_vts_subp_streams; i++ )
271     {
272         hb_subtitle_t * subtitle;
273         int spu_control;
274         int position;
275
276         hb_log( "scan: checking subtitle %d", i + 1 );
277
278         spu_control =
279             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->subp_control[i];
280
281         if( !( spu_control & 0x80000000 ) )
282         {
283             hb_log( "scan: subtitle channel is not active" );
284             continue;
285         }
286
287         if( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
288         {
289             switch( vts->vtsi_mat->vts_video_attr.permitted_df )
290             {
291                 case 1:
292                     position = spu_control & 0xFF;
293                     break;
294                 case 2:
295                     position = ( spu_control >> 8 ) & 0xFF;
296                     break;
297                 default:
298                     position = ( spu_control >> 16 ) & 0xFF;
299             }
300         }
301         else
302         {
303             position = ( spu_control >> 24 ) & 0x7F;
304         }
305
306         subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
307         subtitle->id = ( ( 0x20 + position ) << 8 ) | 0xbd;
308         snprintf( subtitle->lang, sizeof( subtitle->lang ), "%s",
309             lang_for_code( vts->vtsi_mat->vts_subp_attr[i].lang_code ) );
310
311         hb_log( "scan: id=%x, lang=%s", subtitle->id,
312                 subtitle->lang );
313
314         hb_list_add( title->list_subtitle, subtitle );
315     }
316
317     /* Chapters */
318     hb_log( "scan: title %d has %d chapters", t,
319             vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts );
320     for( i = 0, c = 1;
321          i < vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts; i++ )
322     {
323         int pgc_id_next, pgn_next;
324         pgc_t * pgc_next;
325
326         chapter = calloc( sizeof( hb_chapter_t ), 1 );
327         chapter->index = c;
328
329         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
330         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
331         d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
332
333         /* Start cell */
334         chapter->cell_start  = d->pgc->program_map[pgn-1] - 1;
335         chapter->block_start =
336             d->pgc->cell_playback[chapter->cell_start].first_sector;
337
338         /* End cell */
339         if( i != vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts - 1 )
340         {
341             /* The cell before the starting cell of the next chapter,
342                or... */
343             pgc_id_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgcn;
344             pgn_next    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgn;
345             pgc_next    = vts->vts_pgcit->pgci_srp[pgc_id_next-1].pgc;
346             chapter->cell_end = pgc_next->program_map[pgn_next-1] - 2;
347             if( chapter->cell_end < 0 )
348             {
349                 /* Huh? */
350                 free( chapter );
351                 continue;
352             }
353         }
354         else
355         {
356             /* ... the last cell of the title */
357             chapter->cell_end = title->cell_end;
358         }
359         chapter->block_end =
360             d->pgc->cell_playback[chapter->cell_end].last_sector;
361
362         /* Block count, duration */
363         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
364         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
365         d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
366         chapter->block_count = 0;
367         chapter->duration = 0;
368
369         d->cell_cur = chapter->cell_start;
370         while( d->cell_cur <= chapter->cell_end )
371         {
372 #define cp d->pgc->cell_playback[d->cell_cur]
373             chapter->block_count += cp.last_sector + 1 - cp.first_sector;
374             chapter->duration += 90LL * dvdtime2msec( &cp.playback_time );
375 #undef cp
376             FindNextCell( d );
377             d->cell_cur = d->cell_next;
378         }
379
380         if( chapter->block_count < 2048 && chapter->index > 1 )
381         {
382             hb_log( "scan: chapter %d too short (%d blocks, "
383                     "cells=%d->%d), merging", chapter->index,
384                     chapter->block_count, chapter->cell_start,
385                     chapter->cell_end );
386             chapter_old = hb_list_item( title->list_chapter,
387                                         chapter->index - 2 );
388             chapter_old->cell_end    = chapter->cell_end;
389             chapter_old->block_end   = chapter->block_end;
390             chapter_old->block_count += chapter->block_count;
391             free( chapter );
392             chapter = chapter_old;
393         }
394         else
395         {
396             hb_list_add( title->list_chapter, chapter );
397             c++;
398         }
399     }
400
401     /* The durations we get for chapters aren't precise. Scale them so
402        the total matches the title duration */
403     duration = 0;
404     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
405     {
406         chapter = hb_list_item( title->list_chapter, i );
407         duration += chapter->duration;
408     }
409     duration_correction = (float) title->duration / (float) duration;
410     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
411     {
412         int seconds;
413         chapter            = hb_list_item( title->list_chapter, i );
414         chapter->duration  = duration_correction * chapter->duration;
415         seconds            = ( chapter->duration + 45000 ) / 90000;
416         chapter->hours     = seconds / 3600;
417         chapter->minutes   = ( seconds % 3600 ) / 60;
418         chapter->seconds   = seconds % 60;
419
420         hb_log( "scan: chap %d c=%d->%d, b=%d->%d (%d), %lld ms",
421                 chapter->index, chapter->cell_start, chapter->cell_end,
422                 chapter->block_start, chapter->block_end,
423                 chapter->block_count, chapter->duration / 90 );
424     }
425
426     /* Get aspect. We don't get width/height/rate infos here as
427        they tend to be wrong */
428     switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
429     {
430         case 0:
431             title->aspect = HB_ASPECT_BASE * 4 / 3;
432             break;
433         case 3:
434             title->aspect = HB_ASPECT_BASE * 16 / 9;
435             break;
436         default:
437             hb_log( "scan: unknown aspect" );
438             goto fail;
439     }
440
441     hb_log( "scan: aspect = %d", title->aspect );
442
443     /* This title is ok so far */
444     goto cleanup;
445
446 fail:
447     hb_list_close( &title->list_audio );
448     free( title );
449     title = NULL;
450
451 cleanup:
452     if( vts ) ifoClose( vts );
453
454     return title;
455 }
456
457 /***********************************************************************
458  * hb_dvd_start
459  ***********************************************************************
460  * Title and chapter start at 1
461  **********************************************************************/
462 int hb_dvd_start( hb_dvd_t * d, int title, int chapter )
463 {
464     int pgc_id, pgn;
465     int i;
466
467     /* Open the IFO and the VOBs for this title */
468     d->vts = d->vmg->tt_srpt->title[title-1].title_set_nr;
469     d->ttn = d->vmg->tt_srpt->title[title-1].vts_ttn;
470     if( !( d->ifo = ifoOpen( d->reader, d->vts ) ) )
471     {
472         hb_log( "dvd: ifoOpen failed for VTS %d", d->vts );
473         return 0;
474     }
475     if( !( d->file = DVDOpenFile( d->reader, d->vts,
476                                   DVD_READ_TITLE_VOBS ) ) )
477     {
478         hb_log( "dvd: DVDOpenFile failed for VTS %d", d->vts );
479         return 0;
480     }
481
482     /* Get title first and last blocks */
483     pgc_id         = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgcn;
484     pgn            = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgn;
485     d->pgc         = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
486     d->cell_start  = d->pgc->program_map[pgn - 1] - 1;
487     d->cell_end    = d->pgc->nr_of_cells - 1;
488     d->title_start = d->pgc->cell_playback[d->cell_start].first_sector;
489     d->title_end   = d->pgc->cell_playback[d->cell_end].last_sector;
490
491     /* Block count */
492     d->title_block_count = 0;
493     for( i = d->cell_start; i <= d->cell_end; i++ )
494     {
495         d->title_block_count += d->pgc->cell_playback[i].last_sector + 1 -
496             d->pgc->cell_playback[i].first_sector;
497     }
498
499     /* Get pgc for the current chapter */
500     pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgcn;
501     pgn    = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgn;
502     d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
503
504     /* Get the two first cells */
505     d->cell_cur = d->pgc->program_map[pgn-1] - 1;
506     FindNextCell( d );
507
508     d->block     = d->pgc->cell_playback[d->cell_cur].first_sector;
509     d->next_vobu = d->block;
510     d->pack_len  = 0;
511
512     return 1;
513 }
514
515 /***********************************************************************
516  * hb_dvd_stop
517  ***********************************************************************
518  *
519  **********************************************************************/
520 void hb_dvd_stop( hb_dvd_t * d )
521 {
522     if( d->ifo )
523     {
524         ifoClose( d->ifo );
525         d->ifo = NULL;
526     }
527     if( d->file )
528     {
529         DVDCloseFile( d->file );
530         d->file = NULL;
531     }
532 }
533
534 /***********************************************************************
535  * hb_dvd_seek
536  ***********************************************************************
537  *
538  **********************************************************************/
539 int hb_dvd_seek( hb_dvd_t * d, float f )
540 {
541     int count, sizeCell;
542     int i;
543
544     count = f * d->title_block_count;
545
546     for( i = d->cell_start; i <= d->cell_end; i++ )
547     {
548         sizeCell = d->pgc->cell_playback[i].last_sector + 1 -
549             d->pgc->cell_playback[i].first_sector;
550
551         if( count < sizeCell )
552         {
553             d->cell_cur = i;
554             FindNextCell( d );
555
556             /* Now let hb_dvd_read find the next VOBU */
557             d->next_vobu = d->pgc->cell_playback[i].first_sector + count;
558             d->pack_len  = 0;
559             break;
560         }
561
562         count -= sizeCell;
563     }
564
565     if( i > d->cell_end )
566     {
567         return 0;
568     }
569
570     return 1;
571 }
572
573 /***********************************************************************
574  * hb_dvd_read
575  ***********************************************************************
576  *
577  **********************************************************************/
578 int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
579 {
580     if( !d->pack_len )
581     {
582         /* New pack */
583         dsi_t dsi_pack;
584         int   error;
585
586         error = 0;
587         
588         for( ;; )
589         {
590             int block, pack_len, next_vobu;
591
592             if( DVDReadBlocks( d->file, d->next_vobu, 1, b->data ) != 1 )
593             {
594                 hb_log( "dvd: DVDReadBlocks failed (%d)", d->next_vobu );
595                 return 0;
596             }
597
598             navRead_DSI( &dsi_pack, &b->data[DSI_START_BYTE] );
599             
600             block     = dsi_pack.dsi_gi.nv_pck_lbn;
601             pack_len  = dsi_pack.dsi_gi.vobu_ea;
602             next_vobu = block + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
603
604             if( pack_len >  0    &&
605                 pack_len <  1024 &&
606                 block    >= d->next_vobu &&
607                 ( block <= d->title_start + d->title_block_count ||
608                   block <= d->title_end ) )
609             {
610                 /* XXX
611                    This looks like a valid VOBU, but actually we are
612                    just hoping */
613                 if( error )
614                 {
615 #if 0
616                     hb_log( "dvd: found VOBU at %d (b %d, l %d, n %d)",
617                             d->next_vobu, block, pack_len, next_vobu );
618 #endif
619                 }
620                 d->block     = block;
621                 d->pack_len  = pack_len;
622                 d->next_vobu = next_vobu;
623                 break;
624             }
625
626             /* Wasn't a valid VOBU, try next block */
627             if( !error )
628             {
629 #if 0
630                 hb_log( "dvd: looking for a VOBU (%d)", d->next_vobu );
631 #endif
632             }
633
634             if( ++error > 1024 )
635             {
636                 hb_log( "dvd: couldn't find a VOBU after 1024 blocks" );
637                 return 0;
638             }
639
640             (d->next_vobu)++;
641         }
642
643         if( dsi_pack.vobu_sri.next_vobu == SRI_END_OF_CELL )
644         {
645             d->cell_cur  = d->cell_next;
646             d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
647             FindNextCell( d );
648         }
649     }
650     else
651     {
652         if( DVDReadBlocks( d->file, d->block, 1, b->data ) != 1 )
653         {
654             hb_log( "reader: DVDReadBlocks failed (%d)", d->block );
655             return 0;
656         }
657         d->pack_len--;
658     }
659
660     d->block++;
661
662     return 1;
663 }
664
665 /***********************************************************************
666  * hb_dvd_chapter
667  ***********************************************************************
668  * Returns in which chapter the next block to be read is.
669  * Chapter numbers start at 1.
670  **********************************************************************/
671 int hb_dvd_chapter( hb_dvd_t * d )
672 {
673     int     i;
674     int     pgc_id, pgn;
675     pgc_t * pgc;
676
677     for( i = 0;
678          i < d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
679          i++ )
680     {
681         /* Get pgc for chapter (i+1) */
682         pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
683         pgn    = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
684         pgc    = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
685
686         if( d->cell_cur >= pgc->program_map[pgn-1] - 1 &&
687             d->cell_cur <= pgc->nr_of_cells - 1 )
688         {
689             /* We are in this chapter */
690             return i + 1;
691         }
692     }
693
694     /* End of title */
695     return -1;
696 }
697
698 /***********************************************************************
699  * hb_dvd_close
700  ***********************************************************************
701  * Closes and frees everything
702  **********************************************************************/
703 void hb_dvd_close( hb_dvd_t ** _d )
704 {
705     hb_dvd_t * d = *_d;
706
707     if( d->vmg )
708     {
709         ifoClose( d->vmg );
710     }
711     if( d->reader )
712     {
713         DVDClose( d->reader );
714     }
715
716     free( d );
717     *_d = NULL;
718 }
719
720 /***********************************************************************
721  * FindNextCell
722  ***********************************************************************
723  * Assumes pgc and cell_cur are correctly set, and sets cell_next to the
724  * cell to be read when we will be done with cell_cur.
725  **********************************************************************/
726 static void FindNextCell( hb_dvd_t * d )
727 {
728     int i = 0;
729
730     if( d->pgc->cell_playback[d->cell_cur].block_type ==
731             BLOCK_TYPE_ANGLE_BLOCK )
732     {
733
734         while( d->pgc->cell_playback[d->cell_cur+i].block_mode !=
735                    BLOCK_MODE_LAST_CELL )
736         {
737              i++;
738         }
739         d->cell_next = d->cell_cur + i + 1;
740     }
741     else
742     {
743         d->cell_next = d->cell_cur + 1;
744     }
745 }
746
747 /***********************************************************************
748  * dvdtime2msec
749  ***********************************************************************
750  * From lsdvd
751  **********************************************************************/
752 static int dvdtime2msec(dvd_time_t * dt)
753 {
754     double frames_per_s[4] = {-1.0, 25.00, -1.0, 29.97};
755     double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];
756     long   ms;
757     ms  = (((dt->hour &   0xf0) >> 3) * 5 + (dt->hour   & 0x0f)) * 3600000;
758     ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
759     ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;
760
761     if( fps > 0 )
762     {
763         ms += ((dt->frame_u & 0x30) >> 3) * 5 +
764               (dt->frame_u & 0x0f) * 1000.0 / fps;
765     }
766
767     return ms;
768 }