2005-10-16 02:59:13 +00:00
|
|
|
/*
|
2005-10-28 23:01:13 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-10-16 02:59:13 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005, Anthony Minessale II
|
2006-01-03 22:16:23 +00:00
|
|
|
* Copyright (C) 2005 - 2006, Digium, Inc.
|
2005-10-28 23:01:13 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
* Kevin P. Fleming <kpfleming@digium.com>
|
2005-10-16 02:59:13 +00:00
|
|
|
*
|
2005-10-28 23:01:13 +00:00
|
|
|
* Based on app_muxmon.c provided by
|
2005-10-16 02:59:13 +00:00
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
2005-10-28 23:01:13 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2005-10-16 02:59:13 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-10-28 23:01:13 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
2005-10-16 02:59:13 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-10-31 15:33:27 +00:00
|
|
|
* \brief MixMonitor() - Record a call and mix the audio during the recording
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
|
|
|
* \author Kevin P. Fleming <kpfleming@digium.com>
|
|
|
|
*
|
|
|
|
* \note Based on app_muxmon.c provided by
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
2005-10-24 20:12:06 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2007-11-20 23:16:15 +00:00
|
|
|
#include "asterisk/paths.h" /* use ast_config_AST_MONITOR_DIR */
|
2005-10-28 23:01:13 +00:00
|
|
|
#include "asterisk/file.h"
|
2007-08-08 19:30:52 +00:00
|
|
|
#include "asterisk/audiohook.h"
|
2005-10-28 23:01:13 +00:00
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/app.h"
|
2007-11-22 03:50:04 +00:00
|
|
|
#include "asterisk/channel.h"
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
#include "asterisk/autochan.h"
|
2010-04-21 11:27:27 +00:00
|
|
|
#include "asterisk/manager.h"
|
2005-10-28 23:01:13 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<application name="MixMonitor" language="en_US">
|
|
|
|
<synopsis>
|
2009-06-17 19:45:35 +00:00
|
|
|
Record a call and mix the audio during the recording. Use of StopMixMonitor is required
|
|
|
|
to guarantee the audio file is available for processing during dialplan execution.
|
2008-11-01 21:10:07 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="file" required="true" argsep=".">
|
|
|
|
<argument name="filename" required="true">
|
|
|
|
<para>If <replaceable>filename</replaceable> is an absolute path, uses that path, otherwise
|
|
|
|
creates the file in the configured monitoring directory from <filename>asterisk.conf.</filename></para>
|
|
|
|
</argument>
|
|
|
|
<argument name="extension" required="true" />
|
|
|
|
</parameter>
|
|
|
|
<parameter name="options">
|
|
|
|
<optionlist>
|
|
|
|
<option name="a">
|
|
|
|
<para>Append to the file instead of overwriting it.</para>
|
|
|
|
</option>
|
|
|
|
<option name="b">
|
|
|
|
<para>Only save audio to the file while the channel is bridged.</para>
|
|
|
|
<note><para>Does not include conferences or sounds played to each bridged party</para></note>
|
2009-05-28 22:04:00 +00:00
|
|
|
<note><para>If you utilize this option inside a Local channel, you must make sure the Local
|
|
|
|
channel is not optimized away. To do this, be sure to call your Local channel with the
|
|
|
|
<literal>/n</literal> option. For example: Dial(Local/start@mycontext/n)</para></note>
|
2008-11-01 21:10:07 +00:00
|
|
|
</option>
|
|
|
|
<option name="v">
|
|
|
|
<para>Adjust the <emphasis>heard</emphasis> volume by a factor of <replaceable>x</replaceable>
|
|
|
|
(range <literal>-4</literal> to <literal>4</literal>)</para>
|
|
|
|
<argument name="x" required="true" />
|
|
|
|
</option>
|
|
|
|
<option name="V">
|
|
|
|
<para>Adjust the <emphasis>spoken</emphasis> volume by a factor
|
|
|
|
of <replaceable>x</replaceable> (range <literal>-4</literal> to <literal>4</literal>)</para>
|
|
|
|
<argument name="x" required="true" />
|
|
|
|
</option>
|
|
|
|
<option name="W">
|
|
|
|
<para>Adjust both, <emphasis>heard and spoken</emphasis> volumes by a factor
|
|
|
|
of <replaceable>x</replaceable> (range <literal>-4</literal> to <literal>4</literal>)</para>
|
|
|
|
<argument name="x" required="true" />
|
|
|
|
</option>
|
|
|
|
</optionlist>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="command">
|
|
|
|
<para>Will be executed when the recording is over.</para>
|
|
|
|
<para>Any strings matching <literal>^{X}</literal> will be unescaped to <variable>X</variable>.</para>
|
|
|
|
<para>All variables will be evaluated at the time MixMonitor is called.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Records the audio on the current channel to the specified file.</para>
|
|
|
|
<variablelist>
|
|
|
|
<variable name="MIXMONITOR_FILENAME">
|
|
|
|
<para>Will contain the filename used to record.</para>
|
|
|
|
</variable>
|
|
|
|
</variablelist>
|
|
|
|
</description>
|
2008-11-05 18:50:02 +00:00
|
|
|
<see-also>
|
|
|
|
<ref type="application">Monitor</ref>
|
|
|
|
<ref type="application">StopMixMonitor</ref>
|
|
|
|
<ref type="application">PauseMonitor</ref>
|
|
|
|
<ref type="application">UnpauseMonitor</ref>
|
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</application>
|
|
|
|
<application name="StopMixMonitor" language="en_US">
|
|
|
|
<synopsis>
|
2009-06-17 19:45:35 +00:00
|
|
|
Stop recording a call through MixMonitor, and free the recording's file handle.
|
2008-11-01 21:10:07 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Stops the audio recording that was started with a call to <literal>MixMonitor()</literal>
|
|
|
|
on the current channel.</para>
|
|
|
|
</description>
|
2008-11-05 18:50:02 +00:00
|
|
|
<see-also>
|
|
|
|
<ref type="application">MixMonitor</ref>
|
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</application>
|
2010-04-21 11:27:27 +00:00
|
|
|
<manager name="MixMonitorMute" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Mute / unMute a Mixmonitor recording.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
|
|
|
|
<parameter name="Channel" required="true">
|
|
|
|
<para>Used to specify the channel to mute.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="Direction">
|
|
|
|
<para>Which part of the recording to mute: read, write or both (from channel, to channel or both channels).</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="State">
|
|
|
|
<para>Turn mute on or off : 1 to turn on, 0 to turn off.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>This action may be used to mute a MixMonitor recording.</para>
|
|
|
|
</description>
|
|
|
|
</manager>
|
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
***/
|
|
|
|
|
2005-10-16 02:59:13 +00:00
|
|
|
#define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
|
2005-10-28 23:01:13 +00:00
|
|
|
|
2009-05-12 13:59:35 +00:00
|
|
|
static const char * const app = "MixMonitor";
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2009-05-12 13:59:35 +00:00
|
|
|
static const char * const stop_app = "StopMixMonitor";
|
2006-02-16 17:37:03 +00:00
|
|
|
|
2009-05-12 13:59:35 +00:00
|
|
|
static const char * const mixmonitor_spy_type = "MixMonitor";
|
2005-10-28 23:01:13 +00:00
|
|
|
|
|
|
|
struct mixmonitor {
|
2007-08-08 19:30:52 +00:00
|
|
|
struct ast_audiohook audiohook;
|
2007-01-22 19:22:07 +00:00
|
|
|
char *filename;
|
2005-10-16 02:59:13 +00:00
|
|
|
char *post_process;
|
2006-06-12 21:37:29 +00:00
|
|
|
char *name;
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75983 f38db490-d61c-443f-a65b-d21fe96a405b
2007-07-19 23:24:27 +00:00
|
|
|
unsigned int flags;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
struct ast_autochan *autochan;
|
2009-06-17 19:45:35 +00:00
|
|
|
struct mixmonitor_ds *mixmonitor_ds;
|
2005-10-16 02:59:13 +00:00
|
|
|
};
|
|
|
|
|
2009-06-15 19:10:10 +00:00
|
|
|
enum mixmonitor_flags {
|
2005-11-03 21:19:11 +00:00
|
|
|
MUXFLAG_APPEND = (1 << 1),
|
|
|
|
MUXFLAG_BRIDGED = (1 << 2),
|
|
|
|
MUXFLAG_VOLUME = (1 << 3),
|
|
|
|
MUXFLAG_READVOLUME = (1 << 4),
|
|
|
|
MUXFLAG_WRITEVOLUME = (1 << 5),
|
2009-06-15 19:10:10 +00:00
|
|
|
};
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2009-06-15 19:10:10 +00:00
|
|
|
enum mixmonitor_args {
|
2005-11-03 21:19:11 +00:00
|
|
|
OPT_ARG_READVOLUME = 0,
|
|
|
|
OPT_ARG_WRITEVOLUME,
|
|
|
|
OPT_ARG_VOLUME,
|
|
|
|
OPT_ARG_ARRAY_SIZE,
|
2009-06-15 19:10:10 +00:00
|
|
|
};
|
2005-11-03 21:19:11 +00:00
|
|
|
|
|
|
|
AST_APP_OPTIONS(mixmonitor_opts, {
|
|
|
|
AST_APP_OPTION('a', MUXFLAG_APPEND),
|
|
|
|
AST_APP_OPTION('b', MUXFLAG_BRIDGED),
|
|
|
|
AST_APP_OPTION_ARG('v', MUXFLAG_READVOLUME, OPT_ARG_READVOLUME),
|
|
|
|
AST_APP_OPTION_ARG('V', MUXFLAG_WRITEVOLUME, OPT_ARG_WRITEVOLUME),
|
|
|
|
AST_APP_OPTION_ARG('W', MUXFLAG_VOLUME, OPT_ARG_VOLUME),
|
2005-10-16 02:59:13 +00:00
|
|
|
});
|
|
|
|
|
2009-06-17 19:45:35 +00:00
|
|
|
struct mixmonitor_ds {
|
|
|
|
unsigned int destruction_ok;
|
|
|
|
ast_cond_t destruction_condition;
|
|
|
|
ast_mutex_t lock;
|
|
|
|
|
|
|
|
/* The filestream is held in the datastore so it can be stopped
|
|
|
|
* immediately during stop_mixmonitor or channel destruction. */
|
|
|
|
int fs_quit;
|
|
|
|
struct ast_filestream *fs;
|
2009-11-19 21:26:21 +00:00
|
|
|
struct ast_audiohook *audiohook;
|
2009-06-17 19:45:35 +00:00
|
|
|
};
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \pre mixmonitor_ds must be locked before calling this function
|
|
|
|
*/
|
2009-06-17 19:45:35 +00:00
|
|
|
static void mixmonitor_ds_close_fs(struct mixmonitor_ds *mixmonitor_ds)
|
|
|
|
{
|
|
|
|
if (mixmonitor_ds->fs) {
|
|
|
|
ast_closestream(mixmonitor_ds->fs);
|
|
|
|
mixmonitor_ds->fs = NULL;
|
|
|
|
mixmonitor_ds->fs_quit = 1;
|
|
|
|
ast_verb(2, "MixMonitor close filestream\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mixmonitor_ds_destroy(void *data)
|
|
|
|
{
|
|
|
|
struct mixmonitor_ds *mixmonitor_ds = data;
|
|
|
|
|
|
|
|
ast_mutex_lock(&mixmonitor_ds->lock);
|
2009-11-19 21:26:21 +00:00
|
|
|
mixmonitor_ds->audiohook = NULL;
|
2009-06-17 19:45:35 +00:00
|
|
|
mixmonitor_ds->destruction_ok = 1;
|
|
|
|
ast_cond_signal(&mixmonitor_ds->destruction_condition);
|
|
|
|
ast_mutex_unlock(&mixmonitor_ds->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_datastore_info mixmonitor_ds_info = {
|
|
|
|
.type = "mixmonitor",
|
|
|
|
.destroy = mixmonitor_ds_destroy,
|
|
|
|
};
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
static void destroy_monitor_audiohook(struct mixmonitor *mixmonitor)
|
|
|
|
{
|
|
|
|
if (mixmonitor->mixmonitor_ds) {
|
|
|
|
ast_mutex_lock(&mixmonitor->mixmonitor_ds->lock);
|
|
|
|
mixmonitor->mixmonitor_ds->audiohook = NULL;
|
|
|
|
ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
|
|
|
|
}
|
|
|
|
/* kill the audiohook.*/
|
|
|
|
ast_audiohook_lock(&mixmonitor->audiohook);
|
|
|
|
ast_audiohook_detach(&mixmonitor->audiohook);
|
|
|
|
ast_audiohook_unlock(&mixmonitor->audiohook);
|
|
|
|
ast_audiohook_destroy(&mixmonitor->audiohook);
|
|
|
|
}
|
|
|
|
|
2007-08-08 19:30:52 +00:00
|
|
|
static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
2007-08-08 19:30:52 +00:00
|
|
|
struct ast_channel *peer = NULL;
|
|
|
|
int res = 0;
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
if (!chan)
|
|
|
|
return -1;
|
|
|
|
|
2007-08-08 19:30:52 +00:00
|
|
|
ast_audiohook_attach(chan, audiohook);
|
2006-06-12 21:37:29 +00:00
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan)))
|
|
|
|
ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
#define SAMPLES_PER_FRAME 160
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2009-06-17 19:45:35 +00:00
|
|
|
static void mixmonitor_free(struct mixmonitor *mixmonitor)
|
|
|
|
{
|
|
|
|
if (mixmonitor) {
|
|
|
|
if (mixmonitor->mixmonitor_ds) {
|
|
|
|
ast_mutex_destroy(&mixmonitor->mixmonitor_ds->lock);
|
|
|
|
ast_cond_destroy(&mixmonitor->mixmonitor_ds->destruction_condition);
|
|
|
|
ast_free(mixmonitor->mixmonitor_ds);
|
|
|
|
}
|
|
|
|
ast_free(mixmonitor);
|
|
|
|
}
|
|
|
|
}
|
2005-10-28 23:01:13 +00:00
|
|
|
static void *mixmonitor_thread(void *obj)
|
|
|
|
{
|
|
|
|
struct mixmonitor *mixmonitor = obj;
|
2009-06-17 19:45:35 +00:00
|
|
|
struct ast_filestream **fs = NULL;
|
2007-01-22 19:22:07 +00:00
|
|
|
unsigned int oflags;
|
|
|
|
char *ext;
|
|
|
|
int errflag = 0;
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format format_slin;
|
2007-01-22 19:22:07 +00:00
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_format_set(&format_slin, AST_FORMAT_SLINEAR, 0);
|
2007-12-14 14:48:38 +00:00
|
|
|
ast_verb(2, "Begin MixMonitor Recording %s\n", mixmonitor->name);
|
2009-06-17 19:45:35 +00:00
|
|
|
|
|
|
|
fs = &mixmonitor->mixmonitor_ds->fs;
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/* The audiohook must enter and exit the loop locked */
|
|
|
|
ast_audiohook_lock(&mixmonitor->audiohook);
|
2009-06-17 19:45:35 +00:00
|
|
|
while (mixmonitor->audiohook.status == AST_AUDIOHOOK_STATUS_RUNNING && !mixmonitor->mixmonitor_ds->fs_quit) {
|
2007-08-08 19:30:52 +00:00
|
|
|
struct ast_frame *fr = NULL;
|
2005-10-28 23:01:13 +00:00
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if (!(fr = ast_audiohook_read_frame(&mixmonitor->audiohook, SAMPLES_PER_FRAME, AST_AUDIOHOOK_DIRECTION_BOTH, &format_slin))) {
|
2010-04-16 21:22:30 +00:00
|
|
|
ast_audiohook_trigger_wait(&mixmonitor->audiohook);
|
2007-08-08 19:30:52 +00:00
|
|
|
|
2010-04-16 21:22:30 +00:00
|
|
|
if (mixmonitor->audiohook.status != AST_AUDIOHOOK_STATUS_RUNNING) {
|
|
|
|
break;
|
|
|
|
}
|
2007-08-08 19:30:52 +00:00
|
|
|
continue;
|
2010-04-16 21:22:30 +00:00
|
|
|
}
|
2007-08-08 19:30:52 +00:00
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/* audiohook lock is not required for the next block.
|
|
|
|
* Unlock it, but remember to lock it before looping or exiting */
|
|
|
|
ast_audiohook_unlock(&mixmonitor->audiohook);
|
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
if (!ast_test_flag(mixmonitor, MUXFLAG_BRIDGED) || (mixmonitor->autochan->chan && ast_bridged_channel(mixmonitor->autochan->chan))) {
|
2009-06-17 19:45:35 +00:00
|
|
|
ast_mutex_lock(&mixmonitor->mixmonitor_ds->lock);
|
2007-10-31 17:56:21 +00:00
|
|
|
/* Initialize the file if not already done so */
|
2009-06-17 19:45:35 +00:00
|
|
|
if (!*fs && !errflag && !mixmonitor->mixmonitor_ds->fs_quit) {
|
2007-10-31 17:56:21 +00:00
|
|
|
oflags = O_CREAT | O_WRONLY;
|
|
|
|
oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
|
2009-06-17 19:45:35 +00:00
|
|
|
|
2007-10-31 17:56:21 +00:00
|
|
|
if ((ext = strrchr(mixmonitor->filename, '.')))
|
|
|
|
*(ext++) = '\0';
|
|
|
|
else
|
|
|
|
ext = "raw";
|
2009-06-17 19:45:35 +00:00
|
|
|
|
|
|
|
if (!(*fs = ast_writefile(mixmonitor->filename, ext, NULL, oflags, 0, 0666))) {
|
2007-10-31 17:56:21 +00:00
|
|
|
ast_log(LOG_ERROR, "Cannot open %s.%s\n", mixmonitor->filename, ext);
|
|
|
|
errflag = 1;
|
|
|
|
}
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
2009-06-16 18:54:30 +00:00
|
|
|
|
|
|
|
/* Write out the frame(s) */
|
2009-06-17 19:45:35 +00:00
|
|
|
if (*fs) {
|
2009-06-16 18:54:30 +00:00
|
|
|
struct ast_frame *cur;
|
|
|
|
|
|
|
|
for (cur = fr; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
|
2009-06-17 19:45:35 +00:00
|
|
|
ast_writestream(*fs, cur);
|
2009-06-16 18:54:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-17 19:45:35 +00:00
|
|
|
ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
2007-08-08 19:30:52 +00:00
|
|
|
/* All done! free it. */
|
|
|
|
ast_frame_free(fr, 0);
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
ast_audiohook_lock(&mixmonitor->audiohook);
|
2005-10-28 23:01:13 +00:00
|
|
|
}
|
2007-08-08 19:30:52 +00:00
|
|
|
ast_audiohook_unlock(&mixmonitor->audiohook);
|
2005-10-28 23:01:13 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
ast_autochan_destroy(mixmonitor->autochan);
|
2005-10-28 23:01:13 +00:00
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/* Datastore cleanup. close the filestream and wait for ds destruction */
|
2009-06-17 19:45:35 +00:00
|
|
|
ast_mutex_lock(&mixmonitor->mixmonitor_ds->lock);
|
2009-11-19 21:26:21 +00:00
|
|
|
mixmonitor_ds_close_fs(mixmonitor->mixmonitor_ds);
|
2009-06-17 19:45:35 +00:00
|
|
|
if (!mixmonitor->mixmonitor_ds->destruction_ok) {
|
|
|
|
ast_cond_wait(&mixmonitor->mixmonitor_ds->destruction_condition, &mixmonitor->mixmonitor_ds->lock);
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/* kill the audiohook */
|
|
|
|
destroy_monitor_audiohook(mixmonitor);
|
|
|
|
|
|
|
|
if (mixmonitor->post_process) {
|
|
|
|
ast_verb(2, "Executing [%s]\n", mixmonitor->post_process);
|
|
|
|
ast_safe_system(mixmonitor->post_process);
|
|
|
|
}
|
2009-06-17 19:45:35 +00:00
|
|
|
|
|
|
|
ast_verb(2, "End MixMonitor Recording %s\n", mixmonitor->name);
|
|
|
|
mixmonitor_free(mixmonitor);
|
2005-10-16 02:59:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-17 19:45:35 +00:00
|
|
|
static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
struct mixmonitor_ds *mixmonitor_ds;
|
|
|
|
|
|
|
|
if (!(mixmonitor_ds = ast_calloc(1, sizeof(*mixmonitor_ds)))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_mutex_init(&mixmonitor_ds->lock);
|
|
|
|
ast_cond_init(&mixmonitor_ds->destruction_condition, NULL);
|
|
|
|
|
|
|
|
if (!(datastore = ast_datastore_alloc(&mixmonitor_ds_info, NULL))) {
|
|
|
|
ast_mutex_destroy(&mixmonitor_ds->lock);
|
|
|
|
ast_cond_destroy(&mixmonitor_ds->destruction_condition);
|
|
|
|
ast_free(mixmonitor_ds);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
mixmonitor_ds->audiohook = &mixmonitor->audiohook;
|
2009-06-17 19:45:35 +00:00
|
|
|
datastore->data = mixmonitor_ds;
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_channel_datastore_add(chan, datastore);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
mixmonitor->mixmonitor_ds = mixmonitor_ds;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75983 f38db490-d61c-443f-a65b-d21fe96a405b
2007-07-19 23:24:27 +00:00
|
|
|
static void launch_monitor_thread(struct ast_channel *chan, const char *filename, unsigned int flags,
|
2005-10-28 23:01:13 +00:00
|
|
|
int readvol, int writevol, const char *post_process)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
|
|
|
pthread_t thread;
|
2005-10-28 23:01:13 +00:00
|
|
|
struct mixmonitor *mixmonitor;
|
2007-11-13 01:19:53 +00:00
|
|
|
char postprocess2[1024] = "";
|
2006-06-13 13:40:58 +00:00
|
|
|
size_t len;
|
2006-06-12 21:37:29 +00:00
|
|
|
|
2007-01-22 19:22:07 +00:00
|
|
|
len = sizeof(*mixmonitor) + strlen(chan->name) + strlen(filename) + 2;
|
2006-06-13 13:40:58 +00:00
|
|
|
|
2007-11-12 18:44:36 +00:00
|
|
|
postprocess2[0] = 0;
|
2006-06-13 13:40:58 +00:00
|
|
|
/* If a post process system command is given attach it to the structure */
|
|
|
|
if (!ast_strlen_zero(post_process)) {
|
|
|
|
char *p1, *p2;
|
|
|
|
|
|
|
|
p1 = ast_strdupa(post_process);
|
|
|
|
for (p2 = p1; *p2 ; p2++) {
|
|
|
|
if (*p2 == '^' && *(p2+1) == '{') {
|
|
|
|
*p2 = '$';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pbx_substitute_variables_helper(chan, p1, postprocess2, sizeof(postprocess2) - 1);
|
|
|
|
if (!ast_strlen_zero(postprocess2))
|
|
|
|
len += strlen(postprocess2) + 1;
|
2006-06-12 21:37:29 +00:00
|
|
|
}
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2006-06-13 13:40:58 +00:00
|
|
|
/* Pre-allocate mixmonitor structure and spy */
|
2007-06-06 21:20:11 +00:00
|
|
|
if (!(mixmonitor = ast_calloc(1, len))) {
|
2006-06-13 13:40:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
/* Setup the actual spy before creating our thread */
|
|
|
|
if (ast_audiohook_init(&mixmonitor->audiohook, AST_AUDIOHOOK_TYPE_SPY, mixmonitor_spy_type)) {
|
|
|
|
mixmonitor_free(mixmonitor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-12 21:37:29 +00:00
|
|
|
/* Copy over flags and channel name */
|
|
|
|
mixmonitor->flags = flags;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
if (!(mixmonitor->autochan = ast_autochan_setup(chan))) {
|
2009-06-17 19:45:35 +00:00
|
|
|
mixmonitor_free(mixmonitor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setup_mixmonitor_ds(mixmonitor, chan)) {
|
|
|
|
ast_autochan_destroy(mixmonitor->autochan);
|
|
|
|
mixmonitor_free(mixmonitor);
|
2009-02-05 18:34:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-06-13 13:40:58 +00:00
|
|
|
mixmonitor->name = (char *) mixmonitor + sizeof(*mixmonitor);
|
|
|
|
strcpy(mixmonitor->name, chan->name);
|
|
|
|
if (!ast_strlen_zero(postprocess2)) {
|
2007-01-29 23:45:39 +00:00
|
|
|
mixmonitor->post_process = mixmonitor->name + strlen(mixmonitor->name) + strlen(filename) + 2;
|
2006-06-13 13:40:58 +00:00
|
|
|
strcpy(mixmonitor->post_process, postprocess2);
|
|
|
|
}
|
2006-06-12 21:37:29 +00:00
|
|
|
|
2007-01-22 19:22:07 +00:00
|
|
|
mixmonitor->filename = (char *) mixmonitor + sizeof(*mixmonitor) + strlen(chan->name) + 1;
|
|
|
|
strcpy(mixmonitor->filename, filename);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2008-03-12 18:29:33 +00:00
|
|
|
ast_set_flag(&mixmonitor->audiohook, AST_AUDIOHOOK_TRIGGER_SYNC);
|
2007-08-08 19:30:52 +00:00
|
|
|
|
2007-10-31 18:03:17 +00:00
|
|
|
if (readvol)
|
|
|
|
mixmonitor->audiohook.options.read_volume = readvol;
|
|
|
|
if (writevol)
|
|
|
|
mixmonitor->audiohook.options.write_volume = writevol;
|
|
|
|
|
2007-08-08 19:30:52 +00:00
|
|
|
if (startmon(chan, &mixmonitor->audiohook)) {
|
2006-06-12 21:37:29 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to add '%s' spy to channel '%s'\n",
|
2007-08-08 19:30:52 +00:00
|
|
|
mixmonitor_spy_type, chan->name);
|
|
|
|
ast_audiohook_destroy(&mixmonitor->audiohook);
|
2009-08-19 21:21:00 +00:00
|
|
|
mixmonitor_free(mixmonitor);
|
2006-06-12 21:37:29 +00:00
|
|
|
return;
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
2007-05-24 18:30:19 +00:00
|
|
|
ast_pthread_create_detached_background(&thread, NULL, mixmonitor_thread, mixmonitor);
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int mixmonitor_exec(struct ast_channel *chan, const char *data)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
2005-10-28 23:01:13 +00:00
|
|
|
int x, readvol = 0, writevol = 0;
|
2005-10-16 02:59:13 +00:00
|
|
|
struct ast_flags flags = {0};
|
2007-06-24 16:20:18 +00:00
|
|
|
char *parse, *tmp, *slash;
|
2005-10-28 23:01:13 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(filename);
|
|
|
|
AST_APP_ARG(options);
|
|
|
|
AST_APP_ARG(post_process);
|
|
|
|
);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2005-10-28 23:01:13 +00:00
|
|
|
ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n");
|
2005-10-16 02:59:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-05-10 13:22:15 +00:00
|
|
|
parse = ast_strdupa(data);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
if (ast_strlen_zero(args.filename)) {
|
2005-11-04 22:11:51 +00:00
|
|
|
ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n");
|
2005-10-19 18:19:02 +00:00
|
|
|
return -1;
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 16:03:10 +00:00
|
|
|
if (args.options) {
|
2005-11-03 21:19:11 +00:00
|
|
|
char *opts[OPT_ARG_ARRAY_SIZE] = { NULL, };
|
2005-10-28 23:01:13 +00:00
|
|
|
|
2005-11-03 21:19:11 +00:00
|
|
|
ast_app_parse_options(mixmonitor_opts, &flags, opts, args.options);
|
2005-10-28 23:01:13 +00:00
|
|
|
|
|
|
|
if (ast_test_flag(&flags, MUXFLAG_READVOLUME)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
if (ast_strlen_zero(opts[OPT_ARG_READVOLUME])) {
|
2005-10-28 23:01:13 +00:00
|
|
|
ast_log(LOG_WARNING, "No volume level was provided for the heard volume ('v') option.\n");
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if ((sscanf(opts[OPT_ARG_READVOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
ast_log(LOG_NOTICE, "Heard volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_READVOLUME]);
|
2005-10-28 23:01:13 +00:00
|
|
|
} else {
|
|
|
|
readvol = get_volfactor(x);
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
if (ast_test_flag(&flags, MUXFLAG_WRITEVOLUME)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
if (ast_strlen_zero(opts[OPT_ARG_WRITEVOLUME])) {
|
2005-10-28 23:01:13 +00:00
|
|
|
ast_log(LOG_WARNING, "No volume level was provided for the spoken volume ('V') option.\n");
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if ((sscanf(opts[OPT_ARG_WRITEVOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
ast_log(LOG_NOTICE, "Spoken volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_WRITEVOLUME]);
|
2005-10-28 23:01:13 +00:00
|
|
|
} else {
|
|
|
|
writevol = get_volfactor(x);
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-28 23:01:13 +00:00
|
|
|
|
|
|
|
if (ast_test_flag(&flags, MUXFLAG_VOLUME)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
if (ast_strlen_zero(opts[OPT_ARG_VOLUME])) {
|
2005-10-28 23:01:13 +00:00
|
|
|
ast_log(LOG_WARNING, "No volume level was provided for the combined volume ('W') option.\n");
|
2009-08-10 19:20:57 +00:00
|
|
|
} else if ((sscanf(opts[OPT_ARG_VOLUME], "%2d", &x) != 1) || (x < -4) || (x > 4)) {
|
2005-11-03 21:19:11 +00:00
|
|
|
ast_log(LOG_NOTICE, "Combined volume must be a number between -4 and 4, not '%s'\n", opts[OPT_ARG_VOLUME]);
|
2005-10-28 23:01:13 +00:00
|
|
|
} else {
|
|
|
|
readvol = writevol = get_volfactor(x);
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-28 23:01:13 +00:00
|
|
|
|
|
|
|
/* if not provided an absolute path, use the system-configured monitoring directory */
|
|
|
|
if (args.filename[0] != '/') {
|
|
|
|
char *build;
|
|
|
|
|
|
|
|
build = alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(args.filename) + 3);
|
|
|
|
sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, args.filename);
|
|
|
|
args.filename = build;
|
|
|
|
}
|
|
|
|
|
2007-06-24 16:20:18 +00:00
|
|
|
tmp = ast_strdupa(args.filename);
|
|
|
|
if ((slash = strrchr(tmp, '/')))
|
|
|
|
*slash = '\0';
|
|
|
|
ast_mkdir(tmp, 0777);
|
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "MIXMONITOR_FILENAME", args.filename);
|
2007-11-13 16:03:10 +00:00
|
|
|
launch_monitor_thread(chan, args.filename, flags.flags, readvol, writevol, args.post_process);
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2005-10-28 23:01:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
|
2006-02-16 17:37:03 +00:00
|
|
|
{
|
2009-06-17 19:45:35 +00:00
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
|
2009-11-19 21:26:21 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_audiohook_detach_source(chan, mixmonitor_spy_type);
|
2009-06-17 19:45:35 +00:00
|
|
|
if ((datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, NULL))) {
|
2009-11-19 21:26:21 +00:00
|
|
|
struct mixmonitor_ds *mixmonitor_ds = datastore->data;
|
|
|
|
|
|
|
|
ast_mutex_lock(&mixmonitor_ds->lock);
|
|
|
|
|
|
|
|
/* closing the filestream here guarantees the file is avaliable to the dialplan
|
|
|
|
* after calling StopMixMonitor */
|
|
|
|
mixmonitor_ds_close_fs(mixmonitor_ds);
|
|
|
|
|
|
|
|
/* The mixmonitor thread may be waiting on the audiohook trigger.
|
|
|
|
* In order to exit from the mixmonitor loop before waiting on channel
|
|
|
|
* destruction, poke the audiohook trigger. */
|
|
|
|
if (mixmonitor_ds->audiohook) {
|
|
|
|
ast_audiohook_lock(mixmonitor_ds->audiohook);
|
|
|
|
ast_cond_signal(&mixmonitor_ds->audiohook->trigger);
|
|
|
|
ast_audiohook_unlock(mixmonitor_ds->audiohook);
|
|
|
|
mixmonitor_ds->audiohook = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_mutex_unlock(&mixmonitor_ds->lock);
|
|
|
|
|
|
|
|
/* Remove the datastore so the monitor thread can exit */
|
|
|
|
if (!ast_channel_datastore_remove(chan, datastore)) {
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
}
|
2009-06-17 19:45:35 +00:00
|
|
|
}
|
2009-11-19 21:26:21 +00:00
|
|
|
ast_channel_unlock(chan);
|
2009-06-17 19:45:35 +00:00
|
|
|
|
2006-02-16 17:37:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
static char *handle_cli_mixmonitor(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
|
|
|
struct ast_channel *chan;
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
2010-01-05 16:08:12 +00:00
|
|
|
e->command = "mixmonitor {start|stop}";
|
2007-10-11 19:03:06 +00:00
|
|
|
e->usage =
|
|
|
|
"Usage: mixmonitor <start|stop> <chan_name> [args]\n"
|
|
|
|
" The optional arguments are passed to the MixMonitor\n"
|
|
|
|
" application when the 'start' command is used.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc < 3)
|
|
|
|
return CLI_SHOWUSAGE;
|
2005-10-16 02:59:13 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
if (!(chan = ast_channel_get_by_name_prefix(a->argv[2], strlen(a->argv[2])))) {
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_cli(a->fd, "No channel matching '%s' found.\n", a->argv[2]);
|
|
|
|
/* Technically this is a failure, but we don't want 2 errors printing out */
|
|
|
|
return CLI_SUCCESS;
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
if (!strcasecmp(a->argv[1], "start")) {
|
|
|
|
mixmonitor_exec(chan, a->argv[3]);
|
2007-08-08 19:30:52 +00:00
|
|
|
ast_channel_unlock(chan);
|
|
|
|
} else {
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
ast_audiohook_detach_source(chan, mixmonitor_spy_type);
|
|
|
|
}
|
2005-10-28 23:01:13 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
return CLI_SUCCESS;
|
2006-02-16 17:37:03 +00:00
|
|
|
}
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2010-04-21 11:27:27 +00:00
|
|
|
/*! \brief Mute / unmute a MixMonitor channel */
|
|
|
|
static int manager_mute_mixmonitor(struct mansession *s, const struct message *m)
|
|
|
|
{
|
|
|
|
struct ast_channel *c = NULL;
|
|
|
|
|
|
|
|
const char *name = astman_get_header(m, "Channel");
|
|
|
|
const char *id = astman_get_header(m, "ActionID");
|
|
|
|
const char *state = astman_get_header(m, "State");
|
|
|
|
const char *direction = astman_get_header(m,"Direction");
|
|
|
|
|
|
|
|
int clearmute = 1;
|
|
|
|
|
|
|
|
enum ast_audiohook_flags flag;
|
|
|
|
|
|
|
|
if (ast_strlen_zero(direction)) {
|
|
|
|
astman_send_error(s, m, "No direction specified. Must be read, write or both");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(direction, "read")) {
|
|
|
|
flag = AST_AUDIOHOOK_MUTE_READ;
|
|
|
|
} else if (!strcasecmp(direction, "write")) {
|
|
|
|
flag = AST_AUDIOHOOK_MUTE_WRITE;
|
|
|
|
} else if (!strcasecmp(direction, "both")) {
|
|
|
|
flag = AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE;
|
|
|
|
} else {
|
|
|
|
astman_send_error(s, m, "Invalid direction specified. Must be read, write or both");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_strlen_zero(name)) {
|
|
|
|
astman_send_error(s, m, "No channel specified");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_strlen_zero(state)) {
|
|
|
|
astman_send_error(s, m, "No state specified");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearmute = ast_false(state);
|
|
|
|
c = ast_channel_get_by_name(name);
|
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
astman_send_error(s, m, "No such channel");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_audiohook_set_mute(c, mixmonitor_spy_type, flag, clearmute)) {
|
|
|
|
c = ast_channel_unref(c);
|
|
|
|
astman_send_error(s, m, "Cannot set mute flag");
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
astman_append(s, "Response: Success\r\n");
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(id)) {
|
|
|
|
astman_append(s, "ActionID: %s\r\n", id);
|
|
|
|
}
|
|
|
|
|
|
|
|
astman_append(s, "\r\n");
|
|
|
|
|
|
|
|
c = ast_channel_unref(c);
|
|
|
|
|
|
|
|
return AMI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_mixmonitor[] = {
|
2007-10-22 20:05:18 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_mixmonitor, "Execute a MixMonitor command")
|
2005-10-28 23:01:13 +00:00
|
|
|
};
|
2005-10-16 02:59:13 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_unregister_multiple(cli_mixmonitor, ARRAY_LEN(cli_mixmonitor));
|
2006-09-18 19:54:18 +00:00
|
|
|
res = ast_unregister_application(stop_app);
|
2005-10-18 22:52:21 +00:00
|
|
|
res |= ast_unregister_application(app);
|
2010-04-21 11:27:27 +00:00
|
|
|
res |= ast_manager_unregister("MixMonitorMute");
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2005-10-16 02:59:13 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_register_multiple(cli_mixmonitor, ARRAY_LEN(cli_mixmonitor));
|
2008-11-01 21:10:07 +00:00
|
|
|
res = ast_register_application_xml(app, mixmonitor_exec);
|
|
|
|
res |= ast_register_application_xml(stop_app, stop_mixmonitor_exec);
|
2010-04-21 11:27:27 +00:00
|
|
|
res |= ast_manager_register_xml("MixMonitorMute", 0, manager_mute_mixmonitor);
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2005-10-16 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mixed Audio Monitoring Application");
|