Commit 4872a30d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

stream_filter: assume read buffer is non-NULL, simplify

As per the previous commit, this code is no longer necessary.
parent dc513b6d
......@@ -264,8 +264,7 @@ static ssize_t Read( stream_t *s, void *p_read, size_t i_read )
/* Read the buffer */
size_t i_len = __MIN( i_read, p_sys->i_len - p_sys->i_pos );
if( p_read )
memcpy( p_read, p_sys->psz_xspf + p_sys->i_pos, i_len );
memcpy( p_read, p_sys->psz_xspf + p_sys->i_pos, i_len );
p_sys->i_pos += i_len;
return i_len;
......
......@@ -51,7 +51,7 @@ static int Control( stream_t *p_stream, int i_query, va_list args )
static ssize_t Read( stream_t *s, void *buffer, size_t i_read )
{
const ssize_t i_ret = vlc_stream_Read( s->p_source, buffer, i_read );
if( i_ret < 1 || !buffer ) return i_ret;
if( i_ret < 1 ) return i_ret;
uint8_t *p_buffer = buffer;
static const uint8_t ADF_XOR_MASK = 34;
......
......@@ -170,7 +170,7 @@ static ssize_t Read( stream_t *p_stream, void *p_buf, size_t i_toread )
int i_total_read = 0;
int i_ret;
if ( !p_dst || !i_toread )
if ( !i_toread )
return -1;
/* Use data from previous reads */
......
......@@ -360,21 +360,11 @@ static ssize_t AStreamReadBlock(stream_t *s, void *buf, size_t len)
if (sys->p_current == NULL)
return 0;
if (buf == NULL)
{ /* seek if possible, else use plain old read and discard */
bool b_aseek;
vlc_stream_Control(s->p_source, STREAM_CAN_SEEK, &b_aseek);
if (b_aseek)
return AStreamSeekBlock(s, sys->i_pos + len) ? 0 : len;
}
ssize_t i_current = sys->p_current->i_buffer - sys->i_offset;
size_t i_copy = VLC_CLIP((size_t)i_current, 0, len);
/* Copy data */
if (buf != NULL)
memcpy(buf, &sys->p_current->p_buffer[sys->i_offset], i_copy);
memcpy(buf, &sys->p_current->p_buffer[sys->i_offset], i_copy);
sys->i_offset += i_copy;
if (sys->i_offset >= sys->p_current->i_buffer)
......
......@@ -244,7 +244,7 @@ static void AStreamControlReset(stream_t *s)
AStreamPrebufferStream(s);
}
static ssize_t AStreamReadNoSeekStream(stream_t *s, void *buf, size_t len)
static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
{
stream_sys_t *sys = s->p_sys;
stream_track_t *tk = &sys->tk[sys->i_tk];
......@@ -400,7 +400,7 @@ static int AStreamSeekStream(stream_t *s, uint64_t i_pos)
{
const int i_read_max = __MIN(10 * STREAM_READ_ATONCE, i_skip);
int i_read = 0;
if ((i_read = AStreamReadNoSeekStream(s, NULL, i_read_max)) < 0)
if ((i_read = AStreamReadStream(s, NULL, i_read_max)) < 0)
{
msg_Err(s, "AStreamSeekStream: skip failed");
return VLC_EGENERIC;
......@@ -445,24 +445,6 @@ static int AStreamSeekStream(stream_t *s, uint64_t i_pos)
return VLC_SUCCESS;
}
static ssize_t AStreamReadStream(stream_t *s, void *p_read, size_t i_read)
{
stream_sys_t *sys = s->p_sys;
if (!p_read)
{
const uint64_t i_pos_wanted = sys->i_pos + i_read;
if (AStreamSeekStream(s, i_pos_wanted))
{
if (sys->i_pos != i_pos_wanted)
return 0;
}
return i_read;
}
return AStreamReadNoSeekStream(s, p_read, i_read);
}
/****************************************************************************
* AStreamControl:
****************************************************************************/
......
......@@ -192,20 +192,6 @@ static void *Thread (void *data)
static ssize_t Read (stream_t *stream, void *buf, size_t buflen)
{
stream_sys_t *sys = stream->p_sys;
if (buf == NULL) /* caller skips data, get big enough peek buffer */
{
buf = malloc(buflen);
if (unlikely(buf == NULL))
return -1;
ssize_t val = Read(stream, buf, buflen);
free(buf);
return val;
}
assert ((buf != NULL) || (buflen == 0));
ssize_t val = vlc_read_i11e (sys->read_fd, buf, buflen);
return (val >= 0) ? val : 0;
}
......
......@@ -45,13 +45,6 @@ static ssize_t Read(stream_t *stream, void *buf, size_t buflen)
if (sys->eof || unlikely(buflen == 0))
return 0;
if (buf == NULL)
{
char dummy[buflen > 4096 ? 4096 : buflen];
return Read(stream, dummy, sizeof (dummy));
}
sys->zstream.next_out = buf;
sys->zstream.avail_out = buflen;
......
......@@ -297,13 +297,6 @@ static ssize_t Read(stream_t *stream, void *buf, size_t buflen)
return buflen;
vlc_mutex_lock(&sys->lock);
if (buf == NULL)
{
sys->stream_offset += buflen;
copy = buflen;
goto out;
}
if (sys->paused)
{
msg_Err(stream, "reading while paused (buggy demux?)");
......@@ -335,7 +328,6 @@ static ssize_t Read(stream_t *stream, void *buf, size_t buflen)
memcpy(buf, sys->buffer + offset, copy);
sys->stream_offset += copy;
out:
vlc_cond_signal(&sys->wait_space);
vlc_mutex_unlock(&sys->lock);
return copy;
......
......@@ -117,12 +117,6 @@ static ssize_t Read( stream_t *s, void *p_read, size_t i_read )
{
stream_sys_t *p_sys = s->p_sys;
void *p_record = p_read;
/* Allocate a temporary buffer for record when no p_read */
if( p_sys->f && !p_record )
p_record = malloc( i_read );
/* */
const ssize_t i_record = vlc_stream_Read( s->p_source, p_record, i_read );
/* Dump read data */
......@@ -130,8 +124,6 @@ static ssize_t Read( stream_t *s, void *p_read, size_t i_read )
{
if( p_record && i_record > 0 )
Write( s, p_record, i_record );
if( !p_read )
free( p_record );
}
return i_record;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment