OSDN Git Service

Fixed dvd_seek for titles which are not linear
[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
251         hb_log( "scan: id=%x, lang=%s", audio->id,
252                 audio->lang );
253
254         hb_list_add( title->list_audio, audio );
255     }
256
257     if( !hb_list_count( title->list_audio ) )
258     {
259         hb_log( "scan: ignoring title (no audio track)" );
260         goto fail;
261     }
262
263     memcpy( title->palette,
264             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->palette,
265             16 * sizeof( uint32_t ) );
266
267     /* Check for subtitles */
268     for( i = 0; i < vts->vtsi_mat->nr_of_vts_subp_streams; i++ )
269     {
270         hb_subtitle_t * subtitle;
271         int spu_control;
272         int position;
273
274         hb_log( "scan: checking subtitle %d", i + 1 );
275
276         spu_control =
277             vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->subp_control[i];
278
279         if( !( spu_control & 0x80000000 ) )
280         {
281             hb_log( "scan: subtitle channel is not active" );
282             continue;
283         }
284
285         if( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
286         {
287             switch( vts->vtsi_mat->vts_video_attr.permitted_df )
288             {
289                 case 1:
290                     position = spu_control & 0xFF;
291                     break;
292                 case 2:
293                     position = ( spu_control >> 8 ) & 0xFF;
294                     break;
295                 default:
296                     position = ( spu_control >> 16 ) & 0xFF;
297             }
298         }
299         else
300         {
301             position = ( spu_control >> 24 ) & 0x7F;
302         }
303
304         subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
305         subtitle->id = ( ( 0x20 + position ) << 8 ) | 0xbd;
306         snprintf( subtitle->lang, sizeof( subtitle->lang ), "%s",
307             lang_for_code( vts->vtsi_mat->vts_subp_attr[i].lang_code ) );
308
309         hb_log( "scan: id=%x, lang=%s", subtitle->id,
310                 subtitle->lang );
311
312         hb_list_add( title->list_subtitle, subtitle );
313     }
314
315     /* Chapters */
316     hb_log( "scan: title %d has %d chapters", t,
317             vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts );
318     for( i = 0, c = 1;
319          i < vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts; i++ )
320     {
321         int pgc_id_next, pgn_next;
322         pgc_t * pgc_next;
323
324         chapter = calloc( sizeof( hb_chapter_t ), 1 );
325         chapter->index = c;
326
327         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
328         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
329         d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
330
331         /* Start cell */
332         chapter->cell_start  = d->pgc->program_map[pgn-1] - 1;
333         chapter->block_start =
334             d->pgc->cell_playback[chapter->cell_start].first_sector;
335
336         /* End cell */
337         if( i != vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts - 1 )
338         {
339             /* The cell before the starting cell of the next chapter,
340                or... */
341             pgc_id_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgcn;
342             pgn_next    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgn;
343             pgc_next    = vts->vts_pgcit->pgci_srp[pgc_id_next-1].pgc;
344             chapter->cell_end = pgc_next->program_map[pgn_next-1] - 2;
345             if( chapter->cell_end < 0 )
346             {
347                 /* Huh? */
348                 free( chapter );
349                 continue;
350             }
351         }
352         else
353         {
354             /* ... the last cell of the title */
355             chapter->cell_end = title->cell_end;
356         }
357         chapter->block_end =
358             d->pgc->cell_playback[chapter->cell_end].last_sector;
359
360         /* Block count, duration */
361         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
362         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
363         d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
364         chapter->block_count = 0;
365         chapter->duration = 0;
366
367         d->cell_cur = chapter->cell_start;
368         while( d->cell_cur <= chapter->cell_end )
369         {
370 #define cp d->pgc->cell_playback[d->cell_cur]
371             chapter->block_count += cp.last_sector + 1 - cp.first_sector;
372             chapter->duration += 90LL * dvdtime2msec( &cp.playback_time );
373 #undef cp
374             FindNextCell( d );
375             d->cell_cur = d->cell_next;
376         }
377
378         if( chapter->block_count < 2048 && chapter->index > 1 )
379         {
380             hb_log( "scan: chapter %d too short (%d blocks, "
381                     "cells=%d->%d), merging", chapter->index,
382                     chapter->block_count, chapter->cell_start,
383                     chapter->cell_end );
384             chapter_old = hb_list_item( title->list_chapter,
385                                         chapter->index - 2 );
386             chapter_old->cell_end    = chapter->cell_end;
387             chapter_old->block_end   = chapter->block_end;
388             chapter_old->block_count += chapter->block_count;
389             free( chapter );
390             chapter = chapter_old;
391         }
392         else
393         {
394             hb_list_add( title->list_chapter, chapter );
395             c++;
396         }
397     }
398
399     /* The durations we get for chapters aren't precise. Scale them so
400        the total matches the title duration */
401     duration = 0;
402     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
403     {
404         chapter = hb_list_item( title->list_chapter, i );
405         duration += chapter->duration;
406     }
407     duration_correction = (float) title->duration / (float) duration;
408     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
409     {
410         int seconds;
411         chapter            = hb_list_item( title->list_chapter, i );
412         chapter->duration  = duration_correction * chapter->duration;
413         seconds            = ( chapter->duration + 45000 ) / 90000;
414         chapter->hours     = seconds / 3600;
415         chapter->minutes   = ( seconds % 3600 ) / 60;
416         chapter->seconds   = seconds % 60;
417
418         hb_log( "scan: chap %d c=%d->%d, b=%d->%d (%d), %lld ms",
419                 chapter->index, chapter->cell_start, chapter->cell_end,
420                 chapter->block_start, chapter->block_end,
421                 chapter->block_count, chapter->duration / 90 );
422     }
423
424     /* Get aspect. We don't get width/height/rate infos here as
425        they tend to be wrong */
426     switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
427     {
428         case 0:
429             title->aspect = HB_ASPECT_BASE * 4 / 3;
430             break;
431         case 3:
432             title->aspect = HB_ASPECT_BASE * 16 / 9;
433             break;
434         default:
435             hb_log( "scan: unknown aspect" );
436             goto fail;
437     }
438
439     hb_log( "scan: aspect = %d", title->aspect );
440
441     /* This title is ok so far */
442     goto cleanup;
443
444 fail:
445     hb_list_close( &title->list_audio );
446     free( title );
447     title = NULL;
448
449 cleanup:
450     if( vts ) ifoClose( vts );
451
452     return title;
453 }
454
455 /***********************************************************************
456  * hb_dvd_start
457  ***********************************************************************
458  * Title and chapter start at 1
459  **********************************************************************/
460 int hb_dvd_start( hb_dvd_t * d, int title, int chapter )
461 {
462     int pgc_id, pgn;
463     int i;
464
465     /* Open the IFO and the VOBs for this title */
466     d->vts = d->vmg->tt_srpt->title[title-1].title_set_nr;
467     d->ttn = d->vmg->tt_srpt->title[title-1].vts_ttn;
468     if( !( d->ifo = ifoOpen( d->reader, d->vts ) ) )
469     {
470         hb_log( "dvd: ifoOpen failed for VTS %d", d->vts );
471         return 0;
472     }
473     if( !( d->file = DVDOpenFile( d->reader, d->vts,
474                                   DVD_READ_TITLE_VOBS ) ) )
475     {
476         hb_log( "dvd: DVDOpenFile failed for VTS %d", d->vts );
477         return 0;
478     }
479
480     /* Get title first and last blocks */
481     pgc_id         = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgcn;
482     pgn            = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgn;
483     d->pgc         = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
484     d->cell_start  = d->pgc->program_map[pgn - 1] - 1;
485     d->cell_end    = d->pgc->nr_of_cells - 1;
486     d->title_start = d->pgc->cell_playback[d->cell_start].first_sector;
487     d->title_end   = d->pgc->cell_playback[d->cell_end].last_sector;
488
489     /* Block count */
490     d->title_block_count = 0;
491     for( i = d->cell_start; i <= d->cell_end; i++ )
492     {
493         d->title_block_count += d->pgc->cell_playback[i].last_sector + 1 -
494             d->pgc->cell_playback[i].first_sector;
495     }
496
497     /* Get pgc for the current chapter */
498     pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgcn;
499     pgn    = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgn;
500     d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
501
502     /* Get the two first cells */
503     d->cell_cur = d->pgc->program_map[pgn-1] - 1;
504     FindNextCell( d );
505
506     d->block     = d->pgc->cell_playback[d->cell_cur].first_sector;
507     d->next_vobu = d->block;
508     d->pack_len  = 0;
509
510     return 1;
511 }
512
513 /***********************************************************************
514  * hb_dvd_stop
515  ***********************************************************************
516  *
517  **********************************************************************/
518 void hb_dvd_stop( hb_dvd_t * d )
519 {
520     if( d->ifo )
521     {
522         ifoClose( d->ifo );
523         d->ifo = NULL;
524     }
525     if( d->file )
526     {
527         DVDCloseFile( d->file );
528         d->file = NULL;
529     }
530 }
531
532 /***********************************************************************
533  * hb_dvd_seek
534  ***********************************************************************
535  *
536  **********************************************************************/
537 int hb_dvd_seek( hb_dvd_t * d, float f )
538 {
539     int count, sizeCell;
540     int i;
541
542     count = f * d->title_block_count;
543
544     for( i = d->cell_start; i <= d->cell_end; i++ )
545     {
546         sizeCell = d->pgc->cell_playback[i].last_sector + 1 -
547             d->pgc->cell_playback[i].first_sector;
548
549         if( count < sizeCell )
550         {
551             d->cell_cur = i;
552             FindNextCell( d );
553
554             /* Now let hb_dvd_read find the next VOBU */
555             d->next_vobu = d->pgc->cell_playback[i].first_sector + count;
556             d->pack_len  = 0;
557             break;
558         }
559
560         count -= sizeCell;
561     }
562
563     if( i > d->cell_end )
564     {
565         return 0;
566     }
567
568     return 1;
569 }
570
571 /***********************************************************************
572  * hb_dvd_read
573  ***********************************************************************
574  *
575  **********************************************************************/
576 int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
577 {
578     if( !d->pack_len )
579     {
580         /* New pack */
581         dsi_t dsi_pack;
582         int   error;
583
584         error = 0;
585         
586         for( ;; )
587         {
588             int block, pack_len, next_vobu;
589
590             if( DVDReadBlocks( d->file, d->next_vobu, 1, b->data ) != 1 )
591             {
592                 hb_log( "dvd: DVDReadBlocks failed (%d)", d->next_vobu );
593                 return 0;
594             }
595
596             navRead_DSI( &dsi_pack, &b->data[DSI_START_BYTE] );
597             
598             block     = dsi_pack.dsi_gi.nv_pck_lbn;
599             pack_len  = dsi_pack.dsi_gi.vobu_ea;
600             next_vobu = block + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
601
602             if( pack_len >  0    &&
603                 pack_len <  1024 &&
604                 block    >= d->next_vobu &&
605                 ( block <= d->title_start + d->title_block_count ||
606                   block <= d->title_end ) )
607             {
608                 /* XXX
609                    This looks like a valid VOBU, but actually we are
610                    just hoping */
611                 if( error )
612                 {
613 #if 0
614                     hb_log( "dvd: found VOBU at %d (b %d, l %d, n %d)",
615                             d->next_vobu, block, pack_len, next_vobu );
616 #endif
617                 }
618                 d->block     = block;
619                 d->pack_len  = pack_len;
620                 d->next_vobu = next_vobu;
621                 break;
622             }
623
624             /* Wasn't a valid VOBU, try next block */
625             if( !error )
626             {
627 #if 0
628                 hb_log( "dvd: looking for a VOBU (%d)", d->next_vobu );
629 #endif
630             }
631
632             if( ++error > 1024 )
633             {
634                 hb_log( "dvd: couldn't find a VOBU after 1024 blocks" );
635                 return 0;
636             }
637
638             (d->next_vobu)++;
639         }
640
641         if( dsi_pack.vobu_sri.next_vobu == SRI_END_OF_CELL )
642         {
643             d->cell_cur  = d->cell_next;
644             d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
645             FindNextCell( d );
646         }
647     }
648     else
649     {
650         if( DVDReadBlocks( d->file, d->block, 1, b->data ) != 1 )
651         {
652             hb_log( "reader: DVDReadBlocks failed (%d)", d->block );
653             return 0;
654         }
655         d->pack_len--;
656     }
657
658     d->block++;
659
660     return 1;
661 }
662
663 /***********************************************************************
664  * hb_dvd_chapter
665  ***********************************************************************
666  * Returns in which chapter the next block to be read is.
667  * Chapter numbers start at 1.
668  **********************************************************************/
669 int hb_dvd_chapter( hb_dvd_t * d )
670 {
671     int     i;
672     int     pgc_id, pgn;
673     pgc_t * pgc;
674
675     for( i = 0;
676          i < d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
677          i++ )
678     {
679         /* Get pgc for chapter (i+1) */
680         pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
681         pgn    = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
682         pgc    = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
683
684         if( d->cell_cur >= pgc->program_map[pgn-1] - 1 &&
685             d->cell_cur <= pgc->nr_of_cells - 1 )
686         {
687             /* We are in this chapter */
688             return i + 1;
689         }
690     }
691
692     /* End of title */
693     return -1;
694 }
695
696 /***********************************************************************
697  * hb_dvd_close
698  ***********************************************************************
699  * Closes and frees everything
700  **********************************************************************/
701 void hb_dvd_close( hb_dvd_t ** _d )
702 {
703     hb_dvd_t * d = *_d;
704
705     if( d->vmg )
706     {
707         ifoClose( d->vmg );
708     }
709     if( d->reader )
710     {
711         DVDClose( d->reader );
712     }
713
714     free( d );
715     *_d = NULL;
716 }
717
718 /***********************************************************************
719  * FindNextCell
720  ***********************************************************************
721  * Assumes pgc and cell_cur are correctly set, and sets cell_next to the
722  * cell to be read when we will be done with cell_cur.
723  **********************************************************************/
724 static void FindNextCell( hb_dvd_t * d )
725 {
726     int i = 0;
727
728     if( d->pgc->cell_playback[d->cell_cur].block_type ==
729             BLOCK_TYPE_ANGLE_BLOCK )
730     {
731
732         while( d->pgc->cell_playback[d->cell_cur+i].block_mode !=
733                    BLOCK_MODE_LAST_CELL )
734         {
735              i++;
736         }
737         d->cell_next = d->cell_cur + i + 1;
738     }
739     else
740     {
741         d->cell_next = d->cell_cur + 1;
742     }
743 }
744
745 /***********************************************************************
746  * dvdtime2msec
747  ***********************************************************************
748  * From lsdvd
749  **********************************************************************/
750 static int dvdtime2msec(dvd_time_t * dt)
751 {
752     double frames_per_s[4] = {-1.0, 25.00, -1.0, 29.97};
753     double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];
754     long   ms;
755     ms  = (((dt->hour &   0xf0) >> 3) * 5 + (dt->hour   & 0x0f)) * 3600000;
756     ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
757     ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;
758
759     if( fps > 0 )
760     {
761         ms += ((dt->frame_u & 0x30) >> 3) * 5 +
762               (dt->frame_u & 0x0f) * 1000.0 / fps;
763     }
764
765     return ms;
766 }