[asterisk-commits] file: branch file/audiohooks-1.4 r87853 - /team/file/audiohooks-1.4/apps/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 31 13:06:23 CDT 2007
Author: file
Date: Wed Oct 31 13:06:22 2007
New Revision: 87853
URL: http://svn.digium.com/view/asterisk?view=rev&rev=87853
Log:
Convert app_mixmonitor over to audiohooks.
Modified:
team/file/audiohooks-1.4/apps/app_mixmonitor.c
Modified: team/file/audiohooks-1.4/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohooks-1.4/apps/app_mixmonitor.c?view=diff&rev=87853&r1=87852&r2=87853
==============================================================================
--- team/file/audiohooks-1.4/apps/app_mixmonitor.c (original)
+++ team/file/audiohooks-1.4/apps/app_mixmonitor.c Wed Oct 31 13:06:22 2007
@@ -45,7 +45,7 @@
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
-#include "asterisk/chanspy.h"
+#include "asterisk/audiohook.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
@@ -93,11 +93,12 @@
static const char *mixmonitor_spy_type = "MixMonitor";
struct mixmonitor {
- struct ast_channel_spy spy;
+ struct ast_audiohook audiohook;
char *filename;
char *post_process;
char *name;
unsigned int flags;
+ struct ast_channel *chan;
};
enum {
@@ -123,7 +124,7 @@
AST_APP_OPTION_ARG('W', MUXFLAG_VOLUME, OPT_ARG_VOLUME),
});
-static int startmon(struct ast_channel *chan, struct ast_channel_spy *spy)
+static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
{
struct ast_channel *peer;
int res;
@@ -131,9 +132,7 @@
if (!chan)
return -1;
- ast_channel_lock(chan);
- res = ast_channel_spy_add(chan, spy);
- ast_channel_unlock(chan);
+ ast_audiohook_attach(chan, audiohook);
if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan)))
ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
@@ -146,7 +145,6 @@
static void *mixmonitor_thread(void *obj)
{
struct mixmonitor *mixmonitor = obj;
- struct ast_frame *f = NULL;
struct ast_filestream *fs = NULL;
unsigned int oflags;
char *ext;
@@ -155,58 +153,48 @@
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Begin MixMonitor Recording %s\n", mixmonitor->name);
- ast_mutex_lock(&mixmonitor->spy.lock);
-
- while (mixmonitor->spy.chan) {
- struct ast_frame *next;
- int write;
-
- ast_channel_spy_trigger_wait(&mixmonitor->spy);
-
- if (!mixmonitor->spy.chan || mixmonitor->spy.status != CHANSPY_RUNNING)
+ ast_audiohook_lock(&mixmonitor->audiohook);
+
+ while (mixmonitor->audiohook.status == AST_AUDIOHOOK_STATUS_RUNNING) {
+ struct ast_frame *fr = NULL;
+
+ ast_audiohook_trigger_wait(&mixmonitor->audiohook);
+
+ if (mixmonitor->audiohook.status != AST_AUDIOHOOK_STATUS_RUNNING)
break;
- while (1) {
- if (!(f = ast_channel_spy_read_frame(&mixmonitor->spy, SAMPLES_PER_FRAME)))
- break;
-
- write = (!ast_test_flag(mixmonitor, MUXFLAG_BRIDGED) ||
- ast_bridged_channel(mixmonitor->spy.chan));
-
- /* it is possible for ast_channel_spy_read_frame() to return a chain
- of frames if a queue flush was necessary, so process them
- */
- for (; f; f = next) {
- next = AST_LIST_NEXT(f, frame_list);
- if (write && errflag == 0) {
- if (!fs) {
- /* Determine creation flags and filename plus extension for filestream */
- oflags = O_CREAT | O_WRONLY;
- oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
-
- if ((ext = strrchr(mixmonitor->filename, '.')))
- *(ext++) = '\0';
- else
- ext = "raw";
-
- /* Move onto actually creating the filestream */
- if (!(fs = ast_writefile(mixmonitor->filename, ext, NULL, oflags, 0, 0644))) {
- ast_log(LOG_ERROR, "Cannot open %s.%s\n", mixmonitor->filename, ext);
- errflag = 1;
- }
-
- }
- if (fs)
- ast_writestream(fs, f);
+ if (!(fr = ast_audiohook_read_frame(&mixmonitor->audiohook, SAMPLES_PER_FRAME, AST_AUDIOHOOK_DIRECTION_BOTH, AST_FORMAT_SLINEAR)))
+ continue;
+
+ if (!ast_test_flag(mixmonitor, MUXFLAG_BRIDGED) || ast_bridged_channel(mixmonitor->chan)) {
+ /* Initialize the file if not already done so */
+ if (!fs && !errflag) {
+ oflags = O_CREAT | O_WRONLY;
+ oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
+
+ if ((ext = strrchr(mixmonitor->filename, '.')))
+ *(ext++) = '\0';
+ else
+ ext = "raw";
+
+ if (!(fs = ast_writefile(mixmonitor->filename, ext, NULL, oflags, 0, 0644))) {
+ ast_log(LOG_ERROR, "Cannot open %s.%s\n", mixmonitor->filename, ext);
+ errflag = 1;
}
- ast_frame_free(f, 0);
}
+
+ /* Write out the frame */
+ if (fs)
+ ast_writestream(fs, fr);
}
- }
-
- ast_mutex_unlock(&mixmonitor->spy.lock);
-
- ast_channel_spy_free(&mixmonitor->spy);
+
+ /* All done! free it. */
+ ast_frame_free(fr, 0);
+ }
+
+ ast_audiohook_detach(&mixmonitor->audiohook);
+ ast_audiohook_unlock(&mixmonitor->audiohook);
+ ast_audiohook_destroy(&mixmonitor->audiohook);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "End MixMonitor Recording %s\n", mixmonitor->name);
@@ -271,27 +259,23 @@
strcpy(mixmonitor->filename, filename);
/* Setup the actual spy before creating our thread */
- ast_set_flag(&mixmonitor->spy, CHANSPY_FORMAT_AUDIO);
- ast_set_flag(&mixmonitor->spy, CHANSPY_MIXAUDIO);
- mixmonitor->spy.type = mixmonitor_spy_type;
- mixmonitor->spy.status = CHANSPY_RUNNING;
- mixmonitor->spy.read_queue.format = AST_FORMAT_SLINEAR;
- mixmonitor->spy.write_queue.format = AST_FORMAT_SLINEAR;
- if (readvol) {
- ast_set_flag(&mixmonitor->spy, CHANSPY_READ_VOLADJUST);
- mixmonitor->spy.read_vol_adjustment = readvol;
- }
- if (writevol) {
- ast_set_flag(&mixmonitor->spy, CHANSPY_WRITE_VOLADJUST);
- mixmonitor->spy.write_vol_adjustment = writevol;
- }
- ast_mutex_init(&mixmonitor->spy.lock);
-
- if (startmon(chan, &mixmonitor->spy)) {
+ if (ast_audiohook_init(&mixmonitor->audiohook, AST_AUDIOHOOK_TYPE_SPY, mixmonitor_spy_type)) {
+ free(mixmonitor);
+ return;
+ }
+
+ ast_set_flag(&mixmonitor->audiohook, AST_AUDIOHOOK_TRIGGER_WRITE);
+
+ if (readvol)
+ mixmonitor->audiohook.options.read_volume = readvol;
+ if (writevol)
+ mixmonitor->audiohook.options.write_volume = writevol;
+
+ if (startmon(chan, &mixmonitor->audiohook)) {
ast_log(LOG_WARNING, "Unable to add '%s' spy to channel '%s'\n",
- mixmonitor->spy.type, chan->name);
+ mixmonitor_spy_type, chan->name);
/* Since we couldn't add ourselves - bail out! */
- ast_mutex_destroy(&mixmonitor->spy.lock);
+ ast_audiohook_destroy(&mixmonitor->audiohook);
free(mixmonitor);
return;
}
@@ -391,9 +375,7 @@
u = ast_module_user_add(chan);
- ast_channel_lock(chan);
- ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type);
- ast_channel_unlock(chan);
+ ast_audiohook_detach_source(chan, mixmonitor_spy_type);
ast_module_user_remove(u);
@@ -415,7 +397,7 @@
if (!strcasecmp(argv[1], "start"))
mixmonitor_exec(chan, argv[3]);
else if (!strcasecmp(argv[1], "stop"))
- ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type);
+ ast_audiohook_detach_source(chan, mixmonitor_spy_type);
ast_channel_unlock(chan);
More information about the asterisk-commits
mailing list