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 "cachemodel_manager.h"
34 #include "faixbox_manager.h"
35 #include "opj_inttypes.h"
38 #include "fcgi_stdio.h"
39 #define logstream FCGI_stdout
41 #define FCGI_stdout stdout
42 #define FCGI_stderr stderr
43 #define logstream stderr
47 cachemodellist_param_t * gene_cachemodellist(void)
49 cachemodellist_param_t *cachemodellist;
51 cachemodellist = (cachemodellist_param_t *)opj_malloc( sizeof(cachemodellist_param_t));
53 cachemodellist->first = NULL;
54 cachemodellist->last = NULL;
56 return cachemodellist;
59 cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target, opj_bool reqJPP)
61 cachemodel_param_t *cachemodel;
62 faixbox_param_t *tilepart;
63 faixbox_param_t *precpacket;
68 cachemodel = (cachemodel_param_t *)opj_malloc( sizeof(cachemodel_param_t));
70 refer_target( target, &cachemodel->target);
73 if( target->jppstream)
74 cachemodel->jppstream = OPJ_TRUE;
76 cachemodel->jppstream = OPJ_FALSE;
78 if( target->jptstream)
79 cachemodel->jppstream = OPJ_FALSE;
81 cachemodel->jppstream = OPJ_TRUE;
84 cachemodel->mhead_model = OPJ_FALSE;
86 tilepart = target->codeidx->tilepart;
87 numOftiles = get_m( tilepart);
88 numOfelem = get_nmax( tilepart)*numOftiles;
89 cachemodel->tp_model = (opj_bool *)opj_calloc( 1, numOfelem*sizeof(opj_bool));
90 cachemodel->th_model = (opj_bool *)opj_calloc( 1, numOftiles*sizeof(opj_bool));
91 cachemodel->pp_model = (opj_bool **)opj_malloc( target->codeidx->SIZ.Csiz*sizeof(opj_bool *));
92 for( i=0; i<target->codeidx->SIZ.Csiz; i++){
93 precpacket = target->codeidx->precpacket[i];
94 cachemodel->pp_model[i] = (opj_bool *)opj_calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(opj_bool));
96 cachemodel->next = NULL;
99 if( cachemodellist->first) /* there are one or more entries */
100 cachemodellist->last->next = cachemodel;
101 else /* first entry */
102 cachemodellist->first = cachemodel;
103 cachemodellist->last = cachemodel;
107 fprintf( logstream, "local log: cachemodel generated\n");
113 void print_cachemodel( cachemodel_param_t cachemodel)
115 target_param_t *target;
116 Byte8_t TPnum; /* num of tile parts in each tile */
117 Byte8_t Pmax; /* max num of packets per tile */
119 int n; /* FIXME: Is this large enough ? */
121 target = cachemodel.target;
123 fprintf( logstream, "target: %s\n", target->targetname);
124 fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
126 fprintf( logstream, "\t tile part model:\n");
127 TPnum = get_nmax( target->codeidx->tilepart);
129 for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++){
130 for( j=0; j<target->codeidx->SIZ.XTnum; j++){
131 for( k=0; k<TPnum; k++)
132 fprintf( logstream, "%d", cachemodel.tp_model[n++]);
133 fprintf( logstream, " ");
135 fprintf( logstream, "\n");
138 fprintf( logstream, "\t tile header and precinct packet model:\n");
139 for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
140 fprintf( logstream, "\t tile.%" PRIu64 " %d\n", i, cachemodel.th_model[i]);
141 for( j=0; j<target->codeidx->SIZ.Csiz; j++){
142 fprintf( logstream, "\t compo.%" PRIu64 ": ", j);
143 Pmax = get_nmax( target->codeidx->precpacket[j]);
144 for( k=0; k<Pmax; k++)
145 fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
146 fprintf( logstream, "\n");
151 cachemodel_param_t * search_cachemodel( target_param_t *target, cachemodellist_param_t *cachemodellist)
153 cachemodel_param_t *foundcachemodel;
155 foundcachemodel = cachemodellist->first;
157 while( foundcachemodel != NULL){
159 if( foundcachemodel->target == target)
160 return foundcachemodel;
162 foundcachemodel = foundcachemodel->next;
167 void delete_cachemodellist( cachemodellist_param_t **cachemodellist)
169 cachemodel_param_t *cachemodelPtr, *cachemodelNext;
171 cachemodelPtr = (*cachemodellist)->first;
172 while( cachemodelPtr != NULL){
173 cachemodelNext=cachemodelPtr->next;
174 delete_cachemodel( &cachemodelPtr);
175 cachemodelPtr=cachemodelNext;
177 opj_free(*cachemodellist);
180 void delete_cachemodel( cachemodel_param_t **cachemodel)
184 unrefer_target( (*cachemodel)->target);
186 opj_free( (*cachemodel)->tp_model);
187 opj_free( (*cachemodel)->th_model);
189 for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
190 opj_free( (*cachemodel)->pp_model[i]);
191 opj_free( (*cachemodel)->pp_model);
194 fprintf( logstream, "local log: cachemodel deleted\n");
196 opj_free( *cachemodel);
199 opj_bool is_allsent( cachemodel_param_t cachemodel)
201 target_param_t *target;
202 Byte8_t TPnum; /* num of tile parts in each tile */
203 Byte8_t Pmax; /* max num of packets per tile */
205 int n; /* FIXME: is this large enough ? */
207 target = cachemodel.target;
209 if( !cachemodel.mhead_model)
212 TPnum = get_nmax( target->codeidx->tilepart);
214 if( cachemodel.jppstream){
215 for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
216 if( !cachemodel.th_model[i])
219 for( j=0; j<target->codeidx->SIZ.Csiz; j++){
220 Pmax = get_nmax( target->codeidx->precpacket[j]);
221 for( k=0; k<Pmax; k++)
222 if( !cachemodel.pp_model[j][i*Pmax+k])
229 for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++)
230 for( j=0; j<target->codeidx->SIZ.XTnum; j++)
231 for( k=0; k<TPnum; k++)
232 if( !cachemodel.tp_model[n++])