Skip to content

Commit 2206521

Browse files
committed
HLSStream crashes
1 parent 3c7e9e3 commit 2206521

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/AudioTools/AudioCodecs/CodecADTS.h

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,34 @@ class ADTSParser {
105105
ADTSHeader header_ref{0};
106106
bool is_first = true;
107107
bool is_valid = false;
108+
const char *error_fmt_chnange = "- Invalid ADTS change: %s";
109+
const char *error_fmt = "- Invalid ADTS: %s (0x%x)";
108110

109111
bool check() {
110112
if (header.syncword != 0b111111111111) {
113+
LOGW(error_fmt, "sync", header.syncword);
111114
is_valid = false;
112115
}
113116
if (header.id > 6) {
114-
LOGD("- Invalid id");
117+
LOGW(error_fmt, "id", header.id);
115118
is_valid = false;
116119
}
117120
if (header.sampling_freq_idx > 0xb) {
118-
LOGD("- Invalid sampl.freq");
121+
LOGW(error_fmt, "freq", header.sampling_freq_idx);
119122
is_valid = false;
120123
}
121124
if (header.channel_cfg > 2) {
122-
LOGD("- Invalid channels");
125+
LOGW(error_fmt, "channels", header.channel_cfg);
123126
is_valid = false;
124127
}
125-
if (header.frame_length > 1024) {
126-
LOGD("- Invalid frame_length");
128+
if (header.frame_length > 8191) { // tymically <= 768
129+
LOGW(error_fmt, "frame_length", header.frame_length);
127130
is_valid = false;
128131
}
132+
// on subsequent checks we need to compare with the first header
129133
if (!is_first) {
130134
is_valid = checkRef();
131135
}
132-
if (!is_valid) {
133-
LOGD("=> Invalid ADTS");
134-
}
135136
if (is_valid) {
136137
is_first = false;
137138
header_ref = header;
@@ -140,17 +141,34 @@ class ADTSParser {
140141
}
141142

142143
bool checkRef() {
144+
char msg[200] = "";
143145
bool is_valid = true;
144-
if (header.id != header_ref.id) is_valid = false;
145-
if (header.layer != header_ref.layer) is_valid = false;
146-
if (header.profile != header_ref.profile) is_valid = false;
147-
if (header.sampling_freq_idx != header_ref.sampling_freq_idx)
146+
if (header.id != header_ref.id) {
147+
strcat(msg, "id ");
148+
is_valid = false;
149+
}
150+
if (header.layer != header_ref.layer) {
151+
strcat(msg, "layer ");
152+
is_valid = false;
153+
}
154+
if (header.profile != header_ref.profile) {
155+
strcat(msg, "profile ");
148156
is_valid = false;
149-
if (header.channel_cfg != header_ref.channel_cfg) is_valid = false;
150-
if (header.adts_buf_fullness != header_ref.adts_buf_fullness)
157+
}
158+
if (header.sampling_freq_idx != header_ref.sampling_freq_idx) {
159+
strcat(msg, "freq ");
160+
is_valid = false;
161+
}
162+
if (header.channel_cfg != header_ref.channel_cfg) {
163+
strcat(msg, "channel ");
151164
is_valid = false;
165+
}
166+
if (header.adts_buf_fullness != header_ref.adts_buf_fullness) {
167+
strcat(msg, "fullness");
168+
is_valid = false;
169+
}
152170
if (!is_valid) {
153-
LOGE("=> Invalid ADTS change");
171+
LOGW(error_fmt_chnange, msg);
154172
}
155173
return is_valid;
156174
}
@@ -211,7 +229,7 @@ class ADTSDecoder : public AudioDecoder {
211229
void setParseBufferSize(int size) { buffer.resize(size); }
212230

213231
/// Defines where the decoded result is written to
214-
void setOutput(AudioStream &out_stream) override{
232+
void setOutput(AudioStream &out_stream) override {
215233
if (p_dec) {
216234
p_dec->setOutput(out_stream);
217235
} else {

src/AudioTools/AudioLibs/HLSStream.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class URLLoaderHLS {
153153
LOGD("buffer add %d -> %d:", read, buffer.available());
154154

155155
to_write = min(buffer.availableForWrite(), DEFAULT_BUFFER_SIZE);
156+
} else {
157+
delay(10);
156158
}
157159
// After we processed all data we close the stream to get a new url
158160
if (url_stream.totalRead() == url_stream.contentLength()) {
@@ -174,6 +176,7 @@ class URLLoaderHLS {
174176
class URLHistory {
175177
public:
176178
bool add(const char *url) {
179+
if (url==nullptr) return true;
177180
bool found = false;
178181
StrView url_str(url);
179182
for (int j = 0; j < history.size(); j++) {

0 commit comments

Comments
 (0)