Bug 5984 - Convert file offsets to 64 bit

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@10579 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2006-02-20 23:35:12 +00:00
parent 67e55d4d67
commit aa20c556f7
17 changed files with 131 additions and 132 deletions

View File

@@ -147,6 +147,9 @@ endif
ASTCFLAGS= ASTCFLAGS=
# Define this to use files larger than 2GB (useful for sound files longer than 37 hours and logfiles)
ASTCFLAGS+=-D_FILE_OFFSET_BITS=64
# Pentium Pro Optimize # Pentium Pro Optimize
#PROC=i686 #PROC=i686

20
file.c
View File

@@ -67,11 +67,11 @@ struct ast_format {
/*! Write a frame to a channel */ /*! Write a frame to a channel */
int (*write)(struct ast_filestream *, struct ast_frame *); int (*write)(struct ast_filestream *, struct ast_frame *);
/*! seek num samples into file, whence(think normal seek) */ /*! seek num samples into file, whence(think normal seek) */
int (*seek)(struct ast_filestream *, long offset, int whence); int (*seek)(struct ast_filestream *, off_t offset, int whence);
/*! trunc file to current position */ /*! trunc file to current position */
int (*trunc)(struct ast_filestream *fs); int (*trunc)(struct ast_filestream *fs);
/*! tell current position */ /*! tell current position */
long (*tell)(struct ast_filestream *fs); off_t (*tell)(struct ast_filestream *fs);
/*! Read the next frame from the filestream (if available) and report when to get next one /*! Read the next frame from the filestream (if available) and report when to get next one
(in samples) */ (in samples) */
struct ast_frame * (*read)(struct ast_filestream *, int *whennext); struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
@@ -106,9 +106,9 @@ int ast_format_register(const char *name, const char *exts, int format,
struct ast_filestream * (*open)(FILE *f), struct ast_filestream * (*open)(FILE *f),
struct ast_filestream * (*rewrite)(FILE *f, const char *comment), struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
int (*write)(struct ast_filestream *, struct ast_frame *), int (*write)(struct ast_filestream *, struct ast_frame *),
int (*seek)(struct ast_filestream *, long sample_offset, int whence), int (*seek)(struct ast_filestream *, off_t sample_offset, int whence),
int (*trunc)(struct ast_filestream *), int (*trunc)(struct ast_filestream *),
long (*tell)(struct ast_filestream *), off_t (*tell)(struct ast_filestream *),
struct ast_frame * (*read)(struct ast_filestream *, int *whennext), struct ast_frame * (*read)(struct ast_filestream *, int *whennext),
void (*close)(struct ast_filestream *), void (*close)(struct ast_filestream *),
char * (*getcomment)(struct ast_filestream *)) char * (*getcomment)(struct ast_filestream *))
@@ -647,7 +647,7 @@ int ast_playstream(struct ast_filestream *s)
return 0; return 0;
} }
int ast_seekstream(struct ast_filestream *fs, long sample_offset, int whence) int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
return fs->fmt->seek(fs, sample_offset, whence); return fs->fmt->seek(fs, sample_offset, whence);
} }
@@ -657,22 +657,22 @@ int ast_truncstream(struct ast_filestream *fs)
return fs->fmt->trunc(fs); return fs->fmt->trunc(fs);
} }
long ast_tellstream(struct ast_filestream *fs) off_t ast_tellstream(struct ast_filestream *fs)
{ {
return fs->fmt->tell(fs); return fs->fmt->tell(fs);
} }
int ast_stream_fastforward(struct ast_filestream *fs, long ms) int ast_stream_fastforward(struct ast_filestream *fs, off_t ms)
{ {
/* I think this is right, 8000 samples per second, 1000 ms a second so 8 /* I think this is right, 8000 samples per second, 1000 ms a second so 8
* samples per ms */ * samples per ms */
long samples = ms * 8; off_t samples = ms * 8;
return ast_seekstream(fs, samples, SEEK_CUR); return ast_seekstream(fs, samples, SEEK_CUR);
} }
int ast_stream_rewind(struct ast_filestream *fs, long ms) int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
{ {
long samples = ms * 8; off_t samples = ms * 8;
samples = samples * -1; samples = samples * -1;
return ast_seekstream(fs, samples, SEEK_CUR); return ast_seekstream(fs, samples, SEEK_CUR);
} }

View File

@@ -107,7 +107,7 @@ static int check_header(FILE *f)
AU_HEADER(header); AU_HEADER(header);
u_int32_t magic; u_int32_t magic;
u_int32_t hdr_size; u_int32_t hdr_size;
u_int32_t data_size; off_t data_size;
u_int32_t encoding; u_int32_t encoding;
u_int32_t sample_rate; u_int32_t sample_rate;
u_int32_t channels; u_int32_t channels;
@@ -141,7 +141,7 @@ static int check_header(FILE *f)
} }
/* Skip to data */ /* Skip to data */
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
data_size = ftell(f) - hdr_size; data_size = ftello(f) - hdr_size;
if (fseek(f, hdr_size, SEEK_SET) == -1 ) { if (fseek(f, hdr_size, SEEK_SET) == -1 ) {
ast_log(LOG_WARNING, "Failed to skip to data: %d\n", hdr_size); ast_log(LOG_WARNING, "Failed to skip to data: %d\n", hdr_size);
return -1; return -1;
@@ -155,9 +155,9 @@ static int update_header(FILE *f)
u_int32_t datalen; u_int32_t datalen;
int bytes; int bytes;
cur = ftell(f); cur = ftello(f);
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
end = ftell(f); end = ftello(f);
/* data starts 24 bytes in */ /* data starts 24 bytes in */
bytes = end - AU_HEADER_SIZE; bytes = end - AU_HEADER_SIZE;
datalen = htoll(bytes); datalen = htoll(bytes);
@@ -315,16 +315,16 @@ static int au_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int au_seek(struct ast_filestream *fs, long sample_offset, int whence) static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t min, max, cur; off_t min, max, cur;
long offset = 0, samples; unsigned long offset = 0, samples;
samples = sample_offset; samples = sample_offset;
min = AU_HEADER_SIZE; min = AU_HEADER_SIZE;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseek(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
if (whence == SEEK_SET) if (whence == SEEK_SET)
offset = samples + min; offset = samples + min;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -341,16 +341,16 @@ static int au_seek(struct ast_filestream *fs, long sample_offset, int whence)
static int au_trunc(struct ast_filestream *fs) static int au_trunc(struct ast_filestream *fs)
{ {
if (ftruncate(fileno(fs->f), ftell(fs->f))) if (ftruncate(fileno(fs->f), ftello(fs->f)))
return -1; return -1;
return update_header(fs->f); return update_header(fs->f);
} }
static long au_tell(struct ast_filestream *fs) static off_t au_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return offset - AU_HEADER_SIZE; return offset - AU_HEADER_SIZE;
} }

View File

@@ -214,7 +214,7 @@ static int g723_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int g723_seek(struct ast_filestream *fs, long sample_offset, int whence) static int g723_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
return -1; return -1;
} }
@@ -222,12 +222,12 @@ static int g723_seek(struct ast_filestream *fs, long sample_offset, int whence)
static int g723_trunc(struct ast_filestream *fs) static int g723_trunc(struct ast_filestream *fs)
{ {
/* Truncate file to current length */ /* Truncate file to current length */
if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0) if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
return -1; return -1;
return 0; return 0;
} }
static long g723_tell(struct ast_filestream *fs) static off_t g723_tell(struct ast_filestream *fs)
{ {
return -1; return -1;
} }

View File

@@ -391,7 +391,7 @@ static char *g726_getcomment(struct ast_filestream *s)
return NULL; return NULL;
} }
static int g726_seek(struct ast_filestream *fs, long sample_offset, int whence) static int g726_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
return -1; return -1;
} }
@@ -401,7 +401,7 @@ static int g726_trunc(struct ast_filestream *fs)
return -1; return -1;
} }
static long g726_tell(struct ast_filestream *fs) static off_t g726_tell(struct ast_filestream *fs)
{ {
return -1; return -1;
} }

