start using API style in openJPIP library

This commit is contained in:
Kaori Hagihara 2011-10-19 23:29:57 +00:00
parent 47d93279ff
commit 255fcbc3a5
65 changed files with 1136 additions and 741 deletions

View File

@ -5,7 +5,11 @@ What's New for OpenJPIP
! : changed
+ : added
October 14, 2011
October 20, 2011
+ [added] API style in openJPIP library
! [kaori] rearranged directories, applications are all under util/ directory, currently only 'make -f Makefile.nix' works
October 18, 2011
! [kaori] rearranged opj_server, opj_dec_server directory
October 14, 2011

View File

@ -1,19 +1,11 @@
default: t_libopenjpip t_opj_server t_opj_dec_server t_tools
default: t_libopenjpip t_util
t_libopenjpip:
make -C libopenjpip -f Makefile.nix
t_opj_server:
make -C opj_server -f Makefile.nix
t_opj_dec_server:
make -C opj_client/opj_dec_server -f Makefile.nix
t_tools:
make -C tools -f Makefile.nix
t_util:
make -C util -f Makefile.nix
clean:
make clean -C libopenjpip -f Makefile.nix
make clean -C opj_server -f Makefile.nix
make clean -C opj_client/opj_dec_server -f Makefile.nix
make clean -C tools -f Makefile.nix
make clean -C util -f Makefile.nix

View File

@ -2,17 +2,28 @@ ifdef jpipserver
CFLAGS = -O3 -Wall -m32 -DSERVER
LIBNAME = libopenjpip_server.a
else
CFLAGS = -O3 -Wall
J2KINCDIR = ../../../libopenjpeg
CFLAGS = -O3 -Wall -I$(J2KINCDIR)
LIBNAME = libopenjpip_local.a
endif
all: $(LIBNAME)
$(LIBNAME): target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
ifdef jpipserver
$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o
cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
session_manager.o jpip_parser.o
ar r $@ $^
else
$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
session_manager.o jpip_parser.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o \
dec_clientmsg_handler.o
ar r $@ $^
endif
clean:
rm -f $(LIBNAME) *.o *~

View File

@ -41,124 +41,6 @@
//! maximum length of channel identifier
#define MAX_LENOFCID 30
/**
* handle JPT- JPP- stream message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
* @param[in,out] jpipstream address of JPT- JPP- stream pointer
* @param[in,out] streamlen address of stream length
* @param[in,out] msgqueue message queue pointer
*/
void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
/**
* handle PNM request message
*
* @param[in] connected_socket socket descriptor
* @param[in] jpipstream jpipstream pointer
* @param[in] msgqueue message queue pointer
* @param[in] cachelist cache list pointer
*/
void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist);
/**
* handle XML request message
*
* @param[in] connected_socket socket descriptor
* @param[in] jpipstream address of caching jpipstream pointer
* @param[in] cachelist cache list pointer
*/
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
/**
* handle TargetID request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
*/
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle ChannelID request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
*/
void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle distroy ChannelID message
*
* @param[in] connected_socket socket descriptor
* @param[in,out] cachelist cache list pointer
*/
void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle saving JP2 file request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
* @param[in] msgqueue message queue pointer
* @param[in] jpipstream address of caching jpipstream pointer
*/
void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream);
bool handle_clientmsg( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
{
bool quit = false;
msgtype_t msgtype = identify_clientmsg( connected_socket);
switch( msgtype){
case JPIPSTREAM:
handle_JPIPstreamMSG( connected_socket, cachelist, jpipstream, streamlen, msgqueue);
break;
case PNMREQ:
handle_PNMreqMSG( connected_socket, *jpipstream, msgqueue, cachelist);
break;
case XMLREQ:
handle_XMLreqMSG( connected_socket, *jpipstream, cachelist);
break;
case TIDREQ:
handle_TIDreqMSG( connected_socket, cachelist);
break;
case CIDREQ:
handle_CIDreqMSG( connected_socket, cachelist);
break;
case CIDDST:
handle_dstCIDreqMSG( connected_socket, cachelist);
break;
case JP2SAVE:
handle_JP2saveMSG( connected_socket, cachelist, msgqueue, *jpipstream);
break;
case QUIT:
quit = true;
save_codestream( *jpipstream, *streamlen, "jpt");
break;
case MSGERROR:
break;
}
printf("\t end of the connection\n\n");
if( close_socket(connected_socket) != 0){
perror("close");
return false;
}
if( quit)
return false;
return true;
}
void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
{
@ -216,7 +98,7 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
receive_line( connected_socket, tmp);
fw = atoi( tmp);
receive_line( connected_socket, tmp);
fh = atoi( tmp);

View File

@ -0,0 +1,105 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DEC_CLIENTMSG_HANDLER_H_
# define DEC_CLIENTMSG_HANDLER_H_
#include "imgsock_manager.h"
#include "cache_manager.h"
#include "byte_manager.h"
#include "msgqueue_manager.h"
/**
* handle JPT- JPP- stream message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
* @param[in,out] jpipstream address of JPT- JPP- stream pointer
* @param[in,out] streamlen address of stream length
* @param[in,out] msgqueue message queue pointer
*/
void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
/**
* handle PNM request message
*
* @param[in] connected_socket socket descriptor
* @param[in] jpipstream jpipstream pointer
* @param[in] msgqueue message queue pointer
* @param[in] cachelist cache list pointer
*/
void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_param_t *msgqueue, cachelist_param_t *cachelist);
/**
* handle XML request message
*
* @param[in] connected_socket socket descriptor
* @param[in] jpipstream address of caching jpipstream pointer
* @param[in] cachelist cache list pointer
*/
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
/**
* handle TargetID request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
*/
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle ChannelID request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
*/
void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle distroy ChannelID message
*
* @param[in] connected_socket socket descriptor
* @param[in,out] cachelist cache list pointer
*/
void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
/**
* handle saving JP2 file request message
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
* @param[in] msgqueue message queue pointer
* @param[in] jpipstream address of caching jpipstream pointer
*/
void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream);
#endif /* !DEC_CLIENTMSG_HANDLER_H_ */

