[svn-commits] tzafrir: branch tzafrir/monitor-rtp r214062 - /team/tzafrir/monitor-rtp/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 25 13:41:17 CDT 2009


Author: tzafrir
Date: Tue Aug 25 13:41:14 2009
New Revision: 214062

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214062
Log:
ast_writefd: write formatted data to a FD

Add a new internal function, ast_writefd() to file.c . Like
ast_writefile() it writes frames to a file considering their format.
Unlike ast_writefile() it uses an existing file descriptor provided by
the caller.

This is intended to allow the caller e.g. opening a socket and handing
over the resulting file descriptor to the Asterisk core.

Modified:
    team/tzafrir/monitor-rtp/main/file.c

Modified: team/tzafrir/monitor-rtp/main/file.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp/main/file.c?view=diff&rev=214062&r1=214061&r2=214062
==============================================================================
--- team/tzafrir/monitor-rtp/main/file.c (original)
+++ team/tzafrir/monitor-rtp/main/file.c Tue Aug 25 13:41:14 2009
@@ -1008,6 +1008,47 @@
 		ast_log(LOG_WARNING, "No such format '%s'\n", type);
 
 	return fs;
+}
+
+static struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type)
+{
+	struct ast_filestream *fs = NULL;
+	FILE *bfile = NULL;
+	struct ast_format *f;
+
+	ast_log(LOG_NOTICE, "%s: fd=%d type=%s\n", __FUNCTION__, fd, type);
+	if (AST_RWLIST_RDLOCK(&formats)) {
+		ast_log(LOG_WARNING, "Unable to lock format list\n");
+		return NULL;
+	}
+	AST_LIST_TRAVERSE(&formats, f, list) {
+		if (!exts_compare(f->exts, type))
+			continue;
+		bfile = fdopen(fd, "w");
+		if (!bfile) {
+			ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
+		}
+		errno = 0;
+		ast_log(LOG_NOTICE, "%s: calling get_filestream()\n", __FUNCTION__);
+		fs = get_filestream(f, bfile);
+		if (!fs) {
+			ast_log(LOG_WARNING, "get_filestream failed\n");
+			continue;
+		}
+		fs->trans = NULL;
+		fs->fmt = f;
+		fs->flags = 0;
+		fs->mode = 0;
+		fs->realfilename = NULL;
+		fs->filename = stateinfo;
+		fs->vfs = NULL;
+	}
+	AST_RWLIST_UNLOCK(&formats);
+	if (!fs)
+		ast_log(LOG_WARNING, "No such format '%s'\n", type);
+	ast_log(LOG_NOTICE, "%s: returning\n", __FUNCTION__);
+	return fs;
+
 }
 
 struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)




More information about the svn-commits mailing list