Video Streaming using non http backend, Ref ngx_drizzle

agentzh agentzh at gmail.com
Tue Jun 5 04:16:57 UTC 2012


Hello!

On Tue, Jun 5, 2012 at 12:06 PM, sammy_raul <sammyraul1 at gmail.com> wrote:
>
>    /* adjust the pointers of the buffer */
>    b->pos = (u_char *) data;
>    b->last = b->pos + data_size - 1;
>    b->memory = 1;    /* this buffer is in memory */
>    b->last_buf = 1;  /* this is the last buffer in the buffer chain */
>

Setting b->last_buf to 1 means the current buf is the last buf in the
whole response body stream in this context (actually it is the
indicator for the end of the output data stream). So you must not set
this for every single buf.

Also, you should never set this flag in case you're in a subrequest or
things will break.

>
> this function I am calling everytime I am receiving data (1024) from the
> backend
> when it is end of stream I am calling
> ngx_http_finalize_request(r, rc);
>

Call ngx_http_send_header once and call ngx_http_output_filter
multiple times (as needed).

If you need strict non-buffered output behaivor, you have to *wait*
for the downstream to flush out *all* the data before continuing
reading data from upstream. You can check out how the
ngx_http_upstream (in non-buffered mode) and ngx_lua modules do this.

>
> I didn't follow the lua module yet, but will look into it
>

I strongly recommend it because it should save you a *lot* of time (I guess) :)

> Is there anything I am doing wrong while setting the output buffer, do I
> need to change this line b->last_buf = 1;
> or something else.
>

See above.

Regards,
-agentzh

P.S. C programming is hard; let's go scripting! :D



More information about the nginx mailing list