@@ -26,7 +26,6 @@ namespace audio_tools_hls {
26
26
27
27
class URLLoaderHLS {
28
28
public:
29
- // URLLoaderHLS(URLStream &stream) { p_stream = &stream; };
30
29
URLLoaderHLS () = default ;
31
30
32
31
~URLLoaderHLS () { end (); }
@@ -41,8 +40,7 @@ class URLLoaderHLS {
41
40
42
41
void end () {
43
42
TRACED ();
44
- if (p_stream != nullptr ) p_stream->end ();
45
- p_stream = nullptr ;
43
+ url_stream.end ();
46
44
buffer.clear ();
47
45
active = false ;
48
46
}
@@ -80,13 +78,11 @@ class URLLoaderHLS {
80
78
}
81
79
82
80
const char *contentType () {
83
- if (p_stream == nullptr ) return nullptr ;
84
- return p_stream->httpRequest ().reply ().get (CONTENT_TYPE);
81
+ return url_stream.httpRequest ().reply ().get (CONTENT_TYPE);
85
82
}
86
83
87
84
int contentLength () {
88
- if (p_stream == nullptr ) return 0 ;
89
- return p_stream->contentLength ();
85
+ return url_stream.contentLength ();
90
86
}
91
87
92
88
void setBufferSize (int size, int count) {
@@ -98,16 +94,15 @@ class URLLoaderHLS {
98
94
}
99
95
}
100
96
101
- void setCACert (const char *cert) { p_stream-> setCACert (cert); }
97
+ void setCACert (const char *cert) { url_stream. setCACert (cert); }
102
98
103
99
protected:
104
100
Vector<const char *> urls{10 };
105
101
RingBuffer<uint8_t > buffer{0 };
106
102
bool active = false ;
107
103
int buffer_size = DEFAULT_BUFFER_SIZE;
108
104
int buffer_count = HLS_BUFFER_COUNT;
109
- URLStream default_stream;
110
- URLStream *p_stream = &default_stream;
105
+ URLStream url_stream;
111
106
const char *url_to_play = nullptr ;
112
107
113
108
// / try to keep the buffer filled
@@ -126,22 +121,22 @@ class URLLoaderHLS {
126
121
}
127
122
128
123
// switch current stream if we have no more data
129
- if (!*p_stream && !urls.empty ()) {
124
+ if (!url_stream && !urls.empty ()) {
130
125
LOGD (" Refilling" );
131
126
if (url_to_play != nullptr ) {
132
127
delete url_to_play;
133
128
}
134
129
url_to_play = urls[0 ];
135
130
LOGI (" playing %s" , url_to_play);
136
- p_stream-> end ();
137
- p_stream-> setConnectionClose (true );
138
- p_stream-> setTimeout (HLS_TIMEOUT);
139
- p_stream-> begin (url_to_play);
140
- p_stream-> waitForData (HLS_TIMEOUT);
131
+ url_stream. end ();
132
+ url_stream. setConnectionClose (true );
133
+ url_stream. setTimeout (HLS_TIMEOUT);
134
+ url_stream. begin (url_to_play);
135
+ url_stream. waitForData (HLS_TIMEOUT);
141
136
urls.pop_front ();
142
137
// assert(urls[0]!=url);
143
138
144
- LOGI (" Playing %s of %d" , p_stream-> urlStr (), (int )urls.size ());
139
+ LOGI (" Playing %s of %d" , url_stream. urlStr (), (int )urls.size ());
145
140
}
146
141
147
142
int total = 0 ;
@@ -150,7 +145,7 @@ class URLLoaderHLS {
150
145
// try to keep the buffer filled
151
146
while (to_write > 0 ) {
152
147
uint8_t tmp[to_write] = {0 };
153
- int read = p_stream-> readBytes (tmp, to_write);
148
+ int read = url_stream. readBytes (tmp, to_write);
154
149
total += read;
155
150
if (read > 0 ) {
156
151
failed = 0 ;
@@ -160,10 +155,10 @@ class URLLoaderHLS {
160
155
to_write = min (buffer.availableForWrite (), DEFAULT_BUFFER_SIZE);
161
156
}
162
157
// After we processed all data we close the stream to get a new url
163
- if (p_stream-> totalRead () == p_stream-> contentLength ()) {
158
+ if (url_stream. totalRead () == url_stream. contentLength ()) {
164
159
LOGI (" Closing stream because all bytes were processed: available: %d" ,
165
- p_stream-> available ());
166
- p_stream-> end ();
160
+ url_stream. available ());
161
+ url_stream. end ();
167
162
break ;
168
163
}
169
164
LOGD (" Refilled with %d now %d available to write" , total,
0 commit comments