View File

@@ -181,14 +181,14 @@ static char *g729_getcomment(struct ast_filestream *s)
return NULL; return NULL;
} }
static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence) static int g729_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
long bytes; long bytes;
off_t min,cur,max,offset=0; off_t min,cur,max,offset=0;
min = 0; min = 0;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
bytes = 20 * (sample_offset / 160); bytes = 20 * (sample_offset / 160);
if (whence == SEEK_SET) if (whence == SEEK_SET)
@@ -202,7 +202,7 @@ static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
} }
/* protect against seeking beyond begining. */ /* protect against seeking beyond begining. */
offset = (offset < min)?min:offset; offset = (offset < min)?min:offset;
if (fseek(fs->f, offset, SEEK_SET) < 0) if (fseeko(fs->f, offset, SEEK_SET) < 0)
return -1; return -1;
return 0; return 0;
} }
@@ -210,15 +210,15 @@ static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
static int g729_trunc(struct ast_filestream *fs) static int g729_trunc(struct ast_filestream *fs)
{ {
/* Truncate file to current length */ /* Truncate file to current length */
if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0) if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
return -1; return -1;
return 0; return 0;
} }
static long g729_tell(struct ast_filestream *fs) static off_t g729_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return (offset/20)*160; return (offset/20)*160;
} }

View File

@@ -195,14 +195,14 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence) static int gsm_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t offset=0,min,cur,max,distance; off_t offset=0,min,cur,max,distance;
min = 0; min = 0;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
/* have to fudge to frame here, so not fully to sample */ /* have to fudge to frame here, so not fully to sample */
distance = (sample_offset/160) * 33; distance = (sample_offset/160) * 33;
if(whence == SEEK_SET) if(whence == SEEK_SET)
@@ -217,23 +217,23 @@ static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence)
offset = (offset > max)?max:offset; offset = (offset > max)?max:offset;
} else if (offset > max) { } else if (offset > max) {
int i; int i;
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
for (i=0; i< (offset - max) / 33; i++) { for (i=0; i< (offset - max) / 33; i++) {
fwrite(gsm_silence, 1, 33, fs->f); fwrite(gsm_silence, 1, 33, fs->f);
} }
} }
return fseek(fs->f, offset, SEEK_SET); return fseeko(fs->f, offset, SEEK_SET);
} }
static int gsm_trunc(struct ast_filestream *fs) static int gsm_trunc(struct ast_filestream *fs)
{ {
return ftruncate(fileno(fs->f), ftell(fs->f)); return ftruncate(fileno(fs->f), ftello(fs->f));
} }
static long gsm_tell(struct ast_filestream *fs) static off_t gsm_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return (offset/33)*160; return (offset/33)*160;
} }

View File

@@ -221,7 +221,7 @@ static char *h263_getcomment(struct ast_filestream *s)
return NULL; return NULL;
} }
static int h263_seek(struct ast_filestream *fs, long sample_offset, int whence) static int h263_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
/* No way Jose */ /* No way Jose */
return -1; return -1;
@@ -230,16 +230,16 @@ static int h263_seek(struct ast_filestream *fs, long sample_offset, int whence)
static int h263_trunc(struct ast_filestream *fs) static int h263_trunc(struct ast_filestream *fs)
{ {
/* Truncate file to current length */ /* Truncate file to current length */
if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0) if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
return -1; return -1;
return 0; return 0;
} }
static long h263_tell(struct ast_filestream *fs) static off_t h263_tell(struct ast_filestream *fs)
{ {
/* XXX This is totally bogus XXX */ /* XXX This is totally bogus XXX */
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return (offset/20)*160; return (offset/20)*160;
} }

View File

@@ -180,14 +180,14 @@ static char *ilbc_getcomment(struct ast_filestream *s)
return NULL; return NULL;
} }
static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence) static int ilbc_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
long bytes; long bytes;
off_t min,cur,max,offset=0; off_t min,cur,max,offset=0;
min = 0; min = 0;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
bytes = 50 * (sample_offset / 240); bytes = 50 * (sample_offset / 240);
if (whence == SEEK_SET) if (whence == SEEK_SET)
@@ -201,7 +201,7 @@ static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
} }
/* protect against seeking beyond begining. */ /* protect against seeking beyond begining. */
offset = (offset < min)?min:offset; offset = (offset < min)?min:offset;
if (fseek(fs->f, offset, SEEK_SET) < 0) if (fseeko(fs->f, offset, SEEK_SET) < 0)
return -1; return -1;
return 0; return 0;
} }
@@ -209,15 +209,15 @@ static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
static int ilbc_trunc(struct ast_filestream *fs) static int ilbc_trunc(struct ast_filestream *fs)
{ {
/* Truncate file to current length */ /* Truncate file to current length */
if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0) if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
return -1; return -1;
return 0; return 0;
} }
static long ilbc_tell(struct ast_filestream *fs) static off_t ilbc_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return (offset/50)*240; return (offset/50)*240;
} }

View File

@@ -626,14 +626,12 @@ static int ogg_vorbis_trunc(struct ast_filestream *s)
* \return 0 on success, -1 on failure. * \return 0 on success, -1 on failure.
*/ */
static int ogg_vorbis_seek(struct ast_filestream *s, long sample_offset, static int ogg_vorbis_seek(struct ast_filestream *s, off_t sample_offset, int whence) {
int whence)
{
ast_log(LOG_WARNING, "Seeking is not supported on OGG/Vorbis streams!\n"); ast_log(LOG_WARNING, "Seeking is not supported on OGG/Vorbis streams!\n");
return -1; return -1;
} }
static long ogg_vorbis_tell(struct ast_filestream *s) static off_t ogg_vorbis_tell(struct ast_filestream *s)
{ {
ast_log(LOG_WARNING, "Telling is not supported on OGG/Vorbis streams!\n"); ast_log(LOG_WARNING, "Telling is not supported on OGG/Vorbis streams!\n");
return -1; return -1;

View File

@@ -174,14 +174,14 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence) static int pcm_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
long cur, max, offset = 0; off_t cur, max, offset = 0;
int ret = -1; /* assume error */ int ret = -1; /* assume error */
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
@@ -218,20 +218,20 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max); ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max);
offset = max; offset = max;
} }
ret = fseek(fs->f, offset, SEEK_SET); ret = fseeko(fs->f, offset, SEEK_SET);
} }
return ret; return ret;
} }
static int pcm_trunc(struct ast_filestream *fs) static int pcm_trunc(struct ast_filestream *fs)
{ {
return ftruncate(fileno(fs->f), ftell(fs->f)); return ftruncate(fileno(fs->f), ftello(fs->f));
} }
static long pcm_tell(struct ast_filestream *fs) static off_t pcm_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return offset; return offset;
} }

View File

@@ -220,7 +220,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
unsigned long cur, to_write; unsigned long cur, to_write;
cur = stat_buf.st_size; cur = stat_buf.st_size;
if (fseek(fs->f, cur, SEEK_SET) < 0) { if (fseeko(fs->f, cur, SEEK_SET) < 0) {
ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) ); ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
return -1; return -1;
} }
@@ -236,7 +236,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
} }
if (fseek(s->f, fpos, SEEK_SET) < 0) { if (fseeko(s->f, fpos, SEEK_SET) < 0) {
ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) ); ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
return -1; return -1;
} }
@@ -249,14 +249,14 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence) static int pcm_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
long cur, max, offset = 0; off_t cur, max, offset = 0;
int ret = -1; /* assume error */ int ret = -1; /* assume error */
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
@@ -290,24 +290,24 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
} }
ret = 0; /* success */ ret = 0; /* success */
} else { } else {
if (offset > max) { if (offset > max) {
ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max); ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max);
offset = max; offset = max;
} }
ret = fseek(fs->f, offset, SEEK_SET); ret = fseeko(fs->f, offset, SEEK_SET);
} }
return ret; return ret;
} }
static int pcm_trunc(struct ast_filestream *fs) static int pcm_trunc(struct ast_filestream *fs)
{ {
return ftruncate(fileno(fs->f), ftell(fs->f)); return ftruncate(fileno(fs->f), ftello(fs->f));
} }
static long pcm_tell(struct ast_filestream *fs) static off_t pcm_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return offset; return offset;
} }

