[svn-commits] file: branch group/media_formats r407424 - in /team/group/media_formats: apps...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 5 11:36:44 CST 2014


Author: file
Date: Wed Feb  5 11:36:36 2014
New Revision: 407424

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407424
Log:
Knock out almost all applications.

Modified:
    team/group/media_formats/apps/app_amd.c
    team/group/media_formats/apps/app_chanspy.c
    team/group/media_formats/apps/app_dahdibarge.c
    team/group/media_formats/apps/app_dictate.c
    team/group/media_formats/apps/app_festival.c
    team/group/media_formats/apps/app_ices.c
    team/group/media_formats/apps/app_mixmonitor.c
    team/group/media_formats/apps/app_mp3.c
    team/group/media_formats/apps/app_nbscat.c
    team/group/media_formats/apps/app_originate.c
    team/group/media_formats/apps/app_record.c
    team/group/media_formats/apps/app_sms.c
    team/group/media_formats/apps/app_speech_utils.c
    team/group/media_formats/apps/app_talkdetect.c
    team/group/media_formats/apps/app_test.c
    team/group/media_formats/apps/app_voicemail.c
    team/group/media_formats/apps/app_waitforsilence.c
    team/group/media_formats/include/asterisk/format_cache.h
    team/group/media_formats/include/asterisk/mod_format.h
    team/group/media_formats/include/asterisk/rtp_engine.h
    team/group/media_formats/main/format_cache.c

Modified: team/group/media_formats/apps/app_amd.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_amd.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_amd.c (original)
+++ team/group/media_formats/apps/app_amd.c Wed Feb  5 11:36:36 2014
@@ -164,7 +164,7 @@
 	struct ast_frame *f = NULL;
 	struct ast_dsp *silenceDetector = NULL;
 	int dspsilence = 0, framelength = 0;
-	struct ast_format *readFormat;
+	RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);
 	int inInitialSilence = 1;
 	int inGreeting = 0;
 	int voiceDuration = 0;
@@ -414,7 +414,6 @@
 	/* Restore channel read format */
 	if (readFormat && ast_set_read_format(chan, readFormat))
 		ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", ast_channel_name(chan));
-	ao2_cleanup(readFormat);
 
 	/* Free the DSP used to detect silence */
 	ast_dsp_free(silenceDetector);

Modified: team/group/media_formats/apps/app_chanspy.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_chanspy.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_chanspy.c (original)
+++ team/group/media_formats/apps/app_chanspy.c Wed Feb  5 11:36:36 2014
@@ -1120,7 +1120,7 @@
 		.volume = '#',
 		.exit = '\0',
 	};
-	struct ast_format *oldwf;
+	RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
 	int volfactor = 0;
 	int res;
 	char *mailbox = NULL;
@@ -1219,7 +1219,6 @@
 
 	if (oldwf && ast_set_write_format(chan, oldwf) < 0)
 		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
-	ao2_cleanup(oldwf);
 
 	if (ast_test_flag(&flags, OPTION_EXITONHANGUP)) {
 		ast_verb(3, "Stopped spying due to the spied-on channel hanging up.\n");
@@ -1240,7 +1239,7 @@
 		.volume = '#',
 		.exit = '\0',
 	};
-	struct ast_format *oldwf;
+	RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
 	int volfactor = 0;
 	int res;
 	char *mailbox = NULL;
@@ -1345,7 +1344,6 @@
 
 	if (oldwf && ast_set_write_format(chan, oldwf) < 0)
 		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
-	ao2_cleanup(oldwf);
 
 	return res;
 }
@@ -1376,6 +1374,7 @@
 	oldwf = ast_format_copy(ast_channel_writeformat(chan));
 	if (ast_set_write_format(chan, ast_format_slin) < 0) {
 		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+		ao2_cleanup(oldwf);
 		return -1;
 	}
 

Modified: team/group/media_formats/apps/app_dahdibarge.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_dahdibarge.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_dahdibarge.c (original)
+++ team/group/media_formats/apps/app_dahdibarge.c Wed Feb  5 11:36:36 2014
@@ -54,6 +54,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/say.h"
 #include "asterisk/utils.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="DAHDIBarge" language="en_US">
@@ -116,13 +117,13 @@
 	char *buf = __buf + AST_FRIENDLY_OFFSET;
 
 	/* Set it into U-law mode (write) */
-	if (ast_set_write_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
+	if (ast_set_write_format(chan, ast_format_ulaw) < 0) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", ast_channel_name(chan));
 		goto outrun;
 	}
 
 	/* Set it into U-law mode (read) */
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
+	if (ast_set_read_format(chan, ast_format_ulaw) < 0) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", ast_channel_name(chan));
 		goto outrun;
 	}
@@ -217,11 +218,11 @@
 				break;
 			} else if (fd != ast_channel_fd(chan, 0)) {
 				if (f->frametype == AST_FRAME_VOICE) {
-					if (f->subclass.format.id == AST_FORMAT_ULAW) {
+					if (ast_format_cmp(f->subclass.format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
 						/* Carefully write */
 						careful_write(fd, f->data.ptr, f->datalen);
 					} else
-						ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", ast_getformatname(&f->subclass.format));
+						ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", f->subclass.format->codec->name);
 				}
 			}
 			ast_frfree(f);
@@ -230,7 +231,7 @@
 			if (res > 0) {
 				memset(&fr, 0, sizeof(fr));
 				fr.frametype = AST_FRAME_VOICE;
-				ast_format_set(&fr.subclass.format, AST_FORMAT_ULAW, 0);
+				fr.subclass.format = ast_format_copy(ast_format_ulaw);
 				fr.datalen = res;
 				fr.samples = res;
 				fr.data.ptr = buf;
@@ -239,6 +240,7 @@
 					ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
 					/* break; */
 				}
+				ast_frfree(&fr);
 			} else 
 				ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
 		}

Modified: team/group/media_formats/apps/app_dictate.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_dictate.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_dictate.c (original)
+++ team/group/media_formats/apps/app_dictate.c Wed Feb  5 11:36:36 2014
@@ -129,6 +129,7 @@
 	oldr = ast_format_copy(ast_channel_readformat(chan));
 	if ((res = ast_set_read_format(chan, ast_format_slin)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
+		ao2_cleanup(oldr);
 		return -1;
 	}
 

Modified: team/group/media_formats/apps/app_festival.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_festival.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_festival.c (original)
+++ team/group/media_formats/apps/app_festival.c Wed Feb  5 11:36:36 2014
@@ -203,6 +203,7 @@
 	res = ast_set_write_format(chan, ast_format_slin);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		ao2_cleanup(owriteformat);
 		return -1;
 	}
 

Modified: team/group/media_formats/apps/app_ices.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_ices.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_ices.c (original)
+++ team/group/media_formats/apps/app_ices.c Wed Feb  5 11:36:36 2014
@@ -151,6 +151,7 @@
 		close(fds[0]);
 		close(fds[1]);
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		ao2_cleanup(oreadformat);
 		return -1;
 	}
 	if (((char *)data)[0] == '/')

Modified: team/group/media_formats/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_mixmonitor.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_mixmonitor.c (original)
+++ team/group/media_formats/apps/app_mixmonitor.c Wed Feb  5 11:36:36 2014
@@ -57,6 +57,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/test.h"
 #include "asterisk/mixmonitor.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="MixMonitor" language="en_US">
@@ -582,7 +583,7 @@
 				*errflag = 1;
 			} else {
 				struct ast_filestream *tmp = *fs;
-				mixmonitor->mixmonitor_ds->samp_rate = MAX(mixmonitor->mixmonitor_ds->samp_rate, ast_format_rate(&tmp->fmt->format));
+				mixmonitor->mixmonitor_ds->samp_rate = MAX(mixmonitor->mixmonitor_ds->samp_rate, tmp->fmt->format->codec->sample_rate);
 			}
 		}
 	}
@@ -601,7 +602,7 @@
 
 	unsigned int oflags;
 	int errflag = 0;
