Video Streaming using non http backend, Ref ngx_drizzle

sammy_raul sammyraul1 at gmail.com
Tue Jun 5 04:06:23 UTC 2012


Thanks agentzh for explaining so well.

When I am connected to the backend server I am getting buffer which I am
sending to the client like this:

ngx_int_t
ngx_http_ccn_send_output_bufs(ngx_http_request_t *r,
        ngx_http_upstream_ccn_peer_data_t *dp, const unsigned char *data,
size_t data_size)
{
    ngx_http_upstream_t                    *u = r->upstream;
    ngx_int_t                                      rc;
    ngx_buf_t                                     *b;
    ngx_chain_t                                  out;

       /* allocate a buffer for your response body */
    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
    if (b == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
       }

    /* attach this buffer to the buffer chain */
    out.buf = b;
    out.next = NULL;

    /* 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 */


    if ( ! u->header_sent ) {
    	fprintf(stdout, "ngx_http_ccn_send_output_bufs u->header_sent\n");
        r->headers_out.status = NGX_HTTP_OK;

        /* set the Content-Type header */

        r->headers_out.content_type.data =
        		(u_char *) "application/octet-stream";

        r->headers_out.content_type.len =
        		sizeof("application/octet-stream") - 1;

        r->headers_out.content_type_len =
        		sizeof("application/octet-stream") - 1;

        rc = ngx_http_send_header(r);

        if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
        	fprintf(stdout, "ngx_http_ccn_send_output_bufs header sent
error\n");
            return rc;
        }

        u->header_sent = 1;
        fprintf(stdout, "ngx_http_ccn_send_output_bufs
u->header_sent=%d\n",u->header_sent);
    }

    rc = ngx_http_output_filter(r, &out);

    if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
        return rc;
        }

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);

but it is not working as expected which is like playing the video file in
the browser

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

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.

Thanks,
Raul

--
View this message in context: http://nginx.2469901.n2.nabble.com/Video-Streaming-using-non-http-backend-Ref-ngx-drizzle-tp7580235p7580247.html
Sent from the nginx mailing list archive at Nabble.com.



More information about the nginx mailing list