View File

@@ -169,15 +169,15 @@ static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int slinear_seek(struct ast_filestream *fs, long sample_offset, int whence) static int slinear_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t offset=0,min,cur,max; off_t offset=0,min,cur,max;
min = 0; min = 0;
sample_offset <<= 1; sample_offset <<= 1;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
if (whence == SEEK_SET) if (whence == SEEK_SET)
offset = sample_offset; offset = sample_offset;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -189,18 +189,18 @@ static int slinear_seek(struct ast_filestream *fs, long sample_offset, int whenc
} }
/* always protect against seeking past begining. */ /* always protect against seeking past begining. */
offset = (offset < min)?min:offset; offset = (offset < min)?min:offset;
return fseek(fs->f, offset, SEEK_SET); return fseeko(fs->f, offset, SEEK_SET);
} }
static int slinear_trunc(struct ast_filestream *fs) static int slinear_trunc(struct ast_filestream *fs)
{ {
return ftruncate(fileno(fs->f), ftell(fs->f)); return ftruncate(fileno(fs->f), ftello(fs->f));
} }
static long slinear_tell(struct ast_filestream *fs) static off_t slinear_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
return offset / 2; return offset / 2;
} }

View File

@@ -178,14 +178,14 @@ static char *vox_getcomment(struct ast_filestream *s)
return NULL; return NULL;
} }
static int vox_seek(struct ast_filestream *fs, long sample_offset, int whence) static int vox_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t offset=0,min,cur,max,distance; off_t offset=0,min,cur,max,distance;
min = 0; min = 0;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
/* have to fudge to frame here, so not fully to sample */ /* have to fudge to frame here, so not fully to sample */
distance = sample_offset/2; distance = sample_offset/2;
@@ -199,19 +199,19 @@ static int vox_seek(struct ast_filestream *fs, long sample_offset, int whence)
offset = (offset > max)?max:offset; offset = (offset > max)?max:offset;
offset = (offset < min)?min:offset; offset = (offset < min)?min:offset;
} }
fseek(fs->f, offset, SEEK_SET); fseeko(fs->f, offset, SEEK_SET);
return ftell(fs->f); return ftello(fs->f);
} }
static int vox_trunc(struct ast_filestream *fs) static int vox_trunc(struct ast_filestream *fs)
{ {
return ftruncate(fileno(fs->f), ftell(fs->f)); return ftruncate(fileno(fs->f), ftello(fs->f));
} }
static long vox_tell(struct ast_filestream *fs) static off_t vox_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f) << 1; offset = ftello(fs->f) << 1;
return offset; return offset;
} }

View File

