Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/broadcom Some improvements that make playback m...
details: https://anonhg.NetBSD.org/src/rev/c2afc8cbd0f7
branches: trunk
changeset: 332720:c2afc8cbd0f7
user: skrll <skrll%NetBSD.org@localhost>
date: Mon Oct 06 06:59:20 2014 +0000
description:
Some improvements that make playback mostly reliable for me - the final
piece of the jigaw is probably in vchiq:
- prefill vchiq with a number (currently 2) blocks of audio before
starting
- use a kthread as workqueue isn't suited to our usage.
- don't drain on stopping as for some reason it leaves data behind.
diffstat:
sys/arch/arm/broadcom/bcm2835_vcaudio.c | 271 +++++++++++++++++++------------
1 files changed, 162 insertions(+), 109 deletions(-)
diffs (truncated from 522 to 300 lines):
diff -r 22a983d2364b -r c2afc8cbd0f7 sys/arch/arm/broadcom/bcm2835_vcaudio.c
--- a/sys/arch/arm/broadcom/bcm2835_vcaudio.c Mon Oct 06 04:41:59 2014 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_vcaudio.c Mon Oct 06 06:59:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_vcaudio.c,v 1.6 2014/09/02 21:46:35 jmcneill Exp $ */
+/* $NetBSD: bcm2835_vcaudio.c,v 1.7 2014/10/06 06:59:20 skrll Exp $ */
/*-
* Copyright (c) 2013 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.6 2014/09/02 21:46:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.7 2014/10/06 06:59:20 skrll Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -40,7 +40,6 @@
#include <sys/conf.h>
#include <sys/bus.h>
#include <sys/kmem.h>
-#include <sys/workqueue.h>
#include <sys/audioio.h>
#include <dev/audio_if.h>
@@ -68,16 +67,33 @@
VCAUDIO_DEST_HDMI = 2,
};
-struct vcaudio_work {
- struct work vw_wk;
-};
+
+/*
+ * Standard message size is 4000 bytes and VCHIQ can accept 16 messages.
+ *
+ * 4000 bytes of 16bit 48kHz stereo is approximately 21ms.
+ *
+ * We get complete messages at ~10ms intervals.
+ *
+ * Setting blocksize to 2 x 4000 means that we send approx 42ms of audio. We
+ * prefill by two blocks before starting audio meaning we have 83ms of latency.
+ */
+
+#define VCAUDIO_MSGSIZE 4000
+#define VCAUDIO_NUMMSGS 2
+#define VCAUDIO_BLOCKSIZE (VCAUDIO_MSGSIZE * VCAUDIO_NUMMSGS)
+#define VCAUDIO_BUFFERSIZE 128000
+#define VCAUDIO_PREFILLCOUNT 2
struct vcaudio_softc {
device_t sc_dev;
device_t sc_audiodev;
+ lwp_t *sc_lwp;
+
kmutex_t sc_lock;
kmutex_t sc_intr_lock;
+ kcondvar_t sc_datacv;
kmutex_t sc_msglock;
kcondvar_t sc_msgcv;
@@ -89,7 +105,9 @@
void *sc_pintarg;
audio_params_t sc_pparam;
bool sc_started;
- int sc_pbytes;
+ int sc_pblkcnt; // prefill block count
+ int sc_abytes; // available bytes
+ int sc_pbytes; // played bytes
off_t sc_ppos;
void *sc_pstart;
void *sc_pend;
@@ -104,9 +122,6 @@
short sc_peer_version;
- struct workqueue *sc_wq;
- struct vcaudio_work sc_work;
-
int sc_volume;
enum vcaudio_dest sc_dest;
};
@@ -118,18 +133,17 @@
static int vcaudio_init(struct vcaudio_softc *);
static void vcaudio_service_callback(void *,
- const VCHI_CALLBACK_REASON_T,
- void *);
-static int vcaudio_msg_sync(struct vcaudio_softc *, VC_AUDIO_MSG_T *, size_t);
-static void vcaudio_worker(struct work *, void *);
+ const VCHI_CALLBACK_REASON_T, void *);
+static int vcaudio_msg_sync(struct vcaudio_softc *, VC_AUDIO_MSG_T *,
+ size_t);
+static void vcaudio_worker(void *);
static int vcaudio_open(void *, int);
static void vcaudio_close(void *);
static int vcaudio_query_encoding(void *, struct audio_encoding *);
static int vcaudio_set_params(void *, int, int,
- audio_params_t *, audio_params_t *,
- stream_filter_list_t *,
- stream_filter_list_t *);
+ audio_params_t *, audio_params_t *,
+ stream_filter_list_t *, stream_filter_list_t *);
static int vcaudio_halt_output(void *);
static int vcaudio_halt_input(void *);
static int vcaudio_set_port(void *, mixer_ctrl_t *);
@@ -137,14 +151,16 @@
static int vcaudio_query_devinfo(void *, mixer_devinfo_t *);
static int vcaudio_getdev(void *, struct audio_device *);
static int vcaudio_get_props(void *);
-static int vcaudio_round_blocksize(void *, int, int, const audio_params_t *);
+
+static int vcaudio_round_blocksize(void *, int, int,
+ const audio_params_t *);
static size_t vcaudio_round_buffersize(void *, int, size_t);
+
static int vcaudio_trigger_output(void *, void *, void *, int,
- void (*)(void *), void *,
- const audio_params_t *);
+ void (*)(void *), void *, const audio_params_t *);
static int vcaudio_trigger_input(void *, void *, void *, int,
- void (*)(void *), void *,
- const audio_params_t *);
+ void (*)(void *), void *, const audio_params_t *);
+
static void vcaudio_get_locks(void *, kmutex_t **, kmutex_t **);
static const struct audio_hw_if vcaudio_hw_if = {
@@ -167,7 +183,8 @@
};
CFATTACH_DECL2_NEW(vcaudio, sizeof(struct vcaudio_softc),
- vcaudio_match, vcaudio_attach, NULL, NULL, vcaudio_rescan, vcaudio_childdet);
+ vcaudio_match, vcaudio_attach, NULL, NULL, vcaudio_rescan,
+ vcaudio_childdet);
static int
vcaudio_match(device_t parent, cfdata_t match, void *aux)
@@ -187,19 +204,24 @@
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sc->sc_msglock, MUTEX_DEFAULT, IPL_NONE);
- cv_init(&sc->sc_msgcv, "vcaudiocv");
+ cv_init(&sc->sc_msgcv, "msg");
+ cv_init(&sc->sc_datacv, "data");
sc->sc_success = -1;
- error = workqueue_create(&sc->sc_wq, "vcaudiowq", vcaudio_worker,
- sc, PRI_BIO, IPL_SCHED, WQ_MPSAFE);
+
+ error = kthread_create(PRI_BIO, KTHREAD_MPSAFE, NULL, vcaudio_worker,
+ sc, &sc->sc_lwp, "vcaudio");
if (error) {
- aprint_error(": couldn't create workqueue (%d)\n", error);
+ aprint_error(": couldn't create thread (%d)\n", error);
return;
}
aprint_naive("\n");
- aprint_normal(": AUDS\n");
+ aprint_normal(": auds\n");
- vcaudio_rescan(self, NULL, NULL);
+ error = vcaudio_rescan(self, NULL, NULL);
+ if (error)
+ aprint_error_dev(self, "not configured\n");
+
}
static int
@@ -210,8 +232,9 @@
if (ifattr_match(ifattr, "audiobus") && sc->sc_audiodev == NULL) {
error = vcaudio_init(sc);
- if (error)
+ if (error) {
return error;
+ }
sc->sc_audiodev = audio_attach_mi(&vcaudio_hw_if,
sc, sc->sc_dev);
@@ -256,15 +279,15 @@
error = vchi_initialise(&sc->sc_instance);
if (error) {
- device_printf(sc->sc_dev, "couldn't init vchi instance (%d)\n",
- error);
+ aprint_error_dev(sc->sc_dev,
+ "couldn't init vchi instance (%d)\n", error);
return EIO;
}
error = vchi_connect(NULL, 0, sc->sc_instance);
if (error) {
- device_printf(sc->sc_dev, "couldn't connect vchi (%d)\n",
- error);
+ aprint_error_dev(sc->sc_dev,
+ "couldn't connect vchi (%d)\n", error);
return EIO;
}
@@ -283,7 +306,7 @@
error = vchi_service_open(sc->sc_instance, &setup, &sc->sc_service);
if (error) {
- device_printf(sc->sc_dev, "couldn't open service (%d)\n",
+ aprint_error_dev(sc->sc_dev, "couldn't open service (%d)\n",
error);
return EIO;
}
@@ -302,8 +325,8 @@
error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg),
VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
if (error) {
- device_printf(sc->sc_dev, "couldn't send OPEN message (%d)\n",
- error);
+ aprint_error_dev(sc->sc_dev,
+ "couldn't send OPEN message (%d)\n", error);
}
memset(&msg, 0, sizeof(msg));
@@ -313,8 +336,8 @@
msg.u.config.bps = 16;
error = vcaudio_msg_sync(sc, &msg, sizeof(msg));
if (error) {
- device_printf(sc->sc_dev, "couldn't send CONFIG message (%d)\n",
- error);
+ aprint_error_dev(sc->sc_dev,
+ "couldn't send CONFIG message (%d)\n", error);
}
memset(&msg, 0, sizeof(msg));
@@ -323,8 +346,10 @@
msg.u.control.dest = VCAUDIO_DEST_AUTO;
error = vcaudio_msg_sync(sc, &msg, sizeof(msg));
if (error) {
- device_printf(sc->sc_dev, "couldn't send CONTROL message (%d)\n", error);
+ aprint_error_dev(sc->sc_dev,
+ "couldn't send CONTROL message (%d)\n", error);
}
+
vchi_service_release(sc->sc_service);
return 0;
@@ -361,14 +386,17 @@
cv_broadcast(&sc->sc_msgcv);
mutex_exit(&sc->sc_msglock);
break;
+
case VC_AUDIO_MSG_TYPE_COMPLETE:
intr = msg.u.complete.callback;
intrarg = msg.u.complete.cookie;
if (intr && intrarg) {
int count = msg.u.complete.count & 0xffff;
- int perr = (msg.u.complete.count & 0x40000000) != 0;
+ int perr = (msg.u.complete.count & __BIT(30)) != 0;
bool sched = false;
+
mutex_enter(&sc->sc_intr_lock);
+
if (count > 0) {
sc->sc_pbytes += count;
}
@@ -385,7 +413,8 @@
if (sched) {
intr(intrarg);
- workqueue_enqueue(sc->sc_wq, (struct work *)&sc->sc_work, NULL);
+ sc->sc_abytes += sc->sc_pblksize;
+ cv_signal(&sc->sc_datacv);
}
mutex_exit(&sc->sc_intr_lock);
}
@@ -396,7 +425,7 @@
}
static void
-vcaudio_worker(struct work *wk, void *priv)
+vcaudio_worker(void *priv)
{
struct vcaudio_softc *sc = priv;
VC_AUDIO_MSG_T msg;
@@ -406,77 +435,92 @@
int error, resid, off, nb, count;
mutex_enter(&sc->sc_intr_lock);
- intr = sc->sc_pint;
- intrarg = sc->sc_pintarg;
+
+ while (true) {
+ intr = sc->sc_pint;
+ intrarg = sc->sc_pintarg;
- if (intr == NULL || intrarg == NULL) {
- mutex_exit(&sc->sc_intr_lock);
- return;
- }
+ if (intr == NULL || intrarg == NULL) {
Home |
Main Index |
Thread Index |
Old Index