struct
{
int64_t i_start; /* Offset of block for p_first */
- int i_offset; /* Offset for data in p_current */
+ int64_t i_offset; /* Offset for data in p_current */
block_t *p_current; /* Current block */
int i_size; /* Total amount of data in the list */
} immediate;
/* Peek temporary buffer */
- int i_peek;
+ unsigned int i_peek;
uint8_t *p_peek;
/* Stat for both method */
};
/* Method 1: */
-static int AStreamReadBlock( stream_t *s, void *p_read, int i_read );
-static int AStreamPeekBlock( stream_t *s, const uint8_t **p_peek, int i_read );
+static int AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read );
+static int AStreamPeekBlock( stream_t *s, const uint8_t **p_peek, unsigned int i_read );
static int AStreamSeekBlock( stream_t *s, int64_t i_pos );
static void AStreamPrebufferBlock( stream_t *s );
static block_t *AReadBlock( stream_t *s, bool *pb_eof );
/* Method 2 */
-static int AStreamReadStream( stream_t *s, void *p_read, int i_read );
-static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, int i_read );
+static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read );
+static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int i_read );
static int AStreamSeekStream( stream_t *s, int64_t i_pos );
static void AStreamPrebufferStream( stream_t *s );
-static int AReadStream( stream_t *s, void *p_read, int i_read );
+static int AReadStream( stream_t *s, void *p_read, unsigned int i_read );
/* Method 3 */
-static int AStreamReadImmediate( stream_t *s, void *p_read, int i_read );
-static int AStreamPeekImmediate( stream_t *s, const uint8_t **pp_peek, int i_read );
+static int AStreamReadImmediate( stream_t *s, void *p_read, unsigned int i_read );
+static int AStreamPeekImmediate( stream_t *s, const uint8_t **pp_peek, unsigned int i_read );
static int AStreamSeekImmediate( stream_t *s, int64_t i_pos );
/* Common */
s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
if( p_sys == NULL )
- {
- msg_Err( s, "Out of memory when allocating stream_sys_t" );
goto error;
- }
/* UTF16 and UTF32 text file conversion */
s->i_char_width = 1;
{
access_entry_t *p_entry = malloc( sizeof(access_entry_t) );
if( p_entry == NULL )
- {
- msg_Err( s, "Out of memory when allocating access_entry_t" );
goto error;
- }
char *psz_name, *psz_parser = psz_name = psz_list;
p_sys->p_list_access = p_access;
p_entry->psz_path = strdup( p_access->psz_path );
if( p_entry->psz_path == NULL )
{
- msg_Err( s, "Out of memory when duplicating p_access->psz_path" );
free( p_entry );
goto error;
}
p_entry = malloc( sizeof(access_entry_t) );
if( p_entry == NULL )
- {
- msg_Err( p_access, "Out of memory when allocating access_entry_t" );
goto error;
- }
p_entry->i_size = p_tmp->info.i_size;
p_entry->psz_path = psz_name;
TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
vlc_object_detach( s );
if( p_sys->method == Block ) block_ChainRelease( p_sys->block.p_first );
+ else if ( p_sys->method == Immediate ) free( p_sys->immediate.p_buffer );
else free( p_sys->stream.p_buffer );
free( p_sys->p_peek );
static void UStreamDestroy( stream_t *s )
{
- access_t *p_access = (access_t*)vlc_object_find( s, VLC_OBJECT_ACCESS, FIND_PARENT );
+ access_t *p_access = (access_t *)s->p_parent;
AStreamDestroy( s );
- vlc_object_release( p_access );
access_Delete( p_access );
}
static int AStreamRefillBlock( stream_t *s );
-static int AStreamReadBlock( stream_t *s, void *p_read, int i_read )
+static int AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
uint8_t *p_data= (uint8_t*)p_read;
- int i_data = 0;
+ unsigned int i_data = 0;
/* It means EOF */
if( p_sys->block.p_current == NULL )
{
int i_current =
p_sys->block.p_current->i_buffer - p_sys->block.i_offset;
- int i_copy = __MIN( i_current, i_read - i_data);
+ unsigned int i_copy = __MIN( (unsigned int)__MAX(i_current,0), i_read - i_data);
/* Copy data */
if( p_data )
return i_data;
}
-static int AStreamPeekBlock( stream_t *s, const uint8_t **pp_peek, int i_read )
+static int AStreamPeekBlock( stream_t *s, const uint8_t **pp_peek, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
uint8_t *p_data;
- int i_data = 0;
+ unsigned int i_data = 0;
block_t *b;
- int i_offset;
+ unsigned int i_offset;
if( p_sys->block.p_current == NULL ) return 0; /* EOF */
while( b && i_data < i_read )
{
- int i_current = b->i_buffer - i_offset;
+ unsigned int i_current = __MAX(b->i_buffer - i_offset,0);
int i_copy = __MIN( i_current, i_read - i_data );
memcpy( p_data, &b->p_buffer[i_offset], i_copy );
}
else
{
- /* Read enough data */
- while( p_sys->block.i_start + p_sys->block.i_size < i_pos )
+ do
{
+ /* Read and skip enough data */
if( AStreamRefillBlock( s ) )
return VLC_EGENERIC;
while( p_sys->block.p_current &&
- p_sys->i_pos + p_sys->block.p_current->i_buffer < i_pos )
+ p_sys->i_pos + p_sys->block.p_current->i_buffer - p_sys->block.i_offset < i_pos )
{
- p_sys->i_pos += p_sys->block.p_current->i_buffer;
+ p_sys->i_pos += p_sys->block.p_current->i_buffer - p_sys->block.i_offset;
p_sys->block.p_current = p_sys->block.p_current->p_next;
+ p_sys->block.i_offset = 0;
}
}
+ while( p_sys->block.i_start + p_sys->block.i_size < i_pos );
p_sys->block.i_offset = i_pos - p_sys->i_pos;
p_sys->i_pos = i_pos;
****************************************************************************/
static int AStreamRefillStream( stream_t *s );
-static int AStreamReadStream( stream_t *s, void *p_read, int i_read )
+static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
uint8_t *p_data = (uint8_t *)p_read;
- int i_data = 0;
+ unsigned int i_data = 0;
if( tk->i_start >= tk->i_end ) return 0; /* EOF */
{
int i_off = (tk->i_start + p_sys->stream.i_offset) %
STREAM_CACHE_TRACK_SIZE;
- int i_current =
- __MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
- STREAM_CACHE_TRACK_SIZE - i_off );
+ unsigned int i_current =
+ __MAX(0,__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
+ STREAM_CACHE_TRACK_SIZE - i_off ));
int i_copy = __MIN( i_current, i_read - i_data );
if( i_copy <= 0 ) break; /* EOF */
return i_data;
}
-static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, int i_read )
+static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
* Method 3:
****************************************************************************/
-static int AStreamReadImmediate( stream_t *s, void *p_read, int i_read )
+static int AStreamReadImmediate( stream_t *s, void *p_read, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
p_read, i_read );
#endif
- /* No buffer, do as if we were seeking. */
- if( !p_read )
- {
- /* seek within this stream if possible, else use plain old read and discard */
- access_t *p_access = p_sys->p_access;
-
- /* seeking after EOF is not what we want */
- if( !( p_access->info.b_eof ) )
- {
- bool b_aseek;
- access_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
- if( b_aseek )
- return AStreamSeekImmediate( s, p_sys->i_pos + i_read ) ? 0 : i_read;
- }
- }
-
/* First, check if we already have some data in the buffer,
* that we could copy directly */
int i_copy = __MIN( stream_buffered_size( s ), i_read );
return i_to_read + i_copy;
}
-static int AStreamPeekImmediate( stream_t *s, const uint8_t **pp_peek, int i_read )
+static int AStreamPeekImmediate( stream_t *s, const uint8_t **pp_peek, unsigned int i_read )
{
#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamPeekImmediate: %d size=%"PRId64,
i_data = (psz_eol - (char *)p_data) + 1;
p_line = realloc( p_line, i_line + i_data + s->i_char_width ); /* add \0 */
if( !p_line )
- {
- msg_Err( s, "Out of memory when reallocating p_line" );
goto error;
- }
i_data = stream_Read( s, &p_line[i_line], i_data );
if( i_data <= 0 ) break; /* Hmmm */
i_line += i_data - s->i_char_width; /* skip \n */;
/* Read data (+1 for easy \0 append) */
p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + s->i_char_width );
if( !p_line )
- {
- msg_Err( s, "Out of memory when reallocating p_line" );
goto error;
- }
i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
if( i_data <= 0 ) break; /* Hmmm */
i_line += i_data;
/* iconv */
psz_new_line = malloc( i_line );
if( psz_new_line == NULL )
- {
- msg_Err( s, "Out of memory when allocating psz_new_line" );
goto error;
- }
i_in = i_out = (size_t)i_line;
p_in = p_line;
p_out = psz_new_line;
/****************************************************************************
* Access reading/seeking wrappers to handle concatenated streams.
****************************************************************************/
-static int AReadStream( stream_t *s, void *p_read, int i_read )
+static int AReadStream( stream_t *s, void *p_read, unsigned int i_read )
{
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
if( !p_sys->i_list )
{
i_read = p_access->pf_read( p_access, p_read, i_read );
+ if( p_access->b_die )
+ vlc_object_kill( s );
if( p_input )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock );
i_read = p_sys->p_list_access->pf_read( p_sys->p_list_access, p_read,
i_read );
+ if( p_access->b_die )
+ vlc_object_kill( s );
/* If we reached an EOF then switch to the next stream in the list */
if( i_read == 0 && p_sys->i_list_index + 1 < p_sys->i_list )
if( !p_sys->i_list )
{
p_block = p_access->pf_block( p_access );
+ if( p_access->b_die )
+ vlc_object_kill( s );
if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_input && p_block && libvlc_stats (p_access) )
{
}
p_block = p_sys->p_list_access->pf_block( p_access );
+ if( p_access->b_die )
+ vlc_object_kill( s );
b_eof = p_sys->p_list_access->info.b_eof;
if( pb_eof ) *pb_eof = b_eof;
{
return p_bk;
}
+ block_Release( p_bk );
}
- if( p_bk ) block_Release( p_bk );
return NULL;
}