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;
149 hb_log( "scan: opening IFO for VTS %d", title->vts );
150 if( !( vts = ifoOpen( d->reader, title->vts ) ) )
152 hb_error( "scan: ifoOpen failed" );
156 /* Position of the title in the VTS */
157 title->ttn = d->vmg->tt_srpt->title[t-1].vts_ttn;
160 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
161 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
162 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
164 hb_log("pgc_id: %d, pgn: %d: pgc: 0x%x", pgc_id, pgn, d->pgc);
168 hb_error( "scan: pgc not valid, skipping" );
173 title->cell_start = d->pgc->program_map[pgn-1] - 1;
174 title->block_start = d->pgc->cell_playback[title->cell_start].first_sector;
177 title->cell_end = d->pgc->nr_of_cells - 1;
178 title->block_end = d->pgc->cell_playback[title->cell_end].last_sector;
181 title->block_count = 0;
182 d->cell_cur = title->cell_start;
183 while( d->cell_cur <= title->cell_end )
185 #define cp d->pgc->cell_playback[d->cell_cur]
186 title->block_count += cp.last_sector + 1 - cp.first_sector;
189 d->cell_cur = d->cell_next;
192 hb_log( "scan: vts=%d, ttn=%d, cells=%d->%d, blocks=%d->%d, "
193 "%d blocks", title->vts, title->ttn, title->cell_start,
194 title->cell_end, title->block_start, title->block_end,
195 title->block_count );
197 if( title->block_count < 2048 )
199 hb_log( "scan: title too short (%d blocks), ignoring",
200 title->block_count );
206 title->duration = 90LL * dvdtime2msec( &d->pgc->playback_time );
207 title->hours = title->duration / 90000 / 3600;
208 title->minutes = ( ( title->duration / 90000 ) % 3600 ) / 60;
209 title->seconds = ( title->duration / 90000 ) % 60;
210 hb_log( "scan: duration is %02d:%02d:%02d (%lld ms)",
211 title->hours, title->minutes, title->seconds,
212 title->duration / 90 );
214 /* Discard titles under 10 seconds */
215 if( !( title->hours | title->minutes ) && title->seconds < 10 )
217 hb_log( "scan: ignoring title (too short)" );
221 /* Detect languages */
222 for( i = 0; i < vts->vtsi_mat->nr_of_vts_audio_streams; i++ )
224 hb_audio_t * audio, * audio_tmp;
225 int audio_format, lang_code, audio_control,
227 iso639_lang_t * lang;
229 hb_log( "scan: checking audio %d", i + 1 );
231 audio = calloc( sizeof( hb_audio_t ), 1 );
233 audio_format = vts->vtsi_mat->vts_audio_attr[i].audio_format;
234 lang_code = vts->vtsi_mat->vts_audio_attr[i].lang_code;
236 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->audio_control[i];
238 if( !( audio_control & 0x8000 ) )
240 hb_log( "scan: audio channel is not active" );
245 position = ( audio_control & 0x7F00 ) >> 8;
247 switch( audio_format )
250 audio->id = ( ( 0x80 + position ) << 8 ) | 0xbd;
251 audio->codec = HB_ACODEC_AC3;
256 audio->id = 0xc0 + position;
257 audio->codec = HB_ACODEC_MPGA;
261 audio->id = ( ( 0xa0 + position ) << 8 ) | 0xbd;
262 audio->codec = HB_ACODEC_LPCM;
266 audio->id = ( ( 0x88 + position ) << 8 ) | 0xbd;
267 audio->codec = HB_ACODEC_DCA;
273 hb_log( "scan: unknown audio codec (%x)",
282 /* Check for duplicate tracks */
284 for( j = 0; j < hb_list_count( title->list_audio ); j++ )
286 audio_tmp = hb_list_item( title->list_audio, j );
287 if( audio->id == audio_tmp->id )
295 hb_log( "scan: duplicate audio track" );
300 lang = lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code );
302 snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)",
303 strlen(lang->native_name) ? lang->native_name : lang->eng_name,
304 audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec ==
305 HB_ACODEC_DCA ? "DTS" : ( audio->codec ==
306 HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) ) );
307 snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s",
308 strlen(lang->native_name) ? lang->native_name : lang->eng_name );
309 snprintf( audio->iso639_2, sizeof( audio->iso639_2 ), "%s",
312 hb_log( "scan: id=%x, lang=%s, 3cc=%s", audio->id,
313 audio->lang, audio->iso639_2 );
315 hb_list_add( title->list_audio, audio );
318 if( !hb_list_count( title->list_audio ) )
320 hb_log( "scan: ignoring title (no audio track)" );
324 memcpy( title->palette,
325 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->palette,
326 16 * sizeof( uint32_t ) );
328 /* Check for subtitles */
329 for( i = 0; i < vts->vtsi_mat->nr_of_vts_subp_streams; i++ )
331 hb_subtitle_t * subtitle;
334 iso639_lang_t * lang;
336 hb_log( "scan: checking subtitle %d", i + 1 );
339 vts->vts_pgcit->pgci_srp[pgc_id-1].pgc->subp_control[i];
341 if( !( spu_control & 0x80000000 ) )
343 hb_log( "scan: subtitle channel is not active" );
347 if( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
349 switch( vts->vtsi_mat->vts_video_attr.permitted_df )
352 position = spu_control & 0xFF;
355 position = ( spu_control >> 8 ) & 0xFF;
358 position = ( spu_control >> 16 ) & 0xFF;
363 position = ( spu_control >> 24 ) & 0x7F;
366 lang = lang_for_code( vts->vtsi_mat->vts_subp_attr[i].lang_code );
368 subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
369 subtitle->id = ( ( 0x20 + position ) << 8 ) | 0xbd;
370 snprintf( subtitle->lang, sizeof( subtitle->lang ), "%s",
371 strlen(lang->native_name) ? lang->native_name : lang->eng_name);
372 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "%s",
375 hb_log( "scan: id=%x, lang=%s, 3cc=%s", subtitle->id,
376 subtitle->lang, subtitle->iso639_2 );
378 hb_list_add( title->list_subtitle, subtitle );
382 hb_log( "scan: title %d has %d chapters", t,
383 vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts );
385 i < vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts; i++ )
387 int pgc_id_next, pgn_next;
390 chapter = calloc( sizeof( hb_chapter_t ), 1 );
391 /* remember the on-disc chapter number */
392 chapter->index = i + 1;
394 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
395 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
396 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
399 chapter->cell_start = d->pgc->program_map[pgn-1] - 1;
400 chapter->block_start =
401 d->pgc->cell_playback[chapter->cell_start].first_sector;
404 if( i != vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts - 1 )
406 /* The cell before the starting cell of the next chapter,
408 pgc_id_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgcn;
409 pgn_next = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i+1].pgn;
410 pgc_next = vts->vts_pgcit->pgci_srp[pgc_id_next-1].pgc;
411 chapter->cell_end = pgc_next->program_map[pgn_next-1] - 2;
412 if( chapter->cell_end < 0 )
421 /* ... the last cell of the title */
422 chapter->cell_end = title->cell_end;
425 d->pgc->cell_playback[chapter->cell_end].last_sector;
427 /* Block count, duration */
428 pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgcn;
429 pgn = vts->vts_ptt_srpt->title[title->ttn-1].ptt[0].pgn;
430 d->pgc = vts->vts_pgcit->pgci_srp[pgc_id-1].pgc;
431 chapter->block_count = 0;
432 chapter->duration = 0;
434 d->cell_cur = chapter->cell_start;
435 while( d->cell_cur <= chapter->cell_end )
437 #define cp d->pgc->cell_playback[d->cell_cur]
438 chapter->block_count += cp.last_sector + 1 - cp.first_sector;
439 chapter->duration += 90LL * dvdtime2msec( &cp.playback_time );
442 d->cell_cur = d->cell_next;
445 if( chapter->block_count < 2048 && c > 1 )
447 hb_log( "scan: chapter %d(%d) too short (%d blocks, "
448 "cells=%d->%d), merging", c, chapter->index,
449 chapter->block_count, chapter->cell_start,
451 chapter_old = hb_list_item( title->list_chapter, c - 2 );
452 chapter_old->cell_end = chapter->cell_end;
453 chapter_old->block_end = chapter->block_end;
454 chapter_old->block_count += chapter->block_count;
455 chapter_old->duration += chapter->duration;
457 chapter = chapter_old;
461 hb_list_add( title->list_chapter, chapter );
466 /* The durations we get for chapters aren't precise. Scale them so
467 the total matches the title duration */
469 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
471 chapter = hb_list_item( title->list_chapter, i );
472 duration += chapter->duration;
474 duration_correction = (float) title->duration / (float) duration;
475 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
478 chapter = hb_list_item( title->list_chapter, i );
479 chapter->duration = duration_correction * chapter->duration;
480 seconds = ( chapter->duration + 45000 ) / 90000;
481 chapter->hours = seconds / 3600;
482 chapter->minutes = ( seconds % 3600 ) / 60;
483 chapter->seconds = seconds % 60;
485 hb_log( "scan: chap %d c=%d->%d, b=%d->%d (%d), %lld ms",
486 chapter->index, chapter->cell_start, chapter->cell_end,
487 chapter->block_start, chapter->block_end,
488 chapter->block_count, chapter->duration / 90 );
491 /* Get aspect. We don't get width/height/rate infos here as
492 they tend to be wrong */
493 switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
496 title->aspect = HB_ASPECT_BASE * 4 / 3;
499 title->aspect = HB_ASPECT_BASE * 16 / 9;
502 hb_log( "scan: unknown aspect" );
506 hb_log( "scan: aspect = %d", title->aspect );
508 /* This title is ok so far */
512 hb_list_close( &title->list_audio );
517 if( vts ) ifoClose( vts );
522 /***********************************************************************
524 ***********************************************************************
525 * Title and chapter start at 1
526 **********************************************************************/
527 int hb_dvd_start( hb_dvd_t * d, int title, int chapter )
532 /* Open the IFO and the VOBs for this title */
533 d->vts = d->vmg->tt_srpt->title[title-1].title_set_nr;
534 d->ttn = d->vmg->tt_srpt->title[title-1].vts_ttn;
535 if( !( d->ifo = ifoOpen( d->reader, d->vts ) ) )
537 hb_error( "dvd: ifoOpen failed for VTS %d", d->vts );
540 if( !( d->file = DVDOpenFile( d->reader, d->vts,
541 DVD_READ_TITLE_VOBS ) ) )
543 hb_error( "dvd: DVDOpenFile failed for VTS %d", d->vts );
547 /* Get title first and last blocks */
548 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgcn;
549 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[0].pgn;
550 d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
551 d->cell_start = d->pgc->program_map[pgn - 1] - 1;
552 d->cell_end = d->pgc->nr_of_cells - 1;
553 d->title_start = d->pgc->cell_playback[d->cell_start].first_sector;
554 d->title_end = d->pgc->cell_playback[d->cell_end].last_sector;
557 d->title_block_count = 0;
558 for( i = d->cell_start; i <= d->cell_end; i++ )
560 d->title_block_count += d->pgc->cell_playback[i].last_sector + 1 -
561 d->pgc->cell_playback[i].first_sector;
564 /* Get pgc for the current chapter */
565 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgcn;
566 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[chapter-1].pgn;
567 d->pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
569 /* Get the two first cells */
570 d->cell_cur = d->pgc->program_map[pgn-1] - 1;
573 d->block = d->pgc->cell_playback[d->cell_cur].first_sector;
574 d->next_vobu = d->block;
583 /***********************************************************************
585 ***********************************************************************
587 **********************************************************************/
588 void hb_dvd_stop( hb_dvd_t * d )
597 DVDCloseFile( d->file );
602 /***********************************************************************
604 ***********************************************************************
606 **********************************************************************/
607 int hb_dvd_seek( hb_dvd_t * d, float f )
612 count = f * d->title_block_count;
614 for( i = d->cell_start; i <= d->cell_end; i++ )
616 sizeCell = d->pgc->cell_playback[i].last_sector + 1 -
617 d->pgc->cell_playback[i].first_sector;
619 if( count < sizeCell )
624 /* Now let hb_dvd_read find the next VOBU */
625 d->next_vobu = d->pgc->cell_playback[i].first_sector + count;
633 if( i > d->cell_end )
639 * Assume that we are in sync, even if we are not given that it is obvious
640 * that we are out of sync if we have just done a seek.
648 /***********************************************************************
650 ***********************************************************************/
651 int is_nav_pack( unsigned char *buf )
654 * The NAV Pack is comprised of the PCI Packet and DSI Packet, both
655 * of these start at known offsets and start with a special identifier.
658 * PCI = { 00 00 01 bf # private stream header
663 * DSI = { 00 00 01 bf # private stream header
669 * The PCI starts at offset 0x26 into the sector, and the DSI starts at 0x400
671 * This information from: http://dvd.sourceforge.net/dvdinfo/
673 if( ( buf[0x26] == 0x00 && // PCI
677 buf[0x2c] == 0x00 ) &&
678 ( buf[0x400] == 0x00 && // DSI
679 buf[0x401] == 0x00 &&
680 buf[0x402] == 0x01 &&
681 buf[0x403] == 0xbf &&
682 buf[0x406] == 0x01 ) )
691 /***********************************************************************
693 ***********************************************************************
695 **********************************************************************/
696 int hb_dvd_read( hb_dvd_t * d, hb_buffer_t * b )
708 int block, pack_len, next_vobu, read_retry;
710 for( read_retry = 0; read_retry < 3; read_retry++ )
712 if( DVDReadBlocks( d->file, d->next_vobu, 1, b->data ) == 1 )
719 hb_log( "dvd: Read Error on blk %d, attempt %d",
720 d->next_vobu, read_retry );
724 if( read_retry == 3 )
726 hb_log( "dvd: Unrecoverable Read Error from DVD, potential HD or DVD Failure (blk: %d)", d->next_vobu );
730 if ( !is_nav_pack( b->data ) ) {
732 if( d->in_sync == 1 ) {
733 hb_log("DVD: Lost sync, searching for NAV pack at blk %d",
740 navRead_DSI( &dsi_pack, &b->data[DSI_START_BYTE] );
742 block = dsi_pack.dsi_gi.nv_pck_lbn;
743 pack_len = dsi_pack.dsi_gi.vobu_ea;
744 next_vobu = block + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
748 block >= d->next_vobu &&
749 ( block <= d->title_start + d->title_block_count ||
750 block <= d->title_end ) )
753 This looks like a valid VOBU, but actually we are
758 hb_log( "dvd: found VOBU at %d (b %d, l %d, n %d)",
759 d->next_vobu, block, pack_len, next_vobu );
764 d->pack_len = pack_len;
765 d->next_vobu = next_vobu;
769 /* Wasn't a valid VOBU, try next block */
773 hb_log( "dvd: looking for a VOBU (%d)", d->next_vobu );
779 hb_log( "dvd: couldn't find a VOBU after 1024 blocks" );
786 if( d->in_sync == 0 || d->in_sync == 2 )
788 if( d->in_sync == 0 )
790 hb_log( "DVD: In sync with DVD at block %d", d->block );
795 if( dsi_pack.vobu_sri.next_vobu == SRI_END_OF_CELL )
797 hb_log( "DVD: End of Cell (%d) at block %d", d->cell_cur,
799 d->cell_cur = d->cell_next;
801 d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
807 // Revert the cell overlap, and check for a chapter break
808 if( dsi_pack.vobu_sri.prev_vobu == SRI_END_OF_CELL )
810 hb_log( "DVD: Beginning of Cell (%d) at block %d", d->cell_cur,
814 hb_error( "DVD: Assuming missed End of Cell (%d)", d->cell_cur );
815 d->cell_cur = d->cell_next;
816 d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
824 if( d->cell_overlap )
826 b->new_chap = hb_dvd_is_break( d );
833 if( DVDReadBlocks( d->file, d->block, 1, b->data ) != 1 )
835 hb_error( "reader: DVDReadBlocks failed (%d)", d->block );
846 /***********************************************************************
848 ***********************************************************************
849 * Returns in which chapter the next block to be read is.
850 * Chapter numbers start at 1.
851 **********************************************************************/
852 int hb_dvd_chapter( hb_dvd_t * d )
856 int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
859 for( i = nr_of_ptts - 1;
863 /* Get pgc for chapter (i+1) */
864 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
865 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
866 pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
868 if( d->cell_cur - d->cell_overlap >= pgc->program_map[pgn-1] - 1 &&
869 d->cell_cur - d->cell_overlap <= pgc->nr_of_cells - 1 )
871 /* We are in this chapter */
880 /***********************************************************************
882 ***********************************************************************
883 * Returns 1 if the current block is a new chapter start
884 **********************************************************************/
885 int hb_dvd_is_break( hb_dvd_t * d )
889 int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
891 int cell, chapter_length, cell_end;
893 for( i = nr_of_ptts - 1;
897 /* Get pgc for chapter (i+1) */
898 pgc_id = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgcn;
899 pgn = d->ifo->vts_ptt_srpt->title[d->ttn-1].ptt[i].pgn;
900 pgc = d->ifo->vts_pgcit->pgci_srp[pgc_id-1].pgc;
901 cell = pgc->program_map[pgn-1] - 1;
903 if( cell <= d->cell_start )
906 // This must not match against the start cell.
907 if( pgc->cell_playback[cell].first_sector == d->block && cell != d->cell_start )
909 /* Check to see if we merged this chapter into the previous one... */
910 /* As a note, merging chapters is probably bad practice for this very reason */
913 if( i == nr_of_ptts - 1 )
915 cell_end = d->pgc->nr_of_cells;
919 cell_end = pgc->program_map[pgn] - 1;
922 for( j = cell; j < cell_end; j++ )
924 chapter_length += pgc->cell_playback[j].last_sector + 1 -
925 pgc->cell_playback[j].first_sector;
928 if( chapter_length >= 2048 )
930 hb_log("DVD: Chapter Break Cell Found");
931 /* We have a chapter break */
936 hb_log("DVD: Cell Found (len=%d)", chapter_length);
944 /***********************************************************************
946 ***********************************************************************
947 * Closes and frees everything
948 **********************************************************************/
949 void hb_dvd_close( hb_dvd_t ** _d )
959 DVDClose( d->reader );
966 /***********************************************************************
968 ***********************************************************************
969 * Assumes pgc and cell_cur are correctly set, and sets cell_next to the
970 * cell to be read when we will be done with cell_cur.
971 **********************************************************************/
972 static void FindNextCell( hb_dvd_t * d )
976 if( d->pgc->cell_playback[d->cell_cur].block_type ==
977 BLOCK_TYPE_ANGLE_BLOCK )
980 while( d->pgc->cell_playback[d->cell_cur+i].block_mode !=
981 BLOCK_MODE_LAST_CELL )
985 d->cell_next = d->cell_cur + i + 1;
986 hb_log( "DVD: Skipping multi-angle cells %d-%d",
992 d->cell_next = d->cell_cur + 1;
996 /***********************************************************************
998 ***********************************************************************
1000 **********************************************************************/
1001 static int dvdtime2msec(dvd_time_t * dt)
1003 double frames_per_s[4] = {-1.0, 25.00, -1.0, 29.97};
1004 double fps = frames_per_s[(dt->frame_u & 0xc0) >> 6];
1006 ms = (((dt->hour & 0xf0) >> 3) * 5 + (dt->hour & 0x0f)) * 3600000;
1007 ms += (((dt->minute & 0xf0) >> 3) * 5 + (dt->minute & 0x0f)) * 60000;
1008 ms += (((dt->second & 0xf0) >> 3) * 5 + (dt->second & 0x0f)) * 1000;
1012 ms += ((dt->frame_u & 0x30) >> 3) * 5 +
1013 (dt->frame_u & 0x0f) * 1000.0 / fps;