[vlc-commits] stream_filter: assume read buffer is non-NULL, simplify

Rémi Denis-Courmont git at videolan.org
Tue Feb 7 19:10:32 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Feb  7 20:07:17 2017 +0200| [4aebd29e8baabca20455c02aec03f01036f474db] | committer: Rémi Denis-Courmont

stream_filter: assume read buffer is non-NULL, simplify

As per the previous commit, this code is no longer necessary.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4aebd29e8baabca20455c02aec03f01036f474db
---

 modules/access/zip/zipstream.c      |  3 +--
 modules/stream_filter/adf.c         |  2 +-
 modules/stream_filter/aribcam.c     |  2 +-
 modules/stream_filter/cache_block.c | 12 +-----------
 modules/stream_filter/cache_read.c  | 22 ++--------------------
 modules/stream_filter/decomp.c      | 14 --------------
 modules/stream_filter/inflate.c     |  7 -------
 modules/stream_filter/prefetch.c    |  8 --------
 modules/stream_filter/record.c      |  8 --------
 9 files changed, 6 insertions(+), 72 deletions(-)

diff --git a/modules/access/zip/zipstream.c b/modules/access/zip/zipstream.c
index 5bd7771..4eff9f5 100644
--- a/modules/access/zip/zipstream.c
+++ b/modules/access/zip/zipstream.c
@@ -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;
diff --git a/modules/stream_filter/adf.c b/modules/stream_filter/adf.c
index 6d27948..5d3fb0a 100644
--- a/modules/stream_filter/adf.c
+++ b/modules/stream_filter/adf.c
@@ -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;
diff --git a/modules/stream_filter/aribcam.c b/modules/stream_filter/aribcam.c
index 932d421..0b8ada8 100644
--- a/modules/stream_filter/aribcam.c
+++ b/modules/stream_filter/aribcam.c
@@ -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 */
diff --git a/modules/stream_filter/cache_block.c b/modules/stream_filter/cache_block.c
index b41d8b2..fc1187e 100644
--- a/modules/stream_filter/cache_block.c
+++ b/modules/stream_filter/cache_block.c
@@ -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)
diff --git a/modules/stream_filter/cache_read.c b/modules/stream_filter/cache_read.c
index 0601787..d9c33b5 100644
--- a/modules/stream_filter/cache_read.c
+++ b/modules/stream_filter/cache_read.c
@@ -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:
  ****************************************************************************/
diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c
index 12f778f..e3d9af3 100644
--- a/modules/stream_filter/decomp.c
+++ b/modules/stream_filter/decomp.c
@@ -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;
 }
diff --git a/modules/stream_filter/inflate.c b/modules/stream_filter/inflate.c
index d262eb7..05f3a5c 100644
--- a/modules/stream_filter/inflate.c
+++ b/modules/stream_filter/inflate.c
@@ -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;
 
diff --git a/modules/stream_filter/prefetch.c b/modules/stream_filter/prefetch.c
index 6d0c6cd..b1cb479 100644
--- a/modules/stream_filter/prefetch.c
+++ b/modules/stream_filter/prefetch.c
@@ -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;
diff --git a/modules/stream_filter/record.c b/modules/stream_filter/record.c
index da230d3..2ddb276 100644
--- a/modules/stream_filter/record.c
+++ b/modules/stream_filter/record.c
@@ -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;



More information about the vlc-commits mailing list