/*****************************************************************************
* stream.c
*****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2004 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
/****************************************************************************
- * stream_AccessNew: create a stream from a access
+ * stream_UrlNew: create a stream from a access
****************************************************************************/
-stream_t *__stream_UrlNew( vlc_object_t *p_parent, char *psz_url )
+stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
{
- char *psz_access, *psz_demux, *psz_path;
+ char *psz_access, *psz_demux, *psz_path, *psz_dup;
access_t *p_access;
stream_t *p_res;
-
- MRLSplit( p_parent, psz_url, &psz_access, &psz_demux, &psz_path );
-
+
+ if( !psz_url ) return 0;
+
+ psz_dup = strdup( psz_url );
+ MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path );
+
/* Now try a real access */
- p_access = access2_New( p_parent, psz_access, NULL,
- psz_path, VLC_TRUE );
+ p_access = access2_New( p_parent, psz_access, psz_demux, psz_path, 0 );
+ free( psz_dup );
if( p_access == NULL )
{
msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
return NULL;
}
- p_res = stream_AccessNew( p_access, VLC_TRUE );
- if( p_res )
- {
- p_res->pf_destroy = UStreamDestroy;
- return p_res;
- }
- else
+
+ if( !( p_res = stream_AccessNew( p_access, VLC_TRUE ) ) )
{
access2_Delete( p_access );
+ return NULL;
}
+
+ p_res->pf_destroy = UStreamDestroy;
+ return p_res;
}
stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
{
access_t *p_access = (access_t*)vlc_object_find( s, VLC_OBJECT_ACCESS, FIND_PARENT );
AStreamDestroy( s );
+ vlc_object_release( p_access );
access2_Delete( p_access );
}
static void AStreamPrebufferBlock( stream_t *s )
{
stream_sys_t *p_sys = s->p_sys;
+ access_t *p_access = p_sys->p_access;
int64_t i_first = 0;
int64_t i_start;
continue;
}
+ while( b )
+ {
+ /* Append the block */
+ p_sys->block.i_size += b->i_buffer;
+ *p_sys->block.pp_last = b;
+ p_sys->block.pp_last = &b->p_next;
+
+ p_sys->stat.i_read_count++;
+ b = b->p_next;
+ }
+
+ if( p_access->info.b_prebuffered )
+ {
+ /* Access has already prebufferred - update stats and exit */
+ p_sys->stat.i_bytes = p_sys->block.i_size;
+ p_sys->stat.i_read_time = mdate() - i_start;
+ break;
+ }
+
if( i_first == 0 )
{
i_first = mdate();
msg_Dbg( s, "received first data for our buffer");
}
- /* Append the block */
- p_sys->block.i_size += b->i_buffer;
- *p_sys->block.pp_last = b;
- p_sys->block.pp_last = &b->p_next;
-
- p_sys->stat.i_read_count++;
}
p_sys->block.p_current = p_sys->block.p_first;
msleep( STREAM_DATA_WAIT );
}
- i_stop = mdate();
- /* Append the block */
- p_sys->block.i_size += b->i_buffer;
- *p_sys->block.pp_last = b;
- p_sys->block.pp_last = &b->p_next;
+ while( b )
+ {
+ i_stop = mdate();
- /* Fix p_current */
- if( p_sys->block.p_current == NULL )
- p_sys->block.p_current = b;
+ /* Append the block */
+ p_sys->block.i_size += b->i_buffer;
+ *p_sys->block.pp_last = b;
+ p_sys->block.pp_last = &b->p_next;
- /* Update stat */
- p_sys->stat.i_bytes += b->i_buffer;
- p_sys->stat.i_read_time += i_stop - i_start;
- p_sys->stat.i_read_count++;
+ /* Fix p_current */
+ if( p_sys->block.p_current == NULL )
+ p_sys->block.p_current = b;
+ /* Update stat */
+ p_sys->stat.i_bytes += b->i_buffer;
+ p_sys->stat.i_read_time += i_stop - i_start;
+ p_sys->stat.i_read_count++;
+
+ b = b->p_next;
+ i_start = mdate();
+ }
return VLC_SUCCESS;
}