2 * $Id: msgqueue_manager.c 53 2011-05-09 16:55:39Z kaori $
4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
39 #include "msgqueue_manager.h"
40 #include "metadata_manager.h"
44 #include "fcgi_stdio.h"
45 #define logstream FCGI_stdout
47 #define FCGI_stdout stdout
48 #define FCGI_stderr stderr
49 #define logstream stderr
53 #define EXT_TILE_MSG 5
54 #define MAINHEADER_MSG 6
55 #define METADATA_MSG 8
57 msgqueue_param_t * gene_msgqueue( bool stateless, target_param_t *target)
59 msgqueue_param_t *msgqueue;
61 msgqueue = (msgqueue_param_t *)malloc( sizeof(msgqueue_param_t));
63 msgqueue->first = NULL;
64 msgqueue->last = NULL;
66 msgqueue->stateless = stateless;
67 msgqueue->target = target;
72 void delete_msgqueue( msgqueue_param_t **msgqueue)
74 message_param_t *ptr, *next;
79 ptr = (*msgqueue)->first;
86 if( (*msgqueue)->stateless && (*msgqueue)->target)
87 delete_target( &((*msgqueue)->target));
92 void print_msgqueue( msgqueue_param_t *msgqueue)
99 fprintf( logstream, "message queue:\n");
100 ptr = msgqueue->first;
103 fprintf( logstream, "\t class_id: %lld\n", ptr->class_id );
104 fprintf( logstream, "\t in_class_id: %lld\n", ptr->in_class_id );
105 fprintf( logstream, "\t csn: %lld\n", ptr->csn );
106 fprintf( logstream, "\t bin_offset: %#llx\n", ptr->bin_offset );
107 fprintf( logstream, "\t length: %#llx\n", ptr->length );
108 fprintf( logstream, "\t aux: %lld\n", ptr->aux );
109 fprintf( logstream, "\t last_byte: %d\n", ptr->last_byte );
111 print_placeholder( ptr->phld);
113 fprintf( logstream, "\t res_offset: %#llx\n", ptr->res_offset );
114 fprintf( logstream, "\n");
120 void enqueue_message( message_param_t *msg, msgqueue_param_t *msgqueue);
122 void enqueue_mainheader( msgqueue_param_t *msgqueue)
124 target_param_t *target;
125 message_param_t *msg;
127 target = msgqueue->target;
129 msg = (message_param_t *)malloc( sizeof(message_param_t));
131 msg->last_byte = true;
132 msg->in_class_id = 0;
133 msg->class_id = MAINHEADER_MSG;
134 msg->csn = target->csn;
136 msg->length = target->codeidx->mhead_length;
137 msg->aux = 0; // non exist
138 msg->res_offset = target->codeidx->offset;
142 enqueue_message( msg, msgqueue);
144 target->codeidx->mhead_model = true;
147 void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
149 target_param_t *target;
151 Byte8_t numOftparts; // num of tile parts par tile
153 index_param_t *codeidx;
154 faixbox_param_t *tilepart;
155 message_param_t *msg;
156 Byte8_t binOffset, binLength;
159 target = msgqueue->target;
160 codeidx = target->codeidx;
161 tilepart = codeidx->tilepart;
163 numOftparts = get_nmax( tilepart);
164 numOftiles = get_m( tilepart);
166 if( tile_id < 0 || numOftiles <= tile_id){
167 fprintf( FCGI_stderr, "Error, Invalid tile-id %d\n", tile_id);
171 tp_model = &codeidx->tp_model[ tile_id*numOftparts];
174 for( i=0; i<numOftparts-level; i++){
175 binLength = get_elemLen( tilepart, i, tile_id);
178 msg = (message_param_t *)malloc( sizeof(message_param_t));
180 msg->last_byte = i==numOftparts-1? true : false;
181 msg->in_class_id = tile_id;
183 msg->class_id = TILE_MSG;
185 msg->class_id = EXT_TILE_MSG;
187 msg->csn = target->csn;
188 msg->bin_offset = binOffset;
189 msg->length = binLength;
190 msg->aux = numOftparts-i;
191 msg->res_offset = codeidx->offset+get_elemOff( tilepart, i, tile_id)/*-1*/;
195 enqueue_message( msg, msgqueue);
199 binOffset += binLength;
203 void enqueue_box( int meta_id, boxlist_param_t *boxlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
204 void enqueue_phld( int meta_id, placeholderlist_param_t *phldlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
205 void enqueue_boxcontents( int meta_id, boxcontents_param_t *boxcontents, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
207 void enqueue_metadata( int meta_id, msgqueue_param_t *msgqueue)
209 metadatalist_param_t *metadatalist;
210 metadata_param_t *metadata;
213 metadatalist = msgqueue->target->codeidx->metadatalist;
214 metadata = search_metadata( meta_id, metadatalist);
217 fprintf( FCGI_stderr, "Error: metadata-bin %d not found\n", meta_id);
222 if( metadata->boxlist)
223 enqueue_box( meta_id, metadata->boxlist, msgqueue, &binOffset);
225 if( metadata->placeholderlist)
226 enqueue_phld( meta_id, metadata->placeholderlist, msgqueue, &binOffset);
228 if( metadata->boxcontents)
229 enqueue_boxcontents( meta_id, metadata->boxcontents, msgqueue, &binOffset);
231 msgqueue->last->last_byte = true;
234 message_param_t * gene_metamsg( int meta_id, Byte8_t binoffset, Byte8_t length, Byte8_t res_offset, placeholder_param_t *phld, Byte8_t csn);
236 void enqueue_box( int meta_id, boxlist_param_t *boxlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
239 message_param_t *msg;
241 box = boxlist->first;
243 msg = gene_metamsg( meta_id, *binOffset, box->length, box->offset, NULL, msgqueue->target->csn);
244 enqueue_message( msg, msgqueue);
246 *binOffset += box->length;
251 void enqueue_phld( int meta_id, placeholderlist_param_t *phldlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
253 placeholder_param_t *phld;
254 message_param_t *msg;
256 phld = phldlist->first;
258 msg = gene_metamsg( meta_id, *binOffset, phld->LBox, 0, phld, msgqueue->target->csn);
259 enqueue_message( msg, msgqueue);
261 *binOffset += phld->LBox;
266 void enqueue_boxcontents( int meta_id, boxcontents_param_t *boxcontents, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
268 message_param_t *msg;
270 msg = gene_metamsg( meta_id, *binOffset, boxcontents->length, boxcontents->offset, NULL, msgqueue->target->csn);
271 enqueue_message( msg, msgqueue);
273 *binOffset += boxcontents->length;
276 message_param_t * gene_metamsg( int meta_id, Byte8_t binOffset, Byte8_t length, Byte8_t res_offset, placeholder_param_t *phld, Byte8_t csn)
278 message_param_t *msg;
280 msg = (message_param_t *)malloc( sizeof(message_param_t));
282 msg->last_byte = false;
283 msg->in_class_id = meta_id;
284 msg->class_id = METADATA_MSG;
286 msg->bin_offset = binOffset;
287 msg->length = length;
288 msg->aux = 0; // non exist
289 msg->res_offset = res_offset;
296 void enqueue_message( message_param_t *msg, msgqueue_param_t *msgqueue)
299 msgqueue->last->next = msg;
301 msgqueue->first = msg;
303 msgqueue->last = msg;
307 void emit_bin_id_vbas( Byte_t bb, Byte_t c, Byte8_t in_class_id);
308 void emit_vbas( Byte8_t code);
309 void emit_body( message_param_t *msg, int fd);
310 void emit_placeholder( placeholder_param_t *phld);
312 void emit_stream_from_msgqueue( msgqueue_param_t *msgqueue)
314 message_param_t *msg;
315 Byte8_t class_id, csn;
321 msg = msgqueue->first;
325 if( msg->csn == csn){
326 if( msg->class_id == class_id)
330 class_id = msg->class_id;
335 class_id = msg->class_id;
339 c = msg->last_byte ? 1 : 0;
341 emit_bin_id_vbas( bb, c, msg->in_class_id);
344 emit_vbas( class_id);
348 emit_vbas( msg->bin_offset);
349 emit_vbas (msg->length);
351 if( msg->class_id%2) // Aux is present only if the id is odd
352 emit_vbas( msg->aux);
355 emit_placeholder( msg->phld);
357 emit_body( msg, msgqueue->target->fd);
363 void emit_vbas_with_bytelen( Byte8_t code, int bytelength);
364 void print_binarycode( Byte8_t n, int segmentlen);
366 void emit_bin_id_vbas( Byte_t bb, Byte_t c, Byte8_t in_class_id)
371 // A.2.3 In-class identifiers
372 // 7k-3bits, where k is the number of bytes in the VBAS
374 tmp = in_class_id >> 4;
380 in_class_id |= (((bb & 3) << 5) | (c & 1) << 4) << ((bytelength-1)*7);
382 emit_vbas_with_bytelen( in_class_id, bytelength);
385 void emit_vbas( Byte8_t code)
395 emit_vbas_with_bytelen( code, bytelength);
398 void emit_vbas_with_bytelen( Byte8_t code, int bytelength)
405 seg = ( code >> (n*7)) & 0x7f;
408 fputc(( Byte4_t)seg, FCGI_stdout);
413 void emit_body( message_param_t *msg, int fd)
417 if( lseek( fd, msg->res_offset, SEEK_SET)==-1){
418 fprintf( FCGI_stderr, "Error: fseek in emit_body()\n");
422 data = (Byte_t *)malloc( msg->length);
423 if( read( fd, data, msg->length) != msg->length){
425 fprintf( FCGI_stderr, "Error: fread in emit_body()\n");
429 if( fwrite( data, msg->length, 1, FCGI_stdout) < 1){
431 fprintf( FCGI_stderr, "Error: fwrite in emit_body()\n");
437 void emit_bigendian_bytes( Byte8_t code, int bytelength);
439 void emit_placeholder( placeholder_param_t *phld)
441 emit_bigendian_bytes( phld->LBox, 4);
442 if( fwrite( phld->TBox, 4, 1, FCGI_stdout) < 1){
443 fprintf( FCGI_stderr, "Error: fwrite in emit_placeholder()\n");
446 emit_bigendian_bytes( phld->Flags, 4);
447 emit_bigendian_bytes( phld->OrigID, 8);
449 if( fwrite( phld->OrigBH, phld->OrigBHlen, 1, FCGI_stdout) < 1){
450 fprintf( FCGI_stderr, "Error: fwrite in emit_placeholder()\n");
455 void emit_bigendian_bytes( Byte8_t code, int bytelength)
462 seg = ( code >> (n*8)) & 0xff;
463 fputc(( Byte4_t)seg, FCGI_stdout);
467 void print_binarycode( Byte8_t n, int segmentlen)
473 buf[i++] = n%2 ? '1' : '0';
476 for( j=segmentlen-1; j>=i; j--)
479 for( j=i-1, k=0; j>=0; j--, k++){
481 if( !((k+1)%segmentlen))
487 Byte_t * parse_bin_id_vbas( Byte_t *streamptr, Byte_t *bb, Byte_t *c, Byte8_t *in_class_id);
488 Byte_t * parse_vbas( Byte_t *streamptr, Byte8_t *elem);
490 void parse_JPIPstream( Byte_t *JPIPstream, Byte8_t streamlen, Byte8_t offset, msgqueue_param_t *msgqueue)
492 Byte_t *ptr; // stream pointer
493 message_param_t *msg;
495 Byte8_t class_id, csn;
497 class_id = -1; // dummy
500 while( ptr-JPIPstream < streamlen){
501 msg = (message_param_t *)malloc( sizeof(message_param_t));
503 ptr = parse_bin_id_vbas( ptr, &bb, &c, &msg->in_class_id);
505 msg->last_byte = c == 1 ? true : false;
508 ptr = parse_vbas( ptr, &class_id);
509 // fprintf( stdout, "class_id: %lld\n", class_id);
511 msg->class_id = class_id;
514 ptr = parse_vbas( ptr, &csn);
517 ptr = parse_vbas( ptr, &msg->bin_offset);
518 ptr = parse_vbas( ptr, &msg->length);
520 if( msg->class_id%2) // Aux is present only if the id is odd
521 ptr = parse_vbas( ptr, &msg->aux);
525 msg->res_offset = ptr-JPIPstream+offset;
530 msgqueue->last->next = msg;
532 msgqueue->first = msg;
533 msgqueue->last = msg;
539 void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *stream);
541 void parse_metamsg( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t streamlen, metadatalist_param_t *metadatalist)
543 message_param_t *msg;
545 if( metadatalist == NULL)
548 msg = msgqueue->first;
550 if( msg->class_id == METADATA_MSG){
551 metadata_param_t *metadata = gene_metadata( msg->in_class_id, NULL, NULL, NULL);
552 insert_metadata_into_list( metadata, metadatalist);
553 parse_metadata( metadata, msg, stream+msg->res_offset);
559 placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength);
561 void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *datastream)
563 char *boxtype = (char *)(datastream+4);
567 if( strncmp( boxtype, "phld", 4) == 0){
568 if( !metadata->placeholderlist)
569 metadata->placeholderlist = gene_placeholderlist();
571 placeholder_param_t *phld = parse_phld( datastream, msg->length);
573 insert_placeholder_into_list( phld, metadata->placeholderlist);
575 else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
576 (isalnum(boxtype[2])||isblank(boxtype[2])) &&
577 (isalpha(boxtype[3])||isblank(boxtype[3]))){
578 if( !metadata->boxlist)
579 metadata->boxlist = gene_boxlist();
581 box_param_t *box = gene_boxbyOffinStream( datastream, msg->res_offset);
582 insert_box_into_list( box, metadata->boxlist);
585 metadata->boxcontents = gene_boxcontents( msg->res_offset, msg->length);
588 placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength)
590 placeholder_param_t *phld;
592 phld = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
594 phld->LBox = big4( datastream);
595 strcpy( phld->TBox, "phld");
596 phld->Flags = big4( datastream+8);
597 phld->OrigID = big8( datastream+12);
598 phld->OrigBHlen = metalength - 20;
599 phld->OrigBH = (Byte_t *)malloc(phld->OrigBHlen);
600 memcpy( phld->OrigBH, datastream+20, phld->OrigBHlen);
606 Byte_t * parse_bin_id_vbas( Byte_t *streamptr, Byte_t *bb, Byte_t *c, Byte8_t *in_class_id)
614 *bb = (code >> 5) & 3;
615 *c = (code >> 4) & 1;
617 *in_class_id = code & 15;
621 *in_class_id = (*in_class_id << 7) | (code & 0x7f);
626 Byte_t * parse_vbas( Byte_t *streamptr, Byte8_t *elem)
635 *elem = (*elem << 7) | (code & 0x7f);
642 * search a message by class_id
644 * @param[in] class_id class identifiers
645 * @param[in] in_class_id in-class identifiers, -1 means any
646 * @param[in] csn codestream number
647 * @param[in] msg first message pointer of the searching list
648 * @return found message pointer
650 message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg);
654 * delete a message in msgqueue
656 * @param[in] message address of the deleting message pointer
657 * @param[in] msgqueue message queue pointer
659 void delete_message_in_msgqueue( message_param_t **message, msgqueue_param_t *msgqueue);
661 Byte_t * recons_codestream( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *codelen);
663 // usable only to JPT-stream messages
664 Byte_t * recons_j2k( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *j2klen)
666 Byte_t *j2kstream = NULL;
671 j2kstream = recons_codestream( msgqueue, stream, csn, minlev, j2klen);
676 Byte_t * add_emptyboxstream( placeholder_param_t *phld, Byte_t *jp2stream, Byte8_t *jp2len);
677 Byte_t * add_msgstream( message_param_t *message, Byte_t *origstream, Byte_t *j2kstream, Byte8_t *j2klen);
679 Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, Byte8_t *jp2len)
681 message_param_t *ptr;
682 Byte_t *jp2stream = NULL;
683 Byte_t *codestream = NULL;
685 Byte8_t jp2cDBoxOffset = 0, jp2cDBoxlen = 0;
692 ptr = msgqueue->first;
693 while(( ptr = search_message( METADATA_MSG, -1, csn, ptr))!=NULL){
695 if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){
696 jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen;
697 jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
698 jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
701 jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
703 jp2stream = add_msgstream( ptr, stream, jp2stream, jp2len);
707 codestream = recons_codestream( msgqueue, stream, csn, 0, &codelen);
709 if( jp2cDBoxOffset != 0 && codelen <= jp2cDBoxlen)
710 memcpy( jp2stream+jp2cDBoxOffset, codestream, codelen);
717 int get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn);
718 Byte_t * add_emptytilestream( const int tileID, Byte_t *j2kstream, Byte8_t *j2klen);
719 Byte_t * add_EOC( Byte_t *j2kstream, Byte8_t *j2klen);
721 Byte_t * recons_codestream( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *codelen)
723 message_param_t *ptr;
724 Byte_t *codestream = NULL;
731 ptr = msgqueue->first;
732 while(( ptr = search_message( MAINHEADER_MSG, -1, csn, ptr))!=NULL){
733 codestream = add_msgstream( ptr, stream, codestream, codelen);
737 last_tileID = get_last_tileID( msgqueue, csn);
739 for( tileID=0; tileID <= last_tileID; tileID++){
741 ptr = msgqueue->first;
742 while(( ptr = search_message( TILE_MSG, tileID, csn, ptr))!=NULL){
744 codestream = add_msgstream( ptr, stream, codestream, codelen);
747 ptr = msgqueue->first;
748 while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){
749 if( ptr->aux >= minlev){
751 codestream = add_msgstream( ptr, stream, codestream, codelen);
756 codestream = add_emptytilestream( tileID, codestream, codelen);
758 codestream = add_EOC( codestream, codelen);
763 int get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn)
766 message_param_t *msg;
768 msg = msgqueue->first;
770 if((msg->class_id == TILE_MSG || msg->class_id == EXT_TILE_MSG) && msg->csn == csn && last_tileID < msg->in_class_id)
771 last_tileID = msg->in_class_id;
777 message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg)
780 if( in_class_id == -1){
781 if( msg->class_id == class_id && msg->csn == csn)
785 if( msg->class_id == class_id && msg->in_class_id == in_class_id && msg->csn == csn)
793 void delete_message_in_msgqueue( message_param_t **msg, msgqueue_param_t *msgqueue)
795 message_param_t *ptr;
800 if( *msg == msgqueue->first)
801 msgqueue->first = (*msg)->next;
803 ptr = msgqueue->first;
804 while( ptr->next != *msg){
808 ptr->next = (*msg)->next;
810 if( *msg == msgqueue->last)
811 msgqueue->last = ptr;
816 Byte_t * gene_msgstream( message_param_t *message, Byte_t *stream, Byte8_t *length);
817 Byte_t * gene_emptytilestream( const int tileID, Byte8_t *length);
820 Byte_t * add_msgstream( message_param_t *message, Byte_t *origstream, Byte_t *j2kstream, Byte8_t *j2klen)
829 newstream = gene_msgstream( message, origstream, &newlen);
831 buf = (Byte_t *)malloc(( *j2klen)+newlen);
833 memcpy( buf, j2kstream, *j2klen);
834 memcpy( buf+(*j2klen), newstream, newlen);
839 if(j2kstream) free(j2kstream);
845 Byte_t * add_emptyboxstream( placeholder_param_t *phld, Byte_t *jp2stream, Byte8_t *jp2len)
851 if( phld->OrigBHlen == 8)
852 newlen = big4(phld->OrigBH);
854 newlen = big8(phld->OrigBH+8);
856 newstream = (Byte_t *)malloc( newlen);
857 memset( newstream, 0, newlen);
858 memcpy( newstream, phld->OrigBH, phld->OrigBHlen);
860 buf = (Byte_t *)malloc(( *jp2len)+newlen);
862 memcpy( buf, jp2stream, *jp2len);
863 memcpy( buf+(*jp2len), newstream, newlen);
868 if(jp2stream) free(jp2stream);
873 Byte_t * add_emptytilestream( const int tileID, Byte_t *j2kstream, Byte8_t *j2klen)
879 newstream = gene_emptytilestream( tileID, &newlen);
881 buf = (Byte_t *)malloc(( *j2klen)+newlen);
883 memcpy( buf, j2kstream, *j2klen);
884 memcpy( buf+(*j2klen), newstream, newlen);
889 if(j2kstream) free(j2kstream);
894 Byte_t * add_EOC( Byte_t *j2kstream, Byte8_t *j2klen)
896 Byte2_t EOC = 0xd9ff;
900 buf = (Byte_t *)malloc(( *j2klen)+2);
902 memcpy( buf, j2kstream, *j2klen);
903 memcpy( buf+(*j2klen), &EOC, 2);
907 if(j2kstream) free(j2kstream);
912 Byte_t * gene_msgstream( message_param_t *message, Byte_t *stream, Byte8_t *length)
919 *length = message->length;
920 buf = (Byte_t *)malloc( *length);
921 memcpy( buf, stream+message->res_offset, *length);
926 Byte_t * gene_emptytilestream( const int tileID, Byte8_t *length)
929 const Byte2_t SOT = 0x90ff;
930 const Byte2_t Lsot = 0xa << 8;
932 const Byte4_t Psot = 0xe << 24;
933 const Byte_t TPsot = 0, TNsot = 0;
934 const Byte2_t SOD = 0x93ff;
937 buf = (Byte_t *)malloc(*length);
941 memcpy( buf, &SOT, 2);
942 memcpy( buf+2, &Lsot, 2);
943 memcpy( buf+4, &Isot, 2);
944 memcpy( buf+6, &Psot, 4);
945 memcpy( buf+10, &TPsot, 1);
946 memcpy( buf+11, &TNsot, 1);
947 memcpy( buf+12, &SOD, 2);