@@ -234,9 +234,9 @@ static int update_header(FILE *f)
int datalen,filelen,bytes; int datalen,filelen,bytes;
cur = ftell(f); cur = ftello(f);
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
end = ftell(f); end = ftello(f);
/* data starts 44 bytes in */ /* data starts 44 bytes in */
bytes = end - 44; bytes = end - 44;
datalen = htoll(bytes); datalen = htoll(bytes);
@@ -263,7 +263,7 @@ static int update_header(FILE *f)
ast_log(LOG_WARNING, "Unable to set write datalen\n"); ast_log(LOG_WARNING, "Unable to set write datalen\n");
return -1; return -1;
} }
if (fseek(f, cur, SEEK_SET)) { if (fseeko(f, cur, SEEK_SET)) {
ast_log(LOG_WARNING, "Unable to return to position\n"); ast_log(LOG_WARNING, "Unable to return to position\n");
return -1; return -1;
} }
@@ -419,7 +419,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
int bytes = sizeof(tmp); int bytes = sizeof(tmp);
off_t here; off_t here;
/* Send a frame from the file to the appropriate channel */ /* Send a frame from the file to the appropriate channel */
here = ftell(s->f); here = ftello(s->f);
if ((s->maxlen - here) < bytes) if ((s->maxlen - here) < bytes)
bytes = s->maxlen - here; bytes = s->maxlen - here;
if (bytes < 0) if (bytes < 0)
@@ -522,16 +522,15 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
} }
static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence) static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t min,max,cur; off_t min, max, cur, offset = 0, samples;
long offset=0,samples;
samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */ samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */
min = 44; /* wav header is 44 bytes */ min = 44; /* wav header is 44 bytes */
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseeko(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
if (whence == SEEK_SET) if (whence == SEEK_SET)
offset = samples + min; offset = samples + min;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -543,20 +542,20 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
} }
/* always protect the header space. */ /* always protect the header space. */
offset = (offset < min)?min:offset; offset = (offset < min)?min:offset;
return fseek(fs->f,offset,SEEK_SET); return fseeko(fs->f, offset, SEEK_SET);
} }
static int wav_trunc(struct ast_filestream *fs) static int wav_trunc(struct ast_filestream *fs)
{ {
if (ftruncate(fileno(fs->f), ftell(fs->f))) if (ftruncate(fileno(fs->f), ftello(fs->f)))
return -1; return -1;
return update_header(fs->f); return update_header(fs->f);
} }
static long wav_tell(struct ast_filestream *fs) static off_t wav_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
/* subtract header size to get samples, then divide by 2 for 16 bit samples */ /* subtract header size to get samples, then divide by 2 for 16 bit samples */
return (offset - 44)/2; return (offset - 44)/2;
} }

View File

