[trunk] continue work on getting API to use off_t instead of long toward LFS support in JPIP

This commit is contained in:
Mathieu Malaterre 2012-03-26 12:31:27 +00:00
parent 1cf1d6146c
commit 0a97782339
4 changed files with 75 additions and 58 deletions

View File

@ -32,6 +32,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include "box_manager.h"
#include "opj_inttypes.h"
@ -56,32 +57,35 @@ boxlist_param_t * gene_boxlist(void)
return boxlist;
}
boxlist_param_t * get_boxstructure( int fd, Byte8_t offset, Byte8_t length)
boxlist_param_t * get_boxstructure( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length)
{
boxlist_param_t *boxlist;
box_param_t *box;
int pos;
OPJ_OFF_T pos;
boxlist = NULL;
pos = offset;
assert( (OPJ_OFF_T)length>=0);
do{
if(!(box = gene_boxbyOffset( fd, pos)))
break;
pos += box->length;
assert( (OPJ_OFF_T)box->length >= 0);
pos += (OPJ_OFF_T)box->length;
if( !boxlist)
boxlist = gene_boxlist();
insert_box_into_list( box, boxlist);
}while( pos < (int)(offset+length));
}while( pos < offset+(OPJ_OFF_T)length);
return boxlist;
}
box_param_t * gene_boxbyOffset( int fd, Byte8_t offset)
box_param_t * gene_boxbyOffset( int fd, OPJ_OFF_T offset)
{
Byte_t *data;
Byte8_t boxlen, headlen;
Byte8_t boxlen;
Byte_t headlen;
char *boxtype;
box_param_t *box;
@ -128,9 +132,10 @@ box_param_t * gene_boxbyOffset( int fd, Byte8_t offset)
return box;
}
box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset)
box_param_t * gene_boxbyOffinStream( Byte_t *stream, OPJ_OFF_T offset)
{
Byte8_t boxlen, headlen;
Byte8_t boxlen;
Byte_t headlen;
char *boxtype;
box_param_t *box;
@ -162,22 +167,28 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset)
}
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[])
box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[])
{
Byte8_t pos;
OPJ_OFF_T pos;
Byte_t *data;
Byte8_t boxlen, headlen;
Byte8_t boxlen;
Byte_t headlen;
char *boxtype;
box_param_t *foundbox;
if( length==0){ /* set the max length*/
if( (length = get_filesize( fd) - offset) <= 0)
if( get_filesize( fd) <= offset )
return NULL;
assert( get_filesize( fd) > offset );
assert( offset >= 0 );
length = (OPJ_SIZE_T)(get_filesize( fd) - offset);
}
pos = offset;
while( pos < offset+length-7){ /* LBox+TBox-1=7*/
assert( pos >= 0 );
assert( (OPJ_OFF_T)length >= 0 );
while( pos < offset+(OPJ_OFF_T)length-7){ /* LBox+TBox-1=7*/
/* read LBox and TBox*/
if((data = fetch_bytes( fd, pos, 8))){
@ -215,29 +226,27 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char
fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
return NULL;
}
pos+= boxlen;
assert( ((Byte8_t)pos+boxlen)>=(Byte8_t)pos);
pos+= (OPJ_OFF_T)boxlen;
}
fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);
return NULL;
}
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[])
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[])
{
Byte8_t pos;
OPJ_OFF_T pos;
Byte_t *data;
Byte8_t boxlen, headlen;
Byte8_t boxlen;
Byte_t headlen;
char *boxtype;
box_param_t *foundbox;
if( length<=0){ /* set the max length*/
fprintf( FCGI_stderr, "func gene_boxbyTypeinStream(), max length must be more than 0\n");
return NULL;
}
pos = offset;
while( pos < offset+length-7){ /* LBox+TBox-1=7*/
assert( pos >= 0 );
assert( (OPJ_OFF_T)length >= 0 );
while( pos < offset+(OPJ_OFF_T)(length)-7){ /* LBox+TBox-1=7*/
/* read LBox and TBox*/
data = stream + pos;
@ -261,31 +270,39 @@ box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t le
foundbox->next = NULL;
return foundbox;
}
pos+= boxlen;
assert( ((Byte8_t)pos+boxlen)>=(Byte8_t)pos);
pos+= (OPJ_OFF_T)boxlen;
}
fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);
return NULL;
}
box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset)
box_param_t * gene_childboxbyOffset( box_param_t *superbox, OPJ_OFF_T offset)
{
return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset);
}
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[])
box_param_t * gene_childboxbyType( box_param_t *superbox, OPJ_OFF_T offset, const char TBox[])
{
return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, get_DBoxlen( superbox)-offset, TBox);
OPJ_SIZE_T DBOXlen = get_DBoxlen(superbox);
assert( offset >= 0 );
if( DBOXlen < (OPJ_SIZE_T)offset )
{
fprintf( FCGI_stderr, "Error: Impossible happen %lu < %ld\n", DBOXlen, offset);
return NULL;
}
return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, DBOXlen-(OPJ_SIZE_T)offset, TBox);
}
Byte8_t get_DBoxoff( box_param_t *box)
OPJ_OFF_T get_DBoxoff( box_param_t *box)
{
return box->offset+box->headlen;
}
Byte8_t get_DBoxlen( box_param_t *box)
OPJ_SIZE_T get_DBoxlen( box_param_t *box)
{
return box->length-box->headlen;
return box->length - box->headlen;
}
Byte_t * fetch_headbytes( box_param_t *box)
@ -293,27 +310,27 @@ Byte_t * fetch_headbytes( box_param_t *box)
return fetch_bytes( box->fd, box->offset, box->headlen);
}
Byte_t * fetch_DBoxbytes( box_param_t *box, long offset, int size)
Byte_t * fetch_DBoxbytes( box_param_t *box, OPJ_OFF_T offset, OPJ_SIZE_T size)
{
return fetch_bytes( box->fd, get_DBoxoff( box)+offset, size);
}
Byte_t fetch_DBox1byte( box_param_t *box, long offset)
Byte_t fetch_DBox1byte( box_param_t *box, OPJ_OFF_T offset)
{
return fetch_1byte( box->fd, get_DBoxoff( box)+offset);
}
Byte2_t fetch_DBox2bytebigendian( box_param_t *box, long offset)
Byte2_t fetch_DBox2bytebigendian( box_param_t *box, OPJ_OFF_T offset)
{
return fetch_2bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
Byte4_t fetch_DBox4bytebigendian( box_param_t *box, long offset)
Byte4_t fetch_DBox4bytebigendian( box_param_t *box, OPJ_OFF_T offset)
{
return fetch_4bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset)
Byte8_t fetch_DBox8bytebigendian( box_param_t *box, OPJ_OFF_T offset)
{
return fetch_8bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
@ -383,7 +400,7 @@ void delete_box_in_list( box_param_t **box, boxlist_param_t *boxlist)
free( *box);
}
void delete_box_in_list_by_type( char type[], boxlist_param_t *boxlist)
void delete_box_in_list_by_type( const char type[], boxlist_param_t *boxlist)
{
box_param_t *box;

View File

@ -36,7 +36,7 @@
/** box parameters*/
typedef struct box_param{
int fd; /**< file descriptor*/
Byte8_t offset; /**< byte position of the whole Box (LBox) in the file*/
OPJ_OFF_T offset; /**< byte position of the whole Box (LBox) in the file*/
Byte_t headlen; /**< header length 8 or 16*/
Byte8_t length; /**< length of the whole Box*/
char type[4]; /**< type of information in the DBox*/
@ -66,7 +66,7 @@ boxlist_param_t * gene_boxlist(void);
* @param[in] length length of the decomposing region
* @return pointer to the generated boxlist
*/
boxlist_param_t * get_boxstructure( int fd, Byte8_t offset, Byte8_t length);
boxlist_param_t * get_boxstructure( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length);
/**
@ -76,7 +76,7 @@ boxlist_param_t * get_boxstructure( int fd, Byte8_t offset, Byte8_t length);
* @param[in] offset Box offset
* @return pointer to the structure of generate box parameters
*/
box_param_t * gene_boxbyOffset( int fd, Byte8_t offset);
box_param_t * gene_boxbyOffset( int fd, OPJ_OFF_T offset);
/**
@ -86,7 +86,7 @@ box_param_t * gene_boxbyOffset( int fd, Byte8_t offset);
* @param[in] offset Box offset of the whole stream
* @return pointer to the structure of generate box parameters
*/
box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset);
box_param_t * gene_boxbyOffinStream( Byte_t *stream, OPJ_OFF_T offset);
/**
* generate(search) box from JP2 file
@ -97,7 +97,7 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset);
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[]);
box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[]);
/**
* generate(search) box from code stream
@ -108,7 +108,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[]);
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[]);
/**
* generate child box from JP2 file at the given offset
@ -117,7 +117,7 @@ box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t le
* @param[in] offset offset from DBox first byte of superbox
* @return pointer to the structure of generate box parameters
*/
box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset);
box_param_t * gene_childboxbyOffset( box_param_t *superbox, OPJ_OFF_T offset);
/**
* generate(search) box from JP2 file
@ -127,7 +127,7 @@ box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset);
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[]);
box_param_t * gene_childboxbyType( box_param_t *superbox, OPJ_OFF_T offset, const char TBox[]);
/**
* get DBox offset
@ -135,7 +135,7 @@ box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const
* @param[in] box box pointer
* @return DBox offset (byte position) in the file
*/
Byte8_t get_DBoxoff( box_param_t *box);
OPJ_OFF_T get_DBoxoff( box_param_t *box);
/**
@ -144,7 +144,7 @@ Byte8_t get_DBoxoff( box_param_t *box);
* @param[in] box box pointer
* @return DBox length ( content length)
*/
Byte8_t get_DBoxlen( box_param_t *box);
OPJ_SIZE_T get_DBoxlen( box_param_t *box);
/**
@ -164,7 +164,7 @@ Byte_t * fetch_headbytes( box_param_t *box);
* @param[in] size Byte length
* @return pointer to the fetched data
*/
Byte_t * fetch_DBoxbytes( box_param_t *box, long offset, int size);
Byte_t * fetch_DBoxbytes( box_param_t *box, OPJ_OFF_T offset, OPJ_SIZE_T size);
/**
* fetch DBox (Box Contents) 1-byte Byte codes in file stream
@ -173,7 +173,7 @@ Byte_t * fetch_DBoxbytes( box_param_t *box, long offset, int size);
* @param[in] offset start Byte position in DBox
* @return fetched code
*/
Byte_t fetch_DBox1byte( box_param_t *box, long offset);
Byte_t fetch_DBox1byte( box_param_t *box, OPJ_OFF_T offset);
/**
* fetch DBox (Box Contents) 2-byte big endian Byte codes in file stream
@ -182,7 +182,7 @@ Byte_t fetch_DBox1byte( box_param_t *box, long offset);
* @param[in] offset start Byte position in DBox
* @return fetched code
*/
Byte2_t fetch_DBox2bytebigendian( box_param_t *box, long offset);
Byte2_t fetch_DBox2bytebigendian( box_param_t *box, OPJ_OFF_T offset);
/**
* fetch DBox (Box Contents) 4-byte big endian Byte codes in file stream
@ -191,7 +191,7 @@ Byte2_t fetch_DBox2bytebigendian( box_param_t *box, long offset);
* @param[in] offset start Byte position in DBox
* @return fetched code
*/
Byte4_t fetch_DBox4bytebigendian( box_param_t *box, long offset);
Byte4_t fetch_DBox4bytebigendian( box_param_t *box, OPJ_OFF_T offset);
/**
* fetch DBox (Box Contents) 8-byte big endian Byte codes in file stream
@ -200,7 +200,7 @@ Byte4_t fetch_DBox4bytebigendian( box_param_t *box, long offset);
* @param[in] offset start Byte position in DBox
* @return fetched code
*/
Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset);
Byte8_t fetch_DBox8bytebigendian( box_param_t *box, OPJ_OFF_T offset);
/**
@ -242,7 +242,7 @@ void delete_box_in_list( box_param_t **box, boxlist_param_t *boxlist);
* @param[in,out] type box type
* @param[in] boxlist box list pointer
*/
void delete_box_in_list_by_type( char type[], boxlist_param_t *boxlist);
void delete_box_in_list_by_type( const char type[], boxlist_param_t *boxlist);
/**

View File

@ -45,7 +45,7 @@
#endif /*SERVER*/
boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
boxheader_param_t * gene_boxheader( int fd, OPJ_OFF_T offset)
{
Byte8_t boxlen;
Byte_t headlen;
@ -71,9 +71,9 @@ boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
return boxheader;
}
boxheader_param_t * gene_childboxheader( box_param_t *superbox, Byte8_t offset)
boxheader_param_t * gene_childboxheader( box_param_t *superbox, OPJ_OFF_T offset)
{
return gene_boxheader( superbox->fd, get_DBoxoff( superbox)+offset);
return gene_boxheader( superbox->fd, get_DBoxoff(superbox)+offset);
}
void print_boxheader( boxheader_param_t *boxheader)

View File

@ -50,7 +50,7 @@ typedef struct boxheader_param{
* @param[in] offset Box offset
* @return pointer to the structure of generate box header parameters
*/
boxheader_param_t * gene_boxheader( int fd, Byte8_t offset);
boxheader_param_t * gene_boxheader( int fd, OPJ_OFF_T offset);
/**
* generate a child box header at the given offset
@ -59,7 +59,7 @@ boxheader_param_t * gene_boxheader( int fd, Byte8_t offset);
* @param[in] offset offset from DBox first byte of superbox
* @return pointer to the structure of generate box header parameters
*/
boxheader_param_t * gene_childboxheader( box_param_t *superbox, Byte8_t offset);
boxheader_param_t * gene_childboxheader( box_param_t *superbox, OPJ_OFF_T offset);
/**
* print box header parameters