Merge pull request #1418 from LongerVision/master
[openjpeg.git] / src / lib / openjpip / msgqueue_manager.h
1 /*
2  * $Id$
3  *
4  * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2014, Professor Benoit Macq
6  * Copyright (c) 2010-2011, Kaori Hagihara
7  * Copyright (c) 2011,      Lucian Corlaciu, GSoC
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef     MSGQUEUE_MANAGER_H_
33 # define    MSGQUEUE_MANAGER_H_
34
35 #include "byte_manager.h"
36 #include "cachemodel_manager.h"
37 #include "placeholder_manager.h"
38
39 #define PRECINCT_MSG 0
40 #define EXT_PRECINCT_MSG 1
41 #define TILE_HEADER_MSG 2
42 #define TILE_MSG 4
43 #define EXT_TILE_MSG 5
44 #define MAINHEADER_MSG 6
45 #define METADATA_MSG 8
46
47 /** message parameters */
48 typedef struct message_param {
49     OPJ_BOOL
50     last_byte;          /**< if message contains the last byte of the data-bin*/
51     Byte8_t in_class_id;        /**< in-class identifier A.2.3*/
52     Byte8_t class_id;           /**< class identifiers */
53     Byte8_t csn;                /**< index of the codestream*/
54     Byte8_t bin_offset;         /**< offset of the data in this message from the start of the data-bin*/
55     Byte8_t length;             /**< message byte length*/
56     Byte8_t aux;                /**<*/
57     OPJ_OFF_T res_offset;         /**< offset in the resource*/
58     placeholder_param_t *phld;  /**< placeholder pointer in index*/
59     struct message_param *next; /**< pointer to the next message*/
60 } message_param_t;
61
62 /** message queue parameters */
63 typedef struct msgqueue_param {
64     message_param_t *first;         /**< first message pointer of the list*/
65     message_param_t *last;          /**< last  message pointer of the list*/
66     OPJ_BOOL stateless;                 /**< if this is a stateless message queue*/
67     cachemodel_param_t *cachemodel; /**< reference cachemodel pointer*/
68 } msgqueue_param_t;
69
70 /**
71  * generate message queue
72  *
73  * @param[in] stateless   if this is a stateless message queue
74  * @param[in] cachemodel  cachemodel pointer
75  * @return                generated message queue pointer
76  */
77 msgqueue_param_t * gene_msgqueue(OPJ_BOOL stateless,
78                                  cachemodel_param_t *cachemodel);
79
80 /**
81  * delete message queue
82  *
83  * @param[in] msgqueue address of the message queue pointer
84  */
85 void delete_msgqueue(msgqueue_param_t **msgqueue);
86
87 /**
88  * delete a message in msgqueue
89  *
90  * @param[in] message  address of the deleting message pointer
91  * @param[in] msgqueue message queue pointer
92  */
93 void delete_message_in_msgqueue(message_param_t **message,
94                                 msgqueue_param_t *msgqueue);
95
96 /**
97  * print message queue
98  *
99  * @param[in] msgqueue message queue pointer
100  */
101 void print_msgqueue(msgqueue_param_t *msgqueue);
102
103
104 /**
105  * enqueue main header data-bin into message queue
106  *
107  * @param[in,out] msgqueue message queue pointer
108  */
109 void enqueue_mainheader(msgqueue_param_t *msgqueue);
110
111 /**
112  * enqueue tile headers data-bin into message queue
113  *
114  * @param[in]     tile_id  tile id starting from 0
115  * @param[in,out] msgqueue message queue pointer
116  */
117 void enqueue_tileheader(int tile_id, msgqueue_param_t *msgqueue);
118
119 /**
120  * enqueue tile data-bin into message queue
121  *
122  * @param[in]     tile_id  tile id starting from 0
123  * @param[in]     level    decomposition level
124  * @param[in,out] msgqueue message queue pointer
125  */
126 void enqueue_tile(Byte4_t tile_id, int level, msgqueue_param_t *msgqueue);
127
128 /**
129  * enqueue precinct data-bin into message queue
130  *
131  * @param[in]     seq_id   precinct sequence number within its tile
132  * @param[in]     tile_id  tile index
133  * @param[in]     comp_id  component number
134  * @param[in]     layers   num of layers
135  * @param[in,out] msgqueue message queue
136  */
137 void enqueue_precinct(int seq_id, int tile_id, int comp_id, int layers,
138                       msgqueue_param_t *msgqueue);
139
140
141 /**
142  * enqueue Metadata-bin into message queue
143  *
144  * @param[in]     meta_id  metadata-bin id
145  * @param[in,out] msgqueue message queue pointer
146  */
147 void enqueue_metadata(Byte8_t meta_id, msgqueue_param_t *msgqueue);
148
149
150 /**
151  * reconstruct JPT/JPP-stream from message queue
152  *
153  * @param[in] msgqueue message queue pointer
154  * @param[in] tmpfd    file discriptor to write JPT/JPP-stream
155  */
156 void recons_stream_from_msgqueue(msgqueue_param_t *msgqueue, int tmpfd);
157
158
159 /**
160  * parse JPT- JPP- stream to message queue
161  *
162  * @param[in]     JPIPstream   JPT- JPP- stream data pointer
163  * @param[in]     streamlen    JPIPstream length
164  * @param[in]     offset       offset of the stream from the whole beginning
165  * @param[in,out] msgqueue     adding message queue pointer
166  */
167 void parse_JPIPstream(Byte_t *JPIPstream, Byte8_t streamlen, OPJ_OFF_T offset,
168                       msgqueue_param_t *msgqueue);
169
170 /**
171  * parse JPT- JPP- stream to message queue
172  *
173  * @param[in] msgqueue     reference message queue pointer
174  * @param[in] stream       stream data pointer
175  * @param[in] streamlen    stream length
176  * @param[in] metadatalist adding metadata list pointer
177  */
178 void parse_metamsg(msgqueue_param_t *msgqueue, Byte_t *stream,
179                    Byte8_t streamlen, metadatalist_param_t *metadatalist);
180
181 /**
182  * compute precinct ID A.3.2.1
183  *
184  * @param[in]  t                 tile index
185  * @param[in]  c                 component index
186  * @param[in]  s                 sequence number
187  * @param[in]  num_components    total number of components
188  * @param[in]  num_tiles         total number of tiles
189  * @return                       precicnt id
190  */
191 Byte8_t comp_precinct_id(int t, int c, int s, int num_components,
192                          int num_tiles);
193
194 #endif      /* !MSGQUEUE_MANAGER_H_ */