@@ -232,9 +232,9 @@ static int update_header(FILE *f)
off_t cur,end,bytes; off_t cur,end,bytes;
int datalen,filelen; int datalen,filelen;
cur = ftell(f); cur = ftello(f);
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
end = ftell(f); end = ftello(f);
/* in a gsm WAV, data starts 60 bytes in */ /* in a gsm WAV, data starts 60 bytes in */
bytes = end - 60; bytes = end - 60;
datalen = htoll((bytes + 1) & ~0x1); datalen = htoll((bytes + 1) & ~0x1);
@@ -259,7 +259,7 @@ static int update_header(FILE *f)
ast_log(LOG_WARNING, "Unable to set write datalen\n"); ast_log(LOG_WARNING, "Unable to set write datalen\n");
return -1; return -1;
} }
if (fseek(f, cur, SEEK_SET)) { if (fseeko(f, cur, SEEK_SET)) {
ast_log(LOG_WARNING, "Unable to return to position\n"); ast_log(LOG_WARNING, "Unable to return to position\n");
return -1; return -1;
} }
@@ -417,7 +417,7 @@ static void wav_close(struct ast_filestream *s)
ast_update_use_count(); ast_update_use_count();
/* Pad to even length */ /* Pad to even length */
fseek(s->f, 0, SEEK_END); fseek(s->f, 0, SEEK_END);
if (ftell(s->f) & 0x1) if (ftello(s->f) & 0x1)
fwrite(&zero, 1, 1, s->f); fwrite(&zero, 1, 1, s->f);
fclose(s->f); fclose(s->f);
free(s); free(s);
@@ -499,13 +499,13 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
return 0; return 0;
} }
static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence) static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{ {
off_t offset=0,distance,cur,min,max; off_t offset=0,distance,cur,min,max;
min = 60; min = 60;
cur = ftell(fs->f); cur = ftello(fs->f);
fseek(fs->f, 0, SEEK_END); fseek(fs->f, 0, SEEK_END);
max = ftell(fs->f); max = ftello(fs->f);
/* I'm getting sloppy here, I'm only going to go to even splits of the 2 /* I'm getting sloppy here, I'm only going to go to even splits of the 2
* frames, if you want tighter cuts use format_gsm, format_pcm, or format_wav */ * frames, if you want tighter cuts use format_gsm, format_pcm, or format_wav */
distance = (sample_offset/320) * 65; distance = (sample_offset/320) * 65;
@@ -527,20 +527,20 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
} }
} }
fs->secondhalf = 0; fs->secondhalf = 0;
return fseek(fs->f, offset, SEEK_SET); return fseeko(fs->f, offset, SEEK_SET);
} }
static int wav_trunc(struct ast_filestream *fs) static int wav_trunc(struct ast_filestream *fs)
{ {
if (ftruncate(fileno(fs->f), ftell(fs->f))) if (ftruncate(fileno(fs->f), ftello(fs->f)))
return -1; return -1;
return update_header(fs->f); return update_header(fs->f);
} }
static long wav_tell(struct ast_filestream *fs) static off_t wav_tell(struct ast_filestream *fs)
{ {
off_t offset; off_t offset;
offset = ftell(fs->f); offset = ftello(fs->f);
/* since this will most likely be used later in play or record, lets stick /* since this will most likely be used later in play or record, lets stick
* to that level of resolution, just even frames boundaries */ * to that level of resolution, just even frames boundaries */
return (offset - 52)/65*320; return (offset - 52)/65*320;

View File

@@ -31,7 +31,6 @@
#include "asterisk/frame.h" #include "asterisk/frame.h"
#include <fcntl.h> #include <fcntl.h>
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
extern "C" { extern "C" {
#endif #endif
@@ -56,9 +55,9 @@ int ast_format_register(const char *name, const char *exts, int format,
struct ast_filestream * (*open)(FILE *f), struct ast_filestream * (*open)(FILE *f),
struct ast_filestream * (*rewrite)(FILE *f, const char *comment), struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
int (*write)(struct ast_filestream *, struct ast_frame *), int (*write)(struct ast_filestream *, struct ast_frame *),
int (*seek)(struct ast_filestream *, long offset, int whence), int (*seek)(struct ast_filestream *, off_t offset, int whence),
int (*trunc)(struct ast_filestream *), int (*trunc)(struct ast_filestream *),
long (*tell)(struct ast_filestream *), off_t (*tell)(struct ast_filestream *),
struct ast_frame * (*read)(struct ast_filestream *, int *timetonext), struct ast_frame * (*read)(struct ast_filestream *, int *timetonext),
void (*close)(struct ast_filestream *), void (*close)(struct ast_filestream *),
char * (*getcomment)(struct ast_filestream *)); char * (*getcomment)(struct ast_filestream *));
@@ -262,7 +261,7 @@ int ast_playstream(struct ast_filestream *s);
* \param whence SEEK_SET, SEEK_CUR, SEEK_END * \param whence SEEK_SET, SEEK_CUR, SEEK_END
* Returns 0 for success, or -1 for error * Returns 0 for success, or -1 for error
*/ */
int ast_seekstream(struct ast_filestream *fs, long sample_offset, int whence); int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence);
/*! Trunc stream at current location */ /*! Trunc stream at current location */
/*! /*!
@@ -277,7 +276,7 @@ int ast_truncstream(struct ast_filestream *fs);
* \param ms milliseconds to move * \param ms milliseconds to move
* Returns 0 for success, or -1 for error * Returns 0 for success, or -1 for error
*/ */
int ast_stream_fastforward(struct ast_filestream *fs, long ms); int ast_stream_fastforward(struct ast_filestream *fs, off_t ms);
/*! Rewind stream ms */ /*! Rewind stream ms */
/*! /*!
@@ -285,14 +284,14 @@ int ast_stream_fastforward(struct ast_filestream *fs, long ms);
* \param ms milliseconds to move * \param ms milliseconds to move
* Returns 0 for success, or -1 for error * Returns 0 for success, or -1 for error
*/ */
int ast_stream_rewind(struct ast_filestream *fs, long ms); int ast_stream_rewind(struct ast_filestream *fs, off_t ms);
/*! Tell where we are in a stream */ /*! Tell where we are in a stream */
/*! /*!
* \param fs fs to act on * \param fs fs to act on
* Returns a long as a sample offset into stream * Returns a long as a sample offset into stream
*/ */
long ast_tellstream(struct ast_filestream *fs); off_t ast_tellstream(struct ast_filestream *fs);
/*! Read a frame from a filestream */ /*! Read a frame from a filestream */
/*! /*!