W3C home > Mailing lists > Public > www-lib@w3.org > January to March 2001

multipart stream

From: Eric Gibson <emg@lyonfyre.net>
Date: Thu, 22 Mar 2001 14:58:36 -0500
To: www-lib@w3.org
Message-ID: <20010322145836.B3910@sandbender.voxel.net>

	I've been writing a little app that shows images streamed
from a webcam http server in gtk/gnome, and everything was going fine.
I've been doing it off a timer, pulling the picture every 15th of a
second or so, but then I saw netscapes ability to stream jpegs using
the "x-mixed-replace" header :-0. I started writing it, but it's pretty
difficult since it's a never ending stream, so I found your library
and this will simplify things a lot, but one problem... I can't get this
multipart mime stream stuff to work, I started at page one of the
documentation, but I think I'm missing something big time.

The incoming data looks like this:

HTTP/1.0 200 OK
Content-type: multipart/x-mixed-replace;boundary=ThisRandomString
Cache-Control: no-cache
Cache-Control: private
Pragma: no-cache

Content-type: image/jpeg

Content-type: image/jpeg

^K^N^N^M^O^S ^U^S^R^R^S'^\^^^W
.)10.)-,3:J>36F7,-@WAFLNRSR2>ZaZP`JQRO^@C^A^N^N^K^N^N^M^O^S ^U^S^R^R^S'^\^^^W

so on, and so on, ad infinitum...

I modified the chunkbody.c example to do this:

----- CUT ---------------

#include "WWWLib.h"
#include "WWWHTTP.h"
#include "WWWInit.h"

PRIVATE int printer (const char * fmt, va_list pArgs)
    return (vfprintf(stdout, fmt, pArgs));

PRIVATE int tracer (const char * fmt, va_list pArgs)
    return (vfprintf(stderr, fmt, pArgs));

PRIVATE int terminate_handler (HTRequest * request, HTResponse *
			       void * param, int status) 
    /* Check for status */
    /* HTPrint("Load resulted in status %d\n", status); */
	/* we're not handling other requests */
	HTEventList_stopLoop ();
	/* stop here */
    return HT_ERROR;

int main (int argc, char ** argv)
    HTRequest * request = HTRequest_new();
    HTList * converters = HTList_new();		/* List of
converters */
    HTList * encodings = HTList_new();		/* List of encoders
    HTStream * streamoutput = NULL;
    char * url = argc==2 ? argv[1] : NULL;

    /* Initialize libwww core */
    HTLibInit("GCam", "0.0");

    /* Gotta set up our own traces */

    /* Turn on TRACE so we can see what is going on */
#if 0

    /* On windows we must always set up the eventloop */
    /* Register the default set of transport protocols */

    /* Register the default set of protocol modules */

    /* Register the default set of BEFORE and AFTER callback
     * functions */

    /* Register the default set of converters */

    /* Register the default set of transfer encoders and decoders */

    /* Register the default set of MIME header parsers */

    /* Add our own filter to handle termination */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL,

    /* Set up the request and pass it to the Library */
    HTRequest_setOutputStream (request, streamoutput);
    HTRequest_setOutputFormat(request, WWW_RAW);
    HTRequest_setPreemptive(request, YES);

    if (url) {
	char * cwd = HTGetCurrentDirectoryURL();
        char * absolute_url = HTParse(url, cwd, PARSE_ALL);

	BOOL status = HTLoadAbsolute(absolute_url, request);


        if(status) {
          /* I have NO idea what do here, I'm trying to pass the
           * jpegs into a value over and over again so I can write
           * them to the screen */
          printf("Stream could be opened, %d\n", status);
        } else {
          printf("Stream could not be opened, %d\n", status);

    } else {
	HTPrint("Type the URL you want to accces on the command

    /* Clean up the request */

    /* On windows, shut down eventloop as well */
    /* Terminate the Library */
    return 0;

---- CUT -----

I don't even know if that HTLoadAbsolute is writing to the right
stream, I tried using HTLoadToStream but I kept getting a 0 status

I really hate to ask "How do you program" questions like this, but
if somebody could show me how to access the data in the bodies of
the stream I'd really appreciate it! I've been tinkering around with
it for two days, and couldn't figure it out from the documentation
(no offense).


Received on Thursday, 22 March 2001 14:58:38 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:53 UTC