STREAM_CAN_FASTSEEK, /**< arg1= bool * res=cannot fail*/
/* */
- STREAM_SET_POSITION, /**< arg1= int64_t res=can fail */
- STREAM_GET_POSITION, /**< arg1= int64_t * res=cannot fail*/
+ STREAM_SET_POSITION, /**< arg1= uint64_t res=can fail */
+ STREAM_GET_POSITION, /**< arg1= uint64_t * res=cannot fail*/
- STREAM_GET_SIZE, /**< arg1= int64_t * res=cannot fail (0 if no sense)*/
+ STREAM_GET_SIZE, /**< arg1= uint64_t * res=cannot fail (0 if no sense)*/
/* Special for direct access control from demuxer.
* XXX: avoid using it by all means */
*/
static inline int64_t stream_Tell( stream_t *s )
{
- int64_t i_pos;
+ uint64_t i_pos;
stream_Control( s, STREAM_GET_POSITION, &i_pos );
+ if( i_pos >> 62 )
+ return (int64_t)1 << 62;
return i_pos;
}
*/
static inline int64_t stream_Size( stream_t *s )
{
- int64_t i_pos;
+ uint64_t i_pos;
stream_Control( s, STREAM_GET_SIZE, &i_pos );
+ if( i_pos >> 62 )
+ return (int64_t)1 << 62;
return i_pos;
}
-static inline int stream_Seek( stream_t *s, int64_t i_pos )
+static inline int stream_Seek( stream_t *s, uint64_t i_pos )
{
return stream_Control( s, STREAM_SET_POSITION, i_pos );
}
* You must delete it using stream_Delete.
*/
#define stream_MemoryNew( a, b, c, d ) __stream_MemoryNew( VLC_OBJECT(a), b, c, d )
-VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, int64_t i_size, bool b_preserve_memory ) );
+VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, uint64_t i_size, bool b_preserve_memory ) );
/**
* Create a stream_t reading from an URL.
{
case STREAM_SET_POSITION:
{
- int64_t i_position = (int64_t)va_arg( args, int64_t );
+ uint64_t i_position = va_arg( args, uint64_t );
if( i_position >= p_sys->i_len )
return VLC_EGENERIC;
else
case STREAM_GET_POSITION:
{
- int64_t *pi_position = (int64_t*)va_arg( args, int64_t* );
+ uint64_t *pi_position = va_arg( args, uint64_t* );
*pi_position = p_sys->i_pos;
return VLC_SUCCESS;
}
case STREAM_GET_SIZE:
{
- int64_t *pi_size = (int64_t*)va_arg( args, int64_t* );
- *pi_size = (int64_t) p_sys->i_len;
+ uint64_t *pi_size = va_arg( args, uint64_t* );
+ *pi_size = p_sys->i_len;
return VLC_SUCCESS;
}
*(va_arg (args, bool *)) = false;
break;
case STREAM_GET_POSITION:
- *(va_arg (args, int64_t *)) = p_sys->offset;
+ *(va_arg (args, uint64_t *)) = p_sys->offset;
break;
case STREAM_GET_SIZE:
- *(va_arg (args, int64_t *)) = 0;
+ *(va_arg (args, uint64_t *)) = 0;
break;
default:
return VLC_EGENERIC;
typedef struct
{
- int64_t i_offset;
- int64_t i_size;
- int64_t i_cummulated_size;
+ uint64_t i_offset;
+ uint64_t i_size;
+ uint64_t i_cummulated_size;
} rar_file_chunk_t;
typedef struct
{
char *psz_name;
- int64_t i_size;
+ uint64_t i_size;
bool b_complete;
int i_chunk;
rar_file_chunk_t **pp_chunk;
- int64_t i_real_size; /* Gathered size */
+ uint64_t i_real_size; /* Gathered size */
} rar_file_t;
static void RarFileDelete( rar_file_t * );
rar_file_t *p_file;
const rar_file_chunk_t *p_chunk;
- int64_t i_position;
+ uint64_t i_position;
uint8_t *p_peek_alloc;
uint8_t *p_peek;
static int Control( stream_t *, int i_query, va_list );
static int Parse ( stream_t * );
-static int Seek ( stream_t *s, int64_t i_position );
+static int Seek ( stream_t *s, uint64_t i_position );
/****************************************************************************
* Open
while( i_total < i_read )
{
- const int64_t i_chunk_end = p_sys->p_chunk->i_cummulated_size + p_sys->p_chunk->i_size;
+ const uint64_t i_chunk_end = p_sys->p_chunk->i_cummulated_size + p_sys->p_chunk->i_size;
int i_max = __MIN( i_read - i_total, i_chunk_end - p_sys->i_position );
if( i_max <= 0 )
/* */
case STREAM_SET_POSITION:
{
- int64_t i_position = (int64_t)va_arg( args, int64_t );
+ uint64_t i_position = va_arg( args, uint64_t );
return Seek( s, i_position );
}
case STREAM_GET_POSITION:
{
- int64_t *pi_position = (int64_t*)va_arg( args, int64_t* );
+ uint64_t *pi_position = va_arg( args, uint64_t* );
*pi_position = p_sys->i_position - p_sys->i_peek;
return VLC_SUCCESS;
}
case STREAM_GET_SIZE:
{
- int64_t *pi_size = (int64_t*)va_arg( args, int64_t* );
+ uint64_t *pi_size = (uint64_t*)va_arg( args, uint64_t* );
*pi_size = p_sys->p_file->i_real_size;
return VLC_SUCCESS;
}
/****************************************************************************
* Helpers
****************************************************************************/
-static int Seek( stream_t *s, int64_t i_position )
+static int Seek( stream_t *s, uint64_t i_position )
{
stream_sys_t *p_sys = s->p_sys;
- if( i_position < 0 )
- i_position = 0;
- else if( i_position > p_sys->p_file->i_real_size )
+ if( i_position > p_sys->p_file->i_real_size )
i_position = p_sys->p_file->i_real_size;
/* Search the chunk */
p_sys->i_position = i_position;
p_sys->i_peek = 0;
- const int64_t i_seek = p_sys->p_chunk->i_offset +
- ( i_position - p_sys->p_chunk->i_cummulated_size );
+ const uint64_t i_seek = p_sys->p_chunk->i_offset +
+ ( i_position - p_sys->p_chunk->i_cummulated_size );
return stream_Seek( s->p_source, i_seek );
}
}
static int SkipBlock( stream_t *s, const rar_block_t *p_hdr )
{
- int64_t i_size = (int64_t)p_hdr->i_size + p_hdr->i_add_size;
+ uint64_t i_size = (uint64_t)p_hdr->i_size + p_hdr->i_add_size;
- assert( i_size >= 0 );
while( i_size > 0 )
{
int i_skip = __MIN( i_size, INT_MAX );
int i_min_size = 7+21;
if( p_hdr->i_flags & RAR_BLOCK_FILE_HAS_HIGH )
i_min_size += 8;
- if( p_hdr->i_size < i_min_size )
+ if( p_hdr->i_size < (unsigned)i_min_size )
return VLC_EGENERIC;
if( stream_Peek( s->p_source, &p_peek, i_min_size ) < i_min_size )
}
/* Ignore smaller files */
- const int64_t i_file_size = ((int64_t)i_file_size_high << 32) | i_file_size_low;
+ const uint64_t i_file_size = ((uint64_t)i_file_size_high << 32) | i_file_size_low;
if( p_sys->p_file &&
p_sys->p_file->i_size < i_file_size )
{
else if( bookmark.i_byte_offset >= 0 &&
p_input->p->input.p_stream )
{
- const int64_t i_size = stream_Size( p_input->p->input.p_stream );
+ const uint64_t i_size = stream_Size( p_input->p->input.p_stream );
if( i_size > 0 && bookmark.i_byte_offset <= i_size )
{
val.f_float = (double)bookmark.i_byte_offset / i_size;
{
int64_t i_date;
- int64_t i_start;
- int64_t i_end;
+ uint64_t i_start;
+ uint64_t i_end;
uint8_t *p_buffer;
typedef struct
{
char *psz_path;
- int64_t i_size;
+ uint64_t i_size;
} access_entry_t;
stream_read_method_t method; /* method to use */
- int64_t i_pos; /* Current reading offset */
+ uint64_t i_pos; /* Current reading offset */
/* Method 1: pf_block */
struct
{
- int64_t i_start; /* Offset of block for p_first */
- int64_t i_offset; /* Offset for data in p_current */
+ uint64_t i_start; /* Offset of block for p_first */
+ uint64_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 */
+ uint64_t i_size; /* Total amount of data in the list */
block_t *p_first;
block_t **pp_last;
/* Method 2: for pf_read */
struct
{
- int i_offset; /* Buffer offset in the current track */
- int i_tk; /* Current track */
+ unsigned i_offset; /* Buffer offset in the current track */
+ int i_tk; /* Current track */
stream_track_t tk[STREAM_CACHE_TRACK];
/* Global buffer */
uint8_t *p_buffer;
/* */
- int i_used; /* Used since last read */
- int i_read_size;
+ unsigned i_used; /* Used since last read */
+ unsigned i_read_size;
} stream;
bool b_fastseek; /* From access */
/* Stat about reading data */
- int64_t i_read_count;
- int64_t i_bytes;
- int64_t i_read_time;
+ uint64_t i_read_count;
+ uint64_t i_bytes;
+ uint64_t i_read_time;
/* Stat about seek */
- int i_seek_count;
- int64_t i_seek_time;
+ unsigned i_seek_count;
+ uint64_t i_seek_time;
} stat;
/* Method 1: */
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 int AStreamSeekBlock( stream_t *s, uint64_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, 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 int AStreamSeekStream( stream_t *s, uint64_t i_pos );
static void AStreamPrebufferStream( stream_t *s );
static int AReadStream( stream_t *s, void *p_read, unsigned int i_read );
static int AStreamControl( stream_t *s, int i_query, va_list );
static void AStreamDestroy( stream_t *s );
static void UStreamDestroy( stream_t *s );
-static int ASeek( stream_t *s, int64_t i_pos );
+static int ASeek( stream_t *s, uint64_t i_pos );
/****************************************************************************
* stream_CommonNew: create an empty stream structure
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
- bool *p_bool;
- int64_t *pi_64, i_64;
- int i_int;
+ bool *p_bool;
+ uint64_t *pi_64, i_64;
+ int i_int;
switch( i_query )
{
case STREAM_GET_SIZE:
- pi_64 = (int64_t*)va_arg( args, int64_t * );
+ pi_64 = va_arg( args, uint64_t * );
if( s->p_sys->i_list )
{
int i;
break;
case STREAM_GET_POSITION:
- pi_64 = (int64_t*)va_arg( args, int64_t * );
+ pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_pos;
break;
case STREAM_SET_POSITION:
- i_64 = (int64_t)va_arg( args, int64_t );
+ i_64 = va_arg( args, uint64_t );
switch( p_sys->method )
{
case STREAM_METHOD_BLOCK:
return i_data;
}
-static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
+static int AStreamSeekBlock( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
bool b_seek;
/* We already have thoses data, just update p_current/i_offset */
- if( i_offset >= 0 && i_offset < p_sys->block.i_size )
+ if( i_offset >= 0 && (uint64_t)i_offset < p_sys->block.i_size )
{
block_t *b = p_sys->block.p_first;
int i_current = 0;
- while( i_current + b->i_buffer < i_offset )
+ while( i_current + b->i_buffer < (uint64_t)i_offset )
{
i_current += b->i_buffer;
b = b->p_next;
if( !p_read )
{
- const int64_t i_pos_wanted = p_sys->i_pos + i_read;
+ const uint64_t i_pos_wanted = p_sys->i_pos + i_read;
if( AStreamSeekStream( s, i_pos_wanted ) )
{
{
stream_sys_t *p_sys = s->p_sys;
stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
- int64_t i_off;
+ uint64_t i_off;
if( tk->i_start >= tk->i_end ) return 0; /* EOF */
if( i_read > STREAM_CACHE_TRACK_SIZE / 2 )
i_read = STREAM_CACHE_TRACK_SIZE / 2;
- while( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
+ while( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
{
if( p_sys->stream.i_used <= 1 )
{
/* Be sure we will read something */
- p_sys->stream.i_used += i_read -
- (tk->i_end - tk->i_start - p_sys->stream.i_offset);
+ p_sys->stream.i_used += tk->i_start + p_sys->stream.i_offset + i_read - tk->i_end;
}
if( AStreamRefillStream( s ) ) break;
}
- if( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
+ if( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
+ {
i_read = tk->i_end - tk->i_start - p_sys->stream.i_offset;
+ }
+
/* Now, direct pointer or a copy ? */
i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
return i_read;
}
-static int AStreamSeekStream( stream_t *s, int64_t i_pos )
+static int AStreamSeekStream( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
access_Control( p_access, ACCESS_CAN_FASTSEEK, &b_afastseek );
/* FIXME compute seek cost (instead of static 'stupid' value) */
- int64_t i_skip_threshold;
+ uint64_t i_skip_threshold;
if( b_aseek )
i_skip_threshold = b_afastseek ? 128 : 3*p_sys->stream.i_read_size;
else
int i_tk_idx = -1;
/* Prefer the current track */
- if( p_current->i_start <= i_pos && i_pos - p_current->i_end <= i_skip_threshold )
+ if( p_current->i_start <= i_pos && i_pos <= p_current->i_end + i_skip_threshold )
{
tk = p_current;
i_tk_idx = p_sys->stream.i_tk;
if( tk != p_current )
i_skip_threshold = 0;
- if( tk->i_start <= i_pos && i_pos - tk->i_end <= i_skip_threshold )
+ if( tk->i_start <= i_pos && i_pos <= tk->i_end + i_skip_threshold )
{
#ifdef STREAM_DEBUG
msg_Err( s, "AStreamSeekStream: reusing %d start=%"PRId64
if( ASeek( s, tk->i_end ) )
return VLC_EGENERIC;
}
- else
+ else if( i_pos > tk->i_end )
{
- int64_t i_skip = i_pos - tk->i_end;
+ uint64_t i_skip = i_pos - tk->i_end;
while( i_skip > 0 )
{
const int i_read_max = __MIN( 10 * STREAM_READ_ATONCE, i_skip );
* - refilling threshold
* - how much to refill
*/
- if( (tk->i_end - tk->i_start) - p_sys->stream.i_offset < p_sys->stream.i_read_size )
+ if( tk->i_end < tk->i_start + p_sys->stream.i_offset + p_sys->stream.i_read_size )
{
if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
p_sys->stream.i_used = STREAM_READ_ATONCE / 2;
while( i_data < i_read )
{
- int i_off = (tk->i_start + p_sys->stream.i_offset) %
- STREAM_CACHE_TRACK_SIZE;
+ unsigned i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
unsigned int i_current =
- __MAX(0,__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
- STREAM_CACHE_TRACK_SIZE - i_off ));
+ __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 */
/* */
p_sys->stream.i_used += i_copy;
- if( tk->i_end - tk->i_start - p_sys->stream.i_offset <= i_read -i_data )
+ if( tk->i_end + i_data <= tk->i_start + p_sys->stream.i_offset + i_read )
{
- const int i_read_requested = __MAX( __MIN( i_read - i_data,
- STREAM_READ_ATONCE * 10 ),
- STREAM_READ_ATONCE / 2 );
+ const unsigned i_read_requested = __MAX( __MIN( i_read - i_data,
+ STREAM_READ_ATONCE * 10 ),
+ STREAM_READ_ATONCE / 2 );
if( p_sys->stream.i_used < i_read_requested )
p_sys->stream.i_used = i_read_requested;
tk->i_end += i_read;
/* Windows of STREAM_CACHE_TRACK_SIZE */
- if( tk->i_end - tk->i_start > STREAM_CACHE_TRACK_SIZE )
+ if( tk->i_start + STREAM_CACHE_TRACK_SIZE < tk->i_end )
{
- int i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
+ unsigned i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
tk->i_start += i_invalid;
p_sys->stream.i_offset -= i_invalid;
/* */
i_read = STREAM_CACHE_TRACK_SIZE - i_buffered;
- i_read = __MIN( p_sys->stream.i_read_size, i_read );
+ i_read = __MIN( (int)p_sys->stream.i_read_size, i_read );
i_read = AReadStream( s, &tk->p_buffer[i_buffered], i_read );
if( i_read < 0 )
continue;
return p_block;
}
-static int ASeek( stream_t *s, int64_t i_pos )
+static int ASeek( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
- assert( i_pos >= 0 );
/* Check which stream we need to access */
if( p_sys->i_list )
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#include <limits.h>
#include "demux.h"
#include <libvlc.h>
block_fifo_t *p_fifo;
block_t *p_block;
- int64_t i_pos;
+ uint64_t i_pos;
/* Demuxer */
char *psz_name;
static int DStreamControl( stream_t *s, int i_query, va_list args )
{
stream_sys_t *p_sys = s->p_sys;
- int64_t *p_i64;
+ uint64_t *p_i64;
bool *p_b;
switch( i_query )
{
case STREAM_GET_SIZE:
- p_i64 = (int64_t*) va_arg( args, int64_t * );
+ p_i64 = va_arg( args, uint64_t * );
*p_i64 = 0;
return VLC_SUCCESS;
return VLC_SUCCESS;
case STREAM_GET_POSITION:
- p_i64 = (int64_t*) va_arg( args, int64_t * );
+ p_i64 = va_arg( args, uint64_t * );
*p_i64 = p_sys->i_pos;
return VLC_SUCCESS;
case STREAM_SET_POSITION:
{
- int64_t i64 = (int64_t)va_arg( args, int64_t );
- int i_skip;
- if( i64 < p_sys->i_pos ) return VLC_EGENERIC;
- i_skip = i64 - p_sys->i_pos;
+ uint64_t i64 = va_arg( args, uint64_t );
+ if( i64 < p_sys->i_pos )
+ return VLC_EGENERIC;
+ uint64_t i_skip = i64 - p_sys->i_pos;
while( i_skip > 0 )
{
- int i_read = DStreamRead( s, NULL, (long)i_skip );
- if( i_read <= 0 ) return VLC_EGENERIC;
+ int i_read = DStreamRead( s, NULL, __MIN(i_skip, INT_MAX) );
+ if( i_read <= 0 )
+ return VLC_EGENERIC;
i_skip -= i_read;
}
return VLC_SUCCESS;
struct stream_sys_t
{
bool i_preserve_memory;
- int64_t i_pos; /* Current reading offset */
- int64_t i_size;
+ uint64_t i_pos; /* Current reading offset */
+ uint64_t i_size;
uint8_t *p_buffer;
};
* pointed to by p_buffer is freed on stream_Destroy
*/
stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
- int64_t i_size, bool i_preserve_memory )
+ uint64_t i_size, bool i_preserve_memory )
{
stream_t *s = stream_CommonNew( p_this );
stream_sys_t *p_sys;
stream_sys_t *p_sys = s->p_sys;
bool *p_bool;
- int64_t *pi_64, i_64;
+ uint64_t *pi_64, i_64;
int i_int;
switch( i_query )
{
case STREAM_GET_SIZE:
- pi_64 = (int64_t*)va_arg( args, int64_t * );
+ pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_size;
break;
break;
case STREAM_GET_POSITION:
- pi_64 = (int64_t*)va_arg( args, int64_t * );
+ pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_pos;
break;
case STREAM_SET_POSITION:
- i_64 = (int64_t)va_arg( args, int64_t );
- i_64 = __MAX( i_64, 0 );
+ i_64 = va_arg( args, uint64_t );
i_64 = __MIN( i_64, s->p_sys->i_size );
p_sys->i_pos = i_64;
break;
static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
{
stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
- int64_t i_size;
+ uint64_t i_size;
char *psz_buffer;
if( !p_stream )
}
i_size = stream_Size( p_stream );
+ if( i_size > SIZE_MAX - 1 )
+ i_size = SIZE_MAX - 1;
psz_buffer = malloc( i_size + 1 );
if( !psz_buffer )