+/*****************************************************************************
+ * ReadRealIndex:
+ *****************************************************************************/
+
+static void ReadRealIndex( demux_t *p_demux )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ uint8_t buffer[100];
+ uint32_t i_id;
+ uint32_t i_size;
+ int i_version;
+ unsigned int i;
+
+ uint32_t i_index_count;
+
+ if ( p_sys->i_index_offset == 0 )
+ return;
+
+ stream_Seek( p_demux->s, p_sys->i_index_offset );
+
+ if ( stream_Read( p_demux->s, buffer, 20 ) < 20 )
+ return ;
+
+ i_id = VLC_FOURCC( buffer[0], buffer[1], buffer[2], buffer[3] );
+ i_size = GetDWBE( &buffer[4] );
+ i_version = GetWBE( &buffer[8] );
+
+ msg_Dbg( p_demux, "Real index %4.4s size=%d version=%d",
+ (char*)&i_id, i_size, i_version );
+
+ if( (i_size < 20) && (i_id != VLC_FOURCC('I','N','D','X')) )
+ return;
+
+ i_index_count = GetDWBE( &buffer[10] );
+
+ msg_Dbg( p_demux, "Real Index : num : %d ", i_index_count );
+
+ if( i_index_count == 0 )
+ return;
+
+ if( GetDWBE( &buffer[16] ) > 0 )
+ msg_Dbg( p_demux, "Real Index: Does next index exist? %d ",
+ GetDWBE( &buffer[16] ) );
+
+ p_sys->p_index =
+ (rm_index_t *)malloc( sizeof( rm_index_t ) * (i_index_count+1) );
+ if( p_sys->p_index == NULL )
+ {
+ msg_Err( p_demux, "Memory allocation error" );
+ return;
+ }
+
+ memset( p_sys->p_index, 0, sizeof(rm_index_t) * (i_index_count+1) );
+
+ for( i=0; i<i_index_count; i++ )
+ {
+ if( stream_Read( p_demux->s, buffer, 14 ) < 14 )
+ return ;
+
+ if( GetWBE( &buffer[0] ) != 0 )
+ {
+ msg_Dbg( p_demux, "Real Index: invaild version of index entry %d ",
+ GetWBE( &buffer[0] ) );
+ return;
+ }
+
+ p_sys->p_index[i].time_offset = GetDWBE( &buffer[2] );
+ p_sys->p_index[i].file_offset = GetDWBE( &buffer[6] );
+ p_sys->p_index[i].frame_index = GetDWBE( &buffer[10] );
+ msg_Dbg( p_demux, "Real Index: time %d file %d frame %d ",
+ p_sys->p_index[i].time_offset,
+ p_sys->p_index[i].file_offset,
+ p_sys->p_index[i].frame_index );
+
+ }
+}
+