Commit 286a9420 authored by Steve Lhomme's avatar Steve Lhomme

dvdread.c: fix the title duration & time reports

parent d2a821e0
...@@ -300,6 +300,44 @@ static void Close( vlc_object_t *p_this ) ...@@ -300,6 +300,44 @@ static void Close( vlc_object_t *p_this )
free( p_sys ); 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: * Control:
*****************************************************************************/ *****************************************************************************/
...@@ -347,10 +385,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -347,10 +385,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_GET_LENGTH: case DEMUX_GET_LENGTH:
pi64 = (int64_t*)va_arg( args, int64_t * ); 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 * *pi64 = dvdtime_to_time( &p_sys->p_cur_pgc->playback_time, 0 );
p_sys->i_title_blocks / 50 / p_sys->i_mux_rate; p_sys->i_mux_rate = p_sys->i_title_blocks * DVD_VIDEO_LB_LEN / (*pi64 / 20000);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
*pi64 = 0; *pi64 = 0;
...@@ -571,7 +609,7 @@ static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt ) ...@@ -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 ) ) if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
{ {
es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr ); 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 ); block_Release( p_pkt );
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment