- case VLC_FOURCC( 's', 'i', 'p', 'r' ):
- case VLC_FOURCC( '2', '8', '_', '8' ):
- DemuxAudioMethod1( p_demux, tk, i_pts, i_flags );
- break;
- case VLC_FOURCC( 'm','p','4','a' ):
- DemuxAudioMethod2( p_demux, tk, i_pts );
- break;
- default:
- DemuxAudioMethod3( p_demux, tk, i_pts );
- break;
- }
-}
-
-static int Demux( demux_t *p_demux )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- uint8_t header[18];
-
- if( p_sys->i_data_packets >= p_sys->i_data_packets_count &&
- p_sys->i_data_packets_count )
- {
- if( stream_Read( p_demux->s, header, 18 ) < 18 )
- return 0;
-
- if( memcmp( header, "DATA", 4 ) )
- return 0;
-
- p_sys->i_data_offset = stream_Tell( p_demux->s ) - 18;
- p_sys->i_data_size = GetDWBE( &header[4] );
- p_sys->i_data_packets_count = GetDWBE( &header[10] );
- p_sys->i_data_packets = 0;
- p_sys->i_data_offset_next = GetDWBE( &header[14] );
-
- msg_Dbg( p_demux, "entering new DATA packets=%d next=%u",
- p_sys->i_data_packets_count,
- (unsigned int)p_sys->i_data_offset_next );
- }
-
- /* Read Packet Header */
- if( stream_Read( p_demux->s, header, 12 ) < 12 )
- return 0;
- //const int i_version = GetWBE( &header[0] );
- const int i_size = GetWBE( &header[2] ) - 12;
- const int i_id = GetWBE( &header[4] );
- const int64_t i_pts = 1 + 1000 * GetDWBE( &header[6] );
- const int i_flags= header[11]; /* flags 0x02 -> keyframe */
-
- p_sys->i_data_packets++;
-
- if( i_size <= 0 )
- {
- msg_Err( p_demux, "Got a NUKK size to read. (Invalid format?)" );
- return 1;
- }
-
- assert( i_size <= sizeof(p_sys->buffer) );
-
- p_sys->i_buffer = stream_Read( p_demux->s, p_sys->buffer, i_size );
- if( p_sys->i_buffer < i_size )
- return 0;
-
- real_track_t *tk = NULL;
- for( int i = 0; i < p_sys->i_track; i++ )
- {
- if( p_sys->track[i]->i_id == i_id )
- tk = p_sys->track[i];
- }
-
- if( !tk )
- {
- msg_Warn( p_demux, "unknown track id(0x%x)", i_id );
- return 1;
- }
-
- if( tk->fmt.i_cat == VIDEO_ES )
- {
- DemuxVideo( p_demux, tk, i_pts, i_flags );
- }
- else
- {
- assert( tk->fmt.i_cat == AUDIO_ES );
- DemuxAudio( p_demux, tk, i_pts, i_flags );
- }
-
- /* Update PCR */
- mtime_t i_pcr = 0;
- for( int i = 0; i < p_sys->i_track; i++ )
- {
- real_track_t *tk = p_sys->track[i];
-
- if( i_pcr <= 0 || ( tk->i_last_dts > 0 && tk->i_last_dts > i_pcr ) )
- i_pcr = tk->i_last_dts;
- }
- if( i_pcr > 0 && i_pcr != p_sys->i_pcr )
- {
- p_sys->i_pcr = i_pcr;
- es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
- }
- return 1;
-}
-
-/*****************************************************************************
- * Control:
- *****************************************************************************/
-static int ControlGoToIndex( demux_t *p_demux, rm_index_t *p_index )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
-
- p_sys->b_seek = true;
- p_sys->i_pcr = INT64_C(1000) * p_index->i_time_offset;
- for( int i = 0; i < p_sys->i_track; i++ )
- p_sys->track[i]->i_last_dts = 0;
- return stream_Seek( p_demux->s, p_index->i_file_offset );
-}
-static int ControlSeekTime( demux_t *p_demux, mtime_t i_time )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- rm_index_t *p_index = p_sys->p_index;
-
- while( p_index->i_file_offset != 0 )
- {
- if( p_index->i_time_offset * INT64_C(1000) > i_time )
- {
- if( p_index != p_sys->p_index )
- p_index--;
- break;
- }
- p_index++;
- }
- if( p_index->i_file_offset == 0 )
- return VLC_EGENERIC;
- return ControlGoToIndex( p_demux, p_index );
-}
-static int ControlSeekByte( demux_t *p_demux, int64_t i_bytes )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- rm_index_t *p_index = p_sys->p_index;
-
- while( p_index->i_file_offset != 0 )
- {
- if( p_index->i_file_offset > i_bytes )
- {
- if( p_index != p_sys->p_index )
- p_index--;
- break;
- }
- p_index++;
- }
- if( p_index->i_file_offset == 0 )
- return VLC_EGENERIC;
- return ControlGoToIndex( p_demux, p_index );
-}
-
-static int Control( demux_t *p_demux, int i_query, va_list args )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- double f, *pf;
- int64_t i64;
- int64_t *pi64;
-
- switch( i_query )
- {
- case DEMUX_GET_POSITION:
- pf = (double*) va_arg( args, double* );
-
- /* read stream size maybe failed in rtsp streaming,
- so use duration to determin the position at first */
- if( p_sys->i_our_duration > 0 )
- {
- *pf = (double)p_sys->i_pcr / 1000.0 / p_sys->i_our_duration;
- return VLC_SUCCESS;
- }
-
- *pf = 0.0;
- i64 = stream_Size( p_demux->s );
- if( i64 > 0 )
- *pf = (double)1.0*stream_Tell( p_demux->s ) / (double)i64;
- return VLC_SUCCESS;
-
- case DEMUX_GET_TIME:
- pi64 = (int64_t*)va_arg( args, int64_t * );
-
- if( p_sys->i_our_duration > 0 )
- {
- *pi64 = p_sys->i_pcr;
- return VLC_SUCCESS;
- }
-
- /* same as GET_POSTION */
- i64 = stream_Size( p_demux->s );
- if( p_sys->i_our_duration > 0 && i64 > 0 )
- {
- *pi64 = (int64_t)( 1000.0 * p_sys->i_our_duration * stream_Tell( p_demux->s ) / i64 );
- return VLC_SUCCESS;
- }
-
- *pi64 = 0;
- return VLC_EGENERIC;
-
- case DEMUX_SET_POSITION:
- f = (double) va_arg( args, double );
- i64 = (int64_t) ( stream_Size( p_demux->s ) * f );
-
- if( !p_sys->p_index && i64 != 0 )
- {
- /* TODO seek */
- msg_Err( p_demux,"Seek No Index Real File failed!" );
- return VLC_EGENERIC; // no index!
- }
- else if( i64 == 0 )
- {
- /* it is a rtsp stream , it is specials in access/rtsp/... */
- msg_Dbg(p_demux, "Seek in real rtsp stream!");
- p_sys->i_pcr = INT64_C(1000) * ( p_sys->i_our_duration * f );
- p_sys->b_seek = true;
- return stream_Seek( p_demux->s, p_sys->i_pcr );
- }
- return ControlSeekByte( p_demux, i64 );
-
- case DEMUX_SET_TIME:
- if( !p_sys->p_index )
- return VLC_EGENERIC;
-
- i64 = (int64_t) va_arg( args, int64_t );
- return ControlSeekTime( p_demux, i64 );
-
- case DEMUX_GET_LENGTH:
- pi64 = (int64_t*)va_arg( args, int64_t * );
-
- *pi64 = 0;
- if( p_sys->i_our_duration <= 0 )
- return VLC_EGENERIC;
-
- /* our stored duration is in ms, so... */
- *pi64 = INT64_C(1000) * p_sys->i_our_duration;
- return VLC_SUCCESS;
-
- case DEMUX_GET_META:
- {
- vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
-
- /* the core will crash if we provide NULL strings, so check
- * every string first */
- if( p_sys->psz_title )
- vlc_meta_SetTitle( p_meta, p_sys->psz_title );
- if( p_sys->psz_artist )
- vlc_meta_SetArtist( p_meta, p_sys->psz_artist );
- if( p_sys->psz_copyright )
- vlc_meta_SetCopyright( p_meta, p_sys->psz_copyright );
- if( p_sys->psz_description )
- vlc_meta_SetDescription( p_meta, p_sys->psz_description );
- return VLC_SUCCESS;
- }
-
- case DEMUX_GET_FPS:
- default:
- return VLC_EGENERIC;