MFH: r551843 r552018

gecko: update OSS patches

Changes:	cc85508...1f3771f
Changes:	https://github.com/kinetiknz/cubeb/commit/4e60bb8
Approved by:	ports-secteam blanket
This commit is contained in:
Jan Beich 2020-10-10 20:36:11 +00:00
parent b40a952a51
commit 8ab2ba6f0e
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/branches/2020Q4/; revision=552020
6 changed files with 180 additions and 117 deletions

View File

@ -3,7 +3,7 @@
PORTNAME= thunderbird
DISTVERSION= 78.3.2
PORTREVISION= 1
PORTREVISION= 3
CATEGORIES= mail news net-im
MASTER_SITES= MOZILLA/${PORTNAME}/releases/${DISTVERSION}/source \
MOZILLA/${PORTNAME}/candidates/${DISTVERSION}-candidates/build1/source

View File

@ -61,7 +61,7 @@ https://github.com/kinetiknz/cubeb/pull/600
#endif
--- /dev/null
+++ media/libcubeb/src/cubeb_oss.c
@@ -0,0 +1,1242 @@
@@ -0,0 +1,1263 @@
+/*
+ * Copyright © 2019-2020 Nia Alarie <nia@NetBSD.org>
+ * Copyright © 2020 Ka Ho Ng <khng300@gmail.com>
@ -179,19 +179,20 @@ https://github.com/kinetiknz/cubeb/pull/600
+ struct cubeb * context;
+ void * user_ptr;
+ pthread_t thread;
+ pthread_cond_t doorbell_cv;
+ pthread_cond_t stopped_cv;
+ /* protects doorbell_cv, stopped_cv, running, destroying, volume, frames_written */
+ pthread_mutex_t mtx;
+ bool thread_created;
+ bool running;
+ bool destroying;
+ float volume;
+ bool doorbell; /* (m) */
+ pthread_cond_t doorbell_cv; /* (m) */
+ pthread_cond_t stopped_cv; /* (m) */
+ pthread_mutex_t mtx; /* Members protected by this should be marked (m) */
+ bool thread_created; /* (m) */
+ bool running; /* (m) */
+ bool destroying; /* (m) */
+ cubeb_state state; /* (m) */
+ float volume /* (m) */;
+ struct oss_stream play;
+ struct oss_stream record;
+ cubeb_data_callback data_cb;
+ cubeb_state_callback state_cb;
+ uint64_t frames_written;
+ uint64_t frames_written /* (m) */;
+ unsigned int nfr; /* Number of frames allocated */
+ unsigned int nfrags;
+ unsigned int bufframes;
@ -728,10 +729,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created && s->running) {
+ s->running = false;
+ pthread_cond_signal(&s->doorbell_cv);
+ s->doorbell = false;
+ pthread_cond_wait(&s->stopped_cv, &s->mtx);
+ }
+ pthread_mutex_unlock(&s->mtx);
+ if (s->state != CUBEB_STATE_STOPPED) {
+ s->state = CUBEB_STATE_STOPPED;
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STOPPED);
+ } else {
+ pthread_mutex_unlock(&s->mtx);
+ }
+ return CUBEB_OK;
+}
+
@ -741,6 +748,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created) {
+ s->destroying = true;
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -800,10 +808,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+}
+
+/* 1 - Stopped by cubeb_stream_stop, otherwise 0 */
+static int
+oss_audio_loop(cubeb_stream * s)
+oss_audio_loop(cubeb_stream * s, cubeb_state *new_state)
+{
+ int state = CUBEB_STATE_STARTED;
+ cubeb_state state = CUBEB_STATE_STOPPED;
+ int trig = 0;
+ int drain = 0;
+ struct pollfd pfds[2];
@ -821,13 +830,13 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ trig |= PCM_ENABLE_INPUT;
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ memset(s->record.buf, 0, s->bufframes * s->record.frame_size);
+ }
@ -838,7 +847,6 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running || s->destroying) {
+ pthread_mutex_unlock(&s->mtx);
+ state = CUBEB_STATE_STOPPED;
+ break;
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -848,8 +856,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ * play-only stream or record-only stream
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ break;
+ goto breakdown;
+ }
+
+ while ((s->bufframes - ppending) >= s->nfr && rpending >= s->nfr) {
@ -865,7 +872,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ nfr = s->data_cb(s, s->user_ptr, rptr, pptr, n);
+ if (nfr == CUBEB_ERROR) {
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ if (pptr) {
+ float vol;
@ -902,7 +909,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ goto out;
+ goto breakdown;
+ }
+ }
+ }
@ -919,7 +926,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ continue;
+ LOG("Error %d occured when polling playback and record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ } else if (nfds == 0)
+ continue;
+
@ -927,7 +934,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ (pfds[1].revents & (POLLERR | POLLHUP))) {
+ LOG("Error occured on playback, record fds");
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+
+ if (pfds[0].revents) {
@ -942,7 +949,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ break;
+ }
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->play.frame_size;
+ pthread_mutex_lock(&s->mtx);
@ -963,7 +970,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (errno == EAGAIN)
+ break;
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->record.frame_size;
+ rpending += frames;
@ -971,19 +978,26 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ if (drain) {
+ state = CUBEB_STATE_DRAINED;
+ break;
+ goto breakdown;
+ }
+ }
+
+out:
+ return state;
+ return 1;
+
+breakdown:
+ pthread_mutex_lock(&s->mtx);
+ *new_state = s->state = state;
+ s->running = false;
+ pthread_mutex_unlock(&s->mtx);
+ return 0;
+}
+
+static void *
+oss_io_routine(void *arg)
+{
+ cubeb_stream *s = arg;
+ cubeb_state state = CUBEB_STATE_STARTED;
+ cubeb_state new_state;
+ int stopped;
+
+ do {
+ pthread_mutex_lock(&s->mtx);
@ -993,15 +1007,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ pthread_mutex_unlock(&s->mtx);
+
+ state = CUBEB_STATE_STARTED;
+ s->state_cb(s, s->user_ptr, state);
+
+ state = oss_audio_loop(s);
+ assert(state != CUBEB_STATE_STARTED);
+
+ stopped = oss_audio_loop(s, &new_state);
+ if (s->record.fd != -1)
+ ioctl(s->record.fd, SNDCTL_DSP_HALT_INPUT, NULL);
+ s->state_cb(s, s->user_ptr, state);
+ if (!stopped)
+ s->state_cb(s, s->user_ptr, new_state);
+
+ pthread_mutex_lock(&s->mtx);
+ pthread_cond_signal(&s->stopped_cv);
@ -1009,7 +1019,10 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_unlock(&s->mtx);
+ break;
+ }
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ while (!s->doorbell) {
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ }
+ s->doorbell = false;
+ pthread_mutex_unlock(&s->mtx);
+ } while (1);
+
@ -1061,6 +1074,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ ret = CUBEB_ERROR;
+ goto error;
+ }
+ s->state = CUBEB_STATE_STOPPED;
+ s->record.fd = s->play.fd = -1;
+ s->nfr = latency_frames;
+ if (input_device != NULL) {
@ -1169,6 +1183,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ LOG("Failed to create cv");
+ goto error;
+ }
+ s->doorbell = false;
+
+ if (s->play.fd != -1) {
+ if ((s->play.buf = calloc(s->bufframes, s->play.frame_size)) == NULL) {
@ -1196,6 +1211,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+oss_stream_thr_create(cubeb_stream * s)
+{
+ if (s->thread_created) {
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ return CUBEB_OK;
+ }
@ -1211,11 +1227,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+static int
+oss_stream_start(cubeb_stream * s)
+{
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STARTED);
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running && oss_stream_thr_create(s) != CUBEB_OK) {
+ /* Disallow starting an already started stream */
+ assert(!s->running && s->state != CUBEB_STATE_STARTED);
+ if (oss_stream_thr_create(s) != CUBEB_OK) {
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_ERROR);
+ return CUBEB_ERROR;
+ }
+ s->state = CUBEB_STATE_STARTED;
+ s->thread_created = true;
+ s->running = true;
+ pthread_mutex_unlock(&s->mtx);

View File

@ -3,7 +3,7 @@
PORTNAME= firefox
DISTVERSION= 78.3.1
PORTREVISION= 1
PORTREVISION= 3
PORTEPOCH= 1
CATEGORIES= www
MASTER_SITES= MOZILLA/${PORTNAME}/releases/${DISTVERSION}esr/source \

View File

@ -61,7 +61,7 @@ https://github.com/kinetiknz/cubeb/pull/600
#endif
--- /dev/null
+++ media/libcubeb/src/cubeb_oss.c
@@ -0,0 +1,1242 @@
@@ -0,0 +1,1263 @@
+/*
+ * Copyright © 2019-2020 Nia Alarie <nia@NetBSD.org>
+ * Copyright © 2020 Ka Ho Ng <khng300@gmail.com>
@ -179,19 +179,20 @@ https://github.com/kinetiknz/cubeb/pull/600
+ struct cubeb * context;
+ void * user_ptr;
+ pthread_t thread;
+ pthread_cond_t doorbell_cv;
+ pthread_cond_t stopped_cv;
+ /* protects doorbell_cv, stopped_cv, running, destroying, volume, frames_written */
+ pthread_mutex_t mtx;
+ bool thread_created;
+ bool running;
+ bool destroying;
+ float volume;
+ bool doorbell; /* (m) */
+ pthread_cond_t doorbell_cv; /* (m) */
+ pthread_cond_t stopped_cv; /* (m) */
+ pthread_mutex_t mtx; /* Members protected by this should be marked (m) */
+ bool thread_created; /* (m) */
+ bool running; /* (m) */
+ bool destroying; /* (m) */
+ cubeb_state state; /* (m) */
+ float volume /* (m) */;
+ struct oss_stream play;
+ struct oss_stream record;
+ cubeb_data_callback data_cb;
+ cubeb_state_callback state_cb;
+ uint64_t frames_written;
+ uint64_t frames_written /* (m) */;
+ unsigned int nfr; /* Number of frames allocated */
+ unsigned int nfrags;
+ unsigned int bufframes;
@ -728,10 +729,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created && s->running) {
+ s->running = false;
+ pthread_cond_signal(&s->doorbell_cv);
+ s->doorbell = false;
+ pthread_cond_wait(&s->stopped_cv, &s->mtx);
+ }
+ pthread_mutex_unlock(&s->mtx);
+ if (s->state != CUBEB_STATE_STOPPED) {
+ s->state = CUBEB_STATE_STOPPED;
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STOPPED);
+ } else {
+ pthread_mutex_unlock(&s->mtx);
+ }
+ return CUBEB_OK;
+}
+
@ -741,6 +748,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created) {
+ s->destroying = true;
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -800,10 +808,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+}
+
+/* 1 - Stopped by cubeb_stream_stop, otherwise 0 */
+static int
+oss_audio_loop(cubeb_stream * s)
+oss_audio_loop(cubeb_stream * s, cubeb_state *new_state)
+{
+ int state = CUBEB_STATE_STARTED;
+ cubeb_state state = CUBEB_STATE_STOPPED;
+ int trig = 0;
+ int drain = 0;
+ struct pollfd pfds[2];
@ -821,13 +830,13 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ trig |= PCM_ENABLE_INPUT;
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ memset(s->record.buf, 0, s->bufframes * s->record.frame_size);
+ }
@ -838,7 +847,6 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running || s->destroying) {
+ pthread_mutex_unlock(&s->mtx);
+ state = CUBEB_STATE_STOPPED;
+ break;
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -848,8 +856,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ * play-only stream or record-only stream
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ break;
+ goto breakdown;
+ }
+
+ while ((s->bufframes - ppending) >= s->nfr && rpending >= s->nfr) {
@ -865,7 +872,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ nfr = s->data_cb(s, s->user_ptr, rptr, pptr, n);
+ if (nfr == CUBEB_ERROR) {
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ if (pptr) {
+ float vol;
@ -902,7 +909,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ goto out;
+ goto breakdown;
+ }
+ }
+ }
@ -919,7 +926,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ continue;
+ LOG("Error %d occured when polling playback and record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ } else if (nfds == 0)
+ continue;
+
@ -927,7 +934,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ (pfds[1].revents & (POLLERR | POLLHUP))) {
+ LOG("Error occured on playback, record fds");
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+
+ if (pfds[0].revents) {
@ -942,7 +949,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ break;
+ }
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->play.frame_size;
+ pthread_mutex_lock(&s->mtx);
@ -963,7 +970,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (errno == EAGAIN)
+ break;
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->record.frame_size;
+ rpending += frames;
@ -971,19 +978,26 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ if (drain) {
+ state = CUBEB_STATE_DRAINED;
+ break;
+ goto breakdown;
+ }
+ }
+
+out:
+ return state;
+ return 1;
+
+breakdown:
+ pthread_mutex_lock(&s->mtx);
+ *new_state = s->state = state;
+ s->running = false;
+ pthread_mutex_unlock(&s->mtx);
+ return 0;
+}
+
+static void *
+oss_io_routine(void *arg)
+{
+ cubeb_stream *s = arg;
+ cubeb_state state = CUBEB_STATE_STARTED;
+ cubeb_state new_state;
+ int stopped;
+
+ do {
+ pthread_mutex_lock(&s->mtx);
@ -993,15 +1007,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ pthread_mutex_unlock(&s->mtx);
+
+ state = CUBEB_STATE_STARTED;
+ s->state_cb(s, s->user_ptr, state);
+
+ state = oss_audio_loop(s);
+ assert(state != CUBEB_STATE_STARTED);
+
+ stopped = oss_audio_loop(s, &new_state);
+ if (s->record.fd != -1)
+ ioctl(s->record.fd, SNDCTL_DSP_HALT_INPUT, NULL);
+ s->state_cb(s, s->user_ptr, state);
+ if (!stopped)
+ s->state_cb(s, s->user_ptr, new_state);
+
+ pthread_mutex_lock(&s->mtx);
+ pthread_cond_signal(&s->stopped_cv);
@ -1009,7 +1019,10 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_unlock(&s->mtx);
+ break;
+ }
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ while (!s->doorbell) {
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ }
+ s->doorbell = false;
+ pthread_mutex_unlock(&s->mtx);
+ } while (1);
+
@ -1061,6 +1074,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ ret = CUBEB_ERROR;
+ goto error;
+ }
+ s->state = CUBEB_STATE_STOPPED;
+ s->record.fd = s->play.fd = -1;
+ s->nfr = latency_frames;
+ if (input_device != NULL) {
@ -1169,6 +1183,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ LOG("Failed to create cv");
+ goto error;
+ }
+ s->doorbell = false;
+
+ if (s->play.fd != -1) {
+ if ((s->play.buf = calloc(s->bufframes, s->play.frame_size)) == NULL) {
@ -1196,6 +1211,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+oss_stream_thr_create(cubeb_stream * s)
+{
+ if (s->thread_created) {
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ return CUBEB_OK;
+ }
@ -1211,11 +1227,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+static int
+oss_stream_start(cubeb_stream * s)
+{
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STARTED);
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running && oss_stream_thr_create(s) != CUBEB_OK) {
+ /* Disallow starting an already started stream */
+ assert(!s->running && s->state != CUBEB_STATE_STARTED);
+ if (oss_stream_thr_create(s) != CUBEB_OK) {
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_ERROR);
+ return CUBEB_ERROR;
+ }
+ s->state = CUBEB_STATE_STARTED;
+ s->thread_created = true;
+ s->running = true;
+ pthread_mutex_unlock(&s->mtx);

View File

@ -3,7 +3,7 @@
PORTNAME= firefox
DISTVERSION= 81.0.1
PORTREVISION= 1
PORTREVISION= 3
PORTEPOCH= 2
CATEGORIES= www
MASTER_SITES= MOZILLA/${PORTNAME}/releases/${DISTVERSION}/source \

View File

@ -61,7 +61,7 @@ https://github.com/kinetiknz/cubeb/pull/600
#endif
--- /dev/null
+++ media/libcubeb/src/cubeb_oss.c
@@ -0,0 +1,1242 @@
@@ -0,0 +1,1263 @@
+/*
+ * Copyright © 2019-2020 Nia Alarie <nia@NetBSD.org>
+ * Copyright © 2020 Ka Ho Ng <khng300@gmail.com>
@ -179,19 +179,20 @@ https://github.com/kinetiknz/cubeb/pull/600
+ struct cubeb * context;
+ void * user_ptr;
+ pthread_t thread;
+ pthread_cond_t doorbell_cv;
+ pthread_cond_t stopped_cv;
+ /* protects doorbell_cv, stopped_cv, running, destroying, volume, frames_written */
+ pthread_mutex_t mtx;
+ bool thread_created;
+ bool running;
+ bool destroying;
+ float volume;
+ bool doorbell; /* (m) */
+ pthread_cond_t doorbell_cv; /* (m) */
+ pthread_cond_t stopped_cv; /* (m) */
+ pthread_mutex_t mtx; /* Members protected by this should be marked (m) */
+ bool thread_created; /* (m) */
+ bool running; /* (m) */
+ bool destroying; /* (m) */
+ cubeb_state state; /* (m) */
+ float volume /* (m) */;
+ struct oss_stream play;
+ struct oss_stream record;
+ cubeb_data_callback data_cb;
+ cubeb_state_callback state_cb;
+ uint64_t frames_written;
+ uint64_t frames_written /* (m) */;
+ unsigned int nfr; /* Number of frames allocated */
+ unsigned int nfrags;
+ unsigned int bufframes;
@ -728,10 +729,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created && s->running) {
+ s->running = false;
+ pthread_cond_signal(&s->doorbell_cv);
+ s->doorbell = false;
+ pthread_cond_wait(&s->stopped_cv, &s->mtx);
+ }
+ pthread_mutex_unlock(&s->mtx);
+ if (s->state != CUBEB_STATE_STOPPED) {
+ s->state = CUBEB_STATE_STOPPED;
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STOPPED);
+ } else {
+ pthread_mutex_unlock(&s->mtx);
+ }
+ return CUBEB_OK;
+}
+
@ -741,6 +748,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (s->thread_created) {
+ s->destroying = true;
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -800,10 +808,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+}
+
+/* 1 - Stopped by cubeb_stream_stop, otherwise 0 */
+static int
+oss_audio_loop(cubeb_stream * s)
+oss_audio_loop(cubeb_stream * s, cubeb_state *new_state)
+{
+ int state = CUBEB_STATE_STARTED;
+ cubeb_state state = CUBEB_STATE_STOPPED;
+ int trig = 0;
+ int drain = 0;
+ struct pollfd pfds[2];
@ -821,13 +830,13 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ trig |= PCM_ENABLE_INPUT;
+ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
+ LOG("Error %d occured when setting trigger on record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ memset(s->record.buf, 0, s->bufframes * s->record.frame_size);
+ }
@ -838,7 +847,6 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running || s->destroying) {
+ pthread_mutex_unlock(&s->mtx);
+ state = CUBEB_STATE_STOPPED;
+ break;
+ }
+ pthread_mutex_unlock(&s->mtx);
@ -848,8 +856,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ * play-only stream or record-only stream
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ break;
+ goto breakdown;
+ }
+
+ while ((s->bufframes - ppending) >= s->nfr && rpending >= s->nfr) {
@ -865,7 +872,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ nfr = s->data_cb(s, s->user_ptr, rptr, pptr, n);
+ if (nfr == CUBEB_ERROR) {
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ if (pptr) {
+ float vol;
@ -902,7 +909,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ */
+
+ state = CUBEB_STATE_STOPPED;
+ goto out;
+ goto breakdown;
+ }
+ }
+ }
@ -919,7 +926,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ continue;
+ LOG("Error %d occured when polling playback and record fd", errno);
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ } else if (nfds == 0)
+ continue;
+
@ -927,7 +934,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ (pfds[1].revents & (POLLERR | POLLHUP))) {
+ LOG("Error occured on playback, record fds");
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+
+ if (pfds[0].revents) {
@ -942,7 +949,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ break;
+ }
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->play.frame_size;
+ pthread_mutex_lock(&s->mtx);
@ -963,7 +970,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ if (errno == EAGAIN)
+ break;
+ state = CUBEB_STATE_ERROR;
+ goto out;
+ goto breakdown;
+ }
+ frames = n / s->record.frame_size;
+ rpending += frames;
@ -971,19 +978,26 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ if (drain) {
+ state = CUBEB_STATE_DRAINED;
+ break;
+ goto breakdown;
+ }
+ }
+
+out:
+ return state;
+ return 1;
+
+breakdown:
+ pthread_mutex_lock(&s->mtx);
+ *new_state = s->state = state;
+ s->running = false;
+ pthread_mutex_unlock(&s->mtx);
+ return 0;
+}
+
+static void *
+oss_io_routine(void *arg)
+{
+ cubeb_stream *s = arg;
+ cubeb_state state = CUBEB_STATE_STARTED;
+ cubeb_state new_state;
+ int stopped;
+
+ do {
+ pthread_mutex_lock(&s->mtx);
@ -993,15 +1007,11 @@ https://github.com/kinetiknz/cubeb/pull/600
+ }
+ pthread_mutex_unlock(&s->mtx);
+
+ state = CUBEB_STATE_STARTED;
+ s->state_cb(s, s->user_ptr, state);
+
+ state = oss_audio_loop(s);
+ assert(state != CUBEB_STATE_STARTED);
+
+ stopped = oss_audio_loop(s, &new_state);
+ if (s->record.fd != -1)
+ ioctl(s->record.fd, SNDCTL_DSP_HALT_INPUT, NULL);
+ s->state_cb(s, s->user_ptr, state);
+ if (!stopped)
+ s->state_cb(s, s->user_ptr, new_state);
+
+ pthread_mutex_lock(&s->mtx);
+ pthread_cond_signal(&s->stopped_cv);
@ -1009,7 +1019,10 @@ https://github.com/kinetiknz/cubeb/pull/600
+ pthread_mutex_unlock(&s->mtx);
+ break;
+ }
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ while (!s->doorbell) {
+ pthread_cond_wait(&s->doorbell_cv, &s->mtx);
+ }
+ s->doorbell = false;
+ pthread_mutex_unlock(&s->mtx);
+ } while (1);
+
@ -1061,6 +1074,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ ret = CUBEB_ERROR;
+ goto error;
+ }
+ s->state = CUBEB_STATE_STOPPED;
+ s->record.fd = s->play.fd = -1;
+ s->nfr = latency_frames;
+ if (input_device != NULL) {
@ -1169,6 +1183,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+ LOG("Failed to create cv");
+ goto error;
+ }
+ s->doorbell = false;
+
+ if (s->play.fd != -1) {
+ if ((s->play.buf = calloc(s->bufframes, s->play.frame_size)) == NULL) {
@ -1196,6 +1211,7 @@ https://github.com/kinetiknz/cubeb/pull/600
+oss_stream_thr_create(cubeb_stream * s)
+{
+ if (s->thread_created) {
+ s->doorbell = true;
+ pthread_cond_signal(&s->doorbell_cv);
+ return CUBEB_OK;
+ }
@ -1211,11 +1227,16 @@ https://github.com/kinetiknz/cubeb/pull/600
+static int
+oss_stream_start(cubeb_stream * s)
+{
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_STARTED);
+ pthread_mutex_lock(&s->mtx);
+ if (!s->running && oss_stream_thr_create(s) != CUBEB_OK) {
+ /* Disallow starting an already started stream */
+ assert(!s->running && s->state != CUBEB_STATE_STARTED);
+ if (oss_stream_thr_create(s) != CUBEB_OK) {
+ pthread_mutex_unlock(&s->mtx);
+ s->state_cb(s, s->user_ptr, CUBEB_STATE_ERROR);
+ return CUBEB_ERROR;
+ }
+ s->state = CUBEB_STATE_STARTED;
+ s->thread_created = true;
+ s->running = true;
+ pthread_mutex_unlock(&s->mtx);