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.
35 #include "dec_clientmsg_handler.h"
36 #include "ihdrbox_manager.h"
37 #include "jpipstream_manager.h"
38 #include "jp2k_encoder.h"
41 //! maximum length of channel identifier
42 #define MAX_LENOFCID 30
44 void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
45 Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
47 Byte_t *newjpipstream;
50 char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
51 metadatalist_param_t *metadatalist;
53 newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen);
55 parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
57 *jpipstream = update_JPIPstream( newjpipstream, newstreamlen, *jpipstream, streamlen);
60 metadatalist = gene_metadatalist();
61 parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
65 if((cache = search_cache( target, cachelist))){
67 update_cachetid( tid, cache);
69 add_cachecid( cid, cache);
72 cache = gene_cache( target, msgqueue->last->csn, tid, cid);
73 insert_cache_into_list( cache, cachelist);
77 cache = search_cacheBycsn( msgqueue->last->csn, cachelist);
79 if( cache->metadatalist)
80 delete_metadatalist( &cache->metadatalist);
81 cache->metadatalist = metadatalist;
83 response_signal( connected_socket, true);
86 void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist)
89 ihdrbox_param_t *ihdrbox;
90 char cid[MAX_LENOFCID], tmp[10];
94 receive_line( connected_socket, cid);
95 if(!(cache = search_cacheBycid( cid, cachelist)))
96 if(!(cache = search_cacheBytid( cid, cachelist)))
99 receive_line( connected_socket, tmp);
102 receive_line( connected_socket, tmp);
105 pnmstream = jpipstream_to_pnm( jpipstream, msgqueue, cache->csn, fw, fh, &cache->ihdrbox);
106 ihdrbox = cache->ihdrbox;
108 send_PNMstream( connected_socket, pnmstream, ihdrbox->width, ihdrbox->height, ihdrbox->nc, ihdrbox->bpc > 8 ? 255 : (1 << ihdrbox->bpc) - 1);
113 void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
115 char cid[MAX_LENOFCID];
116 cache_param_t *cache;
118 receive_line( connected_socket, cid);
119 if(!(cache = search_cacheBycid( cid, cachelist)))
122 boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
123 Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
124 memcpy( xmlstream, jpipstream+boxcontents->offset, boxcontents->length);
125 send_XMLstream( connected_socket, xmlstream, boxcontents->length);
129 void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
131 char target[MAX_LENOFTARGET], *tid = NULL;
132 cache_param_t *cache;
135 receive_line( connected_socket, target);
136 cache = search_cache( target, cachelist);
140 tidlen = strlen(tid);
142 send_TIDstream( connected_socket, tid, tidlen);
145 void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
147 char target[MAX_LENOFTARGET], *cid = NULL;
148 cache_param_t *cache;
151 receive_line( connected_socket, target);
152 cache = search_cache( target, cachelist);
155 if( cache->numOfcid > 0){
156 cid = cache->cid[ cache->numOfcid-1];
157 cidlen = strlen(cid);
160 send_CIDstream( connected_socket, cid, cidlen);
163 void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
165 char cid[MAX_LENOFCID];
167 receive_line( connected_socket, cid);
168 remove_cachecid( cid, cachelist);
169 response_signal( connected_socket, true);
172 void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
174 char cid[MAX_LENOFCID];
175 cache_param_t *cache;
179 receive_line( connected_socket, cid);
180 if(!(cache = search_cacheBycid( cid, cachelist)))
183 jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len);
186 save_codestream( jp2stream, jp2len, "jp2");