Compare commits

..

4 Commits

Author SHA1 Message Date
Philippe G
ce369638da extend poll() protection - release 2020-08-28 19:40:57 -07:00
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 16 additions and 4 deletions

View File

@@ -243,6 +243,8 @@ static decode_state mad_decode(void) {
MAD(m, synth_frame, &m->synth, &m->frame);
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;
LOG_INFO("setting track_start");
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");
return &ret;
}

View File

@@ -40,10 +40,13 @@
static log_level loglevel;
static struct buffer buf;
static mutex_type poll_mutex;
struct buffer *streambuf = &buf;
#define LOCK mutex_lock(streambuf->mutex)
#define UNLOCK mutex_unlock(streambuf->mutex)
#define LOCK mutex_lock(streambuf->mutex)
#define UNLOCK mutex_unlock(streambuf->mutex)
#define LOCK_L mutex_lock(poll_mutex)
#define UNLOCK_L mutex_unlock(poll_mutex)
static sockfd fd;
@@ -187,6 +190,7 @@ static void *stream_thread() {
} else {
LOCK_L;
pollinfo.fd = fd;
pollinfo.events = POLLIN;
if (stream.state == SEND_HEADERS) {
@@ -195,9 +199,10 @@ static void *stream_thread() {
}
UNLOCK;
if (_poll(ssl, &pollinfo, 100)) {
UNLOCK_L;
LOCK;
// check socket has not been closed while in poll
@@ -350,7 +355,7 @@ static void *stream_thread() {
UNLOCK;
} else {
UNLOCK_L;
LOG_SDEBUG("poll timeout");
}
}
@@ -403,6 +408,7 @@ void stream_init(log_level level, unsigned stream_buf_size) {
*stream.header = '\0';
fd = -1;
mutex_create_p(poll_mutex);
#if LINUX || FREEBSD
touch_memory(streambuf->buf, streambuf->size);
@@ -432,6 +438,7 @@ void stream_close(void) {
#endif
free(stream.header);
buf_destroy(streambuf);
mutex_destroy(poll_mutex);
}
void stream_file(const char *header, size_t header_len, unsigned threshold) {
@@ -581,11 +588,13 @@ bool stream_disconnect(void) {
ssl = NULL;
}
#endif
LOCK_L;
if (fd != -1) {
closesocket(fd);
fd = -1;
disc = true;
}
UNLOCK_L,
stream.state = STOPPED;
UNLOCK;
return disc;