View File

@ -74,8 +74,11 @@ Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbo
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
fprintf( stderr, "opj_decode dinfo:%p cio:%p\n", dinfo, cio);
/* decode the stream and fill the image structure */
image = opj_decode(dinfo, cio);
fprintf( stderr, "done\n");
if(!image) {
fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
@ -95,9 +98,10 @@ Byte_t * j2k_to_pnm( Byte_t *j2kstream, Byte8_t j2klen, ihdrbox_param_t **ihdrbo
if(dinfo) {
opj_destroy_decompress(dinfo);
}
/* free image data structure */
opj_image_destroy(image);
return pnmstream;
}

View File

@ -45,109 +45,6 @@
#define logstream stderr
#endif //SERVER
/**
* REQUEST: target identification by target or tid request
*
* @param[in] query_param structured query
* @param[in] targetlist target list pointer
* @param[out] target address of target pointer
* @return if succeeded (true) or failed (false)
*/
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target);
/**
* REQUEST: channel association
* this must be processed before any process
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[out] cursession address of the associated session pointer
* @param[out] curchannel address of the associated channel pointer
* @return if succeeded (true) or failed (false)
*/
bool associate_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: new channel (cnew) assignment
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[in] target requested target pointer
* @param[in,out] cursession address of the associated/opened session pointer
* @param[in,out] curchannel address of the associated/opened channel pointer
* @return if succeeded (true) or failed (false)
*/
bool open_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
target_param_t *target,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: channel close (cclose)
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[in,out] cursession address of the session pointer of deleting channel
* @param[in,out] curchannel address of the deleting channel pointer
* @return if succeeded (true) or failed (false)
*/
bool close_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: view-window (fsiz)
*
* @param[in] query_param structured query
* @param[in] target requested target pointer
* @param[in,out] cursession associated session pointer
* @param[in,out] curchannel associated channel pointer
* @param[out] msgqueue address of the message queue pointer
* @return if succeeded (true) or failed (false)
*/
bool gene_JPIPstream( query_param_t query_param,
target_param_t *target,
session_param_t *cursession,
channel_param_t *curchannel,
msgqueue_param_t **msgqueue);
bool parse_JPIPrequest( query_param_t query_param,
sessionlist_param_t *sessionlist,
targetlist_param_t *targetlist,
msgqueue_param_t **msgqueue)
{
target_param_t *target = NULL;
session_param_t *cursession = NULL;
channel_param_t *curchannel = NULL;
if( query_param.target[0] != '\0' || query_param.tid[0] != '\0'){
if( !identify_target( query_param, targetlist, &target))
return false;
}
if( query_param.cid[0] != '\0'){
if( !associate_channel( query_param, sessionlist, &cursession, &curchannel))
return false;
}
if( query_param.cnew){
if( !open_channel( query_param, sessionlist, target, &cursession, &curchannel))
return false;
}
if( query_param.cclose[0][0] != '\0')
if( !close_channel( query_param, sessionlist, &cursession, &curchannel))
return false;
if( (query_param.fx > 0 && query_param.fy > 0) || query_param.box_type[0][0] != 0)
if( !gene_JPIPstream( query_param, target, cursession, curchannel, msgqueue))
return false;
return true;
}
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
{

View File

@ -0,0 +1,112 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JPIP_PARSER_H_
# define JPIP_PARSER_H_
#include "bool.h"
#include "query_parser.h"
#include "session_manager.h"
#include "target_manager.h"
#include "msgqueue_manager.h"
#include "channel_manager.h"
/**
* REQUEST: target identification by target or tid request
*
* @param[in] query_param structured query
* @param[in] targetlist target list pointer
* @param[out] target address of target pointer
* @return if succeeded (true) or failed (false)
*/
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target);
/**
* REQUEST: channel association
* this must be processed before any process
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[out] cursession address of the associated session pointer
* @param[out] curchannel address of the associated channel pointer
* @return if succeeded (true) or failed (false)
*/
bool associate_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: new channel (cnew) assignment
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[in] target requested target pointer
* @param[in,out] cursession address of the associated/opened session pointer
* @param[in,out] curchannel address of the associated/opened channel pointer
* @return if succeeded (true) or failed (false)
*/
bool open_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
target_param_t *target,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: channel close (cclose)
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[in,out] cursession address of the session pointer of deleting channel
* @param[in,out] curchannel address of the deleting channel pointer
* @return if succeeded (true) or failed (false)
*/
bool close_channel( query_param_t query_param,
sessionlist_param_t *sessionlist,
session_param_t **cursession,
channel_param_t **curchannel);
/**
* REQUEST: view-window (fsiz)
*
* @param[in] query_param structured query
* @param[in] target requested target pointer
* @param[in,out] cursession associated session pointer
* @param[in,out] curchannel associated channel pointer
* @param[out] msgqueue address of the message queue pointer
* @return if succeeded (true) or failed (false)
*/
bool gene_JPIPstream( query_param_t query_param,
target_param_t *target,
session_param_t *cursession,
channel_param_t *curchannel,
msgqueue_param_t **msgqueue);
#endif /* !JPIP_PARSER_H_ */

View File

@ -73,10 +73,10 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
Byte_t *pnmstream;
Byte_t *j2kstream; // j2k or jp2 codestream
Byte8_t j2klen;
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
pnmstream = j2k_to_pnm( j2kstream, j2klen, ihdrbox);
free( j2kstream);
return pnmstream;

View File

@ -0,0 +1,378 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "openjpip.h"
#include "jpip_parser.h"
#include "channel_manager.h"
#include <stdio.h>
#include "dec_clientmsg_handler.h"
#include "jpipstream_manager.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "jp2k_encoder.h"
server_record_t * init_JPIPserver()
{
server_record_t *record = (server_record_t *)malloc( sizeof(server_record_t));
record->sessionlist = gene_sessionlist();
record->targetlist = gene_targetlist();
return record;
}
void terminate_JPIPserver( server_record_t **rec)
{
delete_sessionlist( &(*rec)->sessionlist);
delete_targetlist( &(*rec)->targetlist);
free( *rec);
}
QR_t * parse_querystring( char *query_string)
{
QR_t *qr;
qr = (QR_t *)malloc( sizeof(QR_t));
qr->query = parse_query( query_string);
qr->msgqueue = NULL;
return qr;
}
bool process_JPIPrequest( server_record_t *rec, QR_t *qr)
{
target_param_t *target = NULL;
session_param_t *cursession = NULL;
channel_param_t *curchannel = NULL;
if( qr->query->target[0] != '\0' || qr->query->tid[0] != '\0'){
if( !identify_target( *(qr->query), rec->targetlist, &target))
return false;
}
if( qr->query->cid[0] != '\0'){
if( !associate_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
return false;
}
if( qr->query->cnew){
if( !open_channel( *(qr->query), rec->sessionlist, target, &cursession, &curchannel))
return false;
}
if( qr->query->cclose[0][0] != '\0')
if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
return false;
if( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0)
if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue))
return false;
return true;
}
void send_responsedata( QR_t *qr)
{
// Currently HTTP support only, find a way for TCP, UDP case
emit_stream_from_msgqueue( qr->msgqueue);
}
void end_QRprocess( server_record_t *rec, QR_t **qr)
{
// TODO: record client preferences if necessary
delete_query( &((*qr)->query));
delete_msgqueue( &((*qr)->msgqueue));
free( *qr);
}
void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec)
{
if( query)
print_queryparam( *qr->query);
if( messages)
print_msgqueue( qr->msgqueue);
if( sessions)
print_allsession( rec->sessionlist);
if( targets)
print_alltarget( rec->targetlist);
}
#ifndef SERVER
dec_server_record_t * init_dec_server()
{
dec_server_record_t *record = (dec_server_record_t *)malloc( sizeof(dec_server_record_t));
record->cachelist = gene_cachelist();
record->jpipstream = NULL;
record->jpipstreamlen = 0;
record->msgqueue = gene_msgqueue( true, NULL);
record->listening_socket = open_listeningsocket();
return record;
}
void terminate_dec_server( dec_server_record_t **rec)
{
delete_cachelist( &(*rec)->cachelist);
free( (*rec)->jpipstream);
if( (*rec)->msgqueue)
delete_msgqueue( &((*rec)->msgqueue));
if( close_socket( (*rec)->listening_socket) != 0)
perror("close");
free( *rec);
}
client_t accept_connection( dec_server_record_t *rec)
{
client_t client;
client = accept_socket( rec->listening_socket);
if( client == -1)
fprintf( stderr, "error: failed to connect to client\n");
return client;
}
bool handle_clientreq( client_t client, dec_server_record_t *rec)
{
bool quit = false;
msgtype_t msgtype = identify_clientmsg( client);
switch( msgtype){
case JPIPSTREAM:
handle_JPIPstreamMSG( client, rec->cachelist, &rec->jpipstream, &rec->jpipstreamlen, rec->msgqueue);
break;
case PNMREQ:
handle_PNMreqMSG( client, rec->jpipstream, rec->msgqueue, rec->cachelist);
break;
case XMLREQ:
handle_XMLreqMSG( client, rec->jpipstream, rec->cachelist);
break;
case TIDREQ:
handle_TIDreqMSG( client, rec->cachelist);
break;
case CIDREQ:
handle_CIDreqMSG( client, rec->cachelist);
break;
case CIDDST:
handle_dstCIDreqMSG( client, rec->cachelist);
break;
case JP2SAVE:
handle_JP2saveMSG( client, rec->cachelist, rec->msgqueue, rec->jpipstream);
break;
case QUIT:
quit = true;
save_codestream( rec->jpipstream, rec->jpipstreamlen, "jpt");
break;
case MSGERROR:
break;
}
printf("\t end of the connection\n\n");
if( close_socket(client) != 0){
perror("close");
return false;
}
if( quit)
return false;
return true;
}
jpip_dec_param_t * init_jpipdecoder( bool jp2)
{
jpip_dec_param_t *dec;
dec = (jpip_dec_param_t *)calloc( 1, sizeof(jpip_dec_param_t));
dec->msgqueue = gene_msgqueue( true, NULL);
if( jp2)
dec->metadatalist = gene_metadatalist();
return dec;
}
bool fread_jpip( char fname[], jpip_dec_param_t *dec)
{
int infd;
struct stat sb;
if(( infd = open( fname, O_RDONLY)) == -1){
fprintf( stderr, "file %s not exist\n", fname);
return false;
}
if( fstat( infd, &sb) == -1){
fprintf( stderr, "input file stream is broken\n");
return false;
}
dec->jpiplen = (Byte8_t)sb.st_size;
dec->jpipstream = (Byte_t *)malloc( dec->jpiplen);
if( read( infd, dec->jpipstream, dec->jpiplen) != dec->jpiplen){
fprintf( stderr, "file reading error\n");
free( dec->jpipstream);
return false;
}
close(infd);
return true;
}
void decode_jpip( jpip_dec_param_t *dec)
{
parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue);
if( dec->metadatalist){ // JP2 encoding
parse_metamsg( dec->msgqueue, dec->jpipstream, dec->jpiplen, dec->metadatalist);
dec->ihdrbox = gene_ihdrbox( dec->metadatalist, dec->jpipstream);
dec->jp2kstream = recons_jp2( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, &dec->jp2klen);
}
else // J2k encoding
// Notice: arguments fw, fh need to be set for LRCP, PCRL, CPRL
dec->jp2kstream = recons_j2k( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, 0, 0, &dec->jp2klen);
}
bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec)
{
int outfd;
#ifdef _WIN32
if(( outfd = open( fname, O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
#else
if(( outfd = open( fname, O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
#endif
fprintf( stderr, "file %s open error\n", fname);
return false;
}
if( write( outfd, dec->jp2kstream, dec->jp2klen) != dec->jp2klen)
fprintf( stderr, "j2k file write error\n");
close(outfd);
return true;
}
void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec)
{
if( messages)
print_msgqueue( dec->msgqueue);
if( metadata)
print_allmetadata( dec->metadatalist);
if( ihdrbox){
printf("W*H: %d*%d\n", dec->ihdrbox->height, dec->ihdrbox->width);
printf("NC: %d, bpc: %d\n", dec->ihdrbox->nc, dec->ihdrbox->bpc);
}
}
void destroy_jpipdecoder( jpip_dec_param_t **dec)
{
free( (*dec)->jpipstream);
delete_msgqueue( &(*dec)->msgqueue);
if( (*dec)->metadatalist){
delete_metadatalist( &(*dec)->metadatalist);
free( (*dec)->ihdrbox);
}
free( (*dec)->jp2kstream);
free( *dec);
}
index_t * get_index_from_JP2file( int fd)
{
char *data;
// Check resource is a JP family file.
if( lseek( fd, 0, SEEK_SET)==-1){
fprintf( stderr, "Error: File broken (lseek error)\n");
return NULL;
}
data = (char *)malloc( 12); // size of header
if( read( fd, data, 12) != 12){
free( data);
fprintf( stderr, "Error: File broken (read error)\n");
return NULL;
}
if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
free( data);
fprintf( stderr, "Error: No JPEG 2000 Signature box in this file\n");
return NULL;
}
free( data);
return parse_jp2file( fd);
}
void destroy_index( index_t **idx)
{
delete_index( idx);
}
void output_index( index_t *index)
{
print_index( *index);
}
#endif //SERVER

View File

@ -0,0 +1,296 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPENJPIP_H_
# define OPENJPIP_H_
#include "session_manager.h"
#include "target_manager.h"
#include "query_parser.h"
#include "msgqueue_manager.h"
#include "bool.h"
#include "cache_manager.h"
#include "byte_manager.h"
#include "imgsock_manager.h"
#include "metadata_manager.h"
#include "ihdrbox_manager.h"
#include "index_manager.h"
#ifdef SERVER
#include "fcgi_stdio.h"
#define logstream FCGI_stdout
#else
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif //SERVER
/*
*==========================================================
* JPIP server API
*==========================================================
*/
//! Server static records
typedef struct server_record{
sessionlist_param_t *sessionlist; //!< list of session records
targetlist_param_t *targetlist; //!< list of target records
} server_record_t;
//! Query/response data for each client
typedef struct QR{
query_param_t *query;
msgqueue_param_t *msgqueue;
} QR_t;
/**
* Initialize the JPIP server
*
* @return intialized server record pointer
*/
server_record_t * init_JPIPserver();
/**
* Terminate the JPIP server
*
* @param[in] rec address of deleting server static record pointer
*/
void terminate_JPIPserver( server_record_t **rec);
/**
* 1st process per client request; parse query string
*
* @param[in] query_string request query string
* @return initialized query/response data pointer
*/
QR_t * parse_querystring( char *query_string);
/**
* 2nd process; process JPIP request and construct message queue
*
* @param[in] rec server static record pointer
* @param[in] qr query/response data pointer
* @return true if succeed, otherwise false
*/
bool process_JPIPrequest( server_record_t *rec, QR_t *qr);
/**
* 3rd process; send response data JPT/JPP-stream
*
* @param[in] qr query/response data pointer
*/
void send_responsedata( QR_t *qr);
/**
* 4th (last) process;
*
* @param[in] rec server static record pinter
* @param[in] qr address of query/response data pointer
*/
void end_QRprocess( server_record_t *rec, QR_t **qr);
#ifndef SERVER
/**
* Option for local tests; print out parameter values to logstream (stderr)
*
* @param[in] query true if query parameters are to be printed out
* @param[in] messages true if queue of messages is to be printed out
* @param[in] sessions true if session list is to be printed out
* @param[in] targets true if target list is to be printed out
* @param[in] qr query/response data pointer
* @param[in] rec server static record pinter
*/
void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec);
#endif //SERVER
/*
*==========================================================
* JPIP decoding server API
*==========================================================
*/
#ifndef SERVER
//! Decoding server static records
typedef struct dec_server_record{
cachelist_param_t *cachelist; //!< cache list
Byte_t *jpipstream; //!< JPT/JPP stream
int jpipstreamlen; //!< length of jpipstream
msgqueue_param_t *msgqueue; //!< parsed message queue of jpipstream
SOCKET listening_socket; //!< listenning socket
} dec_server_record_t;
//! Client socket identifier
typedef SOCKET client_t;
/**
* Initialize the image decoding server
*
* @return intialized decoding server record pointer
*/
dec_server_record_t * init_dec_server();
/**
* Terminate the image decoding server
*
* @param[in] rec address of deleting decoding server static record pointer
*/
void terminate_dec_server( dec_server_record_t **rec);
/**
* Accept client connection
*
* @param[in] rec decoding server static record pointer
* @return client socket ID, -1 if failed
*/
client_t accept_connection( dec_server_record_t *rec);
/**
* Handle client request
*
* @param[in] client client socket ID
* @param[in] rec decoding server static record pointer
* @return true if succeed
*/
bool handle_clientreq( client_t client, dec_server_record_t *rec);
#endif //SERVER
/*
*==========================================================
* JPIP tool API
*==========================================================
*/
#ifndef SERVER
/*
* jpip to JP2 or J2K
*/
//! JPIP decoding parameters
typedef struct jpip_dec_param{
Byte_t *jpipstream; //!< JPT/JPP-stream
Byte8_t jpiplen; //!< length of jpipstream
msgqueue_param_t *msgqueue; //!< message queue
metadatalist_param_t *metadatalist; //!< metadata list going into JP2 file
ihdrbox_param_t *ihdrbox; //!< ihdr box going into JP2 file
Byte_t *jp2kstream; //!< J2K codestream or JP2 file codestream
Byte8_t jp2klen; //!< length of j2kstream or JP2 file
} jpip_dec_param_t;
/**
* Initialize jpip decoder
*
* @param[in] jp2 true in case of jp2 file encoding, else j2k file encoding
* @return JPIP decoding parameters pointer
*/
jpip_dec_param_t * init_jpipdecoder( bool jp2);
/**
* Destroy jpip decoding parameters
*
* @param[in] dec address of JPIP decoding parameters pointer
*/
void destroy_jpipdecoder( jpip_dec_param_t **dec);
/**
* Read jpip codestream from a file
*
* @param[in] fname file name
* @param[in] dec JPIP decoding parameters pointer
* @return true if succeed
*/
bool fread_jpip( char fname[], jpip_dec_param_t *dec);
/**
* Decode jpip codestream
*
* @param[in] dec JPIP decoding parameters pointer
*/
void decode_jpip( jpip_dec_param_t *dec);
/**
* Write J2K/JP2 codestream to a file
*
* @param[in] fname file name
* @param[in] dec JPIP decoding parameters pointer
* @return true if succeed
*/
bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec);
/**
* Option; print out parameter values to stderr
*
* @param[in] messages true if queue of messages is to be printed out
* @param[in] metadata true if metadata is to be printed out
* @param[in] ihdrbox true if image header data is to be printed out
* @param[in] dec JPIP decoding parameters pointer
*/
void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec);
/*
* test the format of index (cidx) box in JP2 file
*/
//! Redefinition of index parameters
typedef index_param_t index_t;
/**
* Parse JP2 file and get index information from cidx box inside
*
* @param[in] fd file descriptor of the JP2 file
* @return pointer to the generated structure of index parameters
*/
index_t * get_index_from_JP2file( int fd);
/**
* Destroy index parameters
*
* @param[in,out] idx addressof the index pointer
*/
void destroy_index( index_t **idx);
/**
* print index parameters
*
* @param[in] index index parameters
*/
void output_index( index_t *index);
#endif //SERVER
#endif /* !OPENJPIP_H_ */

View File

@ -53,11 +53,11 @@
/**
* initialize query parameters
* Get initialized query parameters
*
* @param[in,out] query_param query parameters
* @return initial query parameters
*/
void init_queryparam( query_param_t *query_param);
query_param_t * get_initquery();
/*
* get a pair of field name and value from the string starting fieldname=fieldval&... format
@ -89,11 +89,12 @@ void parse_comps( char *field, query_param_t *query_param);
//! maximum length of field value
#define MAX_LENOFFIELDVAL 128
void parse_query( char *query_string, query_param_t *query_param)
query_param_t * parse_query( char *query_string)
{
query_param_t *query_param;
char *pquery, fieldname[MAX_LENOFFIELDNAME], fieldval[MAX_LENOFFIELDVAL];
init_queryparam( query_param);
query_param = get_initquery();
pquery = query_string;
@ -146,40 +147,46 @@ void parse_query( char *query_string, query_param_t *query_param)
sscanf( fieldval, "%d", &query_param->len);
}
}
return query_param;
}
void init_queryparam( query_param_t *query_param)
query_param_t * get_initquery()
{
query_param_t *query;
int i;
query_param->target[0] = '\0';
query_param->tid[0] = '\0';
query_param->fx = -1;
query_param->fy = -1;
query_param->rx = -1;
query_param->ry = -1;
query_param->rw = -1;
query_param->rh = -1;
query_param->layers = -1;
query_param->lastcomp = -1;
query_param->comps = NULL;
query_param->cid[0] = '\0';
query_param->cnew = false;
memset( query_param->cclose, 0, MAX_NUMOFCCLOSE*MAX_LENOFCID);
memset( query_param->box_type, 0, MAX_NUMOFBOX*4);
memset( query_param->limit, 0, MAX_NUMOFBOX*sizeof(int));
query = (query_param_t *)malloc( sizeof(query_param_t));
query->target[0] = '\0';
query->tid[0] = '\0';
query->fx = -1;
query->fy = -1;
query->rx = -1;
query->ry = -1;
query->rw = -1;
query->rh = -1;
query->layers = -1;
query->lastcomp = -1;
query->comps = NULL;
query->cid[0] = '\0';
query->cnew = false;
memset( query->cclose, 0, MAX_NUMOFCCLOSE*MAX_LENOFCID);
memset( query->box_type, 0, MAX_NUMOFBOX*4);
memset( query->limit, 0, MAX_NUMOFBOX*sizeof(int));
for( i=0; i<MAX_NUMOFBOX; i++){
query_param->w[i] = false;
query_param->s[i] = false;
query_param->g[i] = false;
query_param->a[i] = false;
query_param->priority[i] = false;
query->w[i] = false;
query->s[i] = false;
query->g[i] = false;
query->a[i] = false;
query->priority[i] = false;
}
query_param->root_bin = 0;
query_param->max_depth = -1;
query_param->metadata_only = false;
query_param->return_type = UNKNOWN;
query_param->len = -1;
query->root_bin = 0;
query->max_depth = -1;
query->metadata_only = false;
query->return_type = UNKNOWN;
query->len = -1;
return query;
}
@ -376,3 +383,9 @@ void parse_comps( char *field, query_param_t *query_param)
if(aux!=-1)
query_param->comps[aux] = true;
}
void delete_query( query_param_t **query)
{
free((*query)->comps);
free( *query);
}

View File

@ -60,7 +60,7 @@ typedef struct query_param{
int rx, ry, rw, rh; //!< roi region
int layers; //!< quality layers
int lastcomp; //!< last component number
bool *comps; //!< components for jpp-stream, null means all components
bool *comps; //!< components (dynamic array) for jpp-stream, null means all components
char cid[MAX_LENOFCID]; //!< channel identifier
bool cnew; //!< if there is new channel request(true) or not (false)
char cclose[MAX_NUMOFCCLOSE][MAX_LENOFCID]; //!< closing channel identifiers
@ -83,9 +83,9 @@ typedef struct query_param{
* parse query
*
* @param[in] query_string request query string
* @param[out] query_param query parameters
* @return pointer to query parameters
*/
void parse_query( char *query_string, query_param_t *query_param);
query_param_t * parse_query( char *query_string);
/**
* print query parameters
@ -94,4 +94,12 @@ void parse_query( char *query_string, query_param_t *query_param);
*/
void print_queryparam( query_param_t query_param);
/**
* delete query
*
* @param[in] query address of the deleting query pointer
*/
void delete_query( query_param_t **query);
#endif /* !QUERY_PARSER_H_ */

View File

@ -2,7 +2,7 @@ J2KINCDIR = ../../../../libopenjpeg
J2KLIBDIR = $(J2KINCDIR)/.libs
JPIPLIBDIR = ../../libopenjpip
LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
CFLAGS = -O3 -Wall -I$(JPIPLIBDIR) -I$(J2KINCDIR)
CFLAGS = -O3 -Wall -I$(JPIPLIBDIR)
LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
#-lws2_32
@ -10,8 +10,8 @@ ALL = opj_dec_server
all: $(ALL)
opj_dec_server: opj_dec_server.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o dec_clientmsg_handler.o $(LIBFNAME)
$(CC) $(CFLAGS) $< jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o dec_clientmsg_handler.o $(LDFLAGS) $(LIBFNAME) -o $@
opj_dec_server: opj_dec_server.o $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
clean:
rm -f $(ALL) *.o *~

View File

@ -7,10 +7,6 @@ INCLUDE_DIRECTORIES(
SET(OPJ_SERVER_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/opj_server.c
${CMAKE_CURRENT_SOURCE_DIR}/query_parser.c
${CMAKE_CURRENT_SOURCE_DIR}/channel_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/session_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/jpip_parser.c
)
# Build executable

View File

@ -14,15 +14,7 @@ opj_server_CPPFLAGS = \
opj_server_CFLAGS =
opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm
opj_server_SOURCES = \
channel_manager.c \
opj_server.c \
query_parser.c \
session_manager.c \
jpip_parser.c \
channel_manager.h \
query_parser.h \
session_manager.h \
jpip_parser.h
opj_server.c
install-data-hook:
@echo -e " (B)\t$(bindir)/opj_server$(EXEEXT)" >> $(top_builddir)/report.txt

View File

@ -1,15 +0,0 @@
LIBDIR = ../libopenjpip
LIBFNAME = $(LIBDIR)/libopenjpip_server.a
CFLAGS = -O3 -Wall -m32 -DSERVER -DQUIT_SIGNAL=\"quitJPIP\" -I$(LIBDIR)
LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server
ALL = opj_server
all: $(ALL)
opj_server: opj_server.o query_parser.o channel_manager.o session_manager.o jpip_parser.o $(LIBFNAME)
$(CC) $(CFLAGS) $< query_parser.o channel_manager.o session_manager.o jpip_parser.o $(LDFLAGS) -o $@
clean:
rm -f $(ALL) *.o *~

View File

@ -1,20 +1,22 @@
J2KINCDIR = ../../../libopenjpeg
J2KLIBDIR = $(J2KINCDIR)/.libs
LIBDIR = ../libopenjpip
LIBFNAME = $(LIBDIR)/libopenjpip_local.a
CFLAGS = -O3 -Wall -I$(LIBDIR)
LDFLAGS = -L$(LIBDIR) -lm -lopenjpip_local
LIBFNAME = $(LIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
CFLAGS = -O3 -Wall -I$(LIBDIR) -I$(J2KINCDIR)
LDFLAGS = -L$(LIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
ALL = jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
all: $(ALL)
jpip_to_jp2: jpip_to_jp2.o $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
jpip_to_j2k: jpip_to_j2k.o $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
test_index: test_index.o $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
clean:
rm -f $(ALL) *.o *~

View File

@ -1,114 +0,0 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file
* \brief jpip_to_j2k is a program to convert JPT- JPP- stream to J2K file
*
* \section impinst Implementing instructions
* This program takes two arguments. \n
* -# Input JPT or JPP file
* -# Output J2K file\n
* % ./jpip_to_j2k input.jpt output.j2k
* or
* % ./jpip_to_j2k input.jpp output.j2k
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "msgqueue_manager.h"
#include "jp2k_encoder.h"
int main(int argc,char *argv[])
{
msgqueue_param_t *msgqueue;
int infd, outfd;
Byte8_t jpiplen, j2klen;
struct stat sb;
Byte_t *jpipstream, *j2kstream;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n");
return -1;
}
if(( infd = open( argv[1], O_RDONLY)) == -1){
fprintf( stderr, "file %s not exist\n", argv[1]);
return -1;
}
if( fstat( infd, &sb) == -1){
fprintf( stderr, "input file stream is broken\n");
return -1;
}
jpiplen = (Byte8_t)sb.st_size;
jpipstream = (Byte_t *)malloc( jpiplen);
if( read( infd, jpipstream, jpiplen) != jpiplen){
fprintf( stderr, "file reading error\n");
free( jpipstream);
return -1;
}
close(infd);
msgqueue = gene_msgqueue( true, NULL);
parse_JPIPstream( jpipstream, jpiplen, 0, msgqueue);
//print_msgqueue( msgqueue);
// arguments fw, fh need to be set for LRCP, PCRL, CPRL
j2kstream = recons_j2k( msgqueue, jpipstream, msgqueue->first->csn, 0, 0, &j2klen);
delete_msgqueue( &msgqueue);
free( jpipstream);
#ifdef _WIN32
if(( outfd = open( argv[2], O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
#else
if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
#endif
fprintf( stderr, "file %s open error\n", argv[2]);
return -1;
}
if( write( outfd, j2kstream, j2klen) != j2klen)
fprintf( stderr, "j2k file write error\n");
free( j2kstream);
close(outfd);
return 0;
}

View File

@ -1,130 +0,0 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file
* \brief jpip_to_jp2 is a program to convert JPT- JPP- stream to JP2 file
*
* \section impinst Implementing instructions
* This program takes two arguments. \n
* -# Input JPT or JPP file
* -# Output JP2 file\n
* % ./jpip_to_jp2 input.jpt output.jp2
* or
* % ./jpip_to_jp2 input.jpp output.jp2
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "msgqueue_manager.h"
#include "byte_manager.h"
#include "ihdrbox_manager.h"
#include "metadata_manager.h"
#include "jp2k_encoder.h"
int main(int argc,char *argv[])
{
msgqueue_param_t *msgqueue;
int infd, outfd;
Byte8_t jpiplen, jp2len;
struct stat sb;
Byte_t *jpipstream, *jp2stream;
metadatalist_param_t *metadatalist;
ihdrbox_param_t *ihdrbox;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output jp2 file\n");
return -1;
}
if(( infd = open( argv[1], O_RDONLY)) == -1){
fprintf( stderr, "file %s not exist\n", argv[1]);
return -1;
}
if( fstat( infd, &sb) == -1){
fprintf( stderr, "input file stream is broken\n");
return -1;
}
jpiplen = (Byte8_t)sb.st_size;
jpipstream = (Byte_t *)malloc( jpiplen);
if( read( infd, jpipstream, jpiplen) != jpiplen){
fprintf( stderr, "file reading error\n");
free( jpipstream);
return -1;
}
close(infd);
metadatalist = gene_metadatalist();
msgqueue = gene_msgqueue( true, NULL);
parse_JPIPstream( jpipstream, jpiplen, 0, msgqueue);
parse_metamsg( msgqueue, jpipstream, jpiplen, metadatalist);
print_msgqueue( msgqueue);
//print_allmetadata( metadatalist);
ihdrbox = gene_ihdrbox( metadatalist, jpipstream);
printf("W*H: %d*%d\n", ihdrbox->height, ihdrbox->width);
printf("NC: %d, bpc: %d\n", ihdrbox->nc, ihdrbox->bpc);
jp2stream = recons_jp2( msgqueue, jpipstream, msgqueue->first->csn, &jp2len);
#ifdef _WIN32
if(( outfd = open( argv[2], O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){
#else
if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){
#endif
fprintf( stderr, "file %s open error\n", argv[2]);
return -1;
}
if( write( outfd, jp2stream, jp2len) != jp2len)
fprintf( stderr, "jp2 file write error\n");
//print_msgqueue( msgqueue);
free( ihdrbox);
free( jp2stream);
close(outfd);
delete_msgqueue( &msgqueue);
delete_metadatalist( &metadatalist);
free( jpipstream);
return 0;
}

View File

@ -0,0 +1,33 @@
JPIPLIBDIR = ../libopenjpip
SLIBFNAME = $(JPIPLIBDIR)/libopenjpip_server.a
SCFLAGS = -O3 -Wall -m32 -I$(JPIPLIBDIR) -DSERVER -DQUIT_SIGNAL=\"quitJPIP\"
SLDFLAGS = -L$(JPIPLIBDIR) -lm -lfcgi -lopenjpip_server
J2KINCDIR = ../../../libopenjpeg
J2KLIBDIR = $(J2KINCDIR)/.libs
LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
CFLAGS = -O3 -Wall -I$(JPIPLIBDIR)
LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
ALL = opj_server opj_dec_server jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
all: $(ALL)
opj_server: opj_server.c $(SLIBFNAME)
$(CC) $(SCFLAGS) $< $(SLDFLAGS) $(SLIBFNAME) -o $@
opj_dec_server: opj_dec_server.c $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
jpip_to_jp2: jpip_to_jp2.c $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
jpip_to_j2k: jpip_to_j2k.c $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
test_index: test_index.c $(LIBFNAME)
$(CC) $(CFLAGS) $< $(LDFLAGS) $(LIBFNAME) -o $@
clean:
rm -f $(ALL) *.o *~

View File

@ -3,8 +3,7 @@
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -29,28 +28,45 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JPIP_PARSER_H_
# define JPIP_PARSER_H_
#include "bool.h"
#include "query_parser.h"
#include "session_manager.h"
#include "target_manager.h"
#include "msgqueue_manager.h"
/**
* parse JPIP request
/*! \file
* \brief jpip_to_j2k is a program to convert JPT- JPP- stream to J2K file
*
* @param[in] query_param structured query
* @param[in] sessionlist session list pointer
* @param[in] targetlist target list pointer
* @param[in,out] msgqueue address of the message queue pointer
* @return if succeeded (true) or failed (false)
* \section impinst Implementing instructions
* This program takes two arguments. \n
* -# Input JPT or JPP file
* -# Output J2K file\n
* % ./jpip_to_j2k input.jpt output.j2k
* or
* % ./jpip_to_j2k input.jpp output.j2k
*/
bool parse_JPIPrequest( query_param_t query_param,
sessionlist_param_t *sessionlist,
targetlist_param_t *targetlist,
msgqueue_param_t **msgqueue);
#include <stdio.h>
#include "openjpip.h"
#endif /* !JPIP_PARSER_H_ */
int main(int argc,char *argv[])
{
jpip_dec_param_t *dec;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n");
return -1;
}
dec = init_jpipdecoder( false);
if(!( fread_jpip( argv[1], dec)))
return -1;
decode_jpip( dec);
if(!( fwrite_jp2k( argv[2], dec)))
return -1;
output_log( true, false, false, dec);
destroy_jpipdecoder( &dec);
return 0;
}

View File

@ -3,8 +3,7 @@
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -29,25 +28,45 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DEC_CLIENTMSG_HANDLER_H_
# define DEC_CLIENTMSG_HANDLER_H_
#include "bool.h"
#include "imgsock_manager.h"
#include "cache_manager.h"
#include "byte_manager.h"
#include "msgqueue_manager.h"
/**
* handle client message
/*! \file
* \brief jpip_to_jp2 is a program to convert JPT- JPP- stream to JP2 file
*
* @param[in] connected_socket socket descriptor
* @param[in] cachelist cache list pointer
* @param[in,out] jpipstream address of JPT- JPP- stream pointer
* @param[in,out] streamlen address of stream length
* @param[in,out] msgqueue message queue pointer
* \section impinst Implementing instructions
* This program takes two arguments. \n
* -# Input JPT or JPP file
* -# Output JP2 file\n
* % ./jpip_to_jp2 input.jpt output.jp2
* or
* % ./jpip_to_jp2 input.jpp output.jp2
*/
bool handle_clientmsg( SOCKET connected_socket, cachelist_param_t *cachelist, Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue);
#include <stdio.h>
#include "openjpip.h"
#endif /* !DEC_CLIENTMSG_HANDLER_H_ */
int main(int argc,char *argv[])
{
jpip_dec_param_t *dec;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output jp2 file\n");
return -1;
}
dec = init_jpipdecoder( true);
if(!( fread_jpip( argv[1], dec)))
return -1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return -1;
output_log( true, false, true, dec);
destroy_jpipdecoder( &dec);
return 0;
}

View File

@ -45,13 +45,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include "dec_clientmsg_handler.h"
#include "imgsock_manager.h"
#include "byte_manager.h"
#include "msgqueue_manager.h"
#include "cache_manager.h"
#include "openjpip.h"
#ifdef _WIN32
WSADATA initialisation_win32;
@ -59,10 +53,8 @@ WSADATA initialisation_win32;
int main(int argc, char *argv[]){
SOCKET connected_socket;
Byte_t *jpipstream = NULL;
int jpipstreamlen = 0;
msgqueue_param_t *msgqueue = gene_msgqueue( true, NULL);
dec_server_record_t *server_record;
client_t client;
#ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
@ -72,25 +64,13 @@ int main(int argc, char *argv[]){
printf( "Initialisation Winsock\n");
#endif //_WIN32
SOCKET listening_socket = open_listeningsocket();
server_record = init_dec_server();
cachelist_param_t *cachelist = gene_cachelist();
while(( connected_socket = accept_socket( listening_socket)) != -1 )
if(!(handle_clientmsg( connected_socket, cachelist, &jpipstream, &jpipstreamlen, msgqueue)))
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))
break;
if( close_socket(listening_socket) != 0){
perror("close");
return -1;
}
delete_cachelist( &cachelist);
if( msgqueue)
delete_msgqueue( &msgqueue);
free( jpipstream);
terminate_dec_server( &server_record);
#ifdef _WIN32
if( WSACleanup() != 0){

View File

@ -48,36 +48,18 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "query_parser.h"
#include "jpip_parser.h"
#include "session_manager.h"
#include "target_manager.h"
#include "msgqueue_manager.h"
#include "openjpip.h"
#ifndef QUIT_SIGNAL
#define QUIT_SIGNAL "quitJPIP"
#endif
#ifdef SERVER
#include "fcgi_stdio.h"
#define logstream FCGI_stdout
#else
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif //SERVER
int main(void)
{
sessionlist_param_t *sessionlist;
targetlist_param_t *targetlist;
bool parse_status;
sessionlist = gene_sessionlist();
targetlist = gene_targetlist();
server_record_t *server_record;
server_record = init_JPIPserver();
#ifdef SERVER
char *query_string;
@ -95,37 +77,29 @@ int main(void)
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
query_param_t query_param;
msgqueue_param_t *msgqueue;
parse_query( query_string, &query_param);
QR_t *qr;
bool parse_status;
qr = parse_querystring( query_string);
if( !(parse_status = process_JPIPrequest( server_record, qr)))
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
#ifndef SERVER
print_queryparam( query_param);
local_log( true, true, parse_status, false, qr, server_record);
#endif
msgqueue = NULL;
if( !(parse_status = parse_JPIPrequest( query_param, sessionlist, targetlist, &msgqueue)))
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n");
#ifndef SERVER
// if( parse_status)
// print_allsession( sessionlist);
print_msgqueue( msgqueue);
#endif
send_responsedata( qr);
emit_stream_from_msgqueue( msgqueue);
delete_msgqueue( &msgqueue);
end_QRprocess( server_record, &qr);
}
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
delete_sessionlist( &sessionlist);
delete_targetlist( &targetlist);
terminate_JPIPserver( &server_record);
return 0;
}

View File

@ -42,87 +42,27 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "index_manager.h"
#ifdef SERVER
#include "fcgi_stdio.h"
#define logstream FCGI_stdout
#else
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif //SERVER
/**
* Open JP2 file with the check of JP2 header
*
* @param[in] filename file name string
* @return file descriptor
*/
int myopen_jp2file( char filename[]);
#include "openjpip.h"
int
main(int argc, char *argv[])
{
int fd;
index_param_t *jp2idx;
index_t *jp2idx;
if((fd = myopen_jp2file( argv[1])) == -1){
fprintf( stderr, "jp2 file open error\n");
if( (fd = open( argv[1], O_RDONLY)) == -1){
fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1;
}
if( !(jp2idx = parse_jp2file( fd))){
fprintf( FCGI_stdout, "Status: 501\r\n");
if( !(jp2idx = get_index_from_JP2file( fd))){
fprintf( stderr, "JP2 file broken\n");
return -1;
}
print_index( *jp2idx);
delete_index( &jp2idx);
output_index( jp2idx);
destroy_index( &jp2idx);
close(fd);
return 0;
} /* main */
int myopen_jp2file( char filename[])
{
int fd;
char *data;
if( (fd = open( filename, O_RDONLY)) == -1){
fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filename);
return -1;
}
// Check resource is a JP family file.
if( lseek( fd, 0, SEEK_SET)==-1){
close(fd);
fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filename);
return -1;
}
data = (char *)malloc( 12); // size of header
if( read( fd, data, 12) != 12){
free( data);
close(fd);
fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filename);
return -1;
}
if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
free( data);
close(fd);
fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filename);
return -1;
}
free( data);
return fd;
}