Hi friends, I'm developing a Ground Station and a feture of this station is show the FlightGear screen (simulating a embbeded camera), then i choose to use the jpg-httpd option, but the same show only a piece of screen (left-bottom), is too slow to acquire this image and after less than 1 minute the memory increase until fill complete RAM and swap to harddisk.
Reading the code I could see that the jpg-http processing seems to be unfinished ?? Am I right ? Then I did rewrite the jpg-httpd.h and jpg-httpd.cxx modules (method void HttpdImageChannel :: foundTerminator( void )) to do a better image streaming, using the complete image size specified in JpgFactory -> init( int width, int height ); (call in jpg-httpd.h). The memory leak was fixed and the performance is tooooooo fast comparing with the old method. I want contribute with this code because I believe that is a good idea and could be used by other projects that uses FlightGear. Leidson Campos [EMAIL PROTECTED] Java Universal Messenger See the code bellow (maked by //[Leidson<] at start and //[Leidson>] at end Changes in jpg-httpd.hxx module: class HttpdImageChannel : public netChat { netBuffer buffer ; trJpgFactory *JpgFactory; public: HttpdImageChannel() : buffer(512) { setTerminator("\r\n"); JpgFactory = new trJpgFactory(); // This is a terrible hack but it can't be initialized until // after OpenGL is up an running //[Leidson<] JpgFactory -> init( 700, 400 ); //[Leidson>] } . . . Changes in jpg-httpd.cpp module: #include <Main/fg_props.hxx> #include <Main/globals.hxx> #include "jpg-httpd.hxx" //[Leidson<] #define __MAX_HTTP_BLOCK_SIZE 4096 #define __MAX_STRING_SIZE 2048 #define __TIMEOUT_COUNT 5 #define __HTTP_GET_STRING "GET " //[Leidson>] SG_USING_STD(string); . . . . // Handle http GET requests (rewrite) //[Leidson<] void HttpdImageChannel :: foundTerminator( void ) { closeWhenDone(); char szTemp[256]; char szResponse[__MAX_STRING_SIZE]; char *pRequest = buffer.getData(); int nStep = 0; int nBytesSent = 0; int nTimeoutCount = 0; int nBufferCount = 0; int nImageLen; int nBlockSize; if ( strstr( pRequest, __HTTP_GET_STRING ) != NULL ) { printf( "<<<<<<<<< HTTP Request : %s\n", pRequest ); nImageLen = JpgFactory -> render(); nBlockSize = ( nImageLen < __MAX_HTTP_BLOCK_SIZE ? nImageLen : __MAX_HTTP_BLOCK_SIZE ); if( nImageLen ) { strcpy( szResponse, "HTTP/1.1 200 OK" ); strcat( szResponse, getTerminator() ); strcat( szResponse, "Content-Type: image/jpeg" ); strcat( szResponse, getTerminator() ); printf( "info->numbytes = %d\n", nImageLen ); sprintf( szTemp, "Content-Length: %d", nImageLen ); strcat( szResponse, szTemp ); strcat( szResponse, getTerminator() ); strcat( szResponse, "Connection: close" ); strcat( szResponse, getTerminator() ); strcat( szResponse, getTerminator() ); if( getHandle() == -1 ) { printf( "<<<<<<<<< Invalid socket handle. Ignoring request.\n" ); buffer.remove(); printf( "<<<<<<<<< End of image Transmission.\n" ); return; } if( send( ( char * ) szResponse, strlen( szResponse ) ) <= 0 ) { printf( "<<<<<<<<< Error to send HTTP response. Ignoring request.\n" ); buffer.remove(); printf( "<<<<<<<<< End of image Transmission.\n" ); return; } /* * Send block with size defined by __MAX_HTTP_BLOCK_SIZE */ while( nStep <= nImageLen ) { nBufferCount++; if( getHandle() == -1 ) { printf( "<<<<<<<<< Invalid socket handle. Ignoring request.\n" ); break; } nBytesSent = send( ( char * ) JpgFactory -> data() + nStep, nBlockSize ); if( nBytesSent <= 0 ) { if( nTimeoutCount == __TIMEOUT_COUNT ) { printf( "<<<<<<<<< Timeout reached. Exiting before end of image transmission.\n" ); nTimeoutCount = 0; break; } printf( "<<<<<<<<< Zero bytes sent.\n" ); sleep( 1 ); nTimeoutCount++; continue; } printf( ">>>>>>>>> (%d) BLOCK STEP %d - IMAGELEN %d - BLOCKSIZE %d - SENT %d\n", nBufferCount, nStep, nImageLen, nBlockSize, nBytesSent ); /* * Calculate remaining image. */ if( ( nStep + nBlockSize ) >= nImageLen ) { nBlockSize = ( nImageLen - nStep ); nStep += nBlockSize; } nStep += nBytesSent; nTimeoutCount = 0; usleep( 1000 ); } printf( "<<<<<<<<< End of image Transmission.\n" ); } else { printf( "!!! NO IMAGE !!!\n\tinfo -> numbytes = %d\n", nImageLen ); } /* * Release JPEG buffer. */ JpgFactory -> destroy(); } buffer.remove(); } //[Leidson>] ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel