11
11
#define HLS_MAX_NO_READ 2
12
12
#define HLS_MAX_URL_LEN 256
13
13
#define HLS_TIMEOUT 5000
14
+ #define HLS_UNDER_OVERFLOW_WAIT_TIME 10
14
15
15
16
// / hide hls implementation in it's own namespace
16
17
@@ -91,6 +92,10 @@ class URLLoaderHLS {
91
92
void setBufferSize (int size, int count) {
92
93
buffer_size = size;
93
94
buffer_count = count;
95
+ // support call after begin()!
96
+ if (buffer.size ()!=0 ){
97
+ buffer.resize (buffer_size * buffer_count);
98
+ }
94
99
}
95
100
96
101
void setCACert (const char *cert) { p_stream->setCACert (cert); }
@@ -111,12 +116,12 @@ class URLLoaderHLS {
111
116
// we have nothing to do
112
117
if (urls.empty ()) {
113
118
LOGD (" urls empty" );
114
- delay (10 );
119
+ delay (HLS_UNDER_OVERFLOW_WAIT_TIME );
115
120
return ;
116
121
}
117
122
if (buffer.availableForWrite () == 0 ) {
118
123
LOGD (" buffer full" );
119
- delay (10 );
124
+ delay (HLS_UNDER_OVERFLOW_WAIT_TIME );
120
125
return ;
121
126
}
122
127
@@ -203,7 +208,7 @@ class URLHistory {
203
208
};
204
209
205
210
/* *
206
- * @brief Simple Parser for HLS data. We select the entry with min bandwidth
211
+ * @brief Simple Parser for HLS data.
207
212
* @author Phil Schatzmann
208
213
* @copyright GPLv3
209
214
*/
@@ -271,7 +276,6 @@ class HLSParser {
271
276
const char *indexUrl () { return index_url_str; }
272
277
273
278
const char *segmentsUrl () {
274
- if (segments_url_str == nullptr ) return nullptr ;
275
279
return segments_url_str.c_str ();
276
280
}
277
281
@@ -427,11 +431,13 @@ class HLSParser {
427
431
}
428
432
return result;
429
433
}
434
+
430
435
// / Determine codec for min bandwidth
431
436
bool parseIndexLine (StrView &str) {
432
437
TRACED ();
433
438
LOGI (" > %s" , str.c_str ());
434
439
parseIndexLineMetaData (str);
440
+ // in some exceptional cases the index provided segement info
435
441
parseSegmentLineMetaData (str);
436
442
parseLineURL (str);
437
443
return true ;
@@ -440,10 +446,6 @@ class HLSParser {
440
446
bool parseIndexLineMetaData (StrView &str) {
441
447
int tmp_bandwidth;
442
448
if (str.startsWith (" #" )) {
443
- if (str.indexOf (" #EXTINF" ) >= 0 ) {
444
- next_url_type = URLType::Segment;
445
- }
446
-
447
449
if (str.indexOf (" EXT-X-STREAM-INF" ) >= 0 ) {
448
450
next_url_type = URLType::Index;
449
451
// determine min bandwidth
@@ -541,13 +543,12 @@ class HLSParser {
541
543
memset (tmp, 0 , MAX_HLS_LINE);
542
544
while (true ) {
543
545
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);
546
547
if (len == 0 && url_stream.available () == 0 ) break ;
547
548
StrView str (tmp);
548
549
549
550
// check header
550
- if (str.indexOf (" #EXTM3U" ) >= 0 ) {
551
+ if (str.startsWith (" #EXTM3U" )) {
551
552
is_extm3u = true ;
552
553
resetTimings ();
553
554
}
@@ -572,9 +573,8 @@ class HLSParser {
572
573
573
574
bool parseSegmentLineMetaData (StrView &str) {
574
575
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 );
578
578
LOGI (" media_sequence: %d" , new_media_sequence);
579
579
if (new_media_sequence == media_sequence) {
580
580
LOGW (" MEDIA-SEQUENCE already loaded: %d" , media_sequence);
@@ -673,7 +673,7 @@ class HLSStream : public AbstractURLStream {
673
673
return rc;
674
674
}
675
675
676
- // ends the request
676
+ // / ends the request
677
677
void end () { parser.end (); }
678
678
679
679
// / Sets the ssid that will be used for logging in (when calling begin)
@@ -685,6 +685,7 @@ class HLSStream : public AbstractURLStream {
685
685
// / Returns the string representation of the codec of the audio stream
686
686
const char *codec () { return parser.getCodec (); }
687
687
688
+ // / Provides the content type from the http reply
688
689
const char *contentType () { return parser.contentType (); }
689
690
690
691
// / Provides the content length of the actual .ts Segment
0 commit comments