[1.5][JPIP] new feature to target JP2 files from www (libcurl required)
This commit is contained in:
parent
3459199eba
commit
ff1f022d47
|
@ -7,6 +7,7 @@ What's New for OpenJPIP
|
||||||
|
|
||||||
November 16, 2011
|
November 16, 2011
|
||||||
* [kaori] fixed Region of Interest option, and memory leak of opj_dec_server
|
* [kaori] fixed Region of Interest option, and memory leak of opj_dec_server
|
||||||
|
+ [kaori] new feature to target JP2 files from www (libcurl required)
|
||||||
|
|
||||||
November 8, 2011
|
November 8, 2011
|
||||||
! [kaori] updated main page of doxygen
|
! [kaori] updated main page of doxygen
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
========================================================================
|
========================================================================
|
||||||
OpenJPIP software 2.0 ReadMe
|
OpenJPIP software 2.1 ReadMe
|
||||||
|
|
||||||
OpenJPEG:
|
OpenJPEG:
|
||||||
http://www.openjpeg.org
|
http://www.openjpeg.org
|
||||||
|
@ -26,13 +26,14 @@ OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools,
|
||||||
( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)
|
( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)
|
||||||
The current implementation uses some results from the 2KAN project (http://www.2kan.org).
|
The current implementation uses some results from the 2KAN project (http://www.2kan.org).
|
||||||
|
|
||||||
First Version 2.0 covers:
|
Version 2.1 covers:
|
||||||
- JPT-stream (Tile) and JPP-stream (Precinct) media types
|
- JPT-stream (Tile) and JPP-stream (Precinct) media types
|
||||||
- Session, channels, cache model managements
|
- Session, channels, cache model managements
|
||||||
- JPIP over HTTP
|
- JPIP over HTTP
|
||||||
- Indexing JPEG 2000 files
|
- Indexing JPEG 2000 files
|
||||||
- Embedding XML formatted metadata
|
- Embedding XML formatted metadata
|
||||||
- Region Of Interest (ROI) requests
|
- Region Of Interest (ROI) requests
|
||||||
|
- Access to JP2 files with their URL
|
||||||
|
|
||||||
----------
|
----------
|
||||||
2. License
|
2. License
|
||||||
|
@ -46,8 +47,8 @@ Neither the author, nor the university accept any responsibility for any kind of
|
||||||
3. System requirements
|
3. System requirements
|
||||||
----------
|
----------
|
||||||
|
|
||||||
- OpenJPEG library (currently assumes it is installed on the system => will not use the one built higher in the directory structure)
|
|
||||||
- FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
|
- FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
|
||||||
|
- libcURL library
|
||||||
- Java application launcher at client
|
- Java application launcher at client
|
||||||
<Optional>
|
<Optional>
|
||||||
- Xerces2 java XML parser on the client for accessing embedded image metadata (http://xerces.apache.org/xerces2-j)
|
- Xerces2 java XML parser on the client for accessing embedded image metadata (http://xerces.apache.org/xerces2-j)
|
||||||
|
@ -103,10 +104,10 @@ Client:
|
||||||
% ../opj_dec_server
|
% ../opj_dec_server
|
||||||
|
|
||||||
2. Open image viewers (as many as needed)
|
2. Open image viewers (as many as needed)
|
||||||
% java -jar opj_viewer.jar http://hostname/myFCGI JP2_filename.jp2 [stateless/session] [jptstream/jppstream]
|
% java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [stateless/session] [jptstream/jppstream]
|
||||||
( The arguments
|
( The arguments
|
||||||
- http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
|
- http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
|
||||||
- JP2_filename.jp2 is the name of a JP2 file available on the server.
|
- path/filename.jp2 is the server local path or URL of a JP2 file
|
||||||
- request type stateless for no caching, session (default) for caching
|
- request type stateless for no caching, session (default) for caching
|
||||||
- return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream
|
- return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream
|
||||||
Image viewer GUI instructions:
|
Image viewer GUI instructions:
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 61 KiB |
|
@ -118,7 +118,7 @@ void print_cachemodel( cachemodel_param_t cachemodel)
|
||||||
|
|
||||||
target = cachemodel.target;
|
target = cachemodel.target;
|
||||||
|
|
||||||
fprintf( logstream, "target: %s\n", target->filename);
|
fprintf( logstream, "target: %s\n", target->targetname);
|
||||||
fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
|
fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
|
||||||
|
|
||||||
fprintf( logstream, "\t tile part model:\n");
|
fprintf( logstream, "\t tile part model:\n");
|
||||||
|
|
|
@ -139,7 +139,7 @@ void print_allchannel( channellist_param_t *channellist)
|
||||||
|
|
||||||
ptr = channellist->first;
|
ptr = channellist->first;
|
||||||
while( ptr != NULL){
|
while( ptr != NULL){
|
||||||
fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
|
fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->targetname);
|
||||||
ptr=ptr->next;
|
ptr=ptr->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <curl/curl.h>
|
||||||
#include "target_manager.h"
|
#include "target_manager.h"
|
||||||
|
|
||||||
#ifdef SERVER
|
#ifdef SERVER
|
||||||
|
@ -64,24 +65,26 @@ targetlist_param_t * gene_targetlist()
|
||||||
/**
|
/**
|
||||||
* open jp2 format image file
|
* open jp2 format image file
|
||||||
*
|
*
|
||||||
* @param[in] filename file name (.jp2)
|
* @param[in] filepath file name (.jp2)
|
||||||
* @return file descriptor
|
* @param[out] tmpfname new file name if filepath is a URL
|
||||||
|
* @return file descriptor
|
||||||
*/
|
*/
|
||||||
int open_jp2file( char filename[]);
|
int open_jp2file( char filepath[], char tmpfname[]);
|
||||||
|
|
||||||
target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
|
target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
|
||||||
{
|
{
|
||||||
target_param_t *target;
|
target_param_t *target;
|
||||||
int fd;
|
int fd;
|
||||||
index_param_t *jp2idx;
|
index_param_t *jp2idx;
|
||||||
|
char tmpfname[MAX_LENOFTID];
|
||||||
static int last_csn = 0;
|
static int last_csn = 0;
|
||||||
|
|
||||||
if( targetpath[0]=='\0'){
|
if( targetpath[0]=='\0'){
|
||||||
fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
|
fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((fd = open_jp2file( targetpath)) == -1){
|
if((fd = open_jp2file( targetpath, tmpfname)) == -1){
|
||||||
fprintf( FCGI_stdout, "Status: 404\r\n");
|
fprintf( FCGI_stdout, "Status: 404\r\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -93,8 +96,12 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
|
||||||
|
|
||||||
target = (target_param_t *)malloc( sizeof(target_param_t));
|
target = (target_param_t *)malloc( sizeof(target_param_t));
|
||||||
snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
|
snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
|
||||||
target->filename = strdup( targetpath);
|
target->targetname = strdup( targetpath);
|
||||||
target->fd = fd;
|
target->fd = fd;
|
||||||
|
if( tmpfname[0])
|
||||||
|
target->tmpfname = strdup( tmpfname);
|
||||||
|
else
|
||||||
|
target->tmpfname = NULL;
|
||||||
target->csn = last_csn++;
|
target->csn = last_csn++;
|
||||||
target->codeidx = jp2idx;
|
target->codeidx = jp2idx;
|
||||||
target->num_of_use = 0;
|
target->num_of_use = 0;
|
||||||
|
@ -129,15 +136,20 @@ void unrefer_target( target_param_t *target)
|
||||||
void delete_target( target_param_t **target)
|
void delete_target( target_param_t **target)
|
||||||
{
|
{
|
||||||
close( (*target)->fd);
|
close( (*target)->fd);
|
||||||
|
|
||||||
|
if( (*target)->tmpfname){
|
||||||
|
fprintf( FCGI_stderr, "Temporal file %s is deleted\n", (*target)->tmpfname);
|
||||||
|
remove( (*target)->tmpfname);
|
||||||
|
}
|
||||||
|
|
||||||
if( (*target)->codeidx)
|
if( (*target)->codeidx)
|
||||||
delete_index ( &(*target)->codeidx);
|
delete_index ( &(*target)->codeidx);
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
fprintf( logstream, "local log: target: %s deleted\n", (*target)->filename);
|
fprintf( logstream, "local log: target: %s deleted\n", (*target)->targetname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free( (*target)->filename);
|
free( (*target)->targetname);
|
||||||
|
|
||||||
free(*target);
|
free(*target);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +192,7 @@ void print_target( target_param_t *target)
|
||||||
fprintf( logstream, "target:\n");
|
fprintf( logstream, "target:\n");
|
||||||
fprintf( logstream, "\t tid=%s\n", target->tid);
|
fprintf( logstream, "\t tid=%s\n", target->tid);
|
||||||
fprintf( logstream, "\t csn=%d\n", target->csn);
|
fprintf( logstream, "\t csn=%d\n", target->csn);
|
||||||
fprintf( logstream, "\t target=%s\n\n", target->filename);
|
fprintf( logstream, "\t target=%s\n\n", target->targetname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_alltarget( targetlist_param_t *targetlist)
|
void print_alltarget( targetlist_param_t *targetlist)
|
||||||
|
@ -202,7 +214,7 @@ target_param_t * search_target( char targetname[], targetlist_param_t *targetlis
|
||||||
|
|
||||||
while( foundtarget != NULL){
|
while( foundtarget != NULL){
|
||||||
|
|
||||||
if( strcmp( targetname, foundtarget->filename) == 0)
|
if( strcmp( targetname, foundtarget->targetname) == 0)
|
||||||
return foundtarget;
|
return foundtarget;
|
||||||
|
|
||||||
foundtarget = foundtarget->next;
|
foundtarget = foundtarget->next;
|
||||||
|
@ -227,27 +239,52 @@ target_param_t * search_targetBytid( char tid[], targetlist_param_t *targetlist)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_jp2file( char filename[])
|
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream);
|
||||||
|
|
||||||
|
int open_jp2file( char filepath[], char tmpfname[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *data;
|
char *data;
|
||||||
|
CURL *curl_handle;
|
||||||
if( (fd = open( filename, O_RDONLY)) == -1){
|
|
||||||
fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filename);
|
// download remote target file to local storage
|
||||||
return -1;
|
if( strncmp( filepath, "http://", 7) == 0){
|
||||||
|
curl_handle = curl_easy_init();
|
||||||
|
curl_easy_setopt(curl_handle, CURLOPT_URL, filepath);
|
||||||
|
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
|
||||||
|
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
|
||||||
|
snprintf( tmpfname, MAX_LENOFTID, "%x-%x.jp2", (unsigned int)time(NULL), (unsigned int)rand());
|
||||||
|
fprintf( FCGI_stderr, "%s is downloaded to a temporal new file %s\n", filepath, tmpfname);
|
||||||
|
if( (fd = open( tmpfname, O_RDWR|O_CREAT|O_EXCL, S_IRWXU)) == -1){
|
||||||
|
fprintf( FCGI_stdout, "Reason: File open error %s\r\n", tmpfname);
|
||||||
|
curl_easy_cleanup(curl_handle);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &fd);
|
||||||
|
curl_easy_perform(curl_handle);
|
||||||
|
curl_easy_cleanup(curl_handle);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tmpfname[0] = 0;
|
||||||
|
if( (fd = open( filepath, O_RDONLY)) == -1){
|
||||||
|
fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filepath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check resource is a JP family file.
|
// Check resource is a JP family file.
|
||||||
if( lseek( fd, 0, SEEK_SET)==-1){
|
if( lseek( fd, 0, SEEK_SET)==-1){
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filename);
|
fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (char *)malloc( 12); // size of header
|
data = (char *)malloc( 12); // size of header
|
||||||
|
|
||||||
if( read( fd, data, 12) != 12){
|
if( read( fd, data, 12) != 12){
|
||||||
free( data);
|
free( data);
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filename);
|
fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,9 +292,19 @@ int open_jp2file( char filename[])
|
||||||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
|
||||||
free( data);
|
free( data);
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filename);
|
fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( data);
|
free( data);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||||
|
{
|
||||||
|
int *fd = (int *)stream;
|
||||||
|
int written = write( *fd, ptr, size*nmemb);
|
||||||
|
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
|
@ -40,8 +40,9 @@
|
||||||
//! target parameters
|
//! target parameters
|
||||||
typedef struct target_param{
|
typedef struct target_param{
|
||||||
char tid[MAX_LENOFTID]; //!< taregt identifier
|
char tid[MAX_LENOFTID]; //!< taregt identifier
|
||||||
char *filename; //!< file name
|
char *targetname; //!< local file path or URL
|
||||||
int fd; //!< file descriptor
|
int fd; //!< file descriptor
|
||||||
|
char *tmpfname; //!< temporal file name to download a remote target file
|
||||||
int csn; //!< codestream number
|
int csn; //!< codestream number
|
||||||
index_param_t *codeidx; //!< index information of codestream
|
index_param_t *codeidx; //!< index information of codestream
|
||||||
int num_of_use; //!< numbers of sessions refering to this target
|
int num_of_use; //!< numbers of sessions refering to this target
|
||||||
|
@ -134,9 +135,9 @@ void print_alltarget( targetlist_param_t *targetlist);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search a target by filename
|
* search a target by target name
|
||||||
*
|
*
|
||||||
* @param[in] targetname target filename
|
* @param[in] targetname target name
|
||||||
* @param[in] targetlist target list pointer
|
* @param[in] targetlist target list pointer
|
||||||
* @return found target pointer
|
* @return found target pointer
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
* \section reqlibs Required libraries
|
* \section reqlibs Required libraries
|
||||||
* - OpenJPEG library
|
* - OpenJPEG library
|
||||||
* - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
|
* - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
|
||||||
|
* - libcURL library
|
||||||
*
|
*
|
||||||
* We tested this software with a virtual server running on the same Linux machine as the clients.
|
* We tested this software with a virtual server running on the same Linux machine as the clients.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,13 +2,13 @@ JPIPLIBDIR = ../libopenjpip
|
||||||
|
|
||||||
SLIBFNAME = $(JPIPLIBDIR)/libopenjpip_server.a
|
SLIBFNAME = $(JPIPLIBDIR)/libopenjpip_server.a
|
||||||
SCFLAGS = -O3 -Wall -m32 -I$(JPIPLIBDIR) -DSERVER -DQUIT_SIGNAL=\"quitJPIP\"
|
SCFLAGS = -O3 -Wall -m32 -I$(JPIPLIBDIR) -DSERVER -DQUIT_SIGNAL=\"quitJPIP\"
|
||||||
SLDFLAGS = -L$(JPIPLIBDIR) -lm -lfcgi -lopenjpip_server
|
SLDFLAGS = -L$(JPIPLIBDIR) -lm -lfcgi -lcurl -lopenjpip_server
|
||||||
|
|
||||||
J2KINCDIR = ../../../libopenjpeg
|
J2KINCDIR = ../../../libopenjpeg
|
||||||
J2KLIBDIR = $(J2KINCDIR)/.libs
|
J2KLIBDIR = $(J2KINCDIR)/.libs
|
||||||
LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
|
LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
|
||||||
CFLAGS = -O3 -Wall -I$(JPIPLIBDIR)
|
CFLAGS = -O3 -Wall -I$(JPIPLIBDIR)
|
||||||
LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
|
LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lcurl -lopenjpip_local
|
||||||
|
|
||||||
ALL = opj_server opj_dec_server jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
|
ALL = opj_server opj_dec_server jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
|
||||||
|
|
||||||
|
|
|
@ -83,17 +83,19 @@ int main(void)
|
||||||
|
|
||||||
qr = parse_querystring( query_string);
|
qr = parse_querystring( query_string);
|
||||||
|
|
||||||
if( !(parse_status = process_JPIPrequest( server_record, qr)))
|
parse_status = process_JPIPrequest( server_record, qr);
|
||||||
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
|
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
local_log( true, true, parse_status, false, qr, server_record);
|
local_log( true, true, parse_status, false, qr, server_record);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fprintf( FCGI_stdout, "\r\n");
|
fprintf( FCGI_stdout, "\r\n");
|
||||||
|
|
||||||
send_responsedata( qr);
|
if( parse_status)
|
||||||
|
send_responsedata( qr);
|
||||||
|
else
|
||||||
|
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
|
||||||
|
|
||||||
end_QRprocess( server_record, &qr);
|
end_QRprocess( server_record, &qr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue