1 /* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
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. */
10 #include "dvdread/ifo_read.h"
11 #include "dvdread/nav_read.h"
17 dvd_reader_t * reader;
30 int title_block_count;
41 /***********************************************************************
43 **********************************************************************/
44 static void FindNextCell( hb_dvd_t * );
45 static int dvdtime2msec( dvd_time_t * );
47 char * hb_dvd_name( char * path )
49 static char name[1024];
50 unsigned char unused[1024];
51 dvd_reader_t * reader;
53 reader = DVDOpen( path );
59 if( DVDUDFVolumeInfo( reader, name, sizeof( name ),
60 unused, sizeof( unused ) ) )
70 /***********************************************************************
72 ***********************************************************************
74 **********************************************************************/
75 hb_dvd_t * hb_dvd_init( char * path )
79 d = calloc( sizeof( hb_dvd_t ), 1 );
82 if( !( d->reader = DVDOpen( path ) ) )
84 hb_error( "dvd: DVDOpen failed (%s)", path );
89 if( !( d->vmg = ifoOpen( d->reader, 0 ) ) )
91 hb_error( "dvd: ifoOpen failed" );
95 d->path = strdup( path );
100 if( d->vmg ) ifoClose( d->vmg );
101 if( d->reader ) DVDClose( d->reader );
106 /***********************************************************************
108 **********************************************************************/
109 int hb_dvd_title_count( hb_dvd_t * d )
111 return d->vmg->tt_srpt->nr_of_srpts;
114 /***********************************************************************
116 **********************************************************************/
117 hb_title_t * hb_dvd_title_scan( hb_dvd_t * d, int t )
121 ifo_handle_t * vts = NULL;
123 hb_chapter_t * chapter, * chapter_old;
126 float duration_correction;
127 unsigned char unused[1024];
129 hb_log( "scan: scanning title %d", t );
131 title = hb_title_init( d->path, t );
132 if( DVDUDFVolumeInfo( d->reader, title->name, sizeof( title->name ),
133 unused, sizeof( unused ) ) )
135 char * p_cur, * p_last = d->path;
136 for( p_cur = d->path; *p_cur; p_cur++ )
138 if( p_cur[0] == '/' && p_cur[1] )
143 snprintf( title->name, sizeof( title->name ), "%s", p_last );
146 /* VTS which our title is in */
147 title->vts = d->vmg->tt_srpt->title[t-1].title_set_nr;
151 /* A VTS of 0 means the title wasn't found in the title set */
152 hb_error("Invalid VTS (title set) number: %i", title->vts);
156 hb_log( "scan: opening IFO for VTS %d", title->vts );
157 if( !( vts = ifoOpen( d->reader, title->vts ) ) )
159 hb_error( "scan: ifoOpen failed" );
163 /* Position of the title in the VTS */
164 title->ttn = d->vmg->tt_srpt->title[t-1].vts_ttn;
167 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
168 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
169 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
171 hb_log("pgc_id: %d, pgn: %d: pgc: 0x%x", pgc_id, pgn, d->pgc);
175 hb_error( "scan: pgc not valid, skipping" );
180 title->cell_start = d->pgc->program_map[pgn-1] - 1;
181 title->block_start = d->pgc->cell_playback[title->cell_start].first_sector;
184 title->cell_end = d->pgc->nr_of_cells - 1;
185 title->block_end = d->pgc->cell_playback[title->cell_end].last_sector;
188 title->block_count = 0;
189 d->cell_cur = title->cell_start;
190 while( d->cell_cur <= title->cell_end )
192 #define cp d->pgc->cell_playback[d->cell_cur]
193 title->block_count += cp.last_sector + 1 - cp.first_sector;
196 d->cell_cur = d->cell_next;
199 hb_log( "scan: vts=%d, ttn=%d, cells=%d->%d, blocks=%d->%d, "
200 "%d blocks", title->vts, title->ttn, title->cell_start,
201 title->cell_end, title->block_start, title->block_end,
202 title->block_count );
204 if( title->block_count < 2048 )
206 hb_log( "scan: title too short (%d blocks), ignoring",
207 title->block_count );
213 title->duration = 90LL * dvdtime2msec( &d->pgc->playback_time );
214 title->hours = title->duration / 90000 / 3600;
215 title->minutes = ( ( title->duration / 90000 ) % 3600 ) / 60;
216 title->seconds = ( title->duration / 90000 ) % 60;
217 hb_log( "scan: duration is %02d:%02d:%02d (%lld ms)",
218 title->hours, title->minutes, title->seconds,
219 title->duration / 90 );
221 /* Discard titles under 10 seconds */
222 if( !( title->hours | title->minutes ) && title->seconds < 10 )
224 hb_log( "scan: ignoring title (too short)" );
228 /* Detect languages */
229 for( i = 0; i < vts->vtsi_mat->nr_of_vts_audio_streams; i++ )
231 hb_audio_t * audio, * audio_tmp;
232 int audio_format, lang_code, audio_control,
234 iso639_lang_t * lang;
236 hb_log( "scan: checking audio %d", i + 1 );
238 audio = calloc( sizeof( hb_audio_t ), 1 );
240 audio_format = vts->vtsi_mat->vts_audio_attr[i].audio_format;
241 lang_code = vts->vtsi_mat->vts_audio_attr[i].lang_code;
243 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->audio_control[i];
245 if( !( audio_control & 0x8000 ) )
247 hb_log( "scan: audio channel is not active" );
252 position = ( audio_control & 0x7F00 ) >> 8;
254 switch( audio_format )
257 audio->id = ( ( 0x80 + position ) << 8 ) | 0xbd;
258 audio->codec = HB_ACODEC_AC3;
263 audio->id = 0xc0 + position;
264 audio->codec = HB_ACODEC_MPGA;
268 audio->id = ( ( 0xa0 + position ) << 8 ) | 0xbd;
269 audio->codec = HB_ACODEC_LPCM;
273 audio->id = ( ( 0x88 + position ) << 8 ) | 0xbd;
274 audio->codec = HB_ACODEC_DCA;
280 hb_log( "scan: unknown audio codec (%x)",
289 /* Check for duplicate tracks */
291 for( j = 0; j < hb_list_count( title->list_audio ); j++ )
293 audio_tmp = hb_list_item( title->list_audio, j );
294 if( audio->id == audio_tmp->id )
302 hb_log( "scan: duplicate audio track" );
307 lang = lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code );
309 snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)",
310 strlen(lang->native_name) ? lang->native_name : lang->eng_name,
311 audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec ==
312 HB_ACODEC_DCA ? "DTS" : ( audio->codec ==
313 HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) ) );
314 snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s",
315 strlen(lang->native_name) ? lang->native_name : lang->eng_name );
316 snprintf( audio->iso639_2, sizeof( audio->iso639_2 ), "%s",
319 hb_log( "scan: id=%x, lang=%s, 3cc=%s", audio->id,
320 audio->lang, audio->iso639_2 );
322 hb_list_add( title->list_audio, audio );
325 if( !hb_list_count( title->list_audio ) )
327 hb_log( "scan: ignoring title (no audio track)" );
331 memcpy( title->palette,
332 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->palette,
333 16 * sizeof( uint32_t ) );
335 /* Check for subtitles */
336 for( i = 0; i < vts->vtsi_mat->nr_of_vts_subp_streams; i++ )
338 hb_subtitle_t * subtitle;
341 iso639_lang_t * lang;
343 hb_log( "scan: checking subtitle %d", i + 1 );
346 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->subp_control[i];
348 if( !( spu_control & 0x80000000 ) )
350 hb_log( "scan: subtitle channel is not active" );
354 if( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
356 switch( vts->vtsi_mat->vts_video_attr.permitted_df )
359 position = spu_control & 0xFF;
362 position = ( spu_control >> 8 ) & 0xFF;
365 position = ( spu_control >> 16 ) & 0xFF;
370 position = ( spu_control >> 24 ) & 0x7F;
373 lang = lang_for_code( vts->vtsi_mat->vts_subp_attr[i].lang_code );
375 subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
376 subtitle->id = ( ( 0x20 + position ) << 8 ) | 0xbd;
377 snprintf( subtitle->lang, sizeof( subtitle->lang ), "%s",
378 strlen(lang->native_name) ? lang->native_name : lang->eng_name);
379 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "%s",
382 hb_log( "scan: id=%x, lang=%s, 3cc=%s", subtitle->id,
383 subtitle->lang, subtitle->iso639_2 );
385 hb_list_add( title->list_subtitle, subtitle );
389 hb_log( "scan: title %d has %d chapters", t,
390 vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts );
392 i < vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts; i++ )
394 int pgc_id_next, pgn_next;
397 chapter = calloc( sizeof( hb_chapter_t ), 1 );
398 /* remember the on-disc chapter number */
399 chapter->index = i + 1;
401 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
402 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
403 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
406 chapter->cell_start = d->pgc->program_map[pgn-1] - 1;
407 chapter->block_start =
408 d->pgc->cell_playback[chapter->cell_start].first_sector;
411 if( i != vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts - 1 )
413 /* The cell before the starting cell of the next chapter,
415 pgc_id_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgcn;
416 pgn_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgn;
417 pgc_next = vts->vts_pgcit->pgci_srp[pgc_id_next-1].pgc;
418 chapter->cell_end = pgc_next->program_map[pgn_next-1] - 2;
419 if( chapter->cell_end < 0 )
428 /* ... the last cell of the title */
429 chapter->cell_end = title->cell_end;
432 d->pgc->cell_playback[chapter->cell_end].last_sector;
434 /* Block count, duration */
435 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
436 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
437 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
438 chapter->block_count = 0;
439 chapter->duration = 0;
441 d->cell_cur = chapter->cell_start;
442 while( d->cell_cur <= chapter->cell_end )
444 #define cp d->pgc->cell_playback[d->cell_cur]
445 chapter->block_count += cp.last_sector + 1 - cp.first_sector;
446 chapter->duration += 90LL * dvdtime2msec( &cp.playback_time );
449 d->cell_cur = d->cell_next;
452 if( chapter->block_count < 2048 && c > 1 )
454 hb_log( "scan: chapter %d(%d) too short (%d blocks, "
455 "cells=%d->%d), merging", c, chapter->index,
456 chapter->block_count, chapter->cell_start,
458 chapter_old = hb_list_item( title->list_chapter, c - 2 );
459 chapter_old->cell_end = chapter->cell_end;
460 chapter_old->block_end = chapter->block_end;
461 chapter_old->block_count += chapter->block_count;
462 chapter_old->duration += chapter->duration;
464 chapter = chapter_old;
468 hb_list_add( title->list_chapter, chapter );
473 /* The durations we get for chapters aren't precise. Scale them so
474 the total matches the title duration */
476 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
478 chapter = hb_list_item( title->list_chapter, i );
479 duration += chapter->duration;
481 duration_correction = (float) title->duration / (float) duration;
482 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
485 chapter = hb_list_item( title->list_chapter, i );
486 chapter->duration = duration_correction * chapter->duration;
487 seconds = ( chapter->duration + 45000 ) / 90000;
488 chapter->hours = seconds / 3600;
489 chapter->minutes = ( seconds % 3600 ) / 60;
490 chapter->seconds = seconds % 60;
492 hb_log( "scan: chap %d c=%d->%d, b=%d->%d (%d), %lld ms",
493 chapter->index, chapter->cell_start, chapter->cell_end,
494 chapter->block_start, chapter->block_end,
495 chapter->block_count, chapter->duration / 90 );
498 /* Get aspect. We don't get width/height/rate infos here as
499 they tend to be wrong */
500 switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
503 title->aspect = HB_ASPECT_BASE * 4 / 3;
506 title->aspect = HB_ASPECT_BASE * 16 / 9;
509 hb_log( "scan: unknown aspect" );
513 hb_log( "scan: aspect = %d", title->aspect );
515 /* This title is ok so far */
519 hb_list_close( &title->list_audio );
524 if( vts ) ifoClose( vts );
529 /***********************************************************************
531 ***********************************************************************
532 * Title and chapter start at 1
533 **********************************************************************/
534 int hb_dvd_start( hb_dvd_t * d, int title, int chapter )
539 /* Open the IFO and the VOBs for this title */
540 d->vts = d->vmg->tt_srpt->title[title-1].title_set_nr;
541 d->ttn = d->vmg->tt_srpt->title[title-1].vts_ttn;
542 if( !( d->ifo = ifoOpen( d->reader, d->vts ) ) )
544 hb_error( "dvd: ifoOpen failed for VTS %d", d->vts );
547 if( !( d->file = DVDOpenFile( d->reader, d->vts,
548 DVD_READ_TITLE_VOBS ) ) )
550 hb_error( "dvd: DVDOpenFile failed for VTS %d", d->vts );
554 /* Get title first and last blocks */
555 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgcn;
556 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgn;
557 d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
558 d->cell_start = d->pgc->program_map[pgn - 1] - 1;
559 d->cell_end = d->pgc->nr_of_cells - 1;
560 d->title_start = d->pgc->cell_playback[d->cell_start].first_sector;
561 d->title_end = d->pgc->cell_playback[d->cell_end].last_sector;
564 d->title_block_count = 0;
565 for( i = d->cell_start; i <= d->cell_end; i++ )
567 d->title_block_count += d->pgc->cell_playback[i].last_sector + 1 -
568 d->pgc->cell_playback[i].first_sector;
571 /* Get pgc for the current chapter */
572 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgcn;
573 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgn;
574 d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
576 /* Get the two first cells */
577 d->cell_cur = d->pgc->program_map[pgn-1] - 1;
580 d->block = d->pgc->cell_playback[d->cell_cur].first_sector;
581 d->next_vobu = d->block;
590 /***********************************************************************
592 ***********************************************************************
594 **********************************************************************/
595 void hb_dvd_stop( hb_dvd_t * d )
604 DVDCloseFile( d->file );
609 /***********************************************************************
611 ***********************************************************************
613 **********************************************************************/
614 int hb_dvd_seek( hb_dvd_t * d, float f )
619 count = f * d->title_block_count;
621 for( i = d->cell_start; i <= d->cell_end; i++ )
623 sizeCell = d->pgc->cell_playback[i].last_sector + 1 -
624 d->pgc->cell_playback[i].first_sector;
626 if( count < sizeCell )
631 /* Now let hb_dvd_read find the next VOBU */
632 d->next_vobu = d->pgc->cell_playback[i].first_sector + count;
640 if( i > d->cell_end )
646 * Assume that we are in sync, even if we are not given that it is obvious
647 * that we are out of sync if we have just done a seek.
655 /***********************************************************************
657 ***********************************************************************/
658 int is_nav_pack( unsigned char *buf )
661 * The NAV Pack is comprised of the PCI Packet and DSI Packet, both
662 * of these start at known offsets and start with a special identifier.
665 * PCI = { 00 00 01 bf # private stream header
670 * DSI = { 00 00 01 bf # private stream header
676 * The PCI starts at offset 0x26 into the sector, and the DSI starts at 0x400
678 * This information from: http://dvd.sourceforge.net/dvdinfo/
680 if( ( buf[0x26] == 0x00 && // PCI
684 buf[0x2c] == 0x00 ) &&
685 ( buf[0x400] == 0x00 && // DSI
686 buf[0x401] == 0x00 &&
687 buf[0x402] == 0x01 &&
688 buf[0x403] == 0xbf &&
689 buf[0x406] == 0x01 ) )
698 /***********************************************************************
700 ***********************************************************************
702 **********************************************************************/
703 int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
715 int block, pack_len, next_vobu, read_retry;
717 for( read_retry = 0; read_retry < 3; read_retry++ )
719 if( DVDReadBlocks( d->file, d->next_vobu, 1, b->data ) == 1 )
726 hb_log( "dvd: Read Error on blk %d, attempt %d",
727 d->next_vobu, read_retry );
731 if( read_retry == 3 )
733 hb_log( "dvd: Unrecoverable Read Error from DVD, potential HD or DVD Failure (blk: %d)", d->next_vobu );
737 if ( !is_nav_pack( b->data ) ) {
739 if( d->in_sync == 1 ) {
740 hb_log("DVD: Lost sync, searching for NAV pack at blk %d",
747 navRead_DSI( &dsi_pack, &b->data[DSI_START_BYTE] );
749 block = dsi_pack.dsi_gi.nv_pck_lbn;
750 pack_len = dsi_pack.dsi_gi.vobu_ea;
751 next_vobu = block + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
755 block >= d->next_vobu &&
756 ( block <= d->title_start + d->title_block_count ||
757 block <= d->title_end ) )
760 This looks like a valid VOBU, but actually we are
765 hb_log( "dvd: found VOBU at %d (b %d, l %d, n %d)",
766 d->next_vobu, block, pack_len, next_vobu );
771 d->pack_len = pack_len;
772 d->next_vobu = next_vobu;
776 /* Wasn't a valid VOBU, try next block */
780 hb_log( "dvd: looking for a VOBU (%d)", d->next_vobu );
786 hb_log( "dvd: couldn't find a VOBU after 1024 blocks" );
793 if( d->in_sync == 0 || d->in_sync == 2 )
795 if( d->in_sync == 0 )
797 hb_log( "DVD: In sync with DVD at block %d", d->block );
802 if( dsi_pack.vobu_sri.next_vobu == SRI_END_OF_CELL )
804 hb_log( "DVD: End of Cell (%d) at block %d", d->cell_cur,
806 d->cell_cur = d->cell_next;
808 d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
814 // Revert the cell overlap, and check for a chapter break
815 if( dsi_pack.vobu_sri.prev_vobu == SRI_END_OF_CELL )
817 hb_log( "DVD: Beginning of Cell (%d) at block %d", d->cell_cur,
821 hb_error( "DVD: Assuming missed End of Cell (%d)", d->cell_cur );
822 d->cell_cur = d->cell_next;
823 d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
831 if( d->cell_overlap )
833 b->new_chap = hb_dvd_is_break( d );
840 if( DVDReadBlocks( d->file, d->block, 1, b->data ) != 1 )
842 hb_error( "reader: DVDReadBlocks failed (%d)", d->block );
853 /***********************************************************************
855 ***********************************************************************
856 * Returns in which chapter the next block to be read is.
857 * Chapter numbers start at 1.
858 **********************************************************************/
859 int hb_dvd_chapter( hb_dvd_t * d )
863 int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
866 for( i = nr_of_ptts - 1;
870 /* Get pgc for chapter (i+1) */
871 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
872 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
873 pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
875 if( d->cell_cur - d->cell_overlap >= pgc->program_map[pgn-1] - 1 &&
876 d->cell_cur - d->cell_overlap <= pgc->nr_of_cells - 1 )
878 /* We are in this chapter */
887 /***********************************************************************
889 ***********************************************************************
890 * Returns 1 if the current block is a new chapter start
891 **********************************************************************/
892 int hb_dvd_is_break( hb_dvd_t * d )
896 int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
898 int cell, chapter_length, cell_end;
900 for( i = nr_of_ptts - 1;
904 /* Get pgc for chapter (i+1) */
905 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
906 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
907 pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
908 cell = pgc->program_map[pgn-1] - 1;
910 if( cell <= d->cell_start )
913 // This must not match against the start cell.
914 if( pgc->cell_playback[cell].first_sector == d->block && cell != d->cell_start )
916 /* Check to see if we merged this chapter into the previous one... */
917 /* As a note, merging chapters is probably bad practice for this very reason */
920 if( i == nr_of_ptts - 1 )
922 cell_end = d->pgc->nr_of_cells;
926 cell_end = pgc->program_map[pgn] - 1;
929 for( j = cell; j < cell_end; j++ )
931 chapter_length += pgc->cell_playback[j].last_sector + 1 -
932 pgc->cell_playback[j].first_sector;
935 if( chapter_length >= 2048 )
937 hb_log("DVD: Chapter Break Cell Found");
938 /* We have a chapter break */
943 hb_log("DVD: Cell Found (len=%d)", chapter_length);
951 /***********************************************************************
953 ***********************************************************************
954 * Closes and frees everything
955 **********************************************************************/
956 void hb_dvd_close( hb_dvd_t ** _d )
966 DVDClose( d->reader );
973 /***********************************************************************
975 ***********************************************************************
976 * Assumes pgc and cell_cur are correctly set, and sets cell_next to the
977 * cell to be read when we will be done with cell_cur.
978 **********************************************************************/
979 static void FindNextCell( hb_dvd_t * d )
983 if( d->pgc->cell_playback[d->cell_cur].block_type ==
984 BLOCK_TYPE_ANGLE_BLOCK )
987 while( d->pgc->cell_playback[d->cell_cur+i].block_mode !=
988 BLOCK_MODE_LAST_CELL )
992 d->cell_next = d->cell_cur + i + 1;
993 hb_log( "DVD: Skipping multi-angle cells %d-%d",
999 d->cell_next = d->cell_cur + 1;
1003 /***********************************************************************
1005 ***********************************************************************
1007 **********************************************************************/
1008 static int dvdtime2msec(dvd_time_t * dt)
1010 double frames_per_s[4] = {-1.0, 25.00, -1.0, 29.97};
1011 double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];
1013 ms = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000;
1014 ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
1015 ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;
1019 ms += ((dt->frame_u & 0x30) >> 3) * 5 +
1020 (dt->frame_u & 0x0f) * 1000.0 / fps;