[vlc-commits] hls: Ensure streams are sorted by bandwidth.

Hugo Beauzée-Luyssen git at videolan.org
Fri Feb 3 12:37:07 CET 2012


vlc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Fri Feb  3 12:32:24 2012 +0100| [e2942aee746d12ea0bed999e8110bbbead3ca72d] | committer: Hugo Beauzée-Luyssen

hls: Ensure streams are sorted by bandwidth.

THe standard doesn't guaranty anything, but the code assumes it.

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

 modules/stream_filter/httplive.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 79abe60..b9a2a7c 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -953,6 +953,13 @@ static int parse_Discontinuity(stream_t *s, hls_stream_t *hls, char *p_read)
     return VLC_SUCCESS;
 }
 
+static int hls_CompareStreams( const void* a, const void* b )
+{
+    hls_stream_t*   stream_a = *(hls_stream_t**)a;
+    hls_stream_t*   stream_b = *(hls_stream_t**)b;
+    return stream_a->bandwidth > stream_b->bandwidth;
+}
+
 /* The http://tools.ietf.org/html/draft-pantos-http-live-streaming-04#page-8
  * document defines the following new tags: EXT-X-TARGETDURATION,
  * EXT-X-MEDIA-SEQUENCE, EXT-X-KEY, EXT-X-PROGRAM-DATE-TIME, EXT-X-
@@ -1977,6 +1984,10 @@ static int Open(vlc_object_t *p_this)
         goto fail;
     }
     free(buffer);
+    /* HLS standard doesn't provide any guaranty about streams
+       being sorted by bandwidth, so we sort them */
+    qsort( p_sys->hls_stream->pp_elems, p_sys->hls_stream->i_count,
+           sizeof( hls_stream_t* ), &hls_CompareStreams );
 
     /* Choose first HLS stream to start with */
     int current = p_sys->playback.stream = 0;



More information about the vlc-commits mailing list