func: static int seek_frame_generic(AVFormatContext *s,int stream_index,int64_t timestamp,int flags) int index ; int64_t ret ; AVStream * st ; AVIndexEntry * ie ; st = s -> streams [ stream_index ]; index = av_index_search_timestamp ( st , timestamp , flags ); int av_index_search_timestamp(AVStream *st,int64_t wanted_timestamp,int flags) return ff_index_search_timestamp ( ( st -> index_entries ) , st -> nb_index_entries , wanted_timestamp , flags ) ; int ff_index_search_timestamp(const AVIndexEntry *entries,int nb_entries,int64_t wanted_timestamp,int flags) int a ; int b ; int m ; int64_t timestamp ; a = - 1; b = nb_entries; if ( b && entries [ b - 1 ] . timestamp < wanted_timestamp )  a = b - 1; while ( b - a > 1 )  m = a + b >> 1; timestamp = entries [ m ] . timestamp; if ( timestamp >= wanted_timestamp )  b = m; if ( timestamp <= wanted_timestamp )  a = m; m = ( flags & 1 ? a : b ); if ( ! ( flags & 4 ) )  while ( m >= 0 && m < nb_entries && ! ( entries [ m ] . flags & 0x1 ) )  m += ( flags & 1 ? - 1 : 1 ); if ( m == nb_entries )  return - 1 ; return m ; if ( index < 0 && st -> nb_index_entries && timestamp < st -> index_entries [ 0 ] . timestamp )  if ( index < 0 || index == st -> nb_index_entries - 1 )  AVPacket pkt ; int nonkey = 0 ; if ( st -> nb_index_entries )  ie = & st -> index_entries [ st -> nb_index_entries - 1 ]; if ( ( ret = avio_seek ( s -> pb , ie -> pos , 0 ) ) < 0 )  if ( ( ret = avio_seek ( s -> pb , s -> data_offset , 0 ) ) < 0 )  int read_status ; read_status = av_read_frame ( s , & pkt ); while ( read_status == - '\v' )  if ( read_status < 0 )  if ( stream_index == pkt . stream_index && pkt . dts > timestamp )  if ( pkt . flags & 0x1 )  if ( nonkey ++ > 1000 && ( st -> codec -> codec_id ) != AV_CODEC_ID_CDGRAPHICS )  int av_read_frame(AVFormatContext *s,AVPacket *pkt) const int genpts = s -> flags & 0x1 ; int eof = 0 ; int ret ; AVStream * st ; if ( ! genpts )  ret = ( s -> packet_buffer ? read_from_packet_buffer ( & s -> packet_buffer , & s -> packet_buffer_end , pkt ) : read_frame_internal ( s , pkt ) ); if ( ret < 0 )  AVPacketList * pktl = s -> packet_buffer ; if ( pktl )  AVPacket * next_pkt = & pktl -> pkt ; if ( next_pkt -> dts != ( ( int64_t ) 0x8000000000000000UL ) )  int wrap_bits = s -> streams [ next_pkt -> stream_index ] -> pts_wrap_bits ; int64_t last_dts = next_pkt -> dts ; while ( pktl && next_pkt -> pts == ( ( int64_t ) 0x8000000000000000UL ) )  if ( pktl -> pkt . stream_index == next_pkt -> stream_index && av_compare_mod ( ( next_pkt -> dts ) , pktl -> pkt . dts , ( 2 << wrap_bits - 1 ) ) < 0 )  if ( av_compare_mod ( pktl -> pkt . pts , pktl -> pkt . dts , ( 2 << wrap_bits - 1 ) ) )  next_pkt -> pts = pktl -> pkt . dts; if ( last_dts != ( ( int64_t ) 0x8000000000000000UL ) )  last_dts = pktl -> pkt . dts; pktl = pktl -> next; if ( eof && next_pkt -> pts == ( ( int64_t ) 0x8000000000000000UL ) && last_dts != ( ( int64_t ) 0x8000000000000000UL ) )  next_pkt -> pts = last_dts + ( next_pkt -> duration ); pktl = s -> packet_buffer; if ( ! ( next_pkt -> pts == ( ( int64_t ) 0x8000000000000000UL ) && next_pkt -> dts != ( ( int64_t ) 0x8000000000000000UL ) && ! eof ) )  ret = read_frame_internal ( s , pkt ); if ( ret < 0 )  if ( pktl && ret != - '\v' )  eof = 1; if ( av_dup_packet ( add_to_pktbuf ( & s -> packet_buffer , pkt , & s -> packet_buffer_end ) ) < 0 )  static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer,AVPacket *pkt,AVPacketList **plast_pktl) AVPacketList * pktl = ( av_mallocz ( sizeof ( AVPacketList ) ) ) ; if ( ! pktl )  return ( ( void * ) 0 ) ; pktl -> pkt = * pkt; return & pktl -> pkt ; st = s -> streams [ pkt -> stream_index ]; if ( st -> skip_samples )  st -> skip_samples = 0; if ( s -> iformat -> flags & 0x0100 && pkt -> flags & 0x1 )  av_add_index_entry ( st , pkt -> pos , pkt -> dts , 0 , 0 , 0x1 ); int av_add_index_entry(AVStream *st,int64_t pos,int64_t timestamp,int size,int distance,int flags) timestamp = wrap_timestamp ( st , timestamp ); static int64_t wrap_timestamp(AVStream *st,int64_t timestamp) return timestamp ; return ff_add_index_entry ( & st -> index_entries , & st -> nb_index_entries , & st -> index_entries_allocated_size , pos , timestamp , size , distance , flags ) ; int ff_add_index_entry(AVIndexEntry **index_entries,int *nb_index_entries,unsigned int *index_entries_allocated_size,int64_t pos,int64_t timestamp,int size,int distance,int flags) AVIndexEntry * entries ; AVIndexEntry * ie ; int index ; if ( ( ( ( unsigned int ) ( * nb_index_entries ) ) + 1 ) >= ( 2147483647 * 2U + 1U ) / sizeof ( AVIndexEntry ) )  if ( timestamp == ( ( int64_t ) 0x8000000000000000UL ) )  entries = ( av_fast_realloc ( ( * index_entries ) , index_entries_allocated_size , ( * nb_index_entries + 1 ) * sizeof ( AVIndexEntry ) ) ); if ( ! entries )  * index_entries = entries; index = ff_index_search_timestamp ( ( * index_entries ) , * nb_index_entries , timestamp , 4 ); int ff_index_search_timestamp(const AVIndexEntry *entries,int nb_entries,int64_t wanted_timestamp,int flags) int a ; int b ; int m ; int64_t timestamp ; a = - 1; b = nb_entries; if ( b && entries [ b - 1 ] . timestamp < wanted_timestamp )  a = b - 1; while ( b - a > 1 )  m = a + b >> 1; timestamp = entries [ m ] . timestamp; if ( timestamp >= wanted_timestamp )  b = m; if ( timestamp <= wanted_timestamp )  a = m; m = ( flags & 1 ? a : b ); if ( ! ( flags & 4 ) )  while ( m >= 0 && m < nb_entries && ! ( entries [ m ] . flags & 0x1 ) )  m += ( flags & 1 ? - 1 : 1 ); if ( m == nb_entries )  return - 1 ; return m ; if ( index < 0 )  ie = & entries [ index ]; if ( ie -> timestamp != timestamp )  if ( ie -> timestamp <= timestamp )  memmove ( ( entries + index + 1 ) , ( entries + index ) , sizeof ( AVIndexEntry ) * ( * nb_index_entries - index ) ); 