📄 avi.c
字号:
} p_sys->i_time = AVI_GetPTS( p_stream_master ); for( i_packet = 0; i_packet < 10; i_packet++) {#define p_stream p_sys->track[avi_pk.i_stream] avi_packet_t avi_pk; if( AVI_PacketGetHeader( p_demux, &avi_pk ) ) { return( 0 ); } if( avi_pk.i_stream >= p_sys->i_track || ( avi_pk.i_cat != AUDIO_ES && avi_pk.i_cat != VIDEO_ES ) ) { /* we haven't found an audio or video packet: * - we have seek, found first next packet * - others packets could be found, skip them */ switch( avi_pk.i_fourcc ) { case AVIFOURCC_JUNK: case AVIFOURCC_LIST: case AVIFOURCC_RIFF: return( !AVI_PacketNext( p_demux ) ? 1 : 0 ); case AVIFOURCC_idx1: if( p_sys->b_odml ) { return( !AVI_PacketNext( p_demux ) ? 1 : 0 ); } return( 0 ); /* eof */ default: msg_Warn( p_demux, "seems to have lost position, resync" ); if( AVI_PacketSearch( p_demux ) ) { msg_Err( p_demux, "resync failed" ); return( -1 ); } } } else { /* check for time */ if( __ABS( AVI_GetPTS( p_stream ) - AVI_GetPTS( p_stream_master ) )< 600*1000 ) { /* load it and send to decoder */ block_t *p_frame; if( AVI_PacketRead( p_demux, &avi_pk, &p_frame ) || p_frame == NULL ) { return( -1 ); } p_frame->i_pts = AVI_GetPTS( p_stream ) + 1; if( avi_pk.i_cat != VIDEO_ES ) p_frame->i_dts = p_frame->i_pts; else { p_frame->i_dts = p_frame->i_pts; p_frame->i_pts = 0; } //p_pes->i_rate = p_demux->stream.control.i_rate; es_out_Send( p_demux->out, p_stream->p_es, p_frame ); } else { if( AVI_PacketNext( p_demux ) ) { return( 0 ); } } /* *** update stream time position *** */ if( p_stream->i_samplesize ) { p_stream->i_idxposb += avi_pk.i_size; } else { if( p_stream->i_cat == AUDIO_ES ) { p_stream->i_blockno += p_stream->i_blocksize > 0 ? ( avi_pk.i_size + p_stream->i_blocksize - 1 ) / p_stream->i_blocksize : 1; } p_stream->i_idxposc++; } }#undef p_stream } return( 1 );}/***************************************************************************** * Seek: goto to i_date or i_percent *****************************************************************************/static int Seek( demux_t *p_demux, mtime_t i_date, int i_percent ){ demux_sys_t *p_sys = p_demux->p_sys; unsigned int i_stream; msg_Dbg( p_demux, "seek requested: %"PRId64" seconds %d%%", i_date / 1000000, i_percent ); if( p_sys->b_seekable ) { if( !p_sys->i_length ) { avi_track_t *p_stream; int64_t i_pos; /* use i_percent to create a true i_date */ msg_Warn( p_demux, "seeking without index at %d%%" " only works for interleaved files", i_percent ); if( i_percent >= 100 ) { msg_Warn( p_demux, "cannot seek so far !" ); return VLC_EGENERIC; } i_percent = __MAX( i_percent, 0 ); /* try to find chunk that is at i_percent or the file */ i_pos = __MAX( i_percent * stream_Size( p_demux->s ) / 100, p_sys->i_movi_begin ); /* search first selected stream */ for( i_stream = 0, p_stream = NULL; i_stream < p_sys->i_track; i_stream++ ) { p_stream = p_sys->track[i_stream]; if( p_stream->b_activated ) { break; } } if( !p_stream || !p_stream->b_activated ) { msg_Warn( p_demux, "cannot find any selected stream" ); return VLC_EGENERIC; } /* be sure that the index exist */ if( AVI_StreamChunkSet( p_demux, i_stream, 0 ) ) { msg_Warn( p_demux, "cannot seek" ); return VLC_EGENERIC; } while( i_pos >= p_stream->p_index[p_stream->i_idxposc].i_pos + p_stream->p_index[p_stream->i_idxposc].i_length + 8 ) { /* search after i_idxposc */ if( AVI_StreamChunkSet( p_demux, i_stream, p_stream->i_idxposc + 1 ) ) { msg_Warn( p_demux, "cannot seek" ); return VLC_EGENERIC; } } i_date = AVI_GetPTS( p_stream ); /* TODO better support for i_samplesize != 0 */ msg_Dbg( p_demux, "estimate date %"PRId64, i_date ); } /* */ for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ ) { avi_track_t *p_stream = p_sys->track[i_stream]; if( !p_stream->b_activated ) continue; AVI_TrackSeek( p_demux, i_stream, i_date ); } p_sys->i_time = i_date; msg_Dbg( p_demux, "seek: %"PRId64" seconds", p_sys->i_time /1000000 ); return VLC_SUCCESS; } else { msg_Err( p_demux, "shouldn't yet be executed" ); return VLC_EGENERIC; }}/***************************************************************************** * Control: *****************************************************************************/static double ControlGetPosition( demux_t *p_demux ){ demux_sys_t *p_sys = p_demux->p_sys; if( p_sys->i_length > 0 ) { return (double)p_sys->i_time / (double)( p_sys->i_length * (mtime_t)1000000 ); } else if( stream_Size( p_demux->s ) > 0 ) { unsigned int i; int64_t i_tmp; int64_t i64 = 0; /* search the more advanced selected es */ for( i = 0; i < p_sys->i_track; i++ ) { avi_track_t *tk = p_sys->track[i]; if( tk->b_activated && tk->i_idxposc < tk->i_idxnb ) { i_tmp = tk->p_index[tk->i_idxposc].i_pos + tk->p_index[tk->i_idxposc].i_length + 8; if( i_tmp > i64 ) { i64 = i_tmp; } } } return (double)i64 / stream_Size( p_demux->s ); } return 0.0;}static int Control( demux_t *p_demux, int i_query, va_list args ){ demux_sys_t *p_sys = p_demux->p_sys; int i; double f, *pf; int64_t i64, *pi64; vlc_meta_t *p_meta; switch( i_query ) { case DEMUX_GET_POSITION: pf = (double*)va_arg( args, double * ); *pf = ControlGetPosition( p_demux ); return VLC_SUCCESS; case DEMUX_SET_POSITION: f = (double)va_arg( args, double ); if( p_sys->b_seekable ) { i64 = (mtime_t)(1000000.0 * p_sys->i_length * f ); return Seek( p_demux, i64, (int)(f * 100) ); } else { int64_t i_pos = stream_Size( p_demux->s ) * f; return stream_Seek( p_demux->s, i_pos ); } case DEMUX_GET_TIME: pi64 = (int64_t*)va_arg( args, int64_t * ); *pi64 = p_sys->i_time; return VLC_SUCCESS; case DEMUX_SET_TIME: { int i_percent = 0; i64 = (int64_t)va_arg( args, int64_t ); if( p_sys->i_length > 0 ) { i_percent = 100 * i64 / (p_sys->i_length*1000000); } else if( p_sys->i_time > 0 ) { i_percent = (int)( 100.0 * ControlGetPosition( p_demux ) * (double)i64 / (double)p_sys->i_time ); } return Seek( p_demux, i64, i_percent ); } case DEMUX_GET_LENGTH: pi64 = (int64_t*)va_arg( args, int64_t * ); *pi64 = p_sys->i_length * (mtime_t)1000000; return VLC_SUCCESS; case DEMUX_GET_FPS: pf = (double*)va_arg( args, double * ); *pf = 0.0; for( i = 0; i < (int)p_sys->i_track; i++ ) { avi_track_t *tk = p_sys->track[i]; if( tk->i_cat == VIDEO_ES && tk->i_scale > 0) { *pf = (float)tk->i_rate / (float)tk->i_scale; break; } } return VLC_SUCCESS; case DEMUX_GET_META: p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* ); vlc_meta_Merge( p_meta, p_sys->meta ); return VLC_SUCCESS; default: return VLC_EGENERIC; }}/***************************************************************************** * Function to convert pts to chunk or byte *****************************************************************************/static mtime_t AVI_PTSToChunk( avi_track_t *tk, mtime_t i_pts ){ if( !tk->i_scale ) return (mtime_t)0; return (mtime_t)((int64_t)i_pts * (int64_t)tk->i_rate / (int64_t)tk->i_scale / (int64_t)1000000 );}static mtime_t AVI_PTSToByte( avi_track_t *tk, mtime_t i_pts ){ if( !tk->i_scale || !tk->i_samplesize ) return (mtime_t)0; return (mtime_t)((int64_t)i_pts * (int64_t)tk->i_rate / (int64_t)tk->i_scale / (int64_t)1000000 * (int64_t)tk->i_samplesize );}static mtime_t AVI_GetDPTS( avi_track_t *tk, int64_t i_count ){ mtime_t i_dpts = 0; if( !tk->i_rate ) return i_dpts; i_dpts = (mtime_t)( (int64_t)1000000 * (int64_t)i_count * (int64_t)tk->i_scale / (int64_t)tk->i_rate ); if( tk->i_samplesize ) { return i_dpts / tk->i_samplesize; } return i_dpts;}static mtime_t AVI_GetPTS( avi_track_t *tk ){ if( tk->i_samplesize ) { int64_t i_count = 0; /* we need a valid entry we will emulate one */ if( tk->i_idxposc == tk->i_idxnb ) { if( tk->i_idxposc ) { /* use the last entry */ i_count = tk->p_index[tk->i_idxnb - 1].i_lengthtotal + tk->p_index[tk->i_idxnb - 1].i_length; } } else { i_count = tk->p_index[tk->i_idxposc].i_lengthtotal; } return AVI_GetDPTS( tk, i_count + tk->i_idxposb ); } else { if( tk->i_cat == AUDIO_ES ) { return AVI_GetDPTS( tk, tk->i_blockno ); } else { return AVI_GetDPTS( tk, tk->i_idxposc ); } }}static int AVI_StreamChunkFind( demux_t *p_demux, unsigned int i_stream ){ demux_sys_t *p_sys = p_demux->p_sys; avi_packet_t avi_pk; int i_loop_count = 0; /* find first chunk of i_stream that isn't in index */ if( p_sys->i_movi_lastchunk_pos >= p_sys->i_movi_begin + 12 ) { stream_Seek( p_demux->s, p_sys->i_movi_lastchunk_pos ); if( AVI_PacketNext( p_demux ) ) { return VLC_EGENERIC; } } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -