2 * $Id: msgqueue_manager.c 44 2011-02-15 12:32:29Z 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;
158 target = msgqueue->target;
159 codeidx = target->codeidx;
160 tilepart = codeidx->tilepart;
162 numOftparts = get_nmax( tilepart);
163 numOftiles = get_m( tilepart);
165 if( tile_id < 0 || numOftiles <= tile_id){
166 fprintf( FCGI_stderr, "Error, Invalid tile-id %d\n", tile_id);
170 tp_model = &codeidx->tp_model[ tile_id*numOftparts];
173 for( int i=0; i<numOftparts-level; i++){
174 binLength = get_elemLen( tilepart, i, tile_id);
177 msg = (message_param_t *)malloc( sizeof(message_param_t));
179 msg->last_byte = i==numOftparts-1? true : false;
180 msg->in_class_id = tile_id;
182 msg->class_id = TILE_MSG;
184 msg->class_id = EXT_TILE_MSG;
186 msg->csn = target->csn;
187 msg->bin_offset = binOffset;
188 msg->length = binLength;
189 msg->aux = numOftparts-i;
190 msg->res_offset = codeidx->offset+get_elemOff( tilepart, i, tile_id)/*-1*/;
194 enqueue_message( msg, msgqueue);
198 binOffset += binLength;
202 void enqueue_box( int meta_id, boxlist_param_t *boxlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
203 void enqueue_phld( int meta_id, placeholderlist_param_t *phldlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
204 void enqueue_boxcontents( int meta_id, boxcontents_param_t *boxcontents, msgqueue_param_t *msgqueue, Byte8_t *binOffset);
206 void enqueue_metadata( int meta_id, msgqueue_param_t *msgqueue)
208 metadatalist_param_t *metadatalist;
209 metadata_param_t *metadata;
212 metadatalist = msgqueue->target->codeidx->metadatalist;
213 metadata = search_metadata( meta_id, metadatalist);
216 fprintf( FCGI_stderr, "Error: metadata-bin %d not found\n", meta_id);
221 if( metadata->boxlist)
222 enqueue_box( meta_id, metadata->boxlist, msgqueue, &binOffset);
224 if( metadata->placeholderlist)
225 enqueue_phld( meta_id, metadata->placeholderlist, msgqueue, &binOffset);
227 if( metadata->boxcontents)
228 enqueue_boxcontents( meta_id, metadata->boxcontents, msgqueue, &binOffset);
230 msgqueue->last->last_byte = true;
233 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);
235 void enqueue_box( int meta_id, boxlist_param_t *boxlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
238 message_param_t *msg;
240 box = boxlist->first;
242 msg = gene_metamsg( meta_id, *binOffset, box->length, box->offset, NULL, msgqueue->target->csn);
243 enqueue_message( msg, msgqueue);
245 *binOffset += box->length;
250 void enqueue_phld( int meta_id, placeholderlist_param_t *phldlist, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
252 placeholder_param_t *phld;
253 message_param_t *msg;
255 phld = phldlist->first;
257 msg = gene_metamsg( meta_id, *binOffset, phld->LBox, 0, phld, msgqueue->target->csn);
258 enqueue_message( msg, msgqueue);
260 *binOffset += phld->LBox;
265 void enqueue_boxcontents( int meta_id, boxcontents_param_t *boxcontents, msgqueue_param_t *msgqueue, Byte8_t *binOffset)
267 message_param_t *msg;
269 msg = gene_metamsg( meta_id, *binOffset, boxcontents->length, boxcontents->offset, NULL, msgqueue->target->csn);
270 enqueue_message( msg, msgqueue);
272 *binOffset += boxcontents->length;
275 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)
277 message_param_t *msg;
279 msg = (message_param_t *)malloc( sizeof(message_param_t));
281 msg->last_byte = false;
282 msg->in_class_id = meta_id;
283 msg->class_id = METADATA_MSG;
285 msg->bin_offset = binOffset;
286 msg->length = length;
287 msg->aux = 0; // non exist
288 msg->res_offset = res_offset;
295 void enqueue_message( message_param_t *msg, msgqueue_param_t *msgqueue)
298 msgqueue->last->next = msg;
300 msgqueue->first = msg;
302 msgqueue->last = msg;
306 void emit_bin_id_vbas( Byte_t bb, Byte_t c, Byte8_t in_class_id);
307 void emit_vbas( Byte8_t code);
308 void emit_body( message_param_t *msg, int fd);
309 void emit_placeholder( placeholder_param_t *phld);
311 void emit_stream_from_msgqueue( msgqueue_param_t *msgqueue)
313 message_param_t *msg;
314 Byte8_t class_id, csn;
320 msg = msgqueue->first;
324 if( msg->csn == csn){
325 if( msg->class_id == class_id)
329 class_id = msg->class_id;
334 class_id = msg->class_id;
338 c = msg->last_byte ? 1 : 0;
340 emit_bin_id_vbas( bb, c, msg->in_class_id);
343 emit_vbas( class_id);
347 emit_vbas( msg->bin_offset);
348 emit_vbas (msg->length);
350 if( msg->class_id%2) // Aux is present only if the id is odd
351 emit_vbas( msg->aux);
354 emit_placeholder( msg->phld);
356 emit_body( msg, msgqueue->target->fd);
362 void emit_vbas_with_bytelen( Byte8_t code, int bytelength);
363 void print_binarycode( Byte8_t n, int segmentlen);
365 void emit_bin_id_vbas( Byte_t bb, Byte_t c, Byte8_t in_class_id)
370 // A.2.3 In-class identifiers
371 // 7k-3bits, where k is the number of bytes in the VBAS
373 tmp = in_class_id >> 4;
379 in_class_id |= (((bb & 3) << 5) | (c & 1) << 4) << ((bytelength-1)*7);
381 emit_vbas_with_bytelen( in_class_id, bytelength);
384 void emit_vbas( Byte8_t code)
394 emit_vbas_with_bytelen( code, bytelength);
397 void emit_vbas_with_bytelen( Byte8_t code, int bytelength)
404 seg = ( code >> (n*7)) & 0x7f;
407 fputc(( Byte4_t)seg, FCGI_stdout);
412 void emit_body( message_param_t *msg, int fd)
416 if( lseek( fd, msg->res_offset, SEEK_SET)==-1){
417 fprintf( FCGI_stderr, "Error: fseek in emit_body()\n");
421 data = (Byte_t *)malloc( msg->length);
422 if( read( fd, data, msg->length) != msg->length){
424 fprintf( FCGI_stderr, "Error: fread in emit_body()\n");
428 if( fwrite( data, msg->length, 1, FCGI_stdout) < 1){
430 fprintf( FCGI_stderr, "Error: fwrite in emit_body()\n");
436 void emit_bigendian_bytes( Byte8_t code, int bytelength);
438 void emit_placeholder( placeholder_param_t *phld)
440 emit_bigendian_bytes( phld->LBox, 4);
441 if( fwrite( phld->TBox, 4, 1, FCGI_stdout) < 1){
442 fprintf( FCGI_stderr, "Error: fwrite in emit_placeholder()\n");
445 emit_bigendian_bytes( phld->Flags, 4);
446 emit_bigendian_bytes( phld->OrigID, 8);
448 if( fwrite( phld->OrigBH, phld->OrigBHlen, 1, FCGI_stdout) < 1){
449 fprintf( FCGI_stderr, "Error: fwrite in emit_placeholder()\n");
454 void emit_bigendian_bytes( Byte8_t code, int bytelength)
461 seg = ( code >> (n*8)) & 0xff;
462 fputc(( Byte4_t)seg, FCGI_stdout);
466 void print_binarycode( Byte8_t n, int segmentlen)
471 buf[i++] = n%2 ? '1' : '0';
474 for( int j=segmentlen-1; j>=i; j--)
477 for( int j=i-1, k=0; j>=0; j--, k++){
479 if( !((k+1)%segmentlen))
485 Byte_t * parse_bin_id_vbas( Byte_t *streamptr, Byte_t *bb, Byte_t *c, Byte8_t *in_class_id);
486 Byte_t * parse_vbas( Byte_t *streamptr, Byte8_t *elem);
488 void parse_stream( Byte_t *stream, Byte8_t jptlen, Byte8_t offset, msgqueue_param_t *msgqueue)
490 Byte_t *ptr; // stream pointer
491 message_param_t *msg;
493 Byte8_t class_id, csn;
495 class_id = -1; // dummy
498 while( ptr-stream < jptlen){
499 msg = (message_param_t *)malloc( sizeof(message_param_t));
501 ptr = parse_bin_id_vbas( ptr, &bb, &c, &msg->in_class_id);
503 msg->last_byte = c == 1 ? true : false;
506 ptr = parse_vbas( ptr, &class_id);
507 // fprintf( stdout, "class_id: %lld\n", class_id);
509 msg->class_id = class_id;
512 ptr = parse_vbas( ptr, &csn);
515 ptr = parse_vbas( ptr, &msg->bin_offset);
516 ptr = parse_vbas( ptr, &msg->length);
518 if( msg->class_id%2) // Aux is present only if the id is odd
519 ptr = parse_vbas( ptr, &msg->aux);
523 msg->res_offset = ptr-stream+offset;
528 msgqueue->last->next = msg;
530 msgqueue->first = msg;
531 msgqueue->last = msg;
537 void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *stream);
539 void parse_metamsg( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t jptlen, metadatalist_param_t *metadatalist)
541 message_param_t *msg;
543 if( metadatalist == NULL)
546 msg = msgqueue->first;
548 if( msg->class_id == METADATA_MSG){
549 metadata_param_t *metadata = gene_metadata( msg->in_class_id, NULL, NULL, NULL);
550 insert_metadata_into_list( metadata, metadatalist);
551 parse_metadata( metadata, msg, stream+msg->res_offset);
557 placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength);
559 void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *datastream)
561 char *boxtype = (char *)(datastream+4);
565 if( strncmp( boxtype, "phld", 4) == 0){
566 if( !metadata->placeholderlist)
567 metadata->placeholderlist = gene_placeholderlist();
569 placeholder_param_t *phld = parse_phld( datastream, msg->length);
571 insert_placeholder_into_list( phld, metadata->placeholderlist);
573 else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
574 (isalnum(boxtype[2])||isblank(boxtype[2])) &&
575 (isalpha(boxtype[3])||isblank(boxtype[3]))){
576 if( !metadata->boxlist)
577 metadata->boxlist = gene_boxlist();
579 box_param_t *box = gene_boxbyOffinStream( datastream, msg->res_offset);
580 insert_box_into_list( box, metadata->boxlist);
583 metadata->boxcontents = gene_boxcontents( msg->res_offset, msg->length);
586 placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength)
588 placeholder_param_t *phld;
590 phld = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
592 phld->LBox = big4( datastream);
593 strcpy( phld->TBox, "phld");
594 phld->Flags = big4( datastream+8);
595 phld->OrigID = big8( datastream+12);
596 phld->OrigBHlen = metalength - 20;
597 phld->OrigBH = (Byte_t *)malloc(phld->OrigBHlen);
598 memcpy( phld->OrigBH, datastream+20, phld->OrigBHlen);
604 Byte_t * parse_bin_id_vbas( Byte_t *streamptr, Byte_t *bb, Byte_t *c, Byte8_t *in_class_id)
612 *bb = (code >> 5) & 3;
613 *c = (code >> 4) & 1;
615 *in_class_id = code & 15;
619 *in_class_id = (*in_class_id << 7) | (code & 0x7f);
624 Byte_t * parse_vbas( Byte_t *streamptr, Byte8_t *elem)
633 *elem = (*elem << 7) | (code & 0x7f);
640 * search a message by class_id
642 * @param[in] class_id class identifiers
643 * @param[in] in_class_id in-class identifiers, -1 means any
644 * @param[in] csn codestream number
645 * @param[in] msg first message pointer of the searching list
646 * @return found message pointer
648 message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg);
652 * delete a message in msgqueue
654 * @param[in] message address of the deleting message pointer
655 * @param[in] msgqueue message queue pointer
657 void delete_message_in_msgqueue( message_param_t **message, msgqueue_param_t *msgqueue);
659 Byte_t * recons_codestream( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *codelen);
661 // usable only to JPT-stream messages
662 Byte_t * recons_j2k( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *j2klen)
664 Byte_t *j2kstream = NULL;
669 j2kstream = recons_codestream( msgqueue, stream, csn, minlev, j2klen);
674 Byte_t * add_emptyboxstream( placeholder_param_t *phld, Byte_t *jp2stream, Byte8_t *jp2len);
675 Byte_t * add_msgstream( message_param_t *message, Byte_t *origstream, Byte_t *j2kstream, Byte8_t *j2klen);
677 Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, Byte8_t *jp2len)
679 message_param_t *ptr;
680 Byte_t *jp2stream = NULL;
681 Byte_t *codestream = NULL;
683 Byte8_t jp2cDBoxOffset = 0, jp2cDBoxlen = 0;
690 ptr = msgqueue->first;
691 while(( ptr = search_message( METADATA_MSG, -1, csn, ptr))!=NULL){
693 if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){
694 jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen;
695 jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
696 jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
699 jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
701 jp2stream = add_msgstream( ptr, stream, jp2stream, jp2len);
705 codestream = recons_codestream( msgqueue, stream, csn, 0, &codelen);
707 if( jp2cDBoxOffset != 0 && codelen <= jp2cDBoxlen)
708 memcpy( jp2stream+jp2cDBoxOffset, codestream, codelen);
715 int get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn);
716 Byte_t * add_emptytilestream( const int tileID, Byte_t *j2kstream, Byte8_t *j2klen);
717 Byte_t * add_EOC( Byte_t *j2kstream, Byte8_t *j2klen);
719 Byte_t * recons_codestream( msgqueue_param_t *msgqueue, Byte_t *stream, Byte8_t csn, int minlev, Byte8_t *codelen)
721 message_param_t *ptr;
722 Byte_t *codestream = NULL;
728 ptr = msgqueue->first;
729 while(( ptr = search_message( MAINHEADER_MSG, -1, csn, ptr))!=NULL){
730 codestream = add_msgstream( ptr, stream, codestream, codelen);
734 last_tileID = get_last_tileID( msgqueue, csn);
736 for( int tileID=0; tileID <= last_tileID; tileID++){
738 ptr = msgqueue->first;
739 while(( ptr = search_message( TILE_MSG, tileID, csn, ptr))!=NULL){
741 codestream = add_msgstream( ptr, stream, codestream, codelen);
744 ptr = msgqueue->first;
745 while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){
746 if( ptr->aux >= minlev){
748 codestream = add_msgstream( ptr, stream, codestream, codelen);
753 codestream = add_emptytilestream( tileID, codestream, codelen);
755 codestream = add_EOC( codestream, codelen);
760 int get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn)
763 message_param_t *msg;
765 msg = msgqueue->first;
767 if((msg->class_id == TILE_MSG || msg->class_id == EXT_TILE_MSG) && msg->csn == csn && last_tileID < msg->in_class_id)
768 last_tileID = msg->in_class_id;
774 message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg)
777 if( in_class_id == -1){
778 if( msg->class_id == class_id && msg->csn == csn)
782 if( msg->class_id == class_id && msg->in_class_id == in_class_id && msg->csn == csn)
790 void delete_message_in_msgqueue( message_param_t **msg, msgqueue_param_t *msgqueue)
792 message_param_t *ptr;
797 if( *msg == msgqueue->first)
798 msgqueue->first = (*msg)->next;
800 ptr = msgqueue->first;
801 while( ptr->next != *msg){
805 ptr->next = (*msg)->next;
807 if( *msg == msgqueue->last)
808 msgqueue->last = ptr;
813 Byte_t * gene_msgstream( message_param_t *message, Byte_t *stream, Byte8_t *length);
814 Byte_t * gene_emptytilestream( const int tileID, Byte8_t *length);
817 Byte_t * add_msgstream( message_param_t *message, Byte_t *origstream, Byte_t *j2kstream, Byte8_t *j2klen)
826 newstream = gene_msgstream( message, origstream, &newlen);
828 buf = (Byte_t *)malloc(( *j2klen)+newlen);
830 memcpy( buf, j2kstream, *j2klen);
831 memcpy( buf+(*j2klen), newstream, newlen);
836 if(j2kstream) free(j2kstream);
842 Byte_t * add_emptyboxstream( placeholder_param_t *phld, Byte_t *jp2stream, Byte8_t *jp2len)
848 if( phld->OrigBHlen == 8)
849 newlen = big4(phld->OrigBH);
851 newlen = big8(phld->OrigBH+8);
853 newstream = (Byte_t *)malloc( newlen);
854 memset( newstream, 0, newlen);
855 memcpy( newstream, phld->OrigBH, phld->OrigBHlen);
857 buf = (Byte_t *)malloc(( *jp2len)+newlen);
859 memcpy( buf, jp2stream, *jp2len);
860 memcpy( buf+(*jp2len), newstream, newlen);
865 if(jp2stream) free(jp2stream);
870 Byte_t * add_emptytilestream( const int tileID, Byte_t *j2kstream, Byte8_t *j2klen)
876 newstream = gene_emptytilestream( tileID, &newlen);
878 buf = (Byte_t *)malloc(( *j2klen)+newlen);
880 memcpy( buf, j2kstream, *j2klen);
881 memcpy( buf+(*j2klen), newstream, newlen);
886 if(j2kstream) free(j2kstream);
891 Byte_t * add_EOC( Byte_t *j2kstream, Byte8_t *j2klen)
893 Byte2_t EOC = 0xd9ff;
897 buf = (Byte_t *)malloc(( *j2klen)+2);
899 memcpy( buf, j2kstream, *j2klen);
900 memcpy( buf+(*j2klen), &EOC, 2);
904 if(j2kstream) free(j2kstream);
909 Byte_t * gene_msgstream( message_param_t *message, Byte_t *stream, Byte8_t *length)
916 *length = message->length;
917 buf = (Byte_t *)malloc( *length);
918 memcpy( buf, stream+message->res_offset, *length);
923 Byte_t * gene_emptytilestream( const int tileID, Byte8_t *length)
926 const Byte2_t SOT = 0x90ff;
927 const Byte2_t Lsot = 0xa << 8;
929 const Byte4_t Psot = 0xe << 24;
930 const Byte_t TPsot = 0, TNsot = 0;
931 const Byte2_t SOD = 0x93ff;
934 buf = (Byte_t *)malloc(*length);
938 memcpy( buf, &SOT, 2);
939 memcpy( buf+2, &Lsot, 2);
940 memcpy( buf+4, &Isot, 2);
941 memcpy( buf+6, &Psot, 4);
942 memcpy( buf+10, &TPsot, 1);
943 memcpy( buf+11, &TNsot, 1);
944 memcpy( buf+12, &SOD, 2);