-	struct ast_format format_slin;
+	struct ast_format *format_slin;
 
 	/* Keep callid association before any log messages */
 	if (mixmonitor->callid) {
@@ -619,10 +620,9 @@
 	mixmonitor_save_prep(mixmonitor, mixmonitor->filename_read, fs_read, &oflags, &errflag, &fs_read_ext);
 	mixmonitor_save_prep(mixmonitor, mixmonitor->filename_write, fs_write, &oflags, &errflag, &fs_write_ext);
 
-	ast_format_set(&format_slin, ast_format_slin_by_rate(mixmonitor->mixmonitor_ds->samp_rate), 0);
+	format_slin = ast_format_cache_get_slin_by_rate(mixmonitor->mixmonitor_ds->samp_rate);
 
 	ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
-
 
 	/* The audiohook must enter and exit the loop locked */
 	ast_audiohook_lock(&mixmonitor->audiohook);
@@ -631,7 +631,7 @@
 		struct ast_frame *fr_read = NULL;
 		struct ast_frame *fr_write = NULL;
 
-		if (!(fr = ast_audiohook_read_frame_all(&mixmonitor->audiohook, SAMPLES_PER_FRAME, &format_slin,
+		if (!(fr = ast_audiohook_read_frame_all(&mixmonitor->audiohook, SAMPLES_PER_FRAME, format_slin,
 						&fr_read, &fr_write))) {
 			ast_audiohook_trigger_wait(&mixmonitor->audiohook);
 
@@ -711,6 +711,8 @@
 		ast_cond_wait(&mixmonitor->mixmonitor_ds->destruction_condition, &mixmonitor->mixmonitor_ds->lock);
 	}
 	ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
+
+	ao2_ref(format_slin, -1);
 
 	/* kill the audiohook */
 	destroy_monitor_audiohook(mixmonitor);

Modified: team/group/media_formats/apps/app_mp3.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_mp3.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_mp3.c (original)
+++ team/group/media_formats/apps/app_mp3.c Wed Feb  5 11:36:36 2014
@@ -47,6 +47,7 @@
 #include "asterisk/module.h"
 #include "asterisk/translate.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 #define LOCAL_MPG_123 "/usr/local/bin/mpg123"
 #define MPG_123 "/usr/bin/mpg123"
@@ -143,7 +144,7 @@
 	int fds[2];
 	int ms = -1;
 	int pid = -1;
-	struct ast_format owriteformat;
+	RAII_VAR(struct ast_format *, owriteformat, NULL, ao2_cleanup);
 	int timeout = 2000;
 	struct timeval next;
 	struct ast_frame *f;
@@ -155,7 +156,6 @@
 		.f = { 0, },
 	};
 
-	ast_format_clear(&owriteformat);
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n");
 		return -1;
@@ -168,12 +168,21 @@
 	
 	ast_stopstream(chan);
 
-	ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
-	res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+	owriteformat = ast_format_copy(ast_channel_writeformat(chan));
+	res = ast_set_write_format(chan, ast_format_slin);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
 		return -1;
 	}
+
+	myf.f.frametype = AST_FRAME_VOICE;
+	myf.f.subclass.format = ast_format_copy(ast_format_slin);
+	myf.f.mallocd = 0;
+	myf.f.offset = AST_FRIENDLY_OFFSET;
+	myf.f.src = __PRETTY_FUNCTION__;
+	myf.f.delivery.tv_sec = 0;
+	myf.f.delivery.tv_usec = 0;
+	myf.f.data.ptr = myf.frdata;
 	
 	res = mp3play(data, fds[1]);
 	if (!strncasecmp(data, "http://", 7)) {
@@ -191,16 +200,8 @@
 			if (ms <= 0) {
 				res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);
 				if (res > 0) {
-					myf.f.frametype = AST_FRAME_VOICE;
-					ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
 					myf.f.datalen = res;
 					myf.f.samples = res / 2;
-					myf.f.mallocd = 0;
-					myf.f.offset = AST_FRIENDLY_OFFSET;
-					myf.f.src = __PRETTY_FUNCTION__;
-					myf.f.delivery.tv_sec = 0;
-					myf.f.delivery.tv_usec = 0;
-					myf.f.data.ptr = myf.frdata;
 					if (ast_write(chan, &myf.f) < 0) {
 						res = -1;
 						break;
@@ -241,8 +242,10 @@
 	
 	if (pid > -1)
 		kill(pid, SIGKILL);
-	if (!res && owriteformat.id)
-		ast_set_write_format(chan, &owriteformat);
+	if (!res && owriteformat)
+		ast_set_write_format(chan, owriteformat);
+
+	ast_frfree(&myf.f);
 	
 	return res;
 }

Modified: team/group/media_formats/apps/app_nbscat.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_nbscat.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_nbscat.c (original)
+++ team/group/media_formats/apps/app_nbscat.c Wed Feb  5 11:36:36 2014
@@ -46,6 +46,7 @@
 #include "asterisk/module.h"
 #include "asterisk/translate.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="NBScat" language="en_US">
@@ -115,7 +116,7 @@
 	int fds[2];
 	int ms = -1;
 	int pid = -1;
-	struct ast_format owriteformat;
+	struct ast_format *owriteformat;
 	struct timeval next;
 	struct ast_frame *f;
 	struct myframe {
@@ -124,7 +125,6 @@
 		short frdata[160];
 	} myf;
 
-	ast_format_clear(&owriteformat);
 	if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) {
 		ast_log(LOG_WARNING, "Unable to create socketpair\n");
 		return -1;
@@ -132,12 +132,22 @@
 	
 	ast_stopstream(chan);
 
-	ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
-	res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+	owriteformat = ast_format_copy(ast_channel_writeformat(chan));
+	res = ast_set_write_format(chan, ast_format_slin);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		ao2_cleanup(owriteformat);
 		return -1;
 	}
+
+	myf.f.frametype = AST_FRAME_VOICE;
+	myf.f.subclass.format = ast_format_copy(ast_format_slin);
+	myf.f.mallocd = 0;
+	myf.f.offset = AST_FRIENDLY_OFFSET;
+	myf.f.src = __PRETTY_FUNCTION__;
+	myf.f.delivery.tv_sec = 0;
+	myf.f.delivery.tv_usec = 0;
+	myf.f.data.ptr = myf.frdata;
 	
 	res = NBScatplay(fds[1]);
 	/* Wait 1000 ms first */
@@ -152,16 +162,8 @@
 			if (ms <= 0) {
 				res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
 				if (res > 0) {
-					myf.f.frametype = AST_FRAME_VOICE;
-					ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
 					myf.f.datalen = res;
 					myf.f.samples = res / 2;
-					myf.f.mallocd = 0;
-					myf.f.offset = AST_FRIENDLY_OFFSET;
-					myf.f.src = __PRETTY_FUNCTION__;
-					myf.f.delivery.tv_sec = 0;
-					myf.f.delivery.tv_usec = 0;
-					myf.f.data.ptr = myf.frdata;
 					if (ast_write(chan, &myf.f) < 0) {
 						res = -1;
 						break;
@@ -199,11 +201,13 @@
 	}
 	close(fds[0]);
 	close(fds[1]);
+	ast_frfree(&myf.f);
 	
 	if (pid > -1)
 		kill(pid, SIGKILL);
-	if (!res && owriteformat.id)
-		ast_set_write_format(chan, &owriteformat);
+	if (!res && owriteformat)
+		ast_set_write_format(chan, owriteformat);
+	ao2_cleanup(owriteformat);
 
 	return res;
 }

Modified: team/group/media_formats/apps/app_originate.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_originate.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_originate.c (original)
+++ team/group/media_formats/apps/app_originate.c Wed Feb  5 11:36:36 2014
@@ -45,6 +45,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 static const char app_originate[] = "Originate";
 
@@ -112,22 +113,22 @@
 	int outgoing_status = 0;
 	unsigned int timeout = 30;
 	static const char default_exten[] = "s";
-	struct ast_format tmpfmt;
-	struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 
 	ast_autoservice_start(chan);
 	if (!cap_slin) {
 		goto return_cleanup;
 	}
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR12, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR24, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR32, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR44, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR48, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR96, 0));
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR192, 0));
+
+	ast_format_cap_add(cap_slin, ast_format_slin, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin12, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin16, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin24, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin32, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin44, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin48, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin96, 0);
+	ast_format_cap_add(cap_slin, ast_format_slin192, 0);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "Originate() requires arguments\n");
@@ -222,7 +223,7 @@
 			break;
 		}
 	}
