Project

General

Profile

[Solved] About streaming MJPEG in a plugin

Added by gaspa over 14 years ago

Dear all,
I'm trying to write a plugin that streams MJPEG video. The plugin takes JPEG frames from a pipe (an Unix Domain socket, in fact) and should stream them through a single HTTP connection, each jpeg frame separated from the following by a "--boundarydonotcross", without closing the TCP connection.

In the plugin, I have loop that consumes the actual JPEG frames, puts each one of them in a buffer and then use http_chunk_append_buffer() on each one.

The problem is that lighttpd keeps "buffering" them and never sends them to the client until I return HANDLER_FINISHED. Since it's a live stream, I obviously can't: I must send the frames as they come, without closing the tcp connection. Lighttpd buffers them and eventually runs out of memory.

Is there a way to "flush" the frames to the client as they come, without having to return from the module? Has anyone ever made a streaming module for lighttpd?

ps. Obviously, I can't use the Range: header, as it would require multiple GETs and, thus, multiple TCP connections; for a brief description of what I'd like to develop, here's alittle description of MJPEG over HTTP: http://en.wikipedia.org/wiki/Mjpeg#M-JPEG_over_HTTP

Thanks to everyone,
Cheers,

Gaspa.


Replies (2)

RE: About streaming MJPEG in a plugin - Added by stbuehler about 14 years ago

You describe 2 problems, and i think you only hit one: * If your plugin "blocks", lighty cannot handle the outgoing buffer stream and will never send it * If your plugin is async the buffers will obviously overflow if you fill them faster than the client "wants" them. This means you have to check
if the queue is too full already and start skipping frames (yes, this is what makes live streaming interesting, and no, lighttpd wasn't designed for this use case).

"Flushing" the frames doesn't work - I recommend that you dig somewhat deeper in docs about how tcp/udp works. Perhaps you want to have a look at RTP

    (1-2/2)