From: Steve Lhomme Date: Sat, 5 Mar 2005 14:02:39 +0000 (+0000) Subject: dvdread.c: fix the title duration & time reports X-Git-Tag: 0.8.2~968 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=286a9420a21325a49fdd3b56d721ca3d8e90cde8;p=vlc dvdread.c: fix the title duration & time reports --- diff --git a/modules/access/dvdread.c b/modules/access/dvdread.c index cc35ac75ec..17e58d4382 100644 --- a/modules/access/dvdread.c +++ b/modules/access/dvdread.c @@ -300,6 +300,44 @@ static void Close( vlc_object_t *p_this ) free( p_sys ); } +static int64_t dvdtime_to_time( dvd_time_t *dtime, uint8_t still_time ) +{ +/* Macro to convert Binary Coded Decimal to Decimal */ +#define BCD2D(__x__) (((__x__ & 0xf0) >> 4) * 10 + (__x__ & 0x0f)) + + double f_fps, f_ms; + int64_t i_micro_second = 0; + + if (still_time == 0 || still_time == 0xFF) + { + i_micro_second += (int64_t)(BCD2D(dtime->hour)) * 60 * 60 * 1000000; + i_micro_second += (int64_t)(BCD2D(dtime->minute)) * 60 * 1000000; + i_micro_second += (int64_t)(BCD2D(dtime->second)) * 1000000; + + switch((dtime->frame_u & 0xc0) >> 6) + { + case 1: + f_fps = 25.0; + break; + case 3: + f_fps = 29.97; + break; + default: + f_fps = 2500.0; + break; + } + f_ms = BCD2D(dtime->frame_u&0x3f) * 1000.0 / f_fps; + i_micro_second += (int64_t)(f_ms * 1000.0); + } + else + { + i_micro_second = still_time; + i_micro_second = (int64_t)((double)i_micro_second * 1000000.0); + } + + return i_micro_second; +} + /***************************************************************************** * Control: *****************************************************************************/ @@ -347,10 +385,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) case DEMUX_GET_LENGTH: pi64 = (int64_t*)va_arg( args, int64_t * ); - if( p_sys->i_mux_rate > 0 ) + if (p_demux->info.i_title >= 0 && p_demux->info.i_title < p_sys->i_titles) { - *pi64 = (int64_t)1000000 * DVD_VIDEO_LB_LEN * - p_sys->i_title_blocks / 50 / p_sys->i_mux_rate; + *pi64 = dvdtime_to_time( &p_sys->p_cur_pgc->playback_time, 0 ); + p_sys->i_mux_rate = p_sys->i_title_blocks * DVD_VIDEO_LB_LEN / (*pi64 / 20000); return VLC_SUCCESS; } *pi64 = 0; @@ -571,7 +609,7 @@ static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt ) if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) ) { es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr ); - if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate; +/* if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;*/ } block_Release( p_pkt ); break;