1111#define HLS_MAX_NO_READ 2
1212#define HLS_MAX_URL_LEN 256
1313#define HLS_TIMEOUT 5000
14+ #define HLS_UNDER_OVERFLOW_WAIT_TIME 10
1415
1516// / hide hls implementation in it's own namespace
1617
@@ -91,6 +92,10 @@ class URLLoaderHLS {
9192 void setBufferSize (int size, int count) {
9293 buffer_size = size;
9394 buffer_count = count;
95+ // support call after begin()!
96+ if (buffer.size ()!=0 ){
97+ buffer.resize (buffer_size * buffer_count);
98+ }
9499 }
95100
96101 void setCACert (const char *cert) { p_stream->setCACert (cert); }
@@ -111,12 +116,12 @@ class URLLoaderHLS {
111116 // we have nothing to do
112117 if (urls.empty ()) {
113118 LOGD (" urls empty" );
114- delay (10 );
119+ delay (HLS_UNDER_OVERFLOW_WAIT_TIME );
115120 return ;
116121 }
117122 if (buffer.availableForWrite () == 0 ) {
118123 LOGD (" buffer full" );
119- delay (10 );
124+ delay (HLS_UNDER_OVERFLOW_WAIT_TIME );
120125 return ;
121126 }
122127
@@ -203,7 +208,7 @@ class URLHistory {
203208};
204209
205210/* *
206- * @brief Simple Parser for HLS data. We select the entry with min bandwidth
211+ * @brief Simple Parser for HLS data.
207212 * @author Phil Schatzmann
208213 * @copyright GPLv3
209214 */
@@ -271,7 +276,6 @@ class HLSParser {
271276 const char *indexUrl () { return index_url_str; }
272277
273278 const char *segmentsUrl () {
274- if (segments_url_str == nullptr ) return nullptr ;
275279 return segments_url_str.c_str ();
276280 }
277281
@@ -427,11 +431,13 @@ class HLSParser {
427431 }
428432 return result;
429433 }
434+
430435 // / Determine codec for min bandwidth
431436 bool parseIndexLine (StrView &str) {
432437 TRACED ();
433438 LOGI (" > %s" , str.c_str ());
434439 parseIndexLineMetaData (str);
440+ // in some exceptional cases the index provided segement info
435441 parseSegmentLineMetaData (str);
436442 parseLineURL (str);
437443 return true ;
@@ -440,10 +446,6 @@ class HLSParser {
440446 bool parseIndexLineMetaData (StrView &str) {
441447 int tmp_bandwidth;
442448 if (str.startsWith (" #" )) {
443- if (str.indexOf (" #EXTINF" ) >= 0 ) {
444- next_url_type = URLType::Segment;
445- }
446-
447449 if (str.indexOf (" EXT-X-STREAM-INF" ) >= 0 ) {
448450 next_url_type = URLType::Index;
449451 // determine min bandwidth
@@ -541,13 +543,12 @@ class HLSParser {
541543 memset (tmp, 0 , MAX_HLS_LINE);
542544 while (true ) {
543545 memset (tmp, 0 , MAX_HLS_LINE);
544- size_t len =
545- url_stream.httpRequest ().readBytesUntil (' \n ' , tmp, MAX_HLS_LINE);
546+ size_t len = url_stream.httpRequest ().readBytesUntil (' \n ' , tmp, MAX_HLS_LINE);
546547 if (len == 0 && url_stream.available () == 0 ) break ;
547548 StrView str (tmp);
548549
549550 // check header
550- if (str.indexOf (" #EXTM3U" ) >= 0 ) {
551+ if (str.startsWith (" #EXTM3U" )) {
551552 is_extm3u = true ;
552553 resetTimings ();
553554 }
@@ -572,9 +573,8 @@ class HLSParser {
572573
573574 bool parseSegmentLineMetaData (StrView &str) {
574575 if (str.startsWith (" #" )) {
575- int pos = str.indexOf (" #EXT-X-MEDIA-SEQUENCE:" );
576- if (pos >= 0 ) {
577- int new_media_sequence = atoi (str.c_str () + pos + 22 );
576+ if (str.startsWith (" #EXT-X-MEDIA-SEQUENCE:" )) {
577+ int new_media_sequence = atoi (str.c_str () + 22 );
578578 LOGI (" media_sequence: %d" , new_media_sequence);
579579 if (new_media_sequence == media_sequence) {
580580 LOGW (" MEDIA-SEQUENCE already loaded: %d" , media_sequence);
@@ -673,7 +673,7 @@ class HLSStream : public AbstractURLStream {
673673 return rc;
674674 }
675675
676- // ends the request
676+ // / ends the request
677677 void end () { parser.end (); }
678678
679679 // / Sets the ssid that will be used for logging in (when calling begin)
@@ -685,6 +685,7 @@ class HLSStream : public AbstractURLStream {
685685 // / Returns the string representation of the codec of the audio stream
686686 const char *codec () { return parser.getCodec (); }
687687
688+ // / Provides the content type from the http reply
688689 const char *contentType () { return parser.contentType (); }
689690
690691 // / Provides the content length of the actual .ts Segment
0 commit comments