X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fstream.c;h=7347d5adaef964079ec1627510fe49691b1e2516;hb=9c36906f44fa152559400a8ee130ae3579a37f36;hp=2cbae6f3052e895b28c8f6120d0d3ea90d24549e;hpb=03ed4ccc656086751c3aaf39e0a2b0013f95d972;p=vlc diff --git a/src/input/stream.c b/src/input/stream.c index 2cbae6f305..7347d5adae 100644 --- a/src/input/stream.c +++ b/src/input/stream.c @@ -339,6 +339,15 @@ void stream_AccessReset( stream_t *s ) } } +/**************************************************************************** + * stream_AccessUpdate: + ****************************************************************************/ +void stream_AccessUpdate( stream_t *s ) +{ + stream_sys_t *p_sys = s->p_sys; + p_sys->i_pos = p_sys->p_access->info.i_pos; +} + /**************************************************************************** * AStreamControl: ****************************************************************************/ @@ -385,13 +394,14 @@ static int AStreamControl( stream_t *s, int i_query, va_list args ) case STREAM_CONTROL_ACCESS: i_int = (int) va_arg( args, int ); - if( i_int != ACCESS_SET_PRIVATE_ID_STATE ) + if( i_int != ACCESS_SET_PRIVATE_ID_STATE + && i_int != ACCESS_SET_PRIVATE_ID_CA ) { msg_Err( s, "Hey, what are you thinking ?" "DON'T USE STREAM_CONTROL_ACCESS !!!" ); return VLC_EGENERIC; } - return access2_Control( p_access, i_int, args ); + return access2_vaControl( p_access, i_int, args ); default: msg_Err( s, "invalid stream_vaControl query=0x%x", i_query ); @@ -450,7 +460,10 @@ static void AStreamPrebufferBlock( stream_t *s ) } 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; @@ -476,6 +489,17 @@ static int AStreamReadBlock( stream_t *s, void *p_read, int i_read ) if( p_sys->block.p_current == NULL ) return 0; + if( p_read == NULL ) + { + /* seek within this stream if possible, else use plain old read and discard */ + stream_sys_t *p_sys = s->p_sys; + access_t *p_access = p_sys->p_access; + vlc_bool_t b_aseek; + access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek ); + if( b_aseek ) + return AStreamSeekBlock( s, p_sys->i_pos + i_read ) ? 0 : i_read; + } + while( i_data < i_read ) { int i_current = @@ -792,6 +816,17 @@ static int AStreamReadStream( stream_t *s, void *p_read, int i_read ) if( tk->i_start >= tk->i_end ) return 0; /* EOF */ + if( p_read == NULL ) + { + /* seek within this stream if possible, else use plain old read and discard */ + stream_sys_t *p_sys = s->p_sys; + access_t *p_access = p_sys->p_access; + vlc_bool_t b_aseek; + access2_Control( p_access, ACCESS_CAN_SEEK, &b_aseek ); + if( b_aseek ) + return AStreamSeekStream( s, p_sys->i_pos + i_read ) ? 0 : i_read; + } + #if 0 msg_Dbg( s, "AStreamReadStream: %d pos="I64Fd" tk=%d start="I64Fd " offset=%d end="I64Fd, @@ -930,6 +965,7 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos ) if( !b_aseek ) { /* We can't do nothing */ + msg_Dbg( s, "AStreamSeekStream: can't seek" ); return VLC_EGENERIC; } @@ -1028,6 +1064,7 @@ static int AStreamRefillStream( stream_t *s ) int i_toread = __MIN( p_sys->stream.i_used, STREAM_CACHE_TRACK_SIZE - (tk->i_end - tk->i_start - p_sys->stream.i_offset) ); + vlc_bool_t b_read = VLC_FALSE; int64_t i_start, i_stop; if( i_toread <= 0 ) return VLC_EGENERIC; /* EOF */ @@ -1054,8 +1091,11 @@ static int AStreamRefillStream( stream_t *s ) } else if( i_read == 0 ) { - return VLC_EGENERIC; + if( !b_read ) + return VLC_EGENERIC; + return VLC_SUCCESS; } + b_read = VLC_TRUE; /* Update end */ tk->i_end += i_read; @@ -1089,6 +1129,8 @@ static void AStreamPrebufferStream( stream_t *s ) int64_t i_first = 0; int64_t i_start; + int64_t i_prebuffer = (s->p_sys->p_access->info.i_title > 1 || + s->p_sys->p_access->info.i_seekpoint > 1) ? STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3; msg_Dbg( s, "pre buffering" ); i_start = mdate(); @@ -1099,7 +1141,7 @@ static void AStreamPrebufferStream( stream_t *s ) int64_t i_date = mdate(); int i_read; - if( s->b_die || tk->i_end >= STREAM_CACHE_PREBUFFER_SIZE || + if( s->b_die || tk->i_end >= i_prebuffer || (i_first > 0 && i_first + STREAM_CACHE_PREBUFFER_LENGTH < i_date) ) { int64_t i_byterate; @@ -1135,7 +1177,10 @@ static void AStreamPrebufferStream( stream_t *s ) } if( i_first == 0 ) + { i_first = mdate(); + msg_Dbg( s, "received first data for our buffer"); + } tk->i_end += i_read; @@ -1152,76 +1197,56 @@ static void AStreamPrebufferStream( stream_t *s ) * \param s Stream handle to read from * \return A null-terminated string. This must be freed, */ -#define STREAM_PROBE_LINE 1024 +#define STREAM_PROBE_LINE 2048 +#define STREAM_LINE_MAX (2048*100) char *stream_ReadLine( stream_t *s ) { - char *p_line = NULL; - int i_line = 0; + char *p_line = NULL; + int i_line = 0, i_read = 0; - for( ;; ) + while( i_read < STREAM_LINE_MAX ) { - char *psz_lf, *psz_cr; + char *psz_eol; uint8_t *p_data; - int i_data; - - int i_read; + int i_data; /* Probe new data */ i_data = stream_Peek( s, &p_data, STREAM_PROBE_LINE ); + if( i_data <= 0 ) break; /* No more data */ - if( i_data <= 0 ) /* No data */ - goto exit; - - /* See if there is a '\n' */ - psz_lf = memchr( p_data, '\n', __MAX( i_data - 1, 1 ) ); - psz_cr = memchr( p_data, '\r', __MAX( i_data - 1, 1 ) ); - - if( psz_lf && !psz_cr && p_data[i_data-1] == '\r' ) - { - psz_cr = &p_data[i_data-1]; - } - if( psz_cr && !psz_lf && p_data[i_data-1] == '\n' ) - { - psz_lf = &p_data[i_data-1]; - } - - if( psz_lf || psz_cr ) + /* Check if there is an EOL */ + if( ( psz_eol = memchr( p_data, '\n', i_data ) ) ) { - char *psz; - if( !psz_lf ) - psz = psz_cr; - else if( !psz_cr ) - psz = psz_lf; - else - psz = __MIN( psz_cr, psz_lf ); - - i_read = (psz - (char*)p_data) + 1; - p_line = realloc( p_line, i_read + 1 ); /* +1 for easy \0 append */ - i_read = stream_Read( s, &p_line[i_line], i_read ); - if( i_read > 0 ) - i_line += i_read; - - goto exit; + i_data = (psz_eol - (char *)p_data) + 1; + p_line = realloc( p_line, i_line + i_data + 1 ); + i_data = stream_Read( s, &p_line[i_line], i_data ); + if( i_data <= 0 ) break; /* Hmmm */ + i_line += (i_data - 1); + i_read += i_data; + + /* We have our line */ + break; } /* Read data (+1 for easy \0 append) */ p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + 1 ); - i_read = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE ); - - if( i_read <= 0 ) - goto exit; - i_line += i_read; + i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE ); + if( i_data <= 0 ) break; /* Hmmm */ + i_line += i_data; + i_read += i_data; } -exit: - while( i_line > 0 && - ( p_line[i_line-1] == '\n' || p_line[i_line-1] == '\r' ) ) + /* Remove trailing LF/CR */ + while( i_line > 0 && ( p_line[i_line-1] == '\r' || + p_line[i_line-1] == '\n') ) i_line--; + + if( i_read > 0 ) { - i_line--; - } - if( i_line > 0 ) p_line[i_line] = '\0'; + return p_line; + } - return p_line; + /* We failed to read any data, probably EOF */ + if( p_line ) free( p_line ); + return NULL; } -