-	cap_slin = ast_format_cap_destroy(cap_slin);
+	ao2_cleanup(cap_slin);
 	ast_autoservice_stop(chan);
 
 	return res;

Modified: team/group/media_formats/apps/app_record.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_record.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_record.c (original)
+++ team/group/media_formats/apps/app_record.c Wed Feb  5 11:36:36 2014
@@ -39,6 +39,7 @@
 #include "asterisk/app.h"
 #include "asterisk/channel.h"
 #include "asterisk/dsp.h"	/* use dsp routines for silence detection */
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="Record" language="en_US">
@@ -158,7 +159,7 @@
 	int maxduration = 0;		/* max duration of recording in milliseconds */
 	int gottimeout = 0;		/* did we timeout for maxduration exceeded? */
 	int terminator = '#';
-	struct ast_format rfmt;
+	RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
 	int ioflags;
 	struct ast_silence_generator *silgen = NULL;
 	struct ast_flags flags = { 0, };
@@ -170,8 +171,6 @@
 	);
 	int ms;
 	struct timeval start;
-
-	ast_format_clear(&rfmt);
 
 	/* The next few lines of code parse out the filename and header from the input string */
 	if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
@@ -293,8 +292,8 @@
 	/* The end of beep code.  Now the recording starts */
 
 	if (silence > 0) {
-		ast_format_copy(&rfmt, ast_channel_readformat(chan));
-		res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+		rfmt = ast_format_copy(ast_channel_readformat(chan));
+		res = ast_set_read_format(chan, ast_format_slin);
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
 			pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");
@@ -422,8 +421,8 @@
 		ast_channel_stop_silence_generator(chan, silgen);
 
 out:
-	if ((silence > 0) && rfmt.id) {
-		res = ast_set_read_format(chan, &rfmt);
+	if ((silence > 0) && rfmt) {
+		res = ast_set_read_format(chan, rfmt);
 		if (res) {
 			ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(chan));
 		}

Modified: team/group/media_formats/apps/app_sms.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_sms.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_sms.c (original)
+++ team/group/media_formats/apps/app_sms.c Wed Feb  5 11:36:36 2014
@@ -56,6 +56,7 @@
 #include "asterisk/callerid.h"
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="SMS" language="en_US">
@@ -140,11 +141,11 @@
 static unsigned char wavea[80];
 typedef unsigned char output_t;
 static const output_t *wave_out = wavea;    /* outgoing samples */
-#define __OUT_FMT AST_FORMAT_ALAW;
+#define __OUT_FMT ast_format_alaw
 #else
 typedef signed short output_t;
 static const output_t *wave_out = wave;     /* outgoing samples */
-#define __OUT_FMT AST_FORMAT_SLINEAR
+#define __OUT_FMT ast_format_slin
 #endif
 
 #define OSYNC_BITS	80                      /* initial sync bits */
@@ -1597,7 +1598,7 @@
 #define MAXSAMPLES (800)
 	output_t *buf;
 	sms_t *h = data;
-	int i;
+	int i, res;
 
 	if (samples > MAXSAMPLES) {
 		ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n",
@@ -1608,7 +1609,7 @@
 	buf = ast_alloca(len);
 
 	f.frametype = AST_FRAME_VOICE;
-	ast_format_set(&f.subclass.format, __OUT_FMT, 0);
+	f.subclass.format = ast_format_copy(__OUT_FMT);
 	f.datalen = samples * sizeof(*buf);
 	f.offset = AST_FRIENDLY_OFFSET;
 	f.mallocd = 0;
@@ -1658,7 +1659,9 @@
 			}
 		}
 	}
