[asterisk-commits] branch oej/test-this-branch r13625 - /team/oej/test-this-branch/formats/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Mar 19 10:31:51 MST 2006


Author: oej
Date: Sun Mar 19 11:31:49 2006
New Revision: 13625

URL: http://svn.digium.com/view/asterisk?rev=13625&view=rev
Log:
Make IO in format_g722 compatible with other format drivers

Modified:
    team/oej/test-this-branch/formats/format_g722.c

Modified: team/oej/test-this-branch/formats/format_g722.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/formats/format_g722.c?rev=13625&r1=13624&r2=13625&view=diff
==============================================================================
--- team/oej/test-this-branch/formats/format_g722.c (original)
+++ team/oej/test-this-branch/formats/format_g722.c Sun Mar 19 11:31:49 2006
@@ -39,7 +39,7 @@
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE * f; /* Descriptor */
 	struct ast_channel *owner;
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -56,7 +56,7 @@
 static char *desc = "Raw G722 data";
 static char *exts = "g722";
 
-static struct ast_filestream *g722_open(int fd)
+static struct ast_filestream *g722_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -69,7 +69,7 @@
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_G722;
@@ -83,7 +83,7 @@
 	return tmp;
 }
 
-static struct ast_filestream *g722_rewrite(int fd, const char *comment)
+static struct ast_filestream *g722_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -96,7 +96,7 @@
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&g722_lock);
 		ast_update_use_count();
@@ -114,7 +114,7 @@
 	glistcnt--;
 	ast_mutex_unlock(&g722_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -130,7 +130,7 @@
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -153,20 +153,20 @@
 		ast_log(LOG_WARNING, "Asked to write non-G.722 frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
 	return 0;
 }
 
-static int g722_seek(struct ast_filestream *fs, long sample_offset, int whence)
+static int g722_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
 {
 	off_t offset=0,min,cur,max;
 
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = fseeko(fs->f, 0, SEEK_CUR);
+	max = fseeko(fs->f, 0, SEEK_END);
 	if (whence == SEEK_SET)
 		offset = sample_offset;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -178,19 +178,17 @@
 	}
 	/* always protect against seeking past begining. */
 	offset = (offset < min)?min:offset;
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseeko(fs->f, offset, SEEK_SET);
 }
 
 static int g722_trunc(struct ast_filestream *fs)
 {
-	return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
-}
-
-static long g722_tell(struct ast_filestream *fs)
-{
-	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
-	return offset;
+	return ftruncate(fileno(fs->f), fseeko(fs->f,0,SEEK_CUR));
+}
+
+static off_t g722_tell(struct ast_filestream *fs)
+{
+	return fseeko(fs->f, 0, SEEK_CUR);
 }
 
 static char *g722_getcomment(struct ast_filestream *s)



More information about the asterisk-commits mailing list