Date: Fri, 31 Dec 2021 10:00:32 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org Subject: git: c6218ed82612 - main - www/firefox: Force 32 ms service intervals at most for the CUBEB OSS backend. Message-ID: <202112311000.1BVA0WkW089056@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/ports/commit/?id=c6218ed826128b021740bbd416ab4e0eb35fc108 commit c6218ed826128b021740bbd416ab4e0eb35fc108 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2021-12-27 09:35:09 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2021-12-31 10:00:02 +0000 www/firefox: Force 32 ms service intervals at most for the CUBEB OSS backend. Sometimes a big buffer may be specified by CUBEB. Feed big buffers in smaller chunks to avoid issues with the audio flow. Other CUBEB audio backends apparently do the same. Fixes audio out of sync for youtube videos. The need for this patch will eventually go away as the changes are upstreamed. PR: 260620 Approved by: pi (implicit) --- www/firefox/Makefile | 1 + .../files/patch-media_libcubeb_src_cubeb__oss.c | 59 +++++++++++++--------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/www/firefox/Makefile b/www/firefox/Makefile index a9fb6d5efd76..e3cec497f389 100644 --- a/www/firefox/Makefile +++ b/www/firefox/Makefile @@ -2,6 +2,7 @@ PORTNAME= firefox DISTVERSION= 95.0.2 +PORTREVISION= 1 PORTEPOCH= 2 CATEGORIES= www MASTER_SITES= MOZILLA/${PORTNAME}/releases/${DISTVERSION}/source \ diff --git a/www/firefox/files/patch-media_libcubeb_src_cubeb__oss.c b/www/firefox/files/patch-media_libcubeb_src_cubeb__oss.c index 2449fa3d4195..5ba28fea536b 100644 --- a/www/firefox/files/patch-media_libcubeb_src_cubeb__oss.c +++ b/www/firefox/files/patch-media_libcubeb_src_cubeb__oss.c @@ -1,14 +1,15 @@ ---- media/libcubeb/src/cubeb_oss.c.orig 2021-11-29 14:01:19 UTC +--- media/libcubeb/src/cubeb_oss.c.orig 2021-12-18 20:36:16 UTC +++ media/libcubeb/src/cubeb_oss.c -@@ -96,6 +96,7 @@ struct oss_stream { +@@ -96,6 +96,8 @@ struct oss_stream { oss_devnode_t name; int fd; void * buf; + unsigned int bufframes; ++ unsigned int maxframes; struct stream_info { int channels; -@@ -126,9 +127,6 @@ struct cubeb_stream { +@@ -126,9 +128,6 @@ struct cubeb_stream { cubeb_data_callback data_cb; cubeb_state_callback state_cb; uint64_t frames_written /* (m) */; @@ -18,7 +19,7 @@ }; static char const * -@@ -786,40 +784,72 @@ oss_put_play_frames(cubeb_stream * s, unsigned int nfr +@@ -786,40 +785,72 @@ oss_put_play_frames(cubeb_stream * s, unsigned int nfr } static int @@ -84,9 +85,9 @@ + pfds[0].fd = s->play.fd; + pfds[1].fd = -1; + goto retry; -+ } else if (tnfr > (long)s->play.bufframes) { ++ } else if (tnfr > (long)s->play.maxframes) { + /* too many frames available - limit */ -+ tnfr = (long)s->play.bufframes; ++ tnfr = (long)s->play.maxframes; + } + if (nfr > tnfr) { + nfr = tnfr; @@ -102,9 +103,9 @@ + pfds[0].fd = -1; + pfds[1].fd = s->record.fd; + goto retry; -+ } else if (tnfr > (long)s->record.bufframes) { ++ } else if (tnfr > (long)s->record.maxframes) { + /* too many frames available - limit */ -+ tnfr = (long)s->record.bufframes; ++ tnfr = (long)s->record.maxframes; + } + if (nfr > tnfr) { + nfr = tnfr; @@ -115,7 +116,7 @@ return 0; } -@@ -840,7 +870,7 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta +@@ -840,7 +871,7 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta } trig |= PCM_ENABLE_INPUT; @@ -124,7 +125,7 @@ if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig) == -1) { LOG("Error %d occured when setting trigger on record fd", errno); -@@ -877,6 +907,7 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta +@@ -877,6 +908,7 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta oss_linear32_to_float(s->record.buf, s->record.info.channels * nfr); } } @@ -132,7 +133,7 @@ got = s->data_cb(s, s->user_ptr, s->record.buf, s->play.buf, nfr); if (got == CUBEB_ERROR) { state = CUBEB_STATE_ERROR; -@@ -920,45 +951,10 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta +@@ -920,45 +952,10 @@ oss_audio_loop(cubeb_stream * s, cubeb_state * new_sta } } @@ -181,7 +182,7 @@ } return 1; -@@ -1015,9 +1011,10 @@ static inline int +@@ -1015,9 +1012,10 @@ static inline int oss_calc_frag_shift(unsigned int frames, unsigned int frame_size) { int n = 4; @@ -194,7 +195,7 @@ return n; } -@@ -1037,7 +1034,6 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1037,7 +1035,6 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea cubeb_state_callback state_callback, void * user_ptr) { int ret = CUBEB_OK; @@ -202,7 +203,7 @@ cubeb_stream * s = NULL; const char * defdsp; -@@ -1051,7 +1047,6 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1051,7 +1048,6 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea } s->state = CUBEB_STATE_STOPPED; s->record.fd = s->play.fd = -1; @@ -210,7 +211,7 @@ if (input_device != NULL) { strlcpy(s->record.name, input_device, sizeof(s->record.name)); } else { -@@ -1064,6 +1059,8 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1064,6 +1060,8 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea } if (input_stream_params != NULL) { unsigned int nb_channels; @@ -219,7 +220,7 @@ if (input_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) { LOG("Loopback not supported"); ret = CUBEB_ERROR_NOT_SUPPORTED; -@@ -1077,13 +1074,11 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1077,13 +1075,11 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea ret = CUBEB_ERROR_INVALID_PARAMETER; goto error; } @@ -238,7 +239,7 @@ } if ((ret = oss_copy_params(s->record.fd, s, input_stream_params, &s->record.info)) != CUBEB_OK) { -@@ -1094,11 +1089,17 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1094,11 +1090,17 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea (input_stream_params->format == CUBEB_SAMPLE_FLOAT32NE); s->record.frame_size = s->record.info.channels * (s->record.info.precision / 8); @@ -258,7 +259,7 @@ if (output_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) { LOG("Loopback not supported"); ret = CUBEB_ERROR_NOT_SUPPORTED; -@@ -1113,13 +1114,11 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1113,13 +1115,11 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea ret = CUBEB_ERROR_INVALID_PARAMETER; goto error; } @@ -277,7 +278,7 @@ } if ((ret = oss_copy_params(s->play.fd, s, output_stream_params, &s->play.info)) != CUBEB_OK) { -@@ -1128,19 +1127,16 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1128,19 +1128,16 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea } s->play.floating = (output_stream_params->format == CUBEB_SAMPLE_FLOAT32NE); s->play.frame_size = s->play.info.channels * (s->play.info.precision / 8); @@ -305,7 +306,7 @@ if (ioctl(s->play.fd, SNDCTL_DSP_SETFRAGMENT, &frag)) LOG("Failed to set play fd with SNDCTL_DSP_SETFRAGMENT. frag: 0x%x", frag); -@@ -1148,13 +1144,17 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1148,13 +1145,28 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea if (ioctl(s->play.fd, SNDCTL_DSP_GETOSPACE, &bi)) LOG("Failed to get play fd's buffer info."); else { @@ -313,8 +314,19 @@ - s->nfr = bi.fragsize / s->play.frame_size; + s->play.bufframes = (bi.fragsize * bi.fragstotal) / s->play.frame_size; } ++ int lw; + -+ int lw = s->play.frame_size; ++ /* ++ * Force 32 ms service intervals at most, or when recording is ++ * active, use the recording service intervals as a reference. ++ */ ++ s->play.maxframes = (32 * output_stream_params->rate) / 1000; ++ if (s->record.fd != -1 || s->play.maxframes >= s->play.bufframes) { ++ lw = s->play.frame_size; /* Feed data when possible. */ ++ s->play.maxframes = s->play.bufframes; ++ } else { ++ lw = (s->play.bufframes - s->play.maxframes) * s->play.frame_size; ++ } + if (ioctl(s->play.fd, SNDCTL_DSP_LOW_WATER, &lw)) + LOG("Audio device \"%s\" (play) could not set trigger threshold", + s->play.name); @@ -327,7 +339,7 @@ if (ioctl(s->record.fd, SNDCTL_DSP_SETFRAGMENT, &frag)) LOG("Failed to set record fd with SNDCTL_DSP_SETFRAGMENT. frag: 0x%x", frag); -@@ -1162,11 +1162,15 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1162,11 +1174,16 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea if (ioctl(s->record.fd, SNDCTL_DSP_GETISPACE, &bi)) LOG("Failed to get record fd's buffer info."); else { @@ -337,6 +349,7 @@ + (bi.fragsize * bi.fragstotal) / s->record.frame_size; } + ++ s->record.maxframes = s->record.bufframes; + int lw = s->record.frame_size; + if (ioctl(s->record.fd, SNDCTL_DSP_LOW_WATER, &lw)) + LOG("Audio device \"%s\" (record) could not set trigger threshold", @@ -346,7 +359,7 @@ s->context = context; s->volume = 1.0; s->state_cb = state_callback; -@@ -1188,13 +1192,14 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea +@@ -1188,13 +1205,14 @@ oss_stream_init(cubeb * context, cubeb_stream ** strea s->doorbell = false; if (s->play.fd != -1) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202112311000.1BVA0WkW089056>