-	if (ast_write(chan, &f) < 0) {
+	res = ast_write(chan, &f);
+	ast_frfree(&f);
+	if (res < 0) {
 		ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
 		return -1;
 	}
@@ -2006,9 +2009,9 @@
 		sms_messagetx(&h);
 	}
 
-	res = ast_set_write_format_by_id(chan, __OUT_FMT);
+	res = ast_set_write_format(chan, __OUT_FMT);
 	if (res >= 0) {
-		res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+		res = ast_set_read_format(chan, ast_format_slin);
 	}
 	if (res < 0) {
 		ast_log(LOG_ERROR, "Unable to set to linear mode, giving up\n");

Modified: team/group/media_formats/apps/app_speech_utils.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_speech_utils.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_speech_utils.c (original)
+++ team/group/media_formats/apps/app_speech_utils.c Wed Feb  5 11:36:36 2014
@@ -668,7 +668,7 @@
 	int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0;
 	struct ast_speech *speech = find_speech(chan);
 	struct ast_frame *f = NULL;
-	struct ast_format oldreadformat;
+	RAII_VAR(struct ast_format *, oldreadformat, NULL, ao2_cleanup);
 	char dtmf[AST_MAX_EXTENSION] = "";
 	struct timeval start = { 0, 0 }, current;
 	struct ast_datastore *datastore = NULL;
@@ -684,7 +684,6 @@
 	parse = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, parse);
 
-	ast_format_clear(&oldreadformat);
 	if (speech == NULL)
 		return -1;
 
@@ -700,7 +699,7 @@
 	}
 
 	/* Record old read format */
-	ast_format_copy(&oldreadformat, ast_channel_readformat(chan));
+	oldreadformat = ast_format_copy(ast_channel_readformat(chan));
 
 	/* Change read format to be signed linear */
 	if (ast_set_read_format(chan, &speech->format))
@@ -908,7 +907,7 @@
 			ast_channel_datastore_remove(chan, datastore);
 	} else {
 		/* Channel is okay so restore read format */
-		ast_set_read_format(chan, &oldreadformat);
+		ast_set_read_format(chan, oldreadformat);
 	}
 
 	return 0;

Modified: team/group/media_formats/apps/app_talkdetect.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_talkdetect.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_talkdetect.c (original)
+++ team/group/media_formats/apps/app_talkdetect.c Wed Feb  5 11:36:36 2014
@@ -42,6 +42,8 @@
 #include "asterisk/utils.h"
 #include "asterisk/dsp.h"
 #include "asterisk/app.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="BackgroundDetect" language="en_US">
@@ -91,7 +93,7 @@
 	int analysistime = -1;
 	int continue_analysis = 1;
 	int x;
