[vlc-commits] [Git][videolan/vlc][master] 7 commits: demux: ts: use vlc_stream_GetSize for unsigned offsets
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Sep 9 07:56:50 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
2ba5e519 by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: ts: use vlc_stream_GetSize for unsigned offsets
- - - - -
e4b06028 by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: ps: use unsigned vlc_stream_GetSize
- - - - -
05dd6706 by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: es: use unsigned vlc_stream_GetSize
- - - - -
a94cecbc by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: mp4: use vlc_stream_GetSize
- - - - -
b25913c0 by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: adaptive: use vlc_stream_GetSize
- - - - -
0037dcda by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: avi: use vlc_stream_GetSize
- - - - -
155b7900 by François Cartegnie at 2025-09-09T07:14:01+00:00
demux: avformat: use vlc_stream_GetSize
- - - - -
9 changed files:
- modules/demux/adaptive/http/HTTPConnection.cpp
- modules/demux/avformat/demux.c
- modules/demux/avi/avi.c
- modules/demux/avi/libavi.c
- modules/demux/mp4/libmp4.c
- modules/demux/mp4/mp4.c
- modules/demux/mpeg/es.c
- modules/demux/mpeg/ps.c
- modules/demux/mpeg/ts.c
Changes:
=====================================
modules/demux/adaptive/http/HTTPConnection.cpp
=====================================
@@ -548,8 +548,8 @@ RequestStatus StreamUrlConnection::request(const std::string &path,
contentLength = range.getEndByte() - range.getStartByte() + 1;
}
- int64_t i_size = stream_Size(p_streamurl);
- if(i_size > -1)
+ uint64_t i_size;
+ if(vlc_stream_GetSize(p_streamurl, &i_size) == VLC_SUCCESS)
{
if(!range.isValid() || contentLength > (size_t) i_size)
contentLength = (size_t) i_size;
=====================================
modules/demux/avformat/demux.c
=====================================
@@ -1079,6 +1079,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
const int64_t i_start_time = p_sys->ic->start_time != AV_NOPTS_VALUE ? p_sys->ic->start_time : 0;
double f, *pf;
int64_t i64;
+ uint64_t u64;
switch( i_query )
{
@@ -1087,12 +1088,15 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
return VLC_SUCCESS;
case DEMUX_GET_POSITION:
- pf = va_arg( args, double * ); *pf = 0.0;
- i64 = stream_Size( p_demux->s );
- if( i64 > 0 )
+ pf = va_arg( args, double * );
+ if( vlc_stream_GetSize( p_demux->s, &u64 ) != VLC_SUCCESS )
+ {
+ *pf = 0.0;
+ }
+ else
{
double current = vlc_stream_Tell( p_demux->s );
- *pf = current / (double)i64;
+ *pf = current / (double)u64;
}
if( (p_sys->ic->duration != (int64_t)AV_NOPTS_VALUE) && (p_sys->i_pcr > 0) )
@@ -1115,7 +1119,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
if( p_sys->ic->duration == (int64_t)AV_NOPTS_VALUE ||
(av_seek_frame( p_sys->ic, -1, i64, AVSEEK_FLAG_BACKWARD ) < 0) )
{
- int64_t i_size = stream_Size( p_demux->s );
+ uint64_t i_size;
+ if( vlc_stream_GetSize( p_demux->s, &i_size ) != VLC_SUCCESS ||
+ i_size > INT64_MAX )
+ {
+ msg_Err( p_demux, "Can not use stream size for SET_POSITION" );
+ return VLC_EGENERIC;
+ }
+
i64 = (i_size * f);
msg_Warn( p_demux, "DEMUX_SET_BYTE_POSITION: %"PRId64, i64 );
=====================================
modules/demux/avi/avi.c
=====================================
@@ -1632,7 +1632,10 @@ static int Seek( demux_t *p_demux, vlc_tick_t i_date, double f_ratio, bool b_acc
if( p_sys->i_length == 0 )
{
avi_track_t *p_stream = NULL;
- uint64_t i_pos;
+ uint64_t i_pos, i_stream_size;
+
+ if( vlc_stream_GetSize( p_demux->s, &i_stream_size ) != VLC_SUCCESS )
+ goto failandresetpos;
if ( !p_sys->i_movi_lastchunk_pos && /* set when index is successfully loaded */
! ( p_sys->i_avih_flags & AVIF_ISINTERLEAVED ) )
@@ -1650,8 +1653,7 @@ static int Seek( demux_t *p_demux, vlc_tick_t i_date, double f_ratio, bool b_acc
f_ratio = __MAX( f_ratio, 0 );
/* try to find chunk that is at i_percent or the file */
- i_pos = __MAX( f_ratio * stream_Size( p_demux->s ),
- p_sys->i_movi_begin );
+ i_pos = __MAX( f_ratio * i_stream_size, p_sys->i_movi_begin );
/* search first selected stream (and prefer non-EOF ones) */
for( unsigned i = 0; i < p_sys->i_track; i++ )
{
@@ -1751,15 +1753,16 @@ failandresetpos:
static double ControlGetPosition( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
+ uint64_t i_size;
if( p_sys->i_length != 0 )
{
return (double)p_sys->i_time / (double)p_sys->i_length;
}
- else if( stream_Size( p_demux->s ) > 0 )
+ else if( vlc_stream_GetSize( p_demux->s, &i_size ) == VLC_SUCCESS && i_size )
{
- double i64 = (uint64_t)vlc_stream_Tell( p_demux->s );
- return i64 / stream_Size( p_demux->s );
+ double i64 = vlc_stream_Tell( p_demux->s );
+ return i64 / i_size;
}
return 0.0;
}
@@ -2777,7 +2780,8 @@ static void AVI_IndexCreate( demux_t *p_demux )
avi_chunk_list_t *p_movi;
unsigned int i_stream;
- uint32_t i_movi_end;
+ uint64_t i_movi_end;
+ uint64_t i_stream_size;
vlc_tick_t i_dialog_update;
vlc_dialog_id *p_dialog_id = NULL;
@@ -2791,11 +2795,13 @@ static void AVI_IndexCreate( demux_t *p_demux )
return;
}
+ if( vlc_stream_GetSize( p_demux->s, &i_stream_size ) != VLC_SUCCESS )
+ return;
+
for( i_stream = 0; i_stream < p_sys->i_track; i_stream++ )
avi_index_Init( &p_sys->track[i_stream]->idx );
- i_movi_end = __MIN( (uint32_t)(p_movi->i_chunk_pos + p_movi->i_chunk_size),
- stream_Size( p_demux->s ) );
+ i_movi_end = __MIN( p_movi->i_chunk_pos + p_movi->i_chunk_size, i_stream_size );
vlc_stream_Seek( p_demux->s, p_movi->i_chunk_pos + 12 );
msg_Warn( p_demux, "creating index from LIST-movi, will take time !" );
@@ -2803,7 +2809,7 @@ static void AVI_IndexCreate( demux_t *p_demux )
/* Only show dialog if AVI is > 10MB */
i_dialog_update = vlc_tick_now();
- if( stream_Size( p_demux->s ) > 10000000 )
+ if( i_stream_size > 10000000 )
{
p_dialog_id =
vlc_dialog_display_progress( p_demux, false, 0.0, _("Cancel"),
@@ -2822,7 +2828,7 @@ static void AVI_IndexCreate( demux_t *p_demux )
break;
double f_current = vlc_stream_Tell( p_demux->s );
- double f_size = stream_Size( p_demux->s );
+ double f_size = i_stream_size;
double f_pos = f_current / f_size;
vlc_dialog_update_progress( p_demux, p_dialog_id, f_pos );
=====================================
modules/demux/avi/libavi.c
=====================================
@@ -68,7 +68,8 @@ static int AVI_ChunkReadCommon( stream_t *s, avi_chunk_t *p_chk,
const uint64_t i_pos = vlc_stream_Tell( s );
if( vlc_stream_Peek( s, &p_peek, 8 ) < 8 )
{
- if( stream_Size( s ) > 0 && (uint64_t) stream_Size( s ) > i_pos )
+ uint64_t i_size;
+ if( vlc_stream_GetSize( s, &i_size ) == VLC_SUCCESS && i_size > i_pos )
msg_Warn( s, "can't peek at %"PRIu64, i_pos );
else
msg_Dbg( s, "no more data at %"PRIu64, i_pos );
@@ -1164,7 +1165,8 @@ int AVI_ChunkReadRoot( stream_t *s, avi_chunk_t *p_root )
}
}
- p_list->i_chunk_size = stream_Size( s );
+ if( vlc_stream_GetSize( s, &p_list->i_chunk_size ) != VLC_SUCCESS )
+ p_list->i_chunk_size = 0;
AVI_ChunkDumpDebug_level( VLC_OBJECT(s), p_root, 0 );
return VLC_SUCCESS;
=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -5565,7 +5565,7 @@ MP4_Box_t *MP4_BoxGetRoot( stream_t *p_stream )
return p_vroot;
}
- if( vlc_stream_Tell( p_stream ) + 8 < (uint64_t) stream_Size( p_stream ) )
+ if( vlc_stream_Tell( p_stream ) + 8 < i_size )
{
/* Get the rest of the file */
i_result = MP4_ReadBoxContainerChildren( p_stream, p_vroot, NULL );
=====================================
modules/demux/mp4/mp4.c
=====================================
@@ -4657,11 +4657,11 @@ static int ProbeIndex( demux_t *p_demux )
if ( MP4_BoxCount( p_sys->p_root, "/mfra" ) )
return VLC_EGENERIC;
- i_stream_size = stream_Size( p_demux->s );
- if ( ( i_stream_size >> 62 ) ||
- ( i_stream_size < MP4_MFRO_BOXSIZE ) ||
- ( vlc_stream_Seek( p_demux->s, i_stream_size - MP4_MFRO_BOXSIZE ) != VLC_SUCCESS )
- )
+ if ( vlc_stream_GetSize( p_demux->s, &i_stream_size ) != VLC_SUCCESS )
+ return VLC_EGENERIC;
+
+ if ( i_stream_size < MP4_MFRO_BOXSIZE ||
+ vlc_stream_Seek( p_demux->s, i_stream_size - MP4_MFRO_BOXSIZE ) != VLC_SUCCESS )
{
msg_Dbg( p_demux, "Probing tail for mfro has failed" );
return VLC_EGENERIC;
=====================================
modules/demux/mpeg/es.c
=====================================
@@ -685,8 +685,12 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
* a raw approximation with time/position */
if( i_ret && !p_sys->i_bitrate )
{
- float f_pos = (double)(uint64_t)( vlc_stream_Tell( p_demux->s ) ) /
- (double)(uint64_t)( stream_Size( p_demux->s ) );
+ uint64_t i_stream_size;
+ if( vlc_stream_GetSize( p_demux->s, &i_stream_size ) != VLC_SUCCESS )
+ return VLC_EGENERIC;
+
+ uint64_t i_pos = vlc_stream_Tell( p_demux->s );
+ float f_pos = (double)i_pos / (double)i_stream_size;
/* The first few seconds are guaranteed to be very whacky,
* don't bother trying ... Too bad */
if( f_pos < 0.01f ||
=====================================
modules/demux/mpeg/ps.c
=====================================
@@ -375,7 +375,6 @@ static int Probe( demux_t *p_demux, bool b_end )
static bool FindLength( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
- int64_t i_current_pos = -1, i_size = 0, i_end = 0;
if( !var_CreateGetBool( p_demux, "ps-trust-timestamps" ) )
return true;
@@ -385,18 +384,19 @@ static bool FindLength( demux_t *p_demux )
p_sys->i_length = VLC_TICK_0;
/* Check beginning */
int i = 0;
- i_current_pos = vlc_stream_Tell( p_demux->s );
+ uint64_t i_current_pos = vlc_stream_Tell( p_demux->s );
while( i < 40 && Probe( p_demux, false ) > 0 ) i++;
/* Check end */
- i_size = stream_Size( p_demux->s );
- i_end = VLC_CLIP( i_size, 0, 200000 );
+ uint64_t i_size;
+ if( vlc_stream_GetSize( p_demux->s, &i_size ) != VLC_SUCCESS )
+ return false;
+ uint64_t i_end = VLC_CLIP( i_size, 0, 200000 );
if( vlc_stream_Seek( p_demux->s, i_size - i_end ) == VLC_SUCCESS )
{
i = 0;
while( i < 400 && Probe( p_demux, true ) > 0 ) i++;
- if( i_current_pos >= 0 &&
- vlc_stream_Seek( p_demux->s, i_current_pos ) != VLC_SUCCESS )
+ if( vlc_stream_Seek( p_demux->s, i_current_pos ) != VLC_SUCCESS )
return false;
}
else return false;
@@ -720,7 +720,7 @@ 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;
+ uint64_t u64;
int i_ret;
switch( i_query )
@@ -739,11 +739,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_GET_POSITION:
pf = va_arg( args, double * );
- i64 = stream_Size( p_demux->s ) - p_sys->i_start_byte;
- if( i64 > 0 )
+ if( vlc_stream_GetSize( p_demux->s, &u64 ) == VLC_SUCCESS )
{
double current = vlc_stream_Tell( p_demux->s ) - p_sys->i_start_byte;
- *pf = current / (double)i64;
+ u64 = u64 - p_sys->i_start_byte;
+ *pf = current / (double)u64;
}
else
{
@@ -753,21 +753,25 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_SET_POSITION:
f = va_arg( args, double );
- i64 = stream_Size( p_demux->s ) - p_sys->i_start_byte;
+
+ if( vlc_stream_GetSize( p_demux->s, &u64 ) != VLC_SUCCESS )
+ return VLC_EGENERIC;
+
+ u64 = u64 - p_sys->i_start_byte;
p_sys->i_current_pts = VLC_TICK_INVALID;
p_sys->i_scr = VLC_TICK_INVALID;
if( p_sys->format == CDXA_PS )
{
- i64 = (int64_t)(i64 * f); /* Align to sector payload */
- i64 = p_sys->i_start_byte + i64 - (i64 % CDXA_SECTOR_SIZE) + CDXA_SECTOR_HEADER_SIZE;
+ u64 = (uint64_t)(u64 * f); /* Align to sector payload */
+ u64 = p_sys->i_start_byte + u64 - (u64 % CDXA_SECTOR_SIZE) + CDXA_SECTOR_HEADER_SIZE;
}
else
{
- i64 = p_sys->i_start_byte + (int64_t)(i64 * f);
+ u64 = p_sys->i_start_byte + (uint64_t)(u64 * f);
}
- i_ret = vlc_stream_Seek( p_demux->s, i64 );
+ i_ret = vlc_stream_Seek( p_demux->s, u64 );
if( i_ret == VLC_SUCCESS )
{
NotifyDiscontinuity( p_sys->tk, p_demux->out );
@@ -802,10 +806,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
*va_arg( args, vlc_tick_t * ) = p_sys->i_length;
return VLC_SUCCESS;
}
- else if( p_sys->i_mux_rate > 0 )
+ else if( p_sys->i_mux_rate > 0 &&
+ vlc_stream_GetSize( p_demux->s, &u64 ) == VLC_SUCCESS )
{
- *va_arg( args, vlc_tick_t * ) = vlc_tick_from_samples( stream_Size( p_demux->s ) - p_sys->i_start_byte / 50,
- p_sys->i_mux_rate );
+ *va_arg( args, vlc_tick_t * ) =
+ vlc_tick_from_samples( u64 - p_sys->i_start_byte / 50, p_sys->i_mux_rate );
return VLC_SUCCESS;
}
*va_arg( args, vlc_tick_t * ) = 0;
=====================================
modules/demux/mpeg/ts.c
=====================================
@@ -900,6 +900,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
double f, *pf;
bool b_bool, *pb_bool;
int64_t i64;
+ uint64_t u64;
int i_int;
const ts_pmt_t *p_pmt = NULL;
const ts_pat_t *p_pat = GetPID(p_sys, 0)->u.p_pat;
@@ -954,10 +955,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
}
}
- if( (i64 = stream_Size( p_sys->stream) ) > 0 )
+ if( vlc_stream_GetSize( p_sys->stream, &u64 ) == VLC_SUCCESS )
{
uint64_t offset = vlc_stream_Tell( p_sys->stream );
- *pf = (double)offset / (double)i64;
+ *pf = (double)offset / (double)u64;
return VLC_SUCCESS;
}
break;
@@ -1001,9 +1002,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
}
}
- i64 = stream_Size( p_sys->stream );
- if( i64 > 0 &&
- vlc_stream_Seek( p_sys->stream, (int64_t)(i64 * f) ) == VLC_SUCCESS )
+ if( vlc_stream_GetSize( p_sys->stream, &u64 ) == VLC_SUCCESS &&
+ vlc_stream_Seek( p_sys->stream, (uint64_t)(u64 * f) ) == VLC_SUCCESS )
{
ReadyQueuesPostSeek( p_demux );
return VLC_SUCCESS;
@@ -1845,9 +1845,10 @@ static block_t* ReadTSPacket( demux_t *p_demux )
/* Get a new TS packet */
if( !( p_pkt = vlc_stream_Block( p_sys->stream, p_sys->i_packet_size ) ) )
{
- int64_t size = stream_Size( p_sys->stream );
- if( size >= 0 && (uint64_t)size == vlc_stream_Tell( p_sys->stream ) )
- msg_Dbg( p_demux, "EOF at %"PRIu64, vlc_stream_Tell( p_sys->stream ) );
+ uint64_t size;
+ if( vlc_stream_GetSize( p_sys->stream, &size ) == VLC_SUCCESS &&
+ size == vlc_stream_Tell( p_sys->stream ) )
+ msg_Dbg( p_demux, "EOF at %"PRIu64, size );
else
msg_Dbg( p_demux, "Can't read TS packet at %"PRIu64, vlc_stream_Tell(p_sys->stream) );
return NULL;
@@ -1973,7 +1974,10 @@ static int SeekToTime( demux_t *p_demux, const ts_pmt_t *p_pmt, vlc_tick_t i_see
if( p_pmt->pcr.i_first == i_seektime && p_sys->b_canseek )
return vlc_stream_Seek( p_sys->stream, 0 );
- const int64_t i_stream_size = stream_Size( p_sys->stream );
+ uint64_t i_stream_size;
+ if( vlc_stream_GetSize( p_sys->stream, &i_stream_size ) != VLC_SUCCESS )
+ return VLC_EGENERIC;
+
if( !p_sys->b_canfastseek || i_stream_size < p_sys->i_packet_size )
return VLC_EGENERIC;
@@ -2277,7 +2281,10 @@ static void ProgramSetPCR( demux_t *p_demux, ts_pmt_t *p_pmt, vlc_tick_t i_pcr )
vlc_stream_Tell( p_sys->stream ) > p_pmt->i_last_dts_byte )
{
if( p_pmt->i_last_dts_byte == 0 ) /* first run */
- p_pmt->i_last_dts_byte = stream_Size( p_sys->stream );
+ {
+ if( vlc_stream_GetSize( p_sys->stream, &p_pmt->i_last_dts_byte ) != VLC_SUCCESS )
+ msg_Dbg( p_demux, "Can't get stream size" );
+ }
else
{
p_pmt->i_last_dts = i_pcr;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/da306eb7c8b08825667e4dbe67ff3d14431af21d...155b790003953cc787172f71b2d1aeaded25446b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/da306eb7c8b08825667e4dbe67ff3d14431af21d...155b790003953cc787172f71b2d1aeaded25446b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list