multipart stream

Hello,

	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

--ThisRandomString
Content-type: image/jpeg

ÿØÿà^@^PJFIF^@^A^A^@^@^A^@^A^@^@ÿÛ^@C^@^M
^K
^H^M^K
--ThisRandomString
Content-type: image/jpeg

ÿØÿà^@^PJFIF^@^A^A^@^@^A^@^A^@^@ÿÛ^@C^@^M
^K
^H^M^K
^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
.)10.)-,3:J>36F7,-@WAFLNRSR2>ZaZP`JQROÿÛ^@C^A^N^N
--ThisRandomString

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 *
response,
			       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 */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Turn on TRACE so we can see what is going on */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* On windows we must always set up the eventloop */
#ifdef WWW_WIN_ASYNC
    HTEventInit();
#endif
    
    /* Register the default set of transport protocols */
    HTTransportInit();

    /* Register the default set of protocol modules */
    HTProtocolInit();

    /* Register the default set of BEFORE and AFTER callback
     * functions */
    HTNetInit();

    /* Register the default set of converters */
    HTConverterInit(converters);
    HTFormat_setConversion(converters);

    /* Register the default set of transfer encoders and decoders */
    HTTransferEncoderInit(encodings);
    HTFormat_setTransferCoding(encodings);

    /* Register the default set of MIME header parsers */
    HTMIMEInit();

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

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

        HT_FREE(absolute_url);
        HT_FREE(cwd);

        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
line\n");
    }

    /* Clean up the request */
    HTRequest_delete(request);
    HTFormat_deleteAll();

    /* On windows, shut down eventloop as well */
#ifdef WWW_WIN_ASYNC
    HTEventTerminate();
#endif
   
    /* Terminate the Library */
    HTLibTerminate();
    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).

Thanks!

Eric

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