core.async with aleph#
Tue, 16 Dec 2014 07:34:29 +0000
(More sledge retrospective)
There was a point about three weeks ago when I thought I had a working audio player, then I tried using it on the phone and I got awkward screeches every thirty seconds through my stereo when I told it to play Ziggy Stardust. No, I'm not talking about David Bowie's voice here, this was genuine "a dog ate my CD" style digital audio corruption. The problem seemed to appear only on Wifi: I could replicate it on my laptop, but it didn't show up on localhost and it didn't show up over an ssh tunnel: I suspect it was something related to buffering/backpressure, and facing the prospect of debugging Java code with locks in it I punted and decided to try switching HTTP server instead.
Documentation on HTTP streaming from core.async channels with
Aleph is kind of sparse, at least
insofar as it is lacking a simple example of the kind of thing that
should work. So here is my simple example of the kind of thing that
worked for me: wrap the channel in a call to
manifold.stream/->source
and make sure that the things received on
it are byte-array
(defn transcode-handler [request pathname] {:status 200 :headers {"content-type" "audio/ogg" "x-hello" "goodbye"} :body (manifold/->source (transcode-chan pathname))})
(from server.clj )
I'm sure there are other things you could put on the channel that
would also work, but I don't know what. java.nio.ByteBuffer
doesn't
seem to be one of them, but I'm only going on git commit history and a
very fuzzy recollection of what I was doing that day, it might be that
I did something else wrong.