8#define MAX_HLS_LINE 512
9#define START_URLS_LIMIT 4
10#define HLS_BUFFER_COUNT 2
11#define HLS_MAX_NO_READ 2
12#define HLS_MAX_URL_LEN 256
13#define HLS_TIMEOUT 4000
14#define HLS_UNDER_OVERFLOW_WAIT_TIME 10
15#define HLS_RELOAD_RETRY_DELAY 2000
35template <
typename URLStream>
60 LOGI(
"Adding %s", url);
62 char *str =
new char[url_str.length() + 1];
63 memcpy(str, url_str.c_str(), url_str.length() + 1);
91 return url_stream.httpRequest().reply().get(CONTENT_TYPE);
162 while (to_write > 0) {
163 uint8_t tmp[to_write];
164 memset(tmp, 0, to_write);
165 int read =
url_stream.readBytes(tmp, to_write);
178 LOGI(
"Closing stream because all bytes were processed: available: %d",
183 LOGD(
"Refilled with %d now %d available to write", total,
195 bool add(
const char *url) {
196 if (url ==
nullptr)
return true;
198 StrView url_str(url);
200 if (url_str.equals(
history[j])) {
206 char *str =
new char[url_str.length() + 1];
207 memcpy(str, url, url_str.length() + 1);
230template <
typename URLStream>
343 const char *reqURL)) {
377 const char *(*resolve_url)(
const char *segment,
382 static const char *
resolveURL(
const char *segment,
const char *reqURL) {
386 StrView index_url(reqURL);
388 int end = index_url.lastIndexOf(
"?");
390 result_str.substring(reqURL, 0,
end);
392 end = index_url.lastIndexOf(
"/");
394 result_str.substring(reqURL, 0,
end);
398 if (result_str.isEmpty()) {
402 if (!result_str.endsWith(
"/")) {
406 result_str.add(segment);
407 LOGI(
">> relative addr: %s for %s", segment, reqURL);
408 LOGD(
">> -> %s", result);
446 if (len == 0 &&
url_stream.available() == 0)
break;
450 if (str.startsWith(
"#EXTM3U")) {
468 LOGI(
"> %s", str.c_str());
478 if (str.startsWith(
"#")) {
479 if (str.indexOf(
"EXT-X-STREAM-INF") >= 0) {
482 int pos = str.indexOf(
"BANDWIDTH=");
484 StrView num(str.c_str() + pos + 10);
485 tmp_bandwidth = num.toInt();
493 pos = str.indexOf(
"CODECS=");
496 int end = str.indexOf(
'"', pos + 10);
589 if (len == 0 &&
url_stream.available() == 0)
break;
593 if (str.startsWith(
"#EXTM3U")) {
610 LOGI(
"> %s", str.c_str());
617 if (str.startsWith(
"#")) {
618 if (str.startsWith(
"#EXT-X-MEDIA-SEQUENCE:")) {
619 int new_media_sequence = atoi(str.c_str() + 22);
620 LOGI(
"media_sequence: %d", new_media_sequence);
632 if (str.startsWith(
"#EXTINF")) {
634 StrView sec_str(str.c_str() + 8);
635 float sec = sec_str.toFloat();
636 LOGI(
"adding play time: %f sec", sec);
644 if (!str.startsWith(
"#")) {
651 if (str.startsWith(
"http")) {
662 if (str.startsWith(
"http")) {
670 LOGD(
"Duplicate ignored: %s", str.c_str());
694template <
typename URLStream>
744 return parser.available();
750 return parser.readBytes(data, len);
771 const char *result =
nullptr;
773 result =
parser.contentType();
775 if (result)
LOGI(
"-> Format: %s", result);
782 const char *reqURL)) {
783 parser.setURLResolver(cb);
812 LOGW(
"login not supported");
818 const char *reqMime =
"",
const char *reqData =
"")
override {
static HardwareSerial Serial
Definition Arduino.h:179
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define TRACEE()
Definition AudioLoggerIDF.h:34
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define START_URLS_LIMIT
Definition HLSStream.h:9
#define HLS_RELOAD_RETRY_DELAY
Definition HLSStream.h:15
#define MAX_HLS_LINE
Definition HLSStream.h:8
#define HLS_MAX_URL_LEN
Definition HLSStream.h:12
#define HLS_UNDER_OVERFLOW_WAIT_TIME
Definition HLSStream.h:14
#define HLS_TIMEOUT
Definition HLSStream.h:13
#define HLS_BUFFER_COUNT
Definition HLSStream.h:10
MethodID
supported http methods
Definition HttpTypes.h:3
@ GET
Definition HttpTypes.h:5
#define DEFAULT_BUFFER_SIZE
Definition avr.h:20
#define assert(T)
Definition avr.h:10
Definition HLSStream.h:193
bool add(const char *url)
Definition HLSStream.h:195
Vector< const char * > history
Definition HLSStream.h:222
void clear()
Definition HLSStream.h:217
int size()
Definition HLSStream.h:219