ALSA sound card channel driver. More...
#include "asterisk.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <alsa/asoundlib.h>
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/endian.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/musiconhold.h"
#include "asterisk/poll-compat.h"
Go to the source code of this file.
Data Structures | |
struct | chan_alsa_pvt |
Macros | |
#define | ALSA_INDEV "default" |
#define | ALSA_OUTDEV "default" |
#define | ALSA_PCM_NEW_HW_PARAMS_API |
#define | ALSA_PCM_NEW_SW_PARAMS_API |
#define | BUFFER_FMT ((buffersize * 10) << 16) | (0x0006); |
#define | DEBUG 0 |
#define | DESIRED_RATE 8000 |
#define | FRAME_SIZE 160 |
#define | MAX_BUFFER_SIZE 100 |
#define | MIN_SWITCH_TIME 600 |
#define | PERIOD_FRAMES 80 /* 80 Frames, at 2 bytes each */ |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | alsa_answer (struct ast_channel *c) |
static int | alsa_call (struct ast_channel *c, char *dest, int timeout) |
static snd_pcm_t * | alsa_card_init (char *dev, snd_pcm_stream_t stream) |
static int | alsa_digit (struct ast_channel *c, char digit, unsigned int duration) |
static int | alsa_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
static int | alsa_hangup (struct ast_channel *c) |
static int | alsa_indicate (struct ast_channel *chan, int cond, const void *data, size_t datalen) |
static struct ast_channel * | alsa_new (struct chan_alsa_pvt *p, int state, const char *linkedid) |
static struct ast_frame * | alsa_read (struct ast_channel *chan) |
static struct ast_channel * | alsa_request (const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause) |
static int | alsa_text (struct ast_channel *c, const char *text) |
static int | alsa_write (struct ast_channel *chan, struct ast_frame *f) |
static char * | autoanswer_complete (const char *line, const char *word, int pos, int state) |
static char * | console_answer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | console_autoanswer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | console_dial (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | console_hangup (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | console_mute (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | console_sendtext (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | grab_owner (void) |
static int | load_module (void) |
static int | soundcard_init (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "ALSA Console Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, } |
static struct chan_alsa_pvt | alsa |
static struct ast_channel_tech | alsa_tech |
static ast_mutex_t | alsalock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static int | autoanswer = 1 |
static struct ast_cli_entry | cli_alsa [] |
static const char | config [] = "alsa.conf" |
static char | context [AST_MAX_CONTEXT] = "default" |
static struct ast_jb_conf | default_jbconf |
static char | exten [AST_MAX_EXTENSION] = "s" |
static snd_pcm_format_t | format = SND_PCM_FORMAT_S16_BE |
static struct ast_jb_conf | global_jbconf |
static int | hookstate = 0 |
static char | indevname [50] = ALSA_INDEV |
static char | language [MAX_LANGUAGE] = "" |
static char | mohinterpret [MAX_MUSICCLASS] |
static int | mute = 0 |
static int | noaudiocapture = 0 |
static char | outdevname [50] = ALSA_OUTDEV |
static int | readdev = -1 |
static int | silencesuppression = 0 |
static int | silencethreshold = 1000 |
static const char | tdesc [] = "ALSA Console Channel Driver" |
static int | writedev = -1 |
#define ALSA_INDEV "default" |
Definition at line 74 of file chan_alsa.c.
#define ALSA_OUTDEV "default" |
Definition at line 75 of file chan_alsa.c.
#define ALSA_PCM_NEW_HW_PARAMS_API |
Definition at line 43 of file chan_alsa.c.
#define ALSA_PCM_NEW_SW_PARAMS_API |
Definition at line 44 of file chan_alsa.c.
#define BUFFER_FMT ((buffersize * 10) << 16) | (0x0006); |
Definition at line 85 of file chan_alsa.c.
#define DEBUG 0 |
Definition at line 72 of file chan_alsa.c.
#define DESIRED_RATE 8000 |
Definition at line 76 of file chan_alsa.c.
Referenced by alsa_card_init().
#define FRAME_SIZE 160 |
Definition at line 79 of file chan_alsa.c.
Referenced by alsa_read().
#define MAX_BUFFER_SIZE 100 |
Definition at line 128 of file chan_alsa.c.
#define MIN_SWITCH_TIME 600 |
Definition at line 88 of file chan_alsa.c.
#define PERIOD_FRAMES 80 /* 80 Frames, at 2 bytes each */ |
Definition at line 80 of file chan_alsa.c.
Referenced by alsa_card_init().
|
static |
Definition at line 1024 of file chan_alsa.c.
|
static |
Definition at line 1024 of file chan_alsa.c.
|
static |
Definition at line 353 of file chan_alsa.c.
References alsa, alsalock, ast_mutex_lock, ast_mutex_unlock, ast_setstate(), AST_STATE_UP, ast_verbose(), and chan_alsa_pvt::icard.
|
static |
Definition at line 317 of file chan_alsa.c.
References alsa, alsalock, ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_RINGING, AST_FRAME_CONTROL, ast_indicate(), ast_mutex_lock, ast_mutex_unlock, ast_queue_frame(), ast_verbose(), grab_owner(), chan_alsa_pvt::icard, ast_frame_subclass::integer, chan_alsa_pvt::owner, and ast_frame::subclass.
|
static |
Definition at line 165 of file chan_alsa.c.
References ast_alloca, ast_debug, ast_log(), DESIRED_RATE, LOG_ERROR, LOG_WARNING, and PERIOD_FRAMES.
Referenced by soundcard_init().
|
static |
Definition at line 291 of file chan_alsa.c.
References alsalock, ast_mutex_lock, ast_mutex_unlock, and ast_verbose().
|
static |
Definition at line 526 of file chan_alsa.c.
References alsalock, ast_mutex_lock, ast_mutex_unlock, chan_alsa_pvt::owner, and ast_channel::tech_pvt.
|
static |
Definition at line 367 of file chan_alsa.c.
References alsa, alsalock, ast_module_unref(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), chan_alsa_pvt::icard, chan_alsa_pvt::owner, ast_module_info::self, and ast_channel::tech_pvt.
|
static |
Definition at line 537 of file chan_alsa.c.
References alsalock, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), LOG_WARNING, and ast_channel::name.
|
static |
Definition at line 574 of file chan_alsa.c.
References alsa_tech, ast_channel_alloc(), ast_channel_set_fd(), ast_copy_string(), AST_FORMAT_SLINEAR, ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), chan_alsa_pvt::context, ast_channel::context, chan_alsa_pvt::exten, ast_channel::exten, global_jbconf, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, chan_alsa_pvt::owner, ast_channel::readformat, ast_module_info::self, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.
Referenced by alsa_request(), and console_dial().
|
static |
Definition at line 435 of file chan_alsa.c.
References ast_channel::_state, alsa, alsalock, AST_FORMAT_SLINEAR, AST_FRAME_NULL, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_mutex_lock, ast_mutex_unlock, AST_STATE_UP, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_frame::delivery, f, FRAME_SIZE, ast_frame::frametype, chan_alsa_pvt::icard, ast_frame_subclass::integer, LOG_ERROR, ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_frame::samples, ast_frame::src, state, and ast_frame::subclass.
|
static |
Definition at line 607 of file chan_alsa.c.
References alsa, alsa_new(), alsalock, AST_CAUSE_BUSY, AST_FORMAT_SLINEAR, ast_getformatname_multiple(), ast_log(), ast_mutex_lock, ast_mutex_unlock, AST_STATE_DOWN, ast_channel::linkedid, LOG_NOTICE, LOG_WARNING, and chan_alsa_pvt::owner.
|
static |
Definition at line 301 of file chan_alsa.c.
References alsalock, ast_mutex_lock, ast_mutex_unlock, and ast_verbose().
|
static |
Definition at line 383 of file chan_alsa.c.
References alsa, alsalock, ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_frame::data, ast_frame::datalen, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_alsa_pvt::ocard, ast_frame::ptr, and state.
|
static |
Definition at line 632 of file chan_alsa.c.
References ast_strdup, ast_strlen_zero(), and MIN.
Referenced by console_autoanswer().
|
static |
Definition at line 684 of file chan_alsa.c.
References alsa, alsalock, ast_cli_args::argc, ast_channel_unlock, ast_cli(), AST_CONTROL_ANSWER, ast_mutex_lock, ast_mutex_unlock, ast_queue_control(), ast_verbose(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, grab_owner(), chan_alsa_pvt::icard, chan_alsa_pvt::owner, and ast_cli_entry::usage.
|
static |
Definition at line 648 of file chan_alsa.c.
References alsalock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock, ast_mutex_unlock, autoanswer_complete(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
|
static |
Definition at line 817 of file chan_alsa.c.
References alsa, alsa_new(), alsalock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), ast_exists_extension(), AST_FRAME_DTMF, ast_mutex_lock, ast_mutex_unlock, ast_queue_frame(), AST_STATE_RINGING, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, context, chan_alsa_pvt::context, exten, chan_alsa_pvt::exten, ast_cli_args::fd, ast_frame::frametype, chan_alsa_pvt::owner, strsep(), and ast_cli_entry::usage.
|
static |
Definition at line 779 of file chan_alsa.c.
References alsa, alsalock, ast_cli_args::argc, AST_CAUSE_NORMAL_CLEARING, ast_channel_unlock, ast_cli(), ast_mutex_lock, ast_mutex_unlock, ast_queue_hangup_with_cause(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, grab_owner(), chan_alsa_pvt::owner, and ast_cli_entry::usage.
|
static |
Definition at line 882 of file chan_alsa.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
|
static |
Definition at line 730 of file chan_alsa.c.
References alsa, alsalock, ast_cli_args::argc, ast_cli_args::argv, ast_channel_unlock, ast_cli(), AST_CONTROL_ANSWER, AST_FRAME_TEXT, ast_mutex_lock, ast_mutex_unlock, ast_queue_control(), ast_queue_frame(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_frame::data, ast_frame::datalen, ast_cli_args::fd, grab_owner(), chan_alsa_pvt::owner, ast_frame::ptr, and ast_cli_entry::usage.
|
static |
Definition at line 310 of file chan_alsa.c.
References alsa, alsalock, ast_channel_trylock, DEADLOCK_AVOIDANCE, and chan_alsa_pvt::owner.
Referenced by alsa_call(), console_answer(), console_hangup(), and console_sendtext().
|
static |
Definition at line 935 of file chan_alsa.c.
References ARRAY_LEN, ast_channel_register(), ast_cli_register_multiple(), ast_config_destroy(), ast_config_load, ast_copy_string(), ast_jb_read_conf(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_true(), ast_variable_browse(), ast_verb, CONFIG_STATUS_FILEINVALID, global_jbconf, LOG_ERROR, ast_variable::name, ast_variable::next, soundcard_init(), and ast_variable::value.
|
static |
Definition at line 271 of file chan_alsa.c.
References alsa, alsa_card_init(), ast_log(), chan_alsa_pvt::icard, LOG_ERROR, chan_alsa_pvt::ocard, and writedev.
Referenced by load_module().
|
static |
Definition at line 1003 of file chan_alsa.c.
References alsa, ARRAY_LEN, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, chan_alsa_pvt::icard, chan_alsa_pvt::ocard, and chan_alsa_pvt::owner.
|
static |
Definition at line 1024 of file chan_alsa.c.
|
static |
|
static |
Definition at line 149 of file chan_alsa.c.
Referenced by alsa_new().
|
static |
Definition at line 102 of file chan_alsa.c.
Referenced by alsa_answer(), alsa_call(), alsa_digit(), alsa_fixup(), alsa_hangup(), alsa_indicate(), alsa_read(), alsa_request(), alsa_text(), alsa_write(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), and grab_owner().
|
static |
Definition at line 1024 of file chan_alsa.c.
|
static |
Definition at line 134 of file chan_alsa.c.
|
static |
Definition at line 926 of file chan_alsa.c.
|
static |
Definition at line 105 of file chan_alsa.c.
|
static |
Definition at line 107 of file chan_alsa.c.
Referenced by __ast_goto_if_exists(), acf_isexten_exec(), acf_vmcount_exec(), action_atxfer(), action_extensionstate(), action_originate(), action_redirect(), add_peer_mailboxes(), advanced_options(), aji_mwi_cb(), append_mailbox_mapping(), apply_outgoing(), ast_async_goto(), ast_compile_ael2(), ast_event_hash_mwi(), ast_get_enum(), ast_pbx_outgoing_exten(), build_device(), build_peer(), check_access(), check_peer_ok(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_include(), config_parse_variables(), console_dial(), create_addr_from_peer(), disa_exec(), do_bridge_masquerade(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_exec(), dundi_helper(), ebl_callback(), enum_callback(), extenspy_exec(), extstate_read(), feature_attended_transfer(), feature_blind_transfer(), find_label_in_current_db(), get_also_info(), get_cid_name(), get_destination(), gtalk_load_config(), handle_cli_dialplan_remove_extension(), handle_request_bye(), handle_request_invite(), handle_request_options(), handle_request_refer(), has_voicemail(), hint_read(), iax2_call(), iax2_transfer(), inboxcount2(), isexten_function_read(), jingle_load_config(), launch_ha_netscript(), leave_voicemail(), load_config(), local_call(), local_devicestate(), log_exec(), lua_pbx_exec(), lua_register_switches(), lua_sort_extensions(), manager_show_dialplan(), metermaidstate(), mkintf(), notify_message(), orig_exten(), pbx_builtin_background(), pbx_find_extension(), pbx_parseable_goto(), pickup_exec(), play_message(), process_ast_dsp(), pvalGotoSetTarget(), queue_mwi_event(), readexten_exec(), register_exten(), register_peer_exten(), reload_config(), retrydial_exec(), set_peer_defaults(), set_pvt_defaults(), sip_alloc(), sla_build_station(), sla_build_trunk(), socket_process(), store_config_core(), txt_callback(), unistim_send_mwi_to_peer(), unregister_exten(), update_registry(), vm_box_exists(), vmsayname_exec(), and wait_for_answer().
|
static |
Global jitterbuffer configuration - by default, jb is disabled
Definition at line 63 of file chan_alsa.c.
|
static |
Definition at line 109 of file chan_alsa.c.
Referenced by __analog_ss_thread(), __ast_goto_if_exists(), action_atxfer(), action_extensionstate(), action_originate(), action_redirect(), apply_outgoing(), ast_async_goto(), ast_compile_ael2(), ast_context_remove_extension_callerid2(), ast_ivr_menu_run_internal(), ast_merge_contexts_and_delete(), ast_pbx_outgoing_exten(), ast_walk_extension_priorities(), check_access(), check_user_full(), complete_dialplan_remove_extension(), complete_dpreply(), config_parse_variables(), console_dial(), context_used(), copy_plain_file(), create_queue_member(), disa_exec(), expand_gosub_args(), extenspy_exec(), extstate_read(), feature_attended_transfer(), feature_blind_transfer(), find_label_in_current_context(), find_label_in_current_db(), gen_prios(), get_cid_name(), get_destination(), get_rdnis(), gtalk_alloc(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_remove_extension(), handle_debug_dialplan(), handle_request_invite(), handle_show_dialplan(), hint_read(), initreqprep(), isexten_function_read(), leave_voicemail(), linkprio(), local_call(), local_devicestate(), lua_pbx_exec(), lua_sort_extensions(), manager_show_dialplan(), mgcp_ss(), new_iax(), onedigit_goto(), orig_exten(), originate_exec(), osplookup_exec(), pbx_parseable_goto(), pickup_exec(), pri_ss_thread(), pvalGotoSetTarget(), raise_exception(), readexten_exec(), register_verify(), set_pvt_defaults(), sip_new(), sip_request_call(), sla_build_station(), sla_station_destructor(), socket_process(), store_config_core(), transmit_notify_with_mwi(), transmit_register(), update_scoreboard(), and waitstream_core().
|
static |
Definition at line 93 of file chan_alsa.c.
Referenced by acf_sprintf(), acf_strftime(), acf_strptime(), action_originate(), add_codec_to_answer(), ast_codec_pref_getsize(), ast_getformatbyname(), ast_monitor_stop(), ast_openvstream(), ast_parse_allow_disallow(), ast_rtp_lookup_mime_multiple2(), ast_speech_new(), ast_strftime_locale(), build_peer(), build_user(), check_header(), check_header_fmt(), console_request(), create_video_frame(), echo_exec(), file_count_line(), file_read(), file_write(), get_soxmix_format(), handle_saydatetime(), iax2_request(), local_alloc(), map_video_codec(), minivm_notify_exec(), misdn_new(), nbs_request(), phone_request(), process_sdp_a_audio(), reload_config(), sayunixtime_exec(), sendmail(), set_config(), sip_request_call(), socket_process(), start_monitor_action(), start_monitor_exec(), and unistim_request().
|
static |
Definition at line 70 of file chan_alsa.c.
Referenced by alsa_new(), and load_module().
|
static |
Definition at line 112 of file chan_alsa.c.
|
static |
Definition at line 96 of file chan_alsa.c.
|
static |
Definition at line 108 of file chan_alsa.c.
Referenced by __ast_channel_alloc_ap(), agent_new(), ast_do_masquerade(), begin_dial_channel(), build_peer(), check_peer_ok(), console_new(), create_addr_from_peer(), dahdi_new(), findmeexec(), func_channel_write_real(), gtalk_new(), jingle_new(), local_call(), nbs_new(), oss_new(), read_config(), set_peer_defaults(), set_pvt_defaults(), sip_new(), skinny_new(), store_config_core(), tds_load_module(), unistim_new(), and vm_execmain().
|
static |
Definition at line 110 of file chan_alsa.c.
Referenced by build_peer(), check_peer_ok(), create_addr_from_peer(), set_peer_defaults(), set_pvt_defaults(), sip_alloc(), and store_config_core().
|
static |
Definition at line 135 of file chan_alsa.c.
Referenced by ast_console_toggle_mute(), ast_network_puts_mutable(), dahdi_read(), destroy_callback(), dtmf_detect(), func_mute_write(), initialize_mutehook(), manager_mutestream(), mf_detect(), mute_callback(), send_select_output(), and tone_detect().
|
static |
Definition at line 136 of file chan_alsa.c.
|
static |
Definition at line 97 of file chan_alsa.c.
|
static |
Definition at line 131 of file chan_alsa.c.
|
static |
Definition at line 99 of file chan_alsa.c.
|
static |
Definition at line 100 of file chan_alsa.c.
|
static |
Definition at line 104 of file chan_alsa.c.
|
static |
Definition at line 132 of file chan_alsa.c.
Referenced by soundcard_init().