-	struct ast_format origrformat;
+	RAII_VAR(struct ast_format *, origrformat, NULL, ao2_cleanup);
 	struct ast_dsp *dsp = NULL;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(filename);
@@ -101,7 +103,6 @@
 		AST_APP_ARG(analysistime);
 	);
 
-	ast_format_clear(&origrformat);
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
 		return -1;
@@ -131,8 +132,8 @@
 			}
 		}
 
-		ast_format_copy(&origrformat, ast_channel_readformat(chan));
-		if ((ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR))) {
+		origrformat = ast_format_copy(ast_channel_readformat(chan));
+		if ((ast_set_read_format(chan, ast_format_slin))) {
 			ast_log(LOG_WARNING, "Unable to set read format to linear!\n");
 			res = -1;
 			break;
@@ -187,7 +188,8 @@
 						ast_frfree(fr);
 						break;
 					}
-				} else if ((fr->frametype == AST_FRAME_VOICE) && (fr->subclass.format.id == AST_FORMAT_SLINEAR) && continue_analysis) {
+				} else if ((fr->frametype == AST_FRAME_VOICE) &&
+				(ast_format_cmp(fr->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) && continue_analysis) {
 					int totalsilence;
 					int ms;
 					res = ast_dsp_silence(dsp, fr, &totalsilence);
@@ -233,9 +235,9 @@
 	} while (0);
 
 	if (res > -1) {
-		if (origrformat.id && ast_set_read_format(chan, &origrformat)) {
+		if (origrformat && ast_set_read_format(chan, origrformat)) {
 			ast_log(LOG_WARNING, "Failed to restore read format for %s to %s\n", 
-				ast_channel_name(chan), ast_getformatname(&origrformat));
+				ast_channel_name(chan), origrformat->codec->name);
 		}
 	}
 	if (dsp) {

Modified: team/group/media_formats/apps/app_test.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_test.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_test.c (original)
+++ team/group/media_formats/apps/app_test.c Wed Feb  5 11:36:36 2014
@@ -44,6 +44,7 @@
 #include "asterisk/app.h"
 #include "asterisk/pbx.h"
 #include "asterisk/utils.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="TestServer" language="en_US">
@@ -91,11 +92,12 @@
 	short *foo;
 	struct timeval start;
 	struct ast_frame *f;
-	struct ast_format rformat;
-
-	ast_format_copy(&rformat, ast_channel_readformat(chan));
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
+	struct ast_format *rformat;
+
+	rformat = ast_format_copy(ast_channel_readformat(chan));
+	if (ast_set_read_format(chan, ast_format_slin)) {
 		ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
+		ao2_cleanup(rformat);
 		return -1;
 	}
 	start = ast_tvnow();
@@ -111,7 +113,8 @@
 			res = -1;
 			break;
 		}
-		if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
+		if ((f->frametype == AST_FRAME_VOICE) &&
+			(ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
 			foo = (short *)f->data.ptr;
 			for (x=0;x<f->samples;x++) {
 				noise += abs(foo[x]);
@@ -121,11 +124,13 @@
 		ast_frfree(f);
 	}
 
-	if (rformat.id) {
-		if (ast_set_read_format(chan, &rformat)) {
+	if (rformat) {
+		if (ast_set_read_format(chan, rformat)) {
 			ast_log(LOG_NOTICE, "Unable to restore original format!\n");
+			ao2_ref(rformat, -1);
 			return -1;
 		}
+		ao2_ref(rformat, -1);
 	}
 	if (res < 0)
 		return res;

Modified: team/group/media_formats/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_voicemail.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_voicemail.c (original)
+++ team/group/media_formats/apps/app_voicemail.c Wed Feb  5 11:36:36 2014
@@ -135,6 +135,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/taskprocessor.h"
 #include "asterisk/test.h"
+#include "asterisk/format_cache.h"
 
 #ifdef ODBC_STORAGE
 #include "asterisk/res_odbc.h"
@@ -6103,13 +6104,16 @@
 	if ((recording_fs = ast_readfile(recdata->recording_file, recdata->recording_ext, NULL, 0, 0, VOICEMAIL_DIR_MODE))) {
 		if (!ast_seekstream(recording_fs, 0, SEEK_END)) {
 			long framelength = ast_tellstream(recording_fs);
-			struct ast_format result = {0,};
+			struct ast_format *result;
 			/* XXX This use of ast_getformatbyname seems incorrect here. The file extension does not necessarily correspond
 			 * to the name of the format. For instance, if "raw" were passed in, I don't think ast_getformatbyname would
 			 * find the slinear format
 			 */
-			ast_getformatbyname(recdata->recording_ext, &result);
-			duration = (int) (framelength / ast_format_rate(&result));
+			result = ast_format_cache_get(recdata->recording_ext);
+			if (result) {
+				duration = (int) (framelength / result->codec->sample_rate);
+				ao2_ref(result, -1);
+			}
 		}
 	}
 
@@ -13760,7 +13764,7 @@
 
 	struct ast_channel *test_channel1 = NULL;
 	int res = -1;
-	struct ast_format_cap *nativeformats;
+	struct ast_format_cap *capabilities;
 
 	static const struct ast_channel_tech fake_tech = {
 		.write = fake_write,
@@ -13785,12 +13789,17 @@
 	}
 
 	/* normally this is done in the channel driver */
-	ast_format_set(ast_channel_writeformat(test_channel1), AST_FORMAT_GSM, 0);
-	nativeformats = ast_channel_nativeformats(test_channel1);
-	ast_format_cap_add(nativeformats, ast_channel_writeformat(test_channel1));
-	ast_format_set(ast_channel_rawwriteformat(test_channel1), AST_FORMAT_GSM, 0);
-	ast_format_set(ast_channel_readformat(test_channel1), AST_FORMAT_GSM, 0);
-	ast_format_set(ast_channel_rawreadformat(test_channel1), AST_FORMAT_GSM, 0);
+	capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!capabilities) {
+		goto exit_vmsayname_test;
+	}
+	ast_format_cap_add(capabilities, ast_format_gsm, 0);
+	ast_channel_nativeformats_set(test_channel1, capabilities);
+	ao2_ref(capabilities, -1);
+	ast_channel_set_writeformat(test_channel1, ast_format_gsm);
+	ast_channel_set_rawwriteformat(test_channel1, ast_format_gsm);
+	ast_channel_set_readformat(test_channel1, ast_format_gsm);
+	ast_channel_set_rawreadformat(test_channel1, ast_format_gsm);
 	ast_channel_tech_set(test_channel1, &fake_tech);
 
 	ast_channel_unlock(test_channel1);

Modified: team/group/media_formats/apps/app_waitforsilence.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_waitforsilence.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/apps/app_waitforsilence.c (original)
+++ team/group/media_formats/apps/app_waitforsilence.c Wed Feb  5 11:36:36 2014
@@ -51,6 +51,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/dsp.h"
 #include "asterisk/module.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="WaitForSilence" language="en_US">
@@ -129,7 +130,7 @@
 static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) {
 	struct ast_frame *f = NULL;
 	int dsptime = 0;
-	struct ast_format rfmt;
+	RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
 	int res = 0;
 	struct ast_dsp *sildet;	 /* silence detector dsp */
  	time_t now;
@@ -138,8 +139,8 @@
 	int (*ast_dsp_func)(struct ast_dsp*, struct ast_frame*, int*) =
 				wait_for_silence ? ast_dsp_silence : ast_dsp_noise;
 
-	ast_format_copy(&rfmt, ast_channel_readformat(chan)); /* Set to linear mode */
-	if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
+	rfmt = ast_format_copy(ast_channel_readformat(chan));
+	if ((res = ast_set_read_format(chan, ast_format_slin)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n");
 		return -1;
 	}
@@ -199,8 +200,8 @@
 	}
 
 
-	if (rfmt.id && ast_set_read_format(chan, &rfmt)) {
-		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), ast_channel_name(chan));
+	if (rfmt && ast_set_read_format(chan, rfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", rfmt->codec->name, ast_channel_name(chan));
 	}
 	ast_dsp_free(sildet);
 	return res;

Modified: team/group/media_formats/include/asterisk/format_cache.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cache.h?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/include/asterisk/format_cache.h (original)
+++ team/group/media_formats/include/asterisk/format_cache.h Wed Feb  5 11:36:36 2014
@@ -29,9 +29,49 @@
 struct ast_format;
 
 /*!
- * \brief Built-in cached signed linear format.
+ * \brief Built-in cached signed linear 8kHz format.
  */
 extern struct ast_format *ast_format_slin;
+
+/*!
+ * \brief Built-in cached signed linear 12kHz format.
+ */
+extern struct ast_format *ast_format_slin12;
+
+/*!
+ * \brief Built-in cached signed linear 16kHz format.
+ */
+extern struct ast_format *ast_format_slin16;
+
+/*!
+ * \brief Built-in cached signed linear 24kHz format.
+ */
+extern struct ast_format *ast_format_slin24;
+
+/*!
+ * \brief Built-in cached signed linear 32kHz format.
+ */
+extern struct ast_format *ast_format_slin32;
+
+/*!
+ * \brief Built-in cached signed linear 44kHz format.
+ */
+extern struct ast_format *ast_format_slin44;
+
+/*!
+ * \brief Built-in cached signed linear 48kHz format.
+ */
+extern struct ast_format *ast_format_slin48;
+
+/*!
+ * \brief Built-in cached signed linear 96kHz format.
+ */
+extern struct ast_format *ast_format_slin96;
+
+/*!
+ * \brief Built-in cached signed linear 192kHz format.
+ */
+extern struct ast_format *ast_format_slin192;
 
 /*!
  * \brief Built-in cached ulaw format.
@@ -39,9 +79,14 @@
 extern struct ast_format *ast_format_ulaw;
 
 /*!
- * \brief Builtin- cached alaw format.
+ * \brief Built-in cached alaw format.
  */
 extern struct ast_format *ast_format_alaw;
+
+/*!
+ * \brief Built-in cached gsm format.
+ */
+extern struct ast_format *ast_format_gsm;
 
 /*!
  * \brief Initialize format cache support within the core.
@@ -75,4 +120,16 @@
  */
 struct ast_format *ast_format_cache_get(const char *name);
 
+/*!
+ * \brief Retrieve the best signed linear format given a sample rate.
+ *
+ * \param rate The sample rate
+ *
+ * \return pointer to the signed linear format
+ *
+ * \note The returned format has its reference count incremented. It must be
+ * dropped using ao2_ref or ao2_cleanup.
+ */
+struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate);
+
 #endif /* _AST_FORMAT_CACHE_H */

Modified: team/group/media_formats/include/asterisk/mod_format.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/mod_format.h?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/include/asterisk/mod_format.h (original)
+++ team/group/media_formats/include/asterisk/mod_format.h Wed Feb  5 11:36:36 2014
@@ -44,7 +44,7 @@
 	char name[80];		/*!< Name of format */
 	char exts[80];		/*!< Extensions (separated by | if more than one) 
 	    			this format can read.  First is assumed for writing (e.g. .mp3) */
-	struct ast_format format;	/*!< Format of frames it uses/provides (one only) */
+	struct ast_format *format;	/*!< Format of frames it uses/provides (one only) */
 	/*! 
 	 * \brief Prepare an input stream for playback. 
 	 * \return 0 on success, -1 on error.

Modified: team/group/media_formats/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/rtp_engine.h?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/include/asterisk/rtp_engine.h (original)
+++ team/group/media_formats/include/asterisk/rtp_engine.h Wed Feb  5 11:36:36 2014
@@ -504,8 +504,6 @@
 	void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
 	/*! Callback for setting a payload.  If asterisk  is to be used, asterisk_format will be set, otherwise value in code is used. */
 	void (*payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code);
-	/*! Callback for setting packetization preferences */
-	void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref);
 	/*! Callback for setting the remote address that RTP is to be sent to */
 	void (*remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa);
 	/*! Callback for changing DTMF mode */
@@ -554,8 +552,6 @@
 struct ast_rtp_codecs {
 	/*! Payloads present */
 	struct ao2_container *payloads;
-	/*! Codec packetization preferences */
-	struct ast_codec_pref pref;
 };
 
 /*! Structure that represents the glue that binds an RTP instance to a channel */
@@ -1400,7 +1396,7 @@
  *
  * \since 1.8
  */
-void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
+void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
 
 /*!
  * \brief Begin sending a DTMF digit

Modified: team/group/media_formats/main/format_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_cache.c?view=diff&rev=407424&r1=407423&r2=407424
==============================================================================
--- team/group/media_formats/main/format_cache.c (original)
+++ team/group/media_formats/main/format_cache.c Wed Feb  5 11:36:36 2014
@@ -178,4 +178,26 @@
 	ao2_ref(cached_format, -1);
 
 	return format;
+}
+
+struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate)
+{
+	if (rate >= 192000) {
+		return ao2_bump(ast_format_slin192);
+	} else if (rate >= 96000) {
+		return ao2_bump(ast_format_slin96);
+	} else if (rate >= 48000) {
+		return ao2_bump(ast_format_slin48);
+	} else if (rate >= 44100) {
+		return ao2_bump(ast_format_slin44);
+	} else if (rate >= 32000) {
+		return ao2_bump(ast_format_slin32);
+	} else if (rate >= 24000) {
+		return ao2_bump(ast_format_slin24);
+	} else if (rate >= 16000) {
+		return ao2_bump(ast_format_slin16);
+	} else if (rate >= 12000) {
+		return ao2_bump(ast_format_slin12);
+	}
+	return ao2_bump(ast_format_slin);
 }




More information about the svn-commits mailing list