[vlc-devel] [PATCH] HLS: clean up a little the code

Frédéric Yhuel fyhuel at viotech.net
Thu Apr 19 12:11:47 CEST 2012


Use changes introduced in block_t by
f649a0488d97a72fa6d06fbf807f5052ba65f3aa
---
 modules/stream_filter/httplive.c |   33 +++++++++++----------------------
 1 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 9c2e9d1..aac120f 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -65,7 +65,6 @@ typedef struct segment_s
 {
     int         sequence;   /* unique sequence number */
     int         duration;   /* segment duration (seconds) */
-    uint64_t    size;       /* segment size in bytes */
     uint64_t    bandwidth;  /* bandwidth usage of segments (bits per second)*/
 
     char        *url;
@@ -367,7 +366,6 @@ static segment_t *segment_New(hls_stream_t* hls, const int duration, const char
         return NULL;
 
     segment->duration = duration; /* seconds */
-    segment->size = 0; /* bytes */
     segment->sequence = 0;
     segment->bandwidth = 0;
     segment->url = strdup(uri);
@@ -1479,7 +1477,7 @@ static int hls_DownloadSegmentData(stream_t *s, hls_stream_t *hls, segment_t *se
     if (hls->bandwidth == 0 && segment->duration > 0)
     {
         /* Try to estimate the bandwidth for this stream */
-        hls->bandwidth = (uint64_t)(((double)segment->size * 8) / ((double)segment->duration));
+        hls->bandwidth = segment->data->i_size * 8 / segment->duration;
     }
 
     /* If the segment is encrypted, decode it */
@@ -1494,7 +1492,7 @@ static int hls_DownloadSegmentData(stream_t *s, hls_stream_t *hls, segment_t *se
     msg_Info(s, "downloaded segment %d from stream %d",
                 segment->sequence, *cur_stream);
 
-    uint64_t bw = segment->size * 8 * 1000000 / __MAX(1, duration); /* bits / s */
+    uint64_t bw = segment->data->i_size * 8 * 1000000 / __MAX(1, duration); /* bits / s */
     p_sys->bandwidth = bw;
     if (p_sys->b_meta && (hls->bandwidth != bw))
     {
@@ -1696,20 +1694,17 @@ static int hls_Download(stream_t *s, segment_t *segment)
     if (p_ts == NULL)
         return VLC_EGENERIC;
 
-    segment->size = stream_Size(p_ts);
-    assert(segment->size > 0);
+    int64_t size = stream_Size(p_ts);
+    assert(size > 0);
 
-    segment->data = block_Alloc(segment->size);
+    segment->data = block_Alloc(size);
     if (segment->data == NULL)
     {
         stream_Delete(p_ts);
         return VLC_ENOMEM;
     }
 
-    assert(segment->data->i_buffer == segment->size);
-
     ssize_t length = 0, curlen = 0;
-    uint64_t size;
     do
     {
         /* NOTE: Beware the size reported for a segment by the HLS server may not
@@ -1717,9 +1712,9 @@ static int hls_Download(stream_t *s, segment_t *segment)
          * and enlarge the segment data block if necessary.
          */
         size = stream_Size(p_ts);
-        if (size > segment->size)
+        if (size > segment->data->i_size)
         {
-            msg_Dbg(s, "size changed %"PRIu64, segment->size);
+            msg_Dbg(s, "size changed %"PRIi64, segment->data->i_size);
             block_t *p_block = block_Realloc(segment->data, 0, size);
             if (p_block == NULL)
             {
@@ -1729,11 +1724,9 @@ static int hls_Download(stream_t *s, segment_t *segment)
                 return VLC_ENOMEM;
             }
             segment->data = p_block;
-            segment->size = size;
-            assert(segment->data->i_buffer == segment->size);
             p_block = NULL;
         }
-        length = stream_Read(p_ts, segment->data->p_buffer + curlen, segment->size - curlen);
+        length = stream_Read(p_ts, segment->data->p_buffer + curlen, segment->data->i_size - curlen);
         if (length <= 0)
             break;
         curlen += length;
@@ -2127,12 +2120,8 @@ static int segment_RestorePos(segment_t *segment)
 {
     if (segment->data)
     {
-        uint64_t size = segment->size - segment->data->i_buffer;
-        if (size > 0)
-        {
-            segment->data->i_buffer += size;
-            segment->data->p_buffer -= size;
-        }
+        segment->data->i_buffer = segment->data->i_size;
+        segment->data->p_buffer = segment->data->p_start;
     }
     return VLC_SUCCESS;
 }
@@ -2176,7 +2165,7 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
             continue;
         }
 
-        if (segment->size == segment->data->i_buffer)
+        if (segment->data->i_size == segment->data->i_buffer)
             msg_Info(s, "playing segment %d from stream %d",
                      segment->sequence, p_sys->playback.stream);
 
-- 
1.7.5.4




More information about the vlc-devel mailing list