Compare commits

...

3 Commits

Author SHA1 Message Date
Philippe G
c8054ff9d2 protect stream poll against race condition - release 2020-08-28 17:13:05 -07:00
Philippe G
e0e02f1e5f release ! 2020-08-27 16:43:49 -07:00
Philippe G
7f671909bb better mad sync 2020-08-27 16:40:11 -07:00
2 changed files with 14 additions and 3 deletions

View File

@@ -243,6 +243,8 @@ static decode_state mad_decode(void) {
MAD(m, synth_frame, &m->synth, &m->frame); MAD(m, synth_frame, &m->synth, &m->frame);
if (decode.new_stream) { if (decode.new_stream) {
// seems that mad can use some help in term of sync detection
if (m->stream.next_frame[0] != 0xff || (m->stream.next_frame[1] & 0xf0) != 0xf0) continue;
LOCK_O; LOCK_O;
LOG_INFO("setting track_start"); LOG_INFO("setting track_start");
output.next_sample_rate = decode_newstream(m->synth.pcm.samplerate, output.supported_rates); output.next_sample_rate = decode_newstream(m->synth.pcm.samplerate, output.supported_rates);
@@ -417,3 +419,4 @@ struct codec *register_mad(void) {
LOG_INFO("using mad to decode mp3"); LOG_INFO("using mad to decode mp3");
return &ret; return &ret;
} }

View File

@@ -40,6 +40,7 @@
static log_level loglevel; static log_level loglevel;
static struct buffer buf; static struct buffer buf;
static mutex_type poll_mutex;
struct buffer *streambuf = &buf; struct buffer *streambuf = &buf;
#define LOCK mutex_lock(streambuf->mutex) #define LOCK mutex_lock(streambuf->mutex)
@@ -196,7 +197,11 @@ static void *stream_thread() {
UNLOCK; UNLOCK;
if (_poll(ssl, &pollinfo, 100)) { mutex_lock(poll_mutex);
int pending = _poll(ssl, &pollinfo, 100);
mutex_unlock(poll_mutex);
if (pending) {
LOCK; LOCK;
@@ -350,7 +355,6 @@ static void *stream_thread() {
UNLOCK; UNLOCK;
} else { } else {
LOG_SDEBUG("poll timeout"); LOG_SDEBUG("poll timeout");
} }
} }
@@ -403,6 +407,7 @@ void stream_init(log_level level, unsigned stream_buf_size) {
*stream.header = '\0'; *stream.header = '\0';
fd = -1; fd = -1;
mutex_create_p(poll_mutex);
#if LINUX || FREEBSD #if LINUX || FREEBSD
touch_memory(streambuf->buf, streambuf->size); touch_memory(streambuf->buf, streambuf->size);
@@ -432,6 +437,7 @@ void stream_close(void) {
#endif #endif
free(stream.header); free(stream.header);
buf_destroy(streambuf); buf_destroy(streambuf);
mutex_destroy(poll_mutex);
} }
void stream_file(const char *header, size_t header_len, unsigned threshold) { void stream_file(const char *header, size_t header_len, unsigned threshold) {
@@ -573,6 +579,7 @@ void stream_sock(u32_t ip, u16_t port, const char *header, size_t header_len, un
bool stream_disconnect(void) { bool stream_disconnect(void) {
bool disc = false; bool disc = false;
mutex_lock(poll_mutex);
LOCK; LOCK;
#if USE_SSL #if USE_SSL
if (ssl) { if (ssl) {
@@ -588,5 +595,6 @@ bool stream_disconnect(void) {
} }
stream.state = STOPPED; stream.state = STOPPED;
UNLOCK; UNLOCK;
mutex_unlock(poll_mutex);
return disc; return disc;
} }