Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions | Variables
channel.c File Reference

Channel Management. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include <sys/time.h>
#include <signal.h>
#include <math.h>
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/mod_format.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/translate.h"
#include "asterisk/manager.h"
#include "asterisk/chanvars.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/causes.h"
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/transcap.h"
#include "asterisk/devicestate.h"
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
#include "asterisk/audiohook.h"
#include "asterisk/framehook.h"
#include "asterisk/timing.h"
#include "asterisk/autochan.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"
#include "asterisk/channel_internal.h"
#include "asterisk/features.h"
#include "asterisk/bridge.h"
#include "asterisk/test.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/max_forwards.h"
#include "asterisk/stream.h"
#include "asterisk/message.h"
Include dependency graph for channel.c:

Go to the source code of this file.

Data Structures

struct  ast_channel_iterator
 
struct  ast_party_id_ies
 
struct  ast_party_name_ies
 
struct  ast_party_number_ies
 
struct  ast_party_redirecting_reason_ies
 
struct  ast_party_subaddress_ies
 
struct  ast_silence_generator
 
struct  backends
 the list of registered channel types More...
 
struct  causes_map
 map AST_CAUSE's to readable string representations More...
 
struct  chanlist
 List of channel drivers. More...
 
struct  external_vars
 
struct  manager_channel_variable
 List of channel variables to append to all channel-related events. More...
 
struct  namedgroup_member
 Named group member structure. More...
 
struct  plc_ds
 
struct  set_format_access
 
struct  suppress_data
 
struct  tonepair_def
 
struct  tonepair_state
 

Macros

#define AST_DEFAULT_EMULATE_DTMF_DURATION   100
 
#define AST_MIN_DTMF_GAP   45
 
#define DEFAULT_AMA_FLAGS   AST_AMA_DOCUMENTATION
 
#define DEFAULT_EMULATE_MF_DURATION   55
 
#define FORMAT   "%-15.15s %-40.40s %-13.13s %-13.13s %-13.13s %-13.13s\n"
 
#define STATE2STR_BUFSIZE   32
 

Enumerations

enum  {
  AST_CONNECTED_LINE_NUMBER, AST_CONNECTED_LINE_NAME, AST_CONNECTED_LINE_NUMBER_PLAN, AST_CONNECTED_LINE_ID_PRESENTATION,
  AST_CONNECTED_LINE_SOURCE, AST_CONNECTED_LINE_SUBADDRESS, AST_CONNECTED_LINE_SUBADDRESS_TYPE, AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
  AST_CONNECTED_LINE_SUBADDRESS_VALID, AST_CONNECTED_LINE_TAG, AST_CONNECTED_LINE_VERSION, AST_CONNECTED_LINE_NAME_VALID,
  AST_CONNECTED_LINE_NAME_CHAR_SET, AST_CONNECTED_LINE_NAME_PRESENTATION, AST_CONNECTED_LINE_NUMBER_VALID, AST_CONNECTED_LINE_NUMBER_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_NUMBER, AST_CONNECTED_LINE_PRIV_NUMBER_PLAN, AST_CONNECTED_LINE_PRIV_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_NAME, AST_CONNECTED_LINE_PRIV_NAME_VALID, AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET, AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_SUBADDRESS, AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE, AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID,
  AST_CONNECTED_LINE_PRIV_TAG
}
 Element identifiers for connected line indication frame data. More...
 
enum  {
  AST_REDIRECTING_FROM_NUMBER, AST_REDIRECTING_FROM_NAME, AST_REDIRECTING_FROM_NUMBER_PLAN, AST_REDIRECTING_FROM_ID_PRESENTATION,
  AST_REDIRECTING_TO_NUMBER, AST_REDIRECTING_TO_NAME, AST_REDIRECTING_TO_NUMBER_PLAN, AST_REDIRECTING_TO_ID_PRESENTATION,
  AST_REDIRECTING_REASON_CODE, AST_REDIRECTING_COUNT, AST_REDIRECTING_FROM_SUBADDRESS, AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
  AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_FROM_SUBADDRESS_VALID, AST_REDIRECTING_TO_SUBADDRESS, AST_REDIRECTING_TO_SUBADDRESS_TYPE,
  AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_TO_SUBADDRESS_VALID, AST_REDIRECTING_FROM_TAG, AST_REDIRECTING_TO_TAG,
  AST_REDIRECTING_VERSION, AST_REDIRECTING_FROM_NAME_VALID, AST_REDIRECTING_FROM_NAME_CHAR_SET, AST_REDIRECTING_FROM_NAME_PRESENTATION,
  AST_REDIRECTING_FROM_NUMBER_VALID, AST_REDIRECTING_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_TO_NAME_VALID, AST_REDIRECTING_TO_NAME_CHAR_SET,
  AST_REDIRECTING_TO_NAME_PRESENTATION, AST_REDIRECTING_TO_NUMBER_VALID, AST_REDIRECTING_TO_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NUMBER,
  AST_REDIRECTING_ORIG_NUMBER_VALID, AST_REDIRECTING_ORIG_NUMBER_PLAN, AST_REDIRECTING_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NAME,
  AST_REDIRECTING_ORIG_NAME_VALID, AST_REDIRECTING_ORIG_NAME_CHAR_SET, AST_REDIRECTING_ORIG_NAME_PRESENTATION, AST_REDIRECTING_ORIG_SUBADDRESS,
  AST_REDIRECTING_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_ORIG_TAG,
  AST_REDIRECTING_ORIG_REASON_CODE, AST_REDIRECTING_PRIV_TO_NUMBER, AST_REDIRECTING_PRIV_TO_NUMBER_PLAN, AST_REDIRECTING_PRIV_TO_NUMBER_VALID,
  AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_TO_NAME, AST_REDIRECTING_PRIV_TO_NAME_VALID, AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET,
  AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION, AST_REDIRECTING_PRIV_TO_SUBADDRESS, AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
  AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_TO_TAG, AST_REDIRECTING_PRIV_FROM_NUMBER, AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN,
  AST_REDIRECTING_PRIV_FROM_NUMBER_VALID, AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NAME, AST_REDIRECTING_PRIV_FROM_NAME_VALID,
  AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET, AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION, AST_REDIRECTING_PRIV_FROM_SUBADDRESS, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE,
  AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_FROM_TAG, AST_REDIRECTING_PRIV_ORIG_NUMBER,
  AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID, AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN, AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NAME,
  AST_REDIRECTING_PRIV_ORIG_NAME_VALID, AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET, AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
  AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_ORIG_TAG,
  AST_REDIRECTING_REASON_STR, AST_REDIRECTING_ORIG_REASON_STR
}
 Element identifiers for redirecting indication frame data. More...
 
enum  DtmfDirection { DTMF_RECEIVED, DTMF_SENT }
 

Functions

int __ast_answer (struct ast_channel *chan, unsigned int delay)
 Answer a channel, with a selectable delay before returning. More...
 
static void __ast_change_name_nolink (struct ast_channel *chan, const char *newname)
 this function simply changes the name of the channel and issues a manager_event with out unlinking and linking the channel from the ao2_container. This should only be used when the channel has already been unlinked from the ao2_container. More...
 
struct ast_channel__ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint, const char *file, int line, const char *function, const char *name_fmt,...)
 Create a channel structure. More...
 
static struct ast_channel__ast_channel_alloc_ap (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint, const char *file, int line, const char *function, const char *name_fmt, va_list ap)
 Create a new channel structure. More...
 
struct ast_channel__ast_dummy_channel_alloc (const char *file, int line, const char *function)
 
static int __ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
 
static struct ast_frame__ast_read (struct ast_channel *chan, int dropaudio, int dropnondefault)
 
struct ast_channel__ast_request_and_dial (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
 Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. More...
 
static void __init_state2str_threadbuf (void)
 
static void adjust_frame_for_plc (struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
 
static void apply_plc (struct ast_channel *chan, struct ast_frame *frame)
 
int ast_activate_generator (struct ast_channel *chan, struct ast_generator *gen, void *params)
 
int ast_active_channels (void)
 returns number of active/allocated channels More...
 
int ast_answer (struct ast_channel *chan)
 Answer a channel. More...
 
int ast_auto_answer (struct ast_channel *chan)
 Answer a channel, if it's not already answered. More...
 
int ast_call (struct ast_channel *chan, const char *addr, int timeout)
 Make a call. More...
 
struct ast_channelast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
 Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated. More...
 
const char * ast_cause2str (int cause)
 Gives the string form of a given hangup cause. More...
 
void ast_change_name (struct ast_channel *chan, const char *newname)
 Change channel name. More...
 
const char * ast_channel_amaflags2string (enum ama_flags flag)
 Convert the enum representation of an AMA flag to a string representation. More...
 
struct ast_channelast_channel_bridge_peer (struct ast_channel *chan)
 Get the channel's bridge peer only if the bridge is two-party. More...
 
static int ast_channel_by_exten_cb (void *obj, void *arg, void *data, int flags)
 
static int ast_channel_by_name_cb (void *obj, void *arg, void *data, int flags)
 
static int ast_channel_by_uniqueid_cb (void *obj, void *arg, void *data, int flags)
 
struct ast_channelast_channel_callback (ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
 Call a function with every active channel. More...
 
int ast_channel_cc_params_init (struct ast_channel *chan, const struct ast_cc_config_params *base_params)
 Set up datastore with CCSS parameters for a channel. More...
 
void ast_channel_clear_flag (struct ast_channel *chan, unsigned int flag)
 
void ast_channel_clear_softhangup (struct ast_channel *chan, int flag)
 Clear a set of softhangup flags from a channel. More...
 
static int ast_channel_cmp_cb (void *obj, void *arg, int flags)
 
int ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval offset)
 Compare a offset with when to hangup channel. More...
 
int ast_channel_connected_line_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int is_frame)
 Run a connected line interception macro and update a channel's connected line information. More...
 
int ast_channel_connected_line_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
 Run a connected line interception subroutine and update a channel's connected line information. More...
 
int ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore)
 Add a datastore to a channel. More...
 
struct ast_datastoreast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
 Find a datastore on a channel. More...
 
int ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to)
 Inherit datastores from a parent to a child. More...
 
int ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore)
 Remove a datastore from a channel. More...
 
int ast_channel_defer_dtmf (struct ast_channel *chan)
 Set defer DTMF flag on channel. More...
 
static void ast_channel_destructor (void *obj)
 Free a channel structure. More...
 
int ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Bridge two channels together (early) More...
 
void ast_channel_end_dtmf (struct ast_channel *chan, char digit, struct timeval start, const char *why)
 Simulate a DTMF end on a broken bridge channel. More...
 
enum ast_channel_error ast_channel_errno (void)
 Get error code for latest channel operation. More...
 
int ast_channel_feature_hooks_append (struct ast_channel *chan, struct ast_bridge_features *features)
 Appends to the channel-attached features a channel has access to upon being bridged. More...
 
struct ast_bridge_featuresast_channel_feature_hooks_get (struct ast_channel *chan)
 Gets the channel-attached features a channel has access to upon being bridged. More...
 
int ast_channel_feature_hooks_replace (struct ast_channel *chan, struct ast_bridge_features *features)
 Sets the channel-attached features a channel has access to upon being bridged. More...
 
struct varsheadast_channel_get_ari_vars (struct ast_channel *chan)
 Gets the variables for a given channel, as specified by ast_channel_set_ari_vars(). More...
 
struct ast_bridgeast_channel_get_bridge (const struct ast_channel *chan)
 Get the bridge associated with a channel. More...
 
struct ast_bridge_channelast_channel_get_bridge_channel (struct ast_channel *chan)
 Get a reference to the channel's bridge pointer. More...
 
struct ast_channelast_channel_get_by_exten (const char *exten, const char *context)
 Find a channel by extension and context. More...
 
struct ast_channelast_channel_get_by_name (const char *name)
 Find a channel by name. More...
 
struct ast_channelast_channel_get_by_name_prefix (const char *name, size_t name_len)
 Find a channel by a name prefix. More...
 
int ast_channel_get_cc_agent_type (struct ast_channel *chan, char *agent_type, size_t size)
 Find the appropriate CC agent type to use given a channel. More...
 
struct ast_cc_config_paramsast_channel_get_cc_config_params (struct ast_channel *chan)
 Get the CCSS parameters from a channel. More...
 
int ast_channel_get_device_name (struct ast_channel *chan, char *device_name, size_t name_buffer_length)
 Get a device name given its channel structure. More...
 
int ast_channel_get_duration (struct ast_channel *chan)
 Obtain how long the channel since the channel was created. More...
 
int64_t ast_channel_get_duration_ms (struct ast_channel *chan)
 Obtain how long it's been, in milliseconds, since the channel was created. More...
 
int ast_channel_get_intercept_mode (void)
 Am I currently running an intercept dialplan routine. More...
 
struct varsheadast_channel_get_manager_vars (struct ast_channel *chan)
 Gets the variables for a given channel, as specified by ast_channel_set_manager_vars(). More...
 
int ast_channel_get_up_time (struct ast_channel *chan)
 Obtain how long it has been since the channel was answered. More...
 
int64_t ast_channel_get_up_time_ms (struct ast_channel *chan)
 Obtain how long it has been since the channel was answered in ms. More...
 
struct varsheadast_channel_get_vars (struct ast_channel *chan)
 Gets the variables for a given channel, as set using pbx_builtin_setvar_helper(). More...
 
void ast_channel_hangupcause_hash_set (struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
 Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel. More...
 
int ast_channel_has_ari_vars (void)
 Return whether or not any ARI variables have been set. More...
 
int ast_channel_has_audio_frame_or_monitor (struct ast_channel *chan)
 Check if the channel has active audiohooks, active framehooks, or a monitor. More...
 
int ast_channel_has_hook_requiring_audio (struct ast_channel *chan)
 Check if the channel has any active hooks that require audio. More...
 
int ast_channel_has_manager_vars (void)
 Return whether or not any manager variables have been set. More...
 
static int ast_channel_hash_cb (const void *obj, const int flags)
 
void ast_channel_inherit_variables (const struct ast_channel *parent, struct ast_channel *child)
 Inherits channel variable from parent to child channel. More...
 
int ast_channel_is_bridged (const struct ast_channel *chan)
 Determine if a channel is in a bridge. More...
 
int ast_channel_is_leaving_bridge (struct ast_channel *chan)
 Determine if a channel is leaving a bridge, but not hung up. More...
 
struct ast_channel_iteratorast_channel_iterator_all_new (void)
 Create a new channel iterator. More...
 
struct ast_channel_iteratorast_channel_iterator_by_exten_new (const char *exten, const char *context)
 Create a new channel iterator based on extension. More...
 
struct ast_channel_iteratorast_channel_iterator_by_name_new (const char *name, size_t name_len)
 Create a new channel iterator based on name. More...
 
struct ast_channel_iteratorast_channel_iterator_destroy (struct ast_channel_iterator *i)
 Destroy a channel iterator. More...
 
struct ast_channelast_channel_iterator_next (struct ast_channel_iterator *i)
 Get the next channel for a channel iterator. More...
 
int ast_channel_make_compatible (struct ast_channel *chan, struct ast_channel *peer)
 Make the frame formats of two channels compatible. More...
 
static int ast_channel_make_compatible_helper (struct ast_channel *from, struct ast_channel *to)
 Set up translation from one channel to another. More...
 
int ast_channel_move (struct ast_channel *dest, struct ast_channel *source)
 Move a channel from its current location to a new location. More...
 
void ast_channel_name_to_dial_string (char *channel_name)
 Removes the trailing identifiers from a channel name string. More...
 
int ast_channel_queryoption (struct ast_channel *chan, int option, void *data, int *datalen, int block)
 Checks the value of an option. More...
 
void ast_channel_queue_connected_line_update (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Queue a connected line update frame on a channel. More...
 
void ast_channel_queue_redirecting_update (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Queue a redirecting update frame on a channel. More...
 
const char * ast_channel_reason2str (int reason)
 return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument More...
 
int ast_channel_redirecting_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame)
 Run a redirecting interception macro and update a channel's redirecting information. More...
 
int ast_channel_redirecting_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
 Run a redirecting interception subroutine and update a channel's redirecting information. More...
 
int ast_channel_register (const struct ast_channel_tech *tech)
 Register a new telephony channel in Asterisk. More...
 
struct ast_channelast_channel_release (struct ast_channel *chan)
 Unlink and release reference to a channel. More...
 
void ast_channel_req_accountcodes (struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
 Setup new channel accountcodes from the requestor channel after ast_request(). More...
 
void ast_channel_req_accountcodes_precious (struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
 Setup new channel accountcodes from the requestor channel after ast_request(). More...
 
int ast_channel_request_stream_topology_change (struct ast_channel *chan, struct ast_stream_topology *topology, void *change_source)
 Request that the stream topology of a channel change. More...
 
int ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen)
 Sends HTML on given channel Send HTML or URL on link. More...
 
int ast_channel_sendurl (struct ast_channel *chan, const char *url)
 Sends a URL on a given link Send URL on link. More...
 
void ast_channel_set_ari_vars (size_t varc, char **vars)
 Sets the variables to be stored in the ari_vars field of all snapshots. More...
 
void ast_channel_set_caller (struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 Set the caller id information in the Asterisk channel. More...
 
void ast_channel_set_caller_event (struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name or number changed. More...
 
void ast_channel_set_connected_line (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Set the connected line information in the Asterisk channel. More...
 
void ast_channel_set_fd (struct ast_channel *chan, int which, int fd)
 
void ast_channel_set_flag (struct ast_channel *chan, unsigned int flag)
 Set a flag on a channel. More...
 
void ast_channel_set_manager_vars (size_t varc, char **vars)
 Sets the variables to be stored in the manager_vars field of all snapshots. More...
 
void ast_channel_set_redirecting (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Set the redirecting id information in the Asterisk channel. More...
 
int ast_channel_setoption (struct ast_channel *chan, int option, void *data, int datalen, int block)
 Sets an option on a channel. More...
 
void ast_channel_setwhentohangup_tv (struct ast_channel *chan, struct timeval offset)
 Set when to hangup channel. More...
 
static int ast_channel_softhangup_cb (void *obj, void *arg, int flags)
 
void ast_channel_softhangup_withcause_locked (struct ast_channel *chan, int causecode)
 Lock the given channel, then request softhangup on the channel with the given causecode. More...
 
struct ast_silence_generatorast_channel_start_silence_generator (struct ast_channel *chan)
 Starts a silence generator on the given channel. More...
 
void ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state)
 Stops a previously-started silence generator on the given channel. More...
 
int ast_channel_stream_topology_changed (struct ast_channel *chan, struct ast_stream_topology *topology)
 Provide notice to a channel that the stream topology has changed. More...
 
int ast_channel_stream_topology_changed_externally (struct ast_channel *chan)
 Provide notice from a channel that the topology has changed on it as a result of the remote party renegotiating. More...
 
enum ama_flags ast_channel_string2amaflag (const char *flag)
 Convert a string to a detail record AMA flag. More...
 
int ast_channel_supports_html (struct ast_channel *chan)
 Checks for HTML support on a channel. More...
 
int ast_channel_suppress (struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
 Suppress passing of a frame type on a channel. More...
 
void ast_channel_undefer_dtmf (struct ast_channel *chan)
 Unset defer DTMF flag on channel. More...
 
void ast_channel_unlink (struct ast_channel *chan)
 Remove a channel from the global channels container. More...
 
void ast_channel_unregister (const struct ast_channel_tech *tech)
 Unregister channel driver. More...
 
int ast_channel_unsuppress (struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
 Stop suppressing of a frame type on a channel. More...
 
void ast_channel_update_connected_line (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Indicate that the connected line information has changed. More...
 
void ast_channel_update_redirecting (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Indicate that the redirecting id has changed. More...
 
struct ast_channelast_channel_yank (struct ast_channel *yankee)
 Gain control of a channel in the system. More...
 
int ast_channels_init (void)
 
struct ast_variableast_channeltype_list (void)
 return an ast_variable list of channeltypes More...
 
int ast_check_hangup (struct ast_channel *chan)
 Checks to see if a channel is needing hang up. More...
 
int ast_check_hangup_locked (struct ast_channel *chan)
 
int ast_connected_line_build_data (unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Build the connected line information data frame. More...
 
void ast_connected_line_copy_from_caller (struct ast_party_connected_line *dest, const struct ast_party_caller *src)
 Copy the caller information to the connected line information. More...
 
void ast_connected_line_copy_to_caller (struct ast_party_caller *dest, const struct ast_party_connected_line *src)
 Copy the connected line information to the caller information. More...
 
int ast_connected_line_parse_data (const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
 Parse connected line indication frame data. More...
 
void ast_deactivate_generator (struct ast_channel *chan)
 
static void ast_dummy_channel_destructor (void *obj)
 Free a dummy channel structure. More...
 
const struct ast_channel_techast_get_channel_tech (const char *name)
 Get handle to channel driver based on name. More...
 
ast_group_t ast_get_group (const char *s)
 
struct ast_namedgroups * ast_get_namedgroups (const char *s)
 Create an ast_namedgroups set with group names from comma separated string. More...
 
void ast_hangup (struct ast_channel *chan)
 Hangup a channel. More...
 
int ast_indicate (struct ast_channel *chan, int condition)
 Indicates condition of channel. More...
 
int ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen)
 Indicates condition of channel, with payload. More...
 
void ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *))
 
int ast_is_deferrable_frame (const struct ast_frame *frame)
 Should we keep this frame for later? More...
 
void ast_moh_cleanup (struct ast_channel *chan)
 
int ast_moh_start (struct ast_channel *chan, const char *mclass, const char *interpclass)
 Turn on music on hold on a given channel. More...
 
void ast_moh_stop (struct ast_channel *chan)
 Turn off music on hold on a given channel. More...
 
int ast_namedgroups_intersect (struct ast_namedgroups *a, struct ast_namedgroups *b)
 Return TRUE if group a and b contain at least one common groupname. More...
 
void ast_party_caller_copy (struct ast_party_caller *dest, const struct ast_party_caller *src)
 Copy the source caller information to the destination caller. More...
 
void ast_party_caller_free (struct ast_party_caller *doomed)
 Destroy the caller party contents. More...
 
void ast_party_caller_init (struct ast_party_caller *init)
 Initialize the given caller structure. More...
 
void ast_party_caller_set (struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update)
 Set the caller information based on another caller source. More...
 
void ast_party_caller_set_init (struct ast_party_caller *init, const struct ast_party_caller *guide)
 Initialize the given caller structure using the given guide for a set update operation. More...
 
void ast_party_connected_line_collect_caller (struct ast_party_connected_line *connected, struct ast_party_caller *caller)
 Collect the caller party information into a connected line structure. More...
 
void ast_party_connected_line_copy (struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
 Copy the source connected line information to the destination connected line. More...
 
void ast_party_connected_line_free (struct ast_party_connected_line *doomed)
 Destroy the connected line information contents. More...
 
void ast_party_connected_line_init (struct ast_party_connected_line *init)
 Initialize the given connected line structure. More...
 
void ast_party_connected_line_set (struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
 Set the connected line information based on another connected line source. More...
 
void ast_party_connected_line_set_init (struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
 Initialize the given connected line structure using the given guide for a set update operation. More...
 
void ast_party_dialed_copy (struct ast_party_dialed *dest, const struct ast_party_dialed *src)
 Copy the source dialed party information to the destination dialed party. More...
 
void ast_party_dialed_free (struct ast_party_dialed *doomed)
 Destroy the dialed party contents. More...
 
void ast_party_dialed_init (struct ast_party_dialed *init)
 Initialize the given dialed structure. More...
 
void ast_party_dialed_set (struct ast_party_dialed *dest, const struct ast_party_dialed *src)
 Set the dialed information based on another dialed source. More...
 
void ast_party_dialed_set_init (struct ast_party_dialed *init, const struct ast_party_dialed *guide)
 Initialize the given dialed structure using the given guide for a set update operation. More...
 
void ast_party_id_copy (struct ast_party_id *dest, const struct ast_party_id *src)
 Copy the source party id information to the destination party id. More...
 
void ast_party_id_free (struct ast_party_id *doomed)
 Destroy the party id contents. More...
 
void ast_party_id_init (struct ast_party_id *init)
 Initialize the given party id structure. More...
 
void ast_party_id_invalidate (struct ast_party_id *id)
 Invalidate all components of the given party id. More...
 
struct ast_party_id ast_party_id_merge (struct ast_party_id *base, struct ast_party_id *overlay)
 Merge a given party id into another given party id. More...
 
void ast_party_id_merge_copy (struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay)
 Copy a merge of a given party id into another given party id to a given destination party id. More...
 
int ast_party_id_presentation (const struct ast_party_id *id)
 Determine the overall presentation value for the given party. More...
 
void ast_party_id_reset (struct ast_party_id *id)
 Destroy and initialize the given party id structure. More...
 
void ast_party_id_set (struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update)
 Set the source party id information into the destination party id. More...
 
void ast_party_id_set_init (struct ast_party_id *init, const struct ast_party_id *guide)
 Initialize the given party id structure using the given guide for a set update operation. More...
 
void ast_party_name_copy (struct ast_party_name *dest, const struct ast_party_name *src)
 Copy the source party name information to the destination party name. More...
 
void ast_party_name_free (struct ast_party_name *doomed)
 Destroy the party name contents. More...
 
void ast_party_name_init (struct ast_party_name *init)
 Initialize the given name structure. More...
 
void ast_party_name_set (struct ast_party_name *dest, const struct ast_party_name *src)
 Set the source party name information into the destination party name. More...
 
void ast_party_name_set_init (struct ast_party_name *init, const struct ast_party_name *guide)
 Initialize the given party name structure using the given guide for a set update operation. More...
 
void ast_party_number_copy (struct ast_party_number *dest, const struct ast_party_number *src)
 Copy the source party number information to the destination party number. More...
 
void ast_party_number_free (struct ast_party_number *doomed)
 Destroy the party number contents. More...
 
void ast_party_number_init (struct ast_party_number *init)
 Initialize the given number structure. More...
 
void ast_party_number_set (struct ast_party_number *dest, const struct ast_party_number *src)
 Set the source party number information into the destination party number. More...
 
void ast_party_number_set_init (struct ast_party_number *init, const struct ast_party_number *guide)
 Initialize the given party number structure using the given guide for a set update operation. More...
 
void ast_party_redirecting_copy (struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
 Copy the source redirecting information to the destination redirecting. More...
 
void ast_party_redirecting_free (struct ast_party_redirecting *doomed)
 Destroy the redirecting information contents. More...
 
void ast_party_redirecting_init (struct ast_party_redirecting *init)
 Initialize the given redirecting structure. More...
 
void ast_party_redirecting_reason_copy (struct ast_party_redirecting_reason *dest, const struct ast_party_redirecting_reason *src)
 Copy the source redirecting reason information to the destination redirecting reason. More...
 
void ast_party_redirecting_reason_free (struct ast_party_redirecting_reason *doomed)
 Destroy the redirecting reason contents. More...
 
void ast_party_redirecting_reason_init (struct ast_party_redirecting_reason *init)
 Initialize the given redirecting reason structure. More...
 
void ast_party_redirecting_reason_set (struct ast_party_redirecting_reason *dest, const struct ast_party_redirecting_reason *src)
 Set the redirecting reason information based on another redirecting reason source. More...
 
void ast_party_redirecting_reason_set_init (struct ast_party_redirecting_reason *init, const struct ast_party_redirecting_reason *guide)
 Initialize the given redirecting reason structure using the given guide for a set update operation. More...
 
void ast_party_redirecting_set (struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update)
 Set the redirecting information based on another redirecting source. More...
 
void ast_party_redirecting_set_init (struct ast_party_redirecting *init, const struct ast_party_redirecting *guide)
 Initialize the given redirecting id structure using the given guide for a set update operation. More...
 
void ast_party_subaddress_copy (struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
 Copy the source party subaddress information to the destination party subaddress. More...
 
void ast_party_subaddress_free (struct ast_party_subaddress *doomed)
 Destroy the party subaddress contents. More...
 
void ast_party_subaddress_init (struct ast_party_subaddress *init)
 Initialize the given subaddress structure. More...
 
void ast_party_subaddress_set (struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
 Set the source party subaddress information into the destination party subaddress. More...
 
void ast_party_subaddress_set_init (struct ast_party_subaddress *init, const struct ast_party_subaddress *guide)
 Initialize the given party subaddress structure using the given guide for a set update operation. More...
 
int ast_pre_call (struct ast_channel *chan, const char *sub_args)
 Execute a Gosub call on the channel before a call is placed. More...
 
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 Print call group and pickup group —. More...
 
char * ast_print_namedgroups (struct ast_str **buf, struct ast_namedgroups *group)
 Print named call groups and named pickup groups. More...
 
int ast_prod (struct ast_channel *chan)
 Send empty audio to prime a channel driver. More...
 
int ast_queue_answer (struct ast_channel *chan, const struct ast_stream_topology *topology)
 Queue an ANSWER control frame with topology. More...
 
int ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control)
 Queue a control frame. More...
 
int ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame with payload. More...
 
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to a channel's frame queue. More...
 
int ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to the head of a channel's frame queue. More...
 
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame for channel. More...
 
int ast_queue_hangup_with_cause (struct ast_channel *chan, int cause)
 Queue a hangup frame for channel. More...
 
int ast_queue_hold (struct ast_channel *chan, const char *musicclass)
 Queue a hold frame. More...
 
int ast_queue_unhold (struct ast_channel *chan)
 Queue an unhold frame. More...
 
int ast_raw_answer (struct ast_channel *chan)
 Answer a channel. More...
 
int ast_raw_answer_with_stream_topology (struct ast_channel *chan, struct ast_stream_topology *topology)
 Answer a channel passing in a stream topology. More...
 
struct ast_frameast_read (struct ast_channel *chan)
 Reads a frame. More...
 
static void ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f)
 
struct ast_frameast_read_noaudio (struct ast_channel *chan)
 Reads a frame, returning AST_FRAME_NULL frame if audio. More...
 
struct ast_frameast_read_stream (struct ast_channel *chan)
 Reads a frame, but does not filter to just the default streams. More...
 
struct ast_frameast_read_stream_noaudio (struct ast_channel *chan)
 Reads a frame, but does not filter to just the default streams, returning AST_FRAME_NULL frame if audio. More...
 
int ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
 Reads multiple digits. More...
 
int ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
 
int ast_recvchar (struct ast_channel *chan, int timeout)
 Receives a text character from a channel. More...
 
char * ast_recvtext (struct ast_channel *chan, int timeout)
 Receives a text string from a channel Read a string of text from a channel. More...
 
int ast_redirecting_build_data (unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Build the redirecting id data frame. More...
 
int ast_redirecting_parse_data (const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting)
 Parse redirecting indication frame data. More...
 
struct ast_namedgroups * ast_ref_namedgroups (struct ast_namedgroups *groups)
 
struct ast_channelast_request (const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
 Requests a channel. More...
 
struct ast_channelast_request_and_dial (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cidnum, const char *cidname)
 Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. More...
 
struct ast_channelast_request_with_stream_topology (const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
 Requests a channel (specifying stream topology) More...
 
int ast_safe_sleep (struct ast_channel *chan, int ms)
 Wait, look for hangups. More...
 
int ast_safe_sleep_conditional (struct ast_channel *chan, int timeout_ms, int(*cond)(void *), void *data)
 Wait for a specified amount of time, looking for hangups and a condition argument. More...
 
int ast_safe_sleep_without_silence (struct ast_channel *chan, int ms)
 Wait for a specified amount of time, looking for hangups, and do not generate silence. More...
 
int ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
 function to pronounce character and phonetic strings More...
 
int ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
 says digits of a string More...
 
int ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang)
 says digits More...
 
int ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
 Same as ast_say_digits() with audiofd for received audio and returns 1 on ctrlfd being readable. More...
 
int ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
 says an enumeration More...
 
int ast_say_money_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
 function to pronounce monetary amounts More...
 
int ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
 says a number More...
 
int ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
 
int ast_senddigit (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel. More...
 
int ast_senddigit_begin (struct ast_channel *chan, char digit)
 Send a DTMF digit to a channel. More...
 
int ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel. More...
 
int ast_senddigit_external (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel from an external thread. More...
 
int ast_senddigit_mf (struct ast_channel *chan, char digit, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
 Send an MF digit to a channel. More...
 
int ast_senddigit_mf_begin (struct ast_channel *chan, char digit)
 Send an MF digit to a channel. More...
 
int ast_senddigit_mf_end (struct ast_channel *chan)
 End sending an MF digit to a channel. More...
 
int ast_sendtext (struct ast_channel *chan, const char *text)
 Sends text to a channel. More...
 
int ast_sendtext_data (struct ast_channel *chan, struct ast_msg_data *msg)
 Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback. More...
 
void ast_set_callerid (struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
 Set caller ID number, name and ANI and generate AMI event. More...
 
void ast_set_hangupsource (struct ast_channel *chan, const char *source, int force)
 Set the source of the hangup in this channel and it's bridge. More...
 
void ast_set_party_id_all (struct ast_set_party_id *update_id)
 Set the update marker to update all information of a corresponding party id. More...
 
int ast_set_read_format (struct ast_channel *chan, struct ast_format *format)
 Sets read format on channel chan. More...
 
int ast_set_read_format_from_cap (struct ast_channel *chan, struct ast_format_cap *cap)
 Sets read format on channel chan from capabilities Set read format for channel to whichever component of "format" is best. More...
 
int ast_set_read_format_path (struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
 Set specific read path on channel. More...
 
void ast_set_variables (struct ast_channel *chan, struct ast_variable *vars)
 adds a list of channel variables to a channel More...
 
int ast_set_write_format (struct ast_channel *chan, struct ast_format *format)
 Sets write format on channel chan. More...
 
int ast_set_write_format_from_cap (struct ast_channel *chan, struct ast_format_cap *cap)
 Sets write format on channel chan Set write format for channel to whichever component of "format" is best. More...
 
int ast_set_write_format_interleaved_stereo (struct ast_channel *chan, struct ast_format *format)
 Sets write format for a channel. All internal data will than be handled in an interleaved format. (needed by binaural opus) More...
 
int ast_set_write_format_path (struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format)
 Set specific write path on channel. More...
 
int ast_setstate (struct ast_channel *chan, enum ast_channel_state state)
 Change the state of a channel. More...
 
int ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
 Enable or disable timer ticks for a channel. More...
 
int ast_settimeout_full (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data, unsigned int is_ao2_obj)
 
int ast_softhangup (struct ast_channel *chan, int cause)
 Softly hangup a channel, lock. More...
 
void ast_softhangup_all (void)
 Soft hangup all active channels. More...
 
int ast_softhangup_nolock (struct ast_channel *chan, int cause)
 Softly hangup a channel, don't lock. More...
 
const char * ast_state2str (enum ast_channel_state state)
 Gives the string form of a given channel state. More...
 
int ast_str2cause (const char *name)
 Convert a symbolic hangup cause to number. More...
 
 AST_THREADSTORAGE_RAW (in_intercept_routine)
 
int ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
 
int ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
 
void ast_tonepair_stop (struct ast_channel *chan)
 
int ast_transfer (struct ast_channel *chan, char *dest)
 Transfer a call to dest, if the channel supports transfer. More...
 
int ast_transfer_protocol (struct ast_channel *chan, char *dest, int *protocol)
 Transfer a call to dest, if the channel supports transfer. More...
 
char * ast_transfercapability2str (int transfercapability)
 Gives the string form of a given transfer capability. More...
 
int ast_undestroyed_channels (void)
 
void ast_uninstall_music_functions (void)
 
struct ast_namedgroups * ast_unref_namedgroups (struct ast_namedgroups *groups)
 
int ast_waitfor (struct ast_channel *c, int ms)
 Wait for input on a channel. More...
 
struct ast_channelast_waitfor_n (struct ast_channel **c, int n, int *ms)
 Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds. More...
 
int ast_waitfor_n_fd (int *fds, int n, int *ms, int *exception)
 Wait for x amount of time on a file descriptor to have input. More...
 
struct ast_channelast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
 Wait for x amount of time on a file descriptor to have input. More...
 
int ast_waitfordigit (struct ast_channel *c, int ms)
 Waits for a digit. More...
 
int ast_waitfordigit_full (struct ast_channel *c, int timeout_ms, const char *breakon, int audiofd, int cmdfd)
 Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. More...
 
int ast_write (struct ast_channel *chan, struct ast_frame *fr)
 Write a frame to a channel This function writes the given frame to the indicated channel. More...
 
int ast_write_stream (struct ast_channel *chan, int stream_num, struct ast_frame *fr)
 Write a frame to a stream This function writes the given frame to the indicated stream on the channel. More...
 
int ast_write_video (struct ast_channel *chan, struct ast_frame *fr)
 Write video frame to a channel This function writes the given frame to the indicated channel. More...
 
static int calc_monitor_jump (int samples, int sample_rate, int seek_rate)
 calculates the number of samples to jump forward with in a monitor stream. More...
 
static void call_forward_inherit (struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
 
static void * channel_cc_params_copy (void *data)
 
static void channel_cc_params_destroy (void *data)
 
static void channel_do_masquerade (struct ast_channel *original, struct ast_channel *clonechan)
 Masquerade a channel. More...
 
static int channel_feature_hooks_set_full (struct ast_channel *chan, struct ast_bridge_features *features, int replace)
 
static struct varsheadchannel_get_external_vars (struct external_vars *channelvars, struct ast_channel *chan)
 
static int channel_has_external_vars (struct external_vars *channelvars)
 
static void channel_req_accountcodes (struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship, int precious)
 
static void channel_set_external_vars (struct external_vars *channelvars, size_t varc, char **vars)
 
static void channel_set_intercept_mode (int in_intercept_mode)
 
static void channels_shutdown (void)
 
static void clone_variables (struct ast_channel *original, struct ast_channel *clonechan)
 Clone channel variables from 'clone' channel into 'original' channel. More...
 
static char * complete_channeltypes (struct ast_cli_args *a)
 
static void deactivate_generator_nolock (struct ast_channel *chan)
 
static int deactivate_silence_generator (struct ast_channel *chan)
 
static void destroy_hooks (struct ast_channel *chan)
 
static int does_id_conflict (const char *uniqueid)
 
static const char * dtmf_direction_to_string (enum DtmfDirection direction)
 
static void features_destroy (void *obj)
 
static void free_external_channelvars (struct external_vars *channelvars)
 
static void free_translation (struct ast_channel *clonechan)
 
static int generator_force (const void *data)
 
static void generator_write_format_change (struct ast_channel *chan)
 
static void handle_cause (int cause, int *outstate)
 
static char * handle_cli_core_show_channeltype (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show details about a channel driver - CLI command. More...
 
static char * handle_cli_core_show_channeltypes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show channel types - CLI command. More...
 
static int indicate_connected_line (struct ast_channel *chan, const void *data, size_t datalen)
 
static int indicate_data_internal (struct ast_channel *chan, int _condition, const void *data, size_t datalen)
 
static int indicate_redirecting (struct ast_channel *chan, const void *data, size_t datalen)
 
static int attribute_const is_visible_indication (enum ast_control_frame_type condition)
 
static struct ast_framekill_exception (struct ast_channel *chan)
 
static int kill_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
 
static int kill_hangup (struct ast_channel *chan)
 
static struct ast_framekill_read (struct ast_channel *chan)
 
static int kill_write (struct ast_channel *chan, struct ast_frame *frame)
 
static int namedgroup_cmp_cb (void *obj, void *arg, int flags)
 Comparison function used for named group container. More...
 
static int namedgroup_hash_cb (const void *obj, const int flags)
 Hashing function used for named group container. More...
 
static int namedgroup_match (void *obj, void *arg, int flags)
 
static int party_id_build_data (unsigned char *data, size_t datalen, const struct ast_party_id *id, const char *label, const struct ast_party_id_ies *ies, const struct ast_set_party_id *update)
 
static int party_name_build_data (unsigned char *data, size_t datalen, const struct ast_party_name *name, const char *label, const struct ast_party_name_ies *ies)
 
static int party_number_build_data (unsigned char *data, size_t datalen, const struct ast_party_number *number, const char *label, const struct ast_party_number_ies *ies)
 
static int party_subaddress_build_data (unsigned char *data, size_t datalen, const struct ast_party_subaddress *subaddress, const char *label, const struct ast_party_subaddress_ies *ies)
 
static void plc_ds_destroy (void *data)
 
static void prnt_channel_key (void *v_obj, void *where, ao2_prnt_fn *prnt)
 
static void queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f)
 
static int redirecting_reason_build_data (unsigned char *data, size_t datalen, const struct ast_party_redirecting_reason *reason, const char *label, const struct ast_party_redirecting_reason_ies *ies)
 
static struct ast_channelrequest_channel (const char *type, struct ast_format_cap *request_cap, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
 
static int safe_sleep_conditional (struct ast_channel *chan, int timeout_ms, int(*cond)(void *), void *data, unsigned int generate_silence)
 Wait, look for hangups and condition arg. More...
 
static void send_dtmf_begin_event (struct ast_channel *chan, enum DtmfDirection direction, const char digit)
 
static void send_dtmf_end_event (struct ast_channel *chan, enum DtmfDirection direction, const char digit, long duration_ms)
 
static void send_flash_event (struct ast_channel *chan)
 
static void set_channel_answer_time (struct ast_channel *chan)
 
static int set_format (struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
 
static int set_security_requirements (const struct ast_channel *requestor, struct ast_channel *out)
 
static int should_skip_dtmf (struct ast_channel *chan)
 Determine whether or not we should ignore DTMF in the readq. More...
 
static int should_trigger_dtmf_emulating (struct ast_channel *chan)
 Determine whether or not we have to trigger dtmf emulating using 50 fps timer events especially when no voice frames are received during dtmf processing (direct media or muted sender case using SIP INFO) More...
 
static void * silence_generator_alloc (struct ast_channel *chan, void *data)
 
static int silence_generator_generate (struct ast_channel *chan, void *data, int len, int samples)
 
static void silence_generator_release (struct ast_channel *chan, void *data)
 
static void suppress_datastore_destroy_cb (void *data)
 
static void suppress_framehook_destroy_cb (void *data)
 
static struct ast_framesuppress_framehook_event_cb (struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
 
static void suppress_framehook_fixup_cb (void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan)
 
static const struct ast_datastore_infosuppress_get_datastore_information (enum ast_frame_type frametype)
 
static int tech_write (struct ast_channel *chan, struct ast_stream *stream, struct ast_stream *default_stream, struct ast_frame *frame)
 
static void * tonepair_alloc (struct ast_channel *chan, void *params)
 
static int tonepair_generator (struct ast_channel *chan, void *data, int len, int samples)
 
static void tonepair_release (struct ast_channel *chan, void *params)
 
static void varshead_dtor (void *obj)
 Destructor for lists of variables. More...
 

Variables

static struct external_vars ami_vars
 
static struct external_vars ari_vars
 
const struct ast_channel_tech ast_kill_tech
 Kill the channel channel driver technology descriptor. More...
 
static void(* ast_moh_cleanup_ptr )(struct ast_channel *) = NULL
 
static int(* ast_moh_start_ptr )(struct ast_channel *, const char *, const char *) = NULL
 
static void(* ast_moh_stop_ptr )(struct ast_channel *) = NULL
 
static struct backends backends = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static const struct ast_datastore_info bridge_features_info
 
static const struct causes_map causes []
 
static const struct ast_datastore_info cc_channel_datastore_info
 
static int chancount
 
static ast_mutex_t channel_move_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static struct ao2_containerchannels
 All active channels on the system. More...
 
static struct ast_cli_entry cli_channel []
 
unsigned long global_fin
 
unsigned long global_fout
 
static const struct ast_channel_tech null_tech
 
static const struct ast_datastore_info plc_ds_info
 
static const struct set_format_access set_format_access_read
 
static const struct set_format_access set_format_access_write
 
static struct ast_generator silence_generator
 
static struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , }
 
static const struct ast_datastore_info suppress_datastore_voice
 
static const struct ast_channel_tech surrogate_tech
 Channel technology used to extract a channel from a running application. The channel created with this technology will be immediately hung up - most external applications won't ever want to see this. More...
 
static struct ast_generator tonepair
 

Detailed Description

Channel Management.

Author
Mark Spencer marks[email protected][email protected][email protected]digiu[email protected]m.co[email protected]m

Definition in file channel.c.

Macro Definition Documentation

◆ AST_DEFAULT_EMULATE_DTMF_DURATION

#define AST_DEFAULT_EMULATE_DTMF_DURATION   100

Default amount of time to use when emulating a DTMF digit as a begin and end 100ms

Definition at line 102 of file channel.c.

Referenced by __ast_read(), ast_senddigit(), and ast_senddigit_external().

◆ AST_MIN_DTMF_GAP

#define AST_MIN_DTMF_GAP   45

Minimum amount of time between the end of the last digit and the beginning of a new one - 45ms

Definition at line 112 of file channel.c.

Referenced by __ast_read(), should_skip_dtmf(), and should_trigger_dtmf_emulating().

◆ DEFAULT_AMA_FLAGS

#define DEFAULT_AMA_FLAGS   AST_AMA_DOCUMENTATION

Definition at line 108 of file channel.c.

Referenced by __ast_channel_alloc_ap(), and ast_channel_string2amaflag().

◆ DEFAULT_EMULATE_MF_DURATION

#define DEFAULT_EMULATE_MF_DURATION   55

Default amount of time to use when emulating an MF digit as a begin and end 55ms

Definition at line 106 of file channel.c.

Referenced by ast_senddigit_mf().

◆ FORMAT

#define FORMAT   "%-15.15s %-40.40s %-13.13s %-13.13s %-13.13s %-13.13s\n"

◆ STATE2STR_BUFSIZE

#define STATE2STR_BUFSIZE   32

Definition at line 98 of file channel.c.

Referenced by ast_state2str().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Element identifiers for connected line indication frame data.

Note
Only add to the end of this enum.
Enumerator
AST_CONNECTED_LINE_NUMBER 
AST_CONNECTED_LINE_NAME 
AST_CONNECTED_LINE_NUMBER_PLAN 
AST_CONNECTED_LINE_ID_PRESENTATION 
AST_CONNECTED_LINE_SOURCE 
AST_CONNECTED_LINE_SUBADDRESS 
AST_CONNECTED_LINE_SUBADDRESS_TYPE 
AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN 
AST_CONNECTED_LINE_SUBADDRESS_VALID 
AST_CONNECTED_LINE_TAG 
AST_CONNECTED_LINE_VERSION 
AST_CONNECTED_LINE_NAME_VALID 
AST_CONNECTED_LINE_NAME_CHAR_SET 
AST_CONNECTED_LINE_NAME_PRESENTATION 
AST_CONNECTED_LINE_NUMBER_VALID 
AST_CONNECTED_LINE_NUMBER_PRESENTATION 
AST_CONNECTED_LINE_PRIV_NUMBER 
AST_CONNECTED_LINE_PRIV_NUMBER_PLAN 
AST_CONNECTED_LINE_PRIV_NUMBER_VALID 
AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION 
AST_CONNECTED_LINE_PRIV_NAME 
AST_CONNECTED_LINE_PRIV_NAME_VALID 
AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET 
AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION 
AST_CONNECTED_LINE_PRIV_SUBADDRESS 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID 
AST_CONNECTED_LINE_PRIV_TAG 

Definition at line 8757 of file channel.c.

8757  {
8761  AST_CONNECTED_LINE_ID_PRESENTATION,/* Combined number and name presentation. */
8769  /*
8770  * No more party id combined number and name presentation values
8771  * need to be created.
8772  */
8791 };

◆ anonymous enum

anonymous enum

Element identifiers for redirecting indication frame data.

Note
Only add to the end of this enum.
Enumerator
AST_REDIRECTING_FROM_NUMBER 
AST_REDIRECTING_FROM_NAME 
AST_REDIRECTING_FROM_NUMBER_PLAN 
AST_REDIRECTING_FROM_ID_PRESENTATION 
AST_REDIRECTING_TO_NUMBER 
AST_REDIRECTING_TO_NAME 
AST_REDIRECTING_TO_NUMBER_PLAN 
AST_REDIRECTING_TO_ID_PRESENTATION 
AST_REDIRECTING_REASON_CODE 
AST_REDIRECTING_COUNT 
AST_REDIRECTING_FROM_SUBADDRESS 
AST_REDIRECTING_FROM_SUBADDRESS_TYPE 
AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_FROM_SUBADDRESS_VALID 
AST_REDIRECTING_TO_SUBADDRESS 
AST_REDIRECTING_TO_SUBADDRESS_TYPE 
AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_TO_SUBADDRESS_VALID 
AST_REDIRECTING_FROM_TAG 
AST_REDIRECTING_TO_TAG 
AST_REDIRECTING_VERSION 
AST_REDIRECTING_FROM_NAME_VALID 
AST_REDIRECTING_FROM_NAME_CHAR_SET 
AST_REDIRECTING_FROM_NAME_PRESENTATION 
AST_REDIRECTING_FROM_NUMBER_VALID 
AST_REDIRECTING_FROM_NUMBER_PRESENTATION 
AST_REDIRECTING_TO_NAME_VALID 
AST_REDIRECTING_TO_NAME_CHAR_SET 
AST_REDIRECTING_TO_NAME_PRESENTATION 
AST_REDIRECTING_TO_NUMBER_VALID 
AST_REDIRECTING_TO_NUMBER_PRESENTATION 
AST_REDIRECTING_ORIG_NUMBER 
AST_REDIRECTING_ORIG_NUMBER_VALID 
AST_REDIRECTING_ORIG_NUMBER_PLAN 
AST_REDIRECTING_ORIG_NUMBER_PRESENTATION 
AST_REDIRECTING_ORIG_NAME 
AST_REDIRECTING_ORIG_NAME_VALID 
AST_REDIRECTING_ORIG_NAME_CHAR_SET 
AST_REDIRECTING_ORIG_NAME_PRESENTATION 
AST_REDIRECTING_ORIG_SUBADDRESS 
AST_REDIRECTING_ORIG_SUBADDRESS_TYPE 
AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_ORIG_SUBADDRESS_VALID 
AST_REDIRECTING_ORIG_TAG 
AST_REDIRECTING_ORIG_REASON_CODE 
AST_REDIRECTING_PRIV_TO_NUMBER 
AST_REDIRECTING_PRIV_TO_NUMBER_PLAN 
AST_REDIRECTING_PRIV_TO_NUMBER_VALID 
AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_TO_NAME 
AST_REDIRECTING_PRIV_TO_NAME_VALID 
AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_TO_SUBADDRESS 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_TO_TAG 
AST_REDIRECTING_PRIV_FROM_NUMBER 
AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN 
AST_REDIRECTING_PRIV_FROM_NUMBER_VALID 
AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_FROM_NAME 
AST_REDIRECTING_PRIV_FROM_NAME_VALID 
AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_FROM_TAG 
AST_REDIRECTING_PRIV_ORIG_NUMBER 
AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID 
AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN 
AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_ORIG_NAME 
AST_REDIRECTING_PRIV_ORIG_NAME_VALID 
AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_ORIG_TAG 
AST_REDIRECTING_REASON_STR 
AST_REDIRECTING_ORIG_REASON_STR 

Definition at line 9232 of file channel.c.

9232  {
9236  AST_REDIRECTING_FROM_ID_PRESENTATION,/* Combined number and name presentation. */
9240  AST_REDIRECTING_TO_ID_PRESENTATION,/* Combined number and name presentation. */
9254  /*
9255  * No more party id combined number and name presentation values
9256  * need to be created.
9257  */
9323 };

◆ DtmfDirection

Enumerator
DTMF_RECEIVED 
DTMF_SENT 

Definition at line 3361 of file channel.c.

3361  {
3362  DTMF_RECEIVED,
3363  DTMF_SENT
3364 };

Function Documentation

◆ __ast_answer()

int __ast_answer ( struct ast_channel chan,
unsigned int  delay 
)

Answer a channel, with a selectable delay before returning.

Parameters
chanchannel to answer
delaymaximum amount of time to wait for incoming media

This function answers a channel and handles all necessary call setup functions.

Note
The channel passed does not need to be locked, but is locked by the function when needed.
This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.
Return values
0on success
non-zeroon failure

Definition at line 2704 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_BRIDGE_ACTION, AST_FRAME_BRIDGE_ACTION_SYNC, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_RTCP, AST_FRAME_TEXT, AST_FRAME_TEXT_DATA, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log, ast_queue_frame_head(), ast_raw_answer(), ast_read(), ast_remaining_ms(), AST_STATE_RING, AST_STATE_RINGING, ast_tvnow(), ast_waitfor(), done, errno, frames, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, MAX, SCOPE_TRACE, and ast_frame::subclass.

Referenced by ast_answer(), pbx_builtin_answer(), and pbx_builtin_incomplete().

2705 {
2706  int res = 0;
2707  enum ast_channel_state old_state;
2708  SCOPE_TRACE(1, "%s\n", ast_channel_name(chan));
2709 
2710  old_state = ast_channel_state(chan);
2711  if ((res = ast_raw_answer(chan))) {
2712  return res;
2713  }
2714 
2715  switch (old_state) {
2716  case AST_STATE_RINGING:
2717  case AST_STATE_RING:
2718  /* wait for media to start flowing, but don't wait any longer
2719  * than 'delay' or 500 milliseconds, whichever is longer
2720  */
2721  do {
2723  struct ast_frame *cur;
2724  struct ast_frame *new_frame;
2725  int timeout_ms = MAX(delay, 500);
2726  unsigned int done = 0;
2727  struct timeval start;
2728 
2730 
2731  start = ast_tvnow();
2732  for (;;) {
2733  int ms = ast_remaining_ms(start, timeout_ms);
2734  ms = ast_waitfor(chan, ms);
2735  if (ms < 0) {
2736  ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", ast_channel_name(chan), strerror(errno));
2737  res = -1;
2738  break;
2739  }
2740  if (ms == 0) {
2741  ast_debug(2, "Didn't receive a media frame from %s within %u ms of answering. Continuing anyway\n", ast_channel_name(chan), MAX(delay, 500));
2742  break;
2743  }
2744  cur = ast_read(chan);
2745  if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
2746  (cur->subclass.integer == AST_CONTROL_HANGUP))) {
2747  if (cur) {
2748  ast_frfree(cur);
2749  }
2750  res = -1;
2751  ast_debug(2, "Hangup of channel %s detected in answer routine\n", ast_channel_name(chan));
2752  break;
2753  }
2754 
2755  if ((new_frame = ast_frisolate(cur)) != cur) {
2756  ast_frfree(cur);
2757  }
2758 
2759  AST_LIST_INSERT_HEAD(&frames, new_frame, frame_list);
2760 
2761  /* if a specific delay period was requested, continue
2762  * until that delay has passed. don't stop just because
2763  * incoming media has arrived.
2764  */
2765  if (delay) {
2766  continue;
2767  }
2768 
2769  switch (new_frame->frametype) {
2770  /* all of these frametypes qualify as 'media' */
2771  case AST_FRAME_VOICE:
2772  case AST_FRAME_VIDEO:
2773  case AST_FRAME_TEXT:
2774  case AST_FRAME_TEXT_DATA:
2775  case AST_FRAME_DTMF_BEGIN:
2776  case AST_FRAME_DTMF_END:
2777  case AST_FRAME_IMAGE:
2778  case AST_FRAME_HTML:
2779  case AST_FRAME_MODEM:
2780  case AST_FRAME_RTCP:
2781  done = 1;
2782  break;
2783  case AST_FRAME_CONTROL:
2784  case AST_FRAME_IAX:
2787  case AST_FRAME_NULL:
2788  case AST_FRAME_CNG:
2789  break;
2790  }
2791 
2792  if (done) {
2793  break;
2794  }
2795  }
2796 
2797  ast_channel_lock(chan);
2798  while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
2799  if (res == 0) {
2800  ast_queue_frame_head(chan, cur);
2801  }
2802  ast_frfree(cur);
2803  }
2804  ast_channel_unlock(chan);
2805  } while (0);
2806  break;
2807  default:
2808  break;
2809  }
2810 
2811  return res;
2812 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define LOG_WARNING
Definition: logger.h:274
ast_channel_state
ast_channel states
Definition: channelstate.h:35
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
struct ast_frame_subclass subclass
int done
Definition: test_amihooks.c:48
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define MAX(a, b)
Definition: utils.h:228
static int frames
Definition: parser.c:51
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2033
int errno
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
int ast_raw_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2699
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
#define SCOPE_TRACE(level,...)
Print a trace message with details when a scope is entered or existed.
Definition: logger.h:749
const char * ast_channel_name(const struct ast_channel *chan)
int ast_waitfor(struct ast_channel *c, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ast_frfree(fr)
Data structure associated with a single frame of data.
enum ast_frame_type frametype
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
Queue one or more frames to the head of a channel&#39;s frame queue.
Definition: channel.c:1144

◆ __ast_change_name_nolink()

static void __ast_change_name_nolink ( struct ast_channel chan,
const char *  newname 
)
static

this function simply changes the name of the channel and issues a manager_event with out unlinking and linking the channel from the ao2_container. This should only be used when the channel has already been unlinked from the ao2_container.

Definition at line 6839 of file channel.c.

References ast_channel_name(), ast_channel_name_set(), ast_channel_uniqueid(), ast_manager_event, and EVENT_FLAG_CALL.

Referenced by ast_change_name().

6840 {
6841  /*** DOCUMENTATION
6842  <managerEventInstance>
6843  <synopsis>Raised when the name of a channel is changed.</synopsis>
6844  </managerEventInstance>
6845  ***/
6846  ast_manager_event(chan, EVENT_FLAG_CALL, "Rename",
6847  "Channel: %s\r\n"
6848  "Newname: %s\r\n"
6849  "Uniqueid: %s\r\n",
6850  ast_channel_name(chan), newname, ast_channel_uniqueid(chan));
6851  ast_channel_name_set(chan, newname);
6852 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
#define ast_manager_event(chan, category, event, contents,...)
Definition: manager.h:250
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_name_set(struct ast_channel *chan, const char *name)
Set the channel name.

◆ __ast_channel_alloc()

struct ast_channel* __ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
enum ama_flags  amaflag,
struct ast_endpoint endpoint,
const char *  file,
int  line,
const char *  function,
const char *  name_fmt,
  ... 
)

Create a channel structure.

Since
1.8
Return values
NULLfailure
non-NULLsuccessfully allocated channel
Note
Absolutely NO channel locks should be held before calling this function.
By default, new channels are set to the "s" extension and "default" context.
Since 12.0.0 this function returns with the newly created channel locked.

Definition at line 960 of file channel.c.

References __ast_channel_alloc_ap(), and result.

967 {
968  va_list ap;
969  struct ast_channel *result;
970 
971  va_start(ap, name_fmt);
972  result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
973  assignedids, requestor, amaflag, endpoint, file, line, function, name_fmt, ap);
974  va_end(ap);
975 
976  return result;
977 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
static struct ast_channel * __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, enum ama_flags amaflag, struct ast_endpoint *endpoint, const char *file, int line, const char *function, const char *name_fmt, va_list ap)
Create a new channel structure.
Definition: channel.c:739
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
static PGresult * result
Definition: cel_pgsql.c:88
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ __ast_channel_alloc_ap()

static struct ast_channel* __ast_channel_alloc_ap ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
enum ama_flags  amaflag,
struct ast_endpoint endpoint,
const char *  file,
int  line,
const char *  function,
const char *  name_fmt,
va_list  ap 
)
static

Create a new channel structure.

Definition at line 739 of file channel.c.

References __ast_channel_internal_alloc(), ao2_link_flags, ao2_lock, ao2_ref, ao2_unlock, AST_ALERT_FD, AST_AMA_NONE, ast_atomic_fetchadd_int(), ast_channel_amaflags_set(), ast_channel_autochans(), ast_channel_caller(), ast_channel_connected(), ast_channel_connected_indicated(), ast_channel_context_set(), ast_channel_creationtime_set(), ast_channel_datastores(), ast_channel_destructor(), ast_channel_dialed(), AST_CHANNEL_ERROR_ID_EXISTS, ast_channel_exten_set(), ast_channel_fin_set(), ast_channel_fout_set(), ast_channel_hold_state_set(), ast_channel_internal_alert_readfd(), ast_channel_internal_alertpipe_clear(), ast_channel_internal_alertpipe_init(), ast_channel_internal_errno_set(), ast_channel_internal_fd_clear_all(), ast_channel_internal_finalize(), ast_channel_internal_set_stream_topology(), ast_channel_internal_setup_topics(), ast_channel_lock, ast_channel_name(), ast_channel_name_set(), ast_channel_nativeformats_set(), ast_channel_priority_set(), ast_channel_redirecting(), ast_channel_sched_set(), ast_channel_set_fd(), ast_channel_set_rawreadformat(), ast_channel_set_rawwriteformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_state_set(), ast_channel_streamid_set(), ast_channel_tech_set(), ast_channel_timer(), ast_channel_timer_set(), ast_channel_timingfd(), ast_channel_timingfd_set(), ast_channel_unlock, ast_channel_unref, ast_channel_varshead(), ast_channel_vstreamid_set(), AST_CONTROL_UNHOLD, ast_debug, ast_defaultlanguage, ast_endpoint_add_channel(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_none, ast_get_channel_tech(), AST_LIST_HEAD_INIT_NOLOCK, ast_log, ast_party_caller_init(), ast_party_connected_line_init(), ast_party_dialed_init(), ast_party_redirecting_init(), ast_pbx_hangup_handler_init(), ast_sched_context_create(), ast_shutting_down(), ast_strdup, ast_strdupa, ast_stream_topology_alloc(), ast_strlen_zero, ast_timer_fd(), ast_timer_get_name(), ast_timer_open(), AST_TIMING_FD, ast_tvnow(), chancount, cid_name, cid_num, context, DEFAULT_AMA_FLAGS, does_id_conflict(), exten, make_ari_stubs::file, global_fin, global_fout, ast_party_caller::id, LOG_WARNING, name, ast_party_id::name, NULL, ast_party_id::number, OBJ_NOLOCK, S_OR, ast_party_name::str, ast_party_number::str, chanlist::tech, timer, tmp(), ast_party_name::valid, and ast_party_number::valid.

Referenced by __ast_channel_alloc().

744 {
745  struct ast_channel *tmp;
746  struct varshead *headp;
747  char *tech = "", *tech2 = NULL;
748  struct ast_format_cap *nativeformats;
749  struct ast_sched_context *schedctx;
750  struct ast_timer *timer;
751  struct timeval now;
752  const struct ast_channel_tech *channel_tech;
753  struct ast_stream_topology *topology;
754 
755  /* If shutting down, don't allocate any new channels */
756  if (ast_shutting_down()) {
757  ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
758  return NULL;
759  }
760 
761  tmp = __ast_channel_internal_alloc(ast_channel_destructor, assignedids, requestor,
762  file, line, function);
763  if (!tmp) {
764  /* Channel structure allocation failure. */
765  return NULL;
766  }
767 
769 
770  /*
771  * Init file descriptors to unopened state so
772  * the destructor can know not to close them.
773  */
774  ast_channel_timingfd_set(tmp, -1);
777 
779  if (!nativeformats) {
780  /*
781  * Aborting the channel creation. We do not need to complete staging
782  * the channel snapshot because the channel has not been finalized or
783  * linked into the channels container yet. Nobody else knows about
784  * this channel nor will anybody ever know about it.
785  */
786  return ast_channel_unref(tmp);
787  }
788  ast_format_cap_append(nativeformats, ast_format_none, 0);
789  ast_channel_nativeformats_set(tmp, nativeformats);
790  ao2_ref(nativeformats, -1);
791 
796 
797  if (!(schedctx = ast_sched_context_create())) {
798  ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
799  /* See earlier channel creation abort comment above. */
800  return ast_channel_unref(tmp);
801  }
802  ast_channel_sched_set(tmp, schedctx);
803 
809 
810  if (cid_name) {
811  ast_channel_caller(tmp)->id.name.valid = 1;
813  if (!ast_channel_caller(tmp)->id.name.str) {
814  /* See earlier channel creation abort comment above. */
815  return ast_channel_unref(tmp);
816  }
817  }
818  if (cid_num) {
819  ast_channel_caller(tmp)->id.number.valid = 1;
821  if (!ast_channel_caller(tmp)->id.number.str) {
822  /* See earlier channel creation abort comment above. */
823  return ast_channel_unref(tmp);
824  }
825  }
826 
827  if ((timer = ast_timer_open())) {
828  ast_channel_timer_set(tmp, timer);
829  if (strcmp(ast_timer_get_name(ast_channel_timer(tmp)), "timerfd")) {
830  needqueue = 0;
831  }
833  }
834 
835  if (needqueue && ast_channel_internal_alertpipe_init(tmp)) {
836  /* See earlier channel creation abort comment above. */
837  return ast_channel_unref(tmp);
838  }
839 
840  if (!(topology = ast_stream_topology_alloc())) {
841  return ast_channel_unref(tmp);
842  }
844 
845  /* Always watch the alertpipe */
847  /* And timing pipe */
849 
850  /* Initial state */
853 
854  ast_channel_streamid_set(tmp, -1);
855  ast_channel_vstreamid_set(tmp, -1);
856 
859 
860  now = ast_tvnow();
861  ast_channel_creationtime_set(tmp, &now);
862 
864 
865  if (!ast_strlen_zero(name_fmt)) {
866  char *slash, *slash2;
867  /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
868  * And they all use slightly different formats for their name string.
869  * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
870  * This means, that the stringfields must have a routine that takes the va_lists directly, and
871  * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
872  * This new function was written so this can be accomplished.
873  */
874  ast_channel_name_build_va(tmp, name_fmt, ap);
875  tech = ast_strdupa(ast_channel_name(tmp));
876  if ((slash = strchr(tech, '/'))) {
877  if ((slash2 = strchr(slash + 1, '/'))) {
878  tech2 = slash + 1;
879  *slash2 = '\0';
880  }
881  *slash = '\0';
882  }
883  } else {
884  /*
885  * Start the string with '-' so it becomes an empty string
886  * in the destructor.
887  */
888  ast_channel_name_set(tmp, "-**Unknown**");
889  }
890 
891  if (amaflag != AST_AMA_NONE) {
892  ast_channel_amaflags_set(tmp, amaflag);
893  } else {
895  }
896 
897  if (!ast_strlen_zero(acctcode)) {
898  ast_channel_accountcode_set(tmp, acctcode);
899  }
900  ast_channel_language_set(tmp, ast_defaultlanguage);
901 
902  ast_channel_context_set(tmp, S_OR(context, "default"));
903  ast_channel_exten_set(tmp, S_OR(exten, "s"));
904  ast_channel_priority_set(tmp, 1);
905 
906  headp = ast_channel_varshead(tmp);
908 
912 
913  channel_tech = ast_get_channel_tech(tech);
914  if (!channel_tech && !ast_strlen_zero(tech2)) {
915  channel_tech = ast_get_channel_tech(tech2);
916  }
917  if (channel_tech) {
918  ast_channel_tech_set(tmp, channel_tech);
919  } else {
921  }
922 
923  /* You might scream "locking inversion" at seeing this but it is actually perfectly fine.
924  * Since the channel was just created nothing can know about it yet or even acquire it.
925  */
926  ast_channel_lock(tmp);
927 
929 
930  if (assignedids && (does_id_conflict(assignedids->uniqueid) || does_id_conflict(assignedids->uniqueid2))) {
933  ast_channel_unlock(tmp);
934  /* See earlier channel creation abort comment above. */
935  return ast_channel_unref(tmp);
936  }
937 
938  /* Finalize and link into the channels container. */
942 
944 
945  if (endpoint) {
946  ast_endpoint_add_channel(endpoint, tmp);
947  }
948 
949  /*
950  * And now, since the channel structure is built, and has its name, let
951  * the world know of its existance
952  */
954 
955  ast_debug(1, "Channel %p '%s' allocated\n", tmp, ast_channel_name(tmp));
956 
957  return tmp;
958 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
void ast_party_caller_init(struct ast_party_caller *init)
Initialize the given caller structure.
Definition: channel.c:1978
int ast_shutting_down(void)
Definition: asterisk.c:1834
void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
int ast_channel_internal_alert_readfd(struct ast_channel *chan)
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
#define LOG_WARNING
Definition: logger.h:274
void ast_pbx_hangup_handler_init(struct ast_channel *chan)
Init the hangup handler container on a channel.
static int tmp()
Definition: bt_open.c:389
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
struct ast_timer * ast_timer_open(void)
Open a timer.
Definition: timing.c:122
char * str
Subscriber name (Malloced)
Definition: channel.h:265
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2022
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
const char * uniqueid
Definition: channel.h:606
#define ao2_link_flags(container, obj, flags)
Definition: astobj2.h:1572
#define ao2_unlock(a)
Definition: astobj2.h:730
void ast_channel_internal_errno_set(enum ast_channel_error error)
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:251
#define AST_ALERT_FD
Definition: channel.h:201
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
unsigned long global_fin
Definition: channel.c:95
void ast_party_dialed_init(struct ast_party_dialed *init)
Initialize the given dialed structure.
Definition: channel.c:1928
static int does_id_conflict(const char *uniqueid)
Definition: channel.c:717
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
Number structure.
Definition: app_followme.c:154
struct ast_party_id id
Caller party ID.
Definition: channel.h:421
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
char ast_defaultlanguage[]
Definition: options.c:98
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
struct ast_datastore_list * ast_channel_datastores(struct ast_channel *chan)
#define ao2_lock(a)
Definition: astobj2.h:718
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:629
int ast_endpoint_add_channel(struct ast_endpoint *endpoint, struct ast_channel *chan)
Adds a channel to the given endpoint.
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:236
int ast_channel_timingfd(const struct ast_channel *chan)
#define DEFAULT_AMA_FLAGS
Definition: channel.c:108
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2122
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
Definition: stream.c:650
static struct ao2_container * channels
All active channels on the system.
Definition: channel.c:124
void ast_channel_streamid_set(struct ast_channel *chan, int value)
#define AST_TIMING_FD
Definition: channel.h:202
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get handle to channel driver based on name.
Definition: channel.c:592
struct ast_autochan_list * ast_channel_autochans(struct ast_channel *chan)
void ast_channel_timingfd_set(struct ast_channel *chan, int value)
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
Definition: timing.c:161
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_channel_creationtime_set(struct ast_channel *chan, struct timeval *value)
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
static int chancount
Definition: channel.c:93
void ast_channel_context_set(struct ast_channel *chan, const char *value)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state)
static const struct ast_channel_tech null_tech
Definition: channel.c:708
void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
unsigned long global_fout
Definition: channel.c:95
static void ast_channel_destructor(void *obj)
Free a channel structure.
Definition: channel.c:2192
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:280
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
void ast_channel_hold_state_set(struct ast_channel *chan, int value)
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
const char * ast_timer_get_name(const struct ast_timer *handle)
Get name of timer in use.
Definition: timing.c:196
void ast_channel_name_set(struct ast_channel *chan, const char *name)
Set the channel name.
struct ast_channel * __ast_channel_internal_alloc(void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function)
int ast_channel_internal_setup_topics(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
static struct ast_timer * timer
Definition: chan_iax2.c:360
struct ast_party_connected_line * ast_channel_connected_indicated(struct ast_channel *chan)
void ast_channel_internal_finalize(struct ast_channel *chan)
const char * uniqueid2
Definition: channel.h:607
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2431
struct ast_timer * ast_channel_timer(const struct ast_channel *chan)
void ast_channel_internal_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343

◆ __ast_dummy_channel_alloc()

struct ast_channel* __ast_dummy_channel_alloc ( const char *  file,
int  line,
const char *  function 
)

Definition at line 981 of file channel.c.

References __ast_channel_internal_alloc(), ast_channel_datastores(), ast_channel_hold_state_set(), ast_channel_internal_alertpipe_clear(), ast_channel_internal_fd_clear_all(), ast_channel_internal_setup_topics(), ast_channel_timingfd_set(), ast_channel_varshead(), AST_CONTROL_UNHOLD, ast_dummy_channel_destructor(), AST_LIST_HEAD_INIT_NOLOCK, ast_pbx_hangup_handler_init(), NULL, and tmp().

982 {
983  struct ast_channel *tmp;
984  struct varshead *headp;
985 
987  file, line, function);
988  if (!tmp) {
989  /* Dummy channel structure allocation failure. */
990  return NULL;
991  }
992 
995 
996  /*
997  * Init file descriptors to unopened state just in case
998  * autoservice is called on the channel or something tries to
999  * read a frame from it.
1000  */
1001  ast_channel_timingfd_set(tmp, -1);
1004 
1006 
1008 
1009  headp = ast_channel_varshead(tmp);
1011 
1012  return tmp;
1013 }
void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
Main Channel structure associated with a channel.
static void ast_dummy_channel_destructor(void *obj)
Free a dummy channel structure.
Definition: channel.c:2338
void ast_pbx_hangup_handler_init(struct ast_channel *chan)
Init the hangup handler container on a channel.
static int tmp()
Definition: bt_open.c:389
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
struct ast_datastore_list * ast_channel_datastores(struct ast_channel *chan)
void ast_channel_timingfd_set(struct ast_channel *chan, int value)
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
void ast_channel_hold_state_set(struct ast_channel *chan, int value)
struct ast_channel * __ast_channel_internal_alloc(void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function)
int ast_channel_internal_setup_topics(struct ast_channel *chan)

◆ __ast_queue_frame()

static int __ast_queue_frame ( struct ast_channel chan,
struct ast_frame fin,
int  head,
struct ast_frame after 
)
static

Definition at line 1015 of file channel.c.

References ast_channel_alert_writable(), ast_channel_alert_write(), ast_channel_blocker(), ast_channel_flags(), ast_channel_internal_alert_read(), ast_channel_lock, ast_channel_name(), ast_channel_readq(), ast_channel_timer(), ast_channel_timingfd(), ast_channel_unlock, AST_CONTROL_END_OF_Q, AST_CONTROL_HANGUP, AST_FLAG_BLOCKING, AST_FRAME_CONTROL, AST_FRAME_NULL, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frdup, ast_frfree, AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK(), AST_LIST_INSERT_LIST_AFTER, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log, ast_test_flag, ast_timer_enable_continuous(), errno, frames, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, NULL, and ast_frame::subclass.

Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().

1016 {
1017  struct ast_frame *f;
1018  struct ast_frame *cur;
1019  unsigned int new_frames = 0;
1020  unsigned int new_voice_frames = 0;
1021  unsigned int queued_frames = 0;
1022  unsigned int queued_voice_frames = 0;
1024 
1025  ast_channel_lock(chan);
1026 
1027  /*
1028  * Check the last frame on the queue if we are queuing the new
1029  * frames after it.
1030  */
1031  cur = AST_LIST_LAST(ast_channel_readq(chan));
1032  if (cur && cur->frametype == AST_FRAME_CONTROL && !head && (!after || after == cur)) {
1033  switch (cur->subclass.integer) {
1034  case AST_CONTROL_END_OF_Q:
1035  if (fin->frametype == AST_FRAME_CONTROL
1036  && fin->subclass.integer == AST_CONTROL_HANGUP) {
1037  /*
1038  * Destroy the end-of-Q marker frame so we can queue the hangup
1039  * frame in its place.
1040  */
1042  ast_frfree(cur);
1043 
1044  /*
1045  * This has degenerated to a normal queue append anyway. Since
1046  * we just destroyed the last frame in the queue we must make
1047  * sure that "after" is NULL or bad things will happen.
1048  */
1049  after = NULL;
1050  break;
1051  }
1052  /* Fall through */
1053  case AST_CONTROL_HANGUP:
1054  /* Don't queue anything. */
1055  ast_channel_unlock(chan);
1056  return 0;
1057  default:
1058  break;
1059  }
1060  }
1061 
1062  /* Build copies of all the new frames and count them */
1064  for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
1065  if (!(f = ast_frdup(cur))) {
1066  if (AST_LIST_FIRST(&frames)) {
1068  }
1069  ast_channel_unlock(chan);
1070  return -1;
1071  }
1072 
1074  new_frames++;
1075  if (f->frametype == AST_FRAME_VOICE) {
1076  new_voice_frames++;
1077  }
1078  }
1079 
1080  /* Count how many frames exist on the queue */
1082  queued_frames++;
1083  if (cur->frametype == AST_FRAME_VOICE) {
1084  queued_voice_frames++;
1085  }
1086  }
1087 
1088  if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) {
1089  int count = 0;
1090  ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", ast_channel_name(chan));
1092  /* Save the most recent frame */
1093  if (!AST_LIST_NEXT(cur, frame_list)) {
1094  break;
1095  } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) {
1096  if (++count > 64) {
1097  break;
1098  }
1100  ast_frfree(cur);
1101 
1102  /* Read from the alert pipe for each flushed frame. */
1104  }
1105  }
1107  }
1108 
1109  if (after) {
1111  } else {
1112  if (head) {
1115  }
1117  }
1118 
1119  if (ast_channel_alert_writable(chan)) {
1120  /* Write to the alert pipe for each added frame */
1121  while (new_frames--) {
1122  if (ast_channel_alert_write(chan)) {
1123  ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %u): %s!\n",
1124  ast_channel_name(chan), queued_frames, strerror(errno));
1125  break;
1126  }
1127  }
1128  } else if (ast_channel_timingfd(chan) > -1) {
1130  } else if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING)) {
1131  pthread_kill(ast_channel_blocker(chan), SIGURG);
1132  }
1133 
1134  ast_channel_unlock(chan);
1135 
1136  return 0;
1137 }
#define AST_LIST_INSERT_LIST_AFTER(head, list, elm, field)
Inserts a whole list after a specific entry in a list.
Definition: linkedlists.h:811
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_frdup(fr)
Copies a frame.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
#define NULL
Definition: resample.c:96
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:855
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
struct ast_frame_subclass subclass
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
static int frames
Definition: parser.c:51
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
int ast_channel_timingfd(const struct ast_channel *chan)
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
int errno
pthread_t ast_channel_blocker(const struct ast_channel *chan)
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2946
int ast_timer_enable_continuous(const struct ast_timer *handle)
Enable continuous mode.
Definition: timing.c:176
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
const char * ast_channel_name(const struct ast_channel *chan)
int ast_channel_alert_writable(struct ast_channel *chan)
#define ast_frfree(fr)
Data structure associated with a single frame of data.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
enum ast_frame_type frametype
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
int ast_channel_alert_write(struct ast_channel *chan)
struct ast_timer * ast_channel_timer(const struct ast_channel *chan)
#define AST_LIST_APPEND_LIST(head, list, field)
Appends a whole list to the tail of a list.
Definition: linkedlists.h:782

◆ __ast_read()

static struct ast_frame* __ast_read ( struct ast_channel chan,
int  dropaudio,
int  dropnondefault 
)
static
Todo:
XXX It is possible to write a digit to the audiohook twice if the digit was originally read while the channel was in autoservice.

Definition at line 3529 of file channel.c.

References __ast_queue_frame(), ast_control_read_action_payload::action, ao2_ref, AST_ALERT_READ_FATAL, ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_channel_alert_write(), ast_channel_audiohooks(), ast_channel_audiohooks_set(), ast_channel_connected(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_dtmf_digit_to_emulate(), ast_channel_dtmf_digit_to_emulate_set(), ast_channel_dtmf_tv(), ast_channel_dtmf_tv_set(), ast_channel_dtmff(), ast_channel_emulate_dtmf_duration(), ast_channel_emulate_dtmf_duration_set(), ast_channel_fd_isset(), ast_channel_fdno(), ast_channel_fdno_set(), ast_channel_fin(), ast_channel_fin_set(), ast_channel_flags(), ast_channel_framehooks(), ast_channel_generator(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_get_default_stream(), ast_channel_get_stream_topology(), ast_channel_hangupcause_set(), ast_channel_insmpl(), ast_channel_insmpl_set(), ast_channel_internal_alert_read(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_monitor(), ast_channel_music_state(), ast_channel_name(), ast_channel_outsmpl(), ast_channel_rawreadformat(), ast_channel_readformat(), ast_channel_readq(), ast_channel_readtrans(), ast_channel_softhangup_internal_flag(), ast_channel_softhangup_internal_flag_add(), ast_channel_stream_topology_changed(), ast_channel_tech(), ast_channel_timer(), ast_channel_timingdata(), ast_channel_timingfd(), ast_channel_timingfunc(), ast_channel_unlock, ast_channel_writetrans(), ast_check_hangup(), ast_clear_flag, ast_connected_line_parse_data(), AST_CONTROL_ANSWER, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_READ_ACTION, AST_CONTROL_STREAM_TOPOLOGY_CHANGED, AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE, ast_deactivate_generator(), ast_debug, AST_DEFAULT_EMULATE_DTMF_DURATION, AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_TIMINGDATA_IS_AO2_OBJ, AST_FLAG_ZOMBIE, ast_format_cache_is_slinear(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_get_sample_rate(), ast_format_get_type(), AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_NULL, AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO, AST_FRAME_READ_ACTION_SEND_TEXT, AST_FRAME_READ_ACTION_SEND_TEXT_DATA, AST_FRAME_RTCP, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_framehook_list_read_event(), AST_FRFLAG_REQUEUED, ast_frfree, AST_GENERATOR_FD, ast_indicate_data(), AST_JITTERBUFFER_FD, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log, AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_queue_control(), ast_queue_frame(), ast_queue_frame_head(), ast_read_generator_actions(), ast_seekstream(), ast_sendtext(), ast_sendtext_data(), ast_set_flag, ast_set_read_format_path(), ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_stream_get_position(), ast_stream_topology_get_stream(), ast_test_flag, ast_timer_ack(), ast_timer_disable_continuous(), ast_timer_get_event(), ast_timer_set_rate(), AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, AST_TIMING_FD, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_writestream(), calc_monitor_jump(), ast_frame::data, DEBUGCHAN_FLAG, digit, ast_generator::digit, done, DTMF_RECEIVED, ast_channel_tech::exception, ast_frame_subclass::format, ast_channel_monitor::format, FRAMECOUNT_INC, ast_frame::frametype, ast_generator::generate, ast_frame_subclass::integer, ast_frame::len, LOG_DTMF, LOG_ERROR, LOG_WARNING, NULL, option_dtmfminduration, ast_control_read_action_payload::payload, ast_control_read_action_payload::payload_size, ast_frame::ptr, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_tech::read_stream, ast_frame::samples, SEEK_FORCECUR, send_dtmf_begin_event(), send_dtmf_end_event(), send_flash_event(), set_channel_answer_time(), should_skip_dtmf(), should_trigger_dtmf_emulating(), ast_frame::stream_num, ast_frame::subclass, and ast_frame::uint32.

Referenced by ast_read(), ast_read_noaudio(), ast_read_stream(), and ast_read_stream_noaudio().

3530 {
3531  struct ast_frame *f = NULL; /* the return value */
3532  int prestate;
3533  int cause = 0;
3534  struct ast_stream *stream = NULL, *default_stream = NULL;
3535 
3536  /* this function is very long so make sure there is only one return
3537  * point at the end (there are only two exceptions to this).
3538  */
3539  ast_channel_lock(chan);
3540 
3541  /* Stop if we're a zombie or need a soft hangup */
3543  if (ast_channel_generator(chan))
3545 
3546  /*
3547  * It is possible for chan->_softhangup to be set and there
3548  * still be control frames that need to be read. Instead of
3549  * just going to 'done' in the case of ast_check_hangup(), we
3550  * need to queue the end-of-Q frame so that it can mark the end
3551  * of the read queue. If there are frames to be read,
3552  * ast_queue_control() will be called repeatedly, but will only
3553  * queue the first end-of-Q frame.
3554  */
3556  ast_log(LOG_WARNING, "GOT HERE\n");
3558  } else {
3559  goto done;
3560  }
3561  } else {
3562 #ifdef AST_DEVMODE
3563  /*
3564  * The ast_waitfor() code records which of the channel's file
3565  * descriptors reported that data is available. In theory,
3566  * ast_read() should only be called after ast_waitfor() reports
3567  * that a channel has data available for reading. However,
3568  * there still may be some edge cases throughout the code where
3569  * ast_read() is called improperly. This can potentially cause
3570  * problems, so if this is a developer build, make a lot of
3571  * noise if this happens so that it can be addressed.
3572  *
3573  * One of the potential problems is blocking on a dead channel.
3574  */
3575  if (ast_channel_fdno(chan) == -1) {
3577  "ast_read() on chan '%s' called with no recorded file descriptor.\n",
3578  ast_channel_name(chan));
3579  }
3580 #endif
3581  }
3582 
3583  prestate = ast_channel_state(chan);
3584 
3585  if (ast_channel_timingfd(chan) > -1 && ast_channel_fdno(chan) == AST_TIMING_FD) {
3586  enum ast_timer_event res;
3587  int trigger_dtmf_emulating = should_trigger_dtmf_emulating(chan);
3588 
3590 
3592 
3593  switch (res) {
3595  if (ast_timer_ack(ast_channel_timer(chan), 1) < 0) {
3596  ast_log(LOG_ERROR, "Failed to acknoweldge timer in ast_read\n");
3597  goto done;
3598  }
3599 
3600  if (ast_channel_timingfunc(chan)) {
3601  /* save a copy of func/data before unlocking the channel */
3603  void *data = ast_channel_timingdata(chan);
3604  int got_ref = 0;
3606  ao2_ref(data, 1);
3607  got_ref = 1;
3608  }
3609  ast_channel_fdno_set(chan, -1);
3610  ast_channel_unlock(chan);
3611  func(data);
3612  if (got_ref) {
3613  ao2_ref(data, -1);
3614  }
3615 
3616  if (trigger_dtmf_emulating) {
3617  /*
3618  * Since we're breaking out of this switch block and not
3619  * returning, we need to re-lock the channel.
3620  */
3621  ast_channel_lock(chan);
3622  /* generate null frame to trigger dtmf emulating */
3623  f = &ast_null_frame;
3624  break;
3625  }
3626  } else if (trigger_dtmf_emulating) {
3627  /* generate null frame to trigger dtmf emualating */
3628  f = &ast_null_frame;
3629  break;
3630  } else {
3632  /* generate very last null frame to trigger dtmf emulating */
3633  f = &ast_null_frame;
3634  break;
3635  }
3636 
3637  /* cannot 'goto done' because the channel is already unlocked */
3638  return &ast_null_frame;
3639 
3641  if (AST_LIST_EMPTY(ast_channel_readq(chan)) ||
3644  }
3645  break;
3646  }
3647 
3649  /* if the AST_GENERATOR_FD is set, call the generator with args
3650  * set to -1 so it can do whatever it needs to.
3651  */
3652  void *tmp = ast_channel_generatordata(chan);
3653  ast_channel_generatordata_set(chan, NULL); /* reset to let ast_write get through */
3654  ast_channel_generator(chan)->generate(chan, tmp, -1, -1);
3655  ast_channel_generatordata_set(chan, tmp);
3656  f = &ast_null_frame;
3657  ast_channel_fdno_set(chan, -1);
3658  goto done;
3661  }
3662 
3663  /* Read and ignore anything on the alertpipe, but read only
3664  one sizeof(blah) per frame that we send from it */
3666  f = &ast_null_frame;
3667  goto done;
3668  }
3669 
3670  /* Check for pending read queue */
3671  if (!AST_LIST_EMPTY(ast_channel_readq(chan))) {
3672  int skipped_dtmf_frame = 0;
3673  int skip_dtmf = should_skip_dtmf(chan);
3674 
3676  /* We have to be picky about which frame we pull off of the readq because
3677  * there are cases where we want to leave DTMF frames on the queue until
3678  * some later time. */
3679 
3680  if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
3681  skipped_dtmf_frame = 1;
3682  continue;
3683  }
3684 
3686  break;
3687  }
3689 
3690  if (!f) {
3691  /* There were no acceptable frames on the readq. */
3692  f = &ast_null_frame;
3693  if (!skipped_dtmf_frame) {
3694  /*
3695  * Do not trigger alert pipe if only buffered dtmf begin or end frames
3696  * are left in the readq.
3697  */
3699  } else {
3700  /*
3701  * Safely disable continous timer events if only buffered dtmf begin or end
3702  * frames are left in the readq.
3703  */
3705  }
3706  }
3707 
3708  /* Interpret hangup and end-of-Q frames to return NULL */
3709  /* XXX why not the same for frames from the channel ? */
3710  if (f->frametype == AST_FRAME_CONTROL) {
3711  switch (f->subclass.integer) {
3712  case AST_CONTROL_HANGUP:
3714  cause = f->data.uint32;
3715  /* Fall through */
3716  case AST_CONTROL_END_OF_Q:
3717  ast_frfree(f);
3718  f = NULL;
3719  break;
3720  default:
3721  break;
3722  }
3723  } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) {
3724  if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3727  } else {
3728  /* Since this channel driver does not support multistream determine the default stream this frame
3729  * originated from and update the frame to include it.
3730  */
3731  stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3732  /* In order to allow media to be passed up the underlying media type has to have a format negotiated on
3733  * the channel itself. In cases where this hasn't happened the channel driver is incorrectly passing up
3734  * a frame for a format that has not been negotiated. If this occurs just drop the frame as we have no
3735  * stream that it came from.
3736  */
3737  if (!stream) {
3738  ast_frfree(f);
3739  f = &ast_null_frame;
3740  } else {
3741  f->stream_num = ast_stream_get_position(stream);
3742  }
3743  }
3744  }
3745  } else {
3747  if (ast_channel_tech(chan)->exception)
3748  f = ast_channel_tech(chan)->exception(chan);
3749  else {
3750  ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", ast_channel_name(chan));
3751  f = &ast_null_frame;
3752  }
3753  /* Clear the exception flag */
3755  } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) {
3756  f = ast_channel_tech(chan)->read_stream(chan);
3757 
3758  /* This channel driver supports multistream so the stream_num on the frame is valid, the only
3759  * thing different is that we need to find the default stream so we know whether to invoke the
3760  * default stream logic or not (such as transcoding).
3761  */
3762  if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3765  }
3766  } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read) {
3767  f = ast_channel_tech(chan)->read(chan);
3768 
3769  /* Since this channel driver does not support multistream determine the default stream this frame
3770  * originated from and update the frame to include it.
3771  */
3772  if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) {
3773  stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format));
3774  if (!stream) {
3775  ast_frfree(f);
3776  f = &ast_null_frame;
3777  } else {
3778  f->stream_num = ast_stream_get_position(stream);
3779  }
3780  }
3781  }
3782  else
3783  ast_log(LOG_WARNING, "No read routine on channel %s\n", ast_channel_name(chan));
3784  }
3785 
3786  if (stream == default_stream) {
3787  /* Perform the framehook read event here. After the frame enters the framehook list
3788  * there is no telling what will happen, <insert mad scientist laugh here>!!! */
3790  }
3791 
3792  /*
3793  * Reset the recorded file descriptor that triggered this read so that we can
3794  * easily detect when ast_read() is called without properly using ast_waitfor().
3795  */
3796  ast_channel_fdno_set(chan, -1);
3797 
3798  if (f) {
3799  struct ast_frame *readq_tail = AST_LIST_LAST(ast_channel_readq(chan));
3800  struct ast_control_read_action_payload *read_action_payload;
3802  int hooked = 0;
3803 
3804 
3805  /* if the channel driver returned more than one frame, stuff the excess
3806  into the readq for the next ast_read call
3807  */
3808  if (AST_LIST_NEXT(f, frame_list)) {
3812  }
3813 
3814  if (dropnondefault && stream != default_stream) {
3815  /* If the frame originates from a non-default stream and the caller can not handle other streams
3816  * absorb the frame and replace it with a null one instead.
3817  */
3818  ast_frfree(f);
3819  f = &ast_null_frame;
3820  }
3821 
3822  switch (f->frametype) {
3823  case AST_FRAME_CONTROL:
3824  if (f->subclass.integer == AST_CONTROL_ANSWER) {
3825  if (prestate == AST_STATE_UP && ast_channel_is_bridged(chan)) {
3826  ast_debug(1, "Dropping duplicate answer!\n");
3827  ast_frfree(f);
3828  f = &ast_null_frame;
3829  } else {
3830  /*
3831  * Mark when outgoing channel answered so we can know how
3832  * long the channel has been up.
3833  */
3835 
3836  ast_setstate(chan, AST_STATE_UP);
3837  }
3838  } else if (f->subclass.integer == AST_CONTROL_READ_ACTION) {
3839  read_action_payload = f->data.ptr;
3840  switch (read_action_payload->action) {
3844  if (ast_connected_line_parse_data(read_action_payload->payload,
3845  read_action_payload->payload_size, &connected)) {
3847  break;
3848  }
3849  ast_channel_unlock(chan);
3850  if (ast_channel_connected_line_sub(NULL, chan, &connected, 0) &&
3853  read_action_payload->payload,
3854  read_action_payload->payload_size);
3855  }
3857  ast_channel_lock(chan);
3858  break;
3860  ast_channel_unlock(chan);
3861  ast_sendtext(chan, (const char *)read_action_payload->payload);
3862  ast_channel_lock(chan);
3863  break;
3865  ast_channel_unlock(chan);
3866  ast_sendtext_data(chan, (struct ast_msg_data *)read_action_payload->payload);
3867  ast_channel_lock(chan);
3868  break;
3869  }
3870  ast_frfree(f);
3871  f = &ast_null_frame;
3872  } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE && dropnondefault) {
3873  /* The caller of this function is incapable of handling streams so we don't accept the change request
3874  * and stick to the streams currently on the channel.
3875  */
3877  ast_frfree(f);
3878  f = &ast_null_frame;
3879  } else if (f->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_CHANGED && dropnondefault) {
3880  /* The caller of this function is incapable of handling streams so we absorb the notification that the
3881  * stream topology has changed.
3882  */
3883  ast_frfree(f);
3884  f = &ast_null_frame;
3885  } else if (f->subclass.integer == AST_CONTROL_FLASH) {
3886  send_flash_event(chan);
3887  }
3888  break;
3889  case AST_FRAME_DTMF_END:
3891  ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
3892  /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
3894  queue_dtmf_readq(chan, f);
3895  ast_frfree(f);
3896  f = &ast_null_frame;
3898  if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
3900  /* If it hasn't been long enough, defer this digit */
3901  queue_dtmf_readq(chan, f);
3902  ast_frfree(f);
3903  f = &ast_null_frame;
3904  } else {
3905  /* There was no begin, turn this into a begin and send the end later */
3906  struct timeval tv = ast_tvnow();
3910  ast_channel_dtmf_tv_set(chan, &tv);
3911  if (f->len) {
3912  if (f->len > option_dtmfminduration)
3914  else
3916  } else
3918  ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass.integer, ast_channel_emulate_dtmf_duration(chan), ast_channel_name(chan));
3919 
3920  /*
3921  * Start generating 50 fps timer events (null frames) for dtmf emulating
3922  * independently from any existing incoming voice frames.
3923  * If channel generator is already activated in regular mode use these
3924  * timer events to generate null frames.
3925  */
3926  if (!ast_channel_generator(chan)) {
3928  }
3929  }
3930  if (ast_channel_audiohooks(chan)) {
3931  struct ast_frame *old_frame = f;
3932  /*!
3933  * \todo XXX It is possible to write a digit to the audiohook twice
3934  * if the digit was originally read while the channel was in autoservice. */
3936  if (old_frame != f)
3937  ast_frfree(old_frame);
3938  }
3939  } else {
3940  struct timeval now = ast_tvnow();
3942  ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3944  if (!f->len)
3945  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3946 
3947  /* detect tones that were received on
3948  * the wire with durations shorter than
3949  * option_dtmfminduration and set f->len
3950  * to the actual duration of the DTMF
3951  * frames on the wire. This will cause
3952  * dtmf emulation to be triggered later
3953  * on.
3954  */
3956  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
3957  ast_log(LOG_DTMF, "DTMF end '%c' detected to have actual duration %ld on the wire, emulation will be triggered on %s\n", f->subclass.integer, f->len, ast_channel_name(chan));
3958  }
3959  } else if (!f->len) {
3960  ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3962  }
3964  ast_log(LOG_DTMF, "DTMF end '%c' has duration %ld but want minimum %u, emulating on %s\n", f->subclass.integer, f->len, option_dtmfminduration, ast_channel_name(chan));
3968  ast_frfree(f);
3969  f = &ast_null_frame;
3970 
3971  /* Start generating 50 fps timer events (null frames) for dtmf emulating
3972  * independently from any existing incoming voice frames.
3973  * If channel generator is already activated in regular mode use these
3974  * timer events to generate null frames.
3975  */
3976  if (!ast_channel_generator(chan)) {
3978  }
3979  } else {
3980  ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
3981  if (f->len < option_dtmfminduration) {
3983  }
3984  ast_channel_dtmf_tv_set(chan, &now);
3985 
3986  /* Start generating 50 fps timer events (null frames) for dtmf emulating
3987  * independently from any existing incoming voice frames.
3988  * If channel generator is already activated in regular mode use these
3989  * timer events to generate null frames.
3990  */
3991  if (!ast_channel_generator(chan)) {
3993  }
3994  }
3995  if (ast_channel_audiohooks(chan)) {
3996  struct ast_frame *old_frame = f;
3998  if (old_frame != f)
3999  ast_frfree(old_frame);
4000  }
4001  }
4002  break;
4003  case AST_FRAME_DTMF_BEGIN:
4005  ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
4007  (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
4009  ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
4010  ast_frfree(f);
4011  f = &ast_null_frame;
4012  } else {
4013  struct timeval now = ast_tvnow();
4015  ast_channel_dtmf_tv_set(chan, &now);
4016  ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
4017  }
4018  break;
4019  case AST_FRAME_NULL:
4020  /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4021  * is reached , because we want to make sure we pass at least one
4022  * voice frame through before starting the next digit, to ensure a gap
4023  * between DTMF digits. */
4025  struct timeval now = ast_tvnow();
4026  if (!ast_channel_emulate_dtmf_duration(chan)) {
4029  } else if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) >= ast_channel_emulate_dtmf_duration(chan)) {
4031  ast_frfree(f);
4032  f = ast_channel_dtmff(chan);
4035  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4036  ast_channel_dtmf_tv_set(chan, &now);
4039  ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4040  if (ast_channel_audiohooks(chan)) {
4041  struct ast_frame *old_frame = f;
4043  if (old_frame != f) {
4044  ast_frfree(old_frame);
4045  }
4046  }
4047 
4048  /* Start generating 50 fps timer events (null frames) for dtmf emulating
4049  * independently from any existing incoming voice frames.
4050  * If channel generator is already activated in regular mode use these
4051  * timer events to generate null frames.
4052  */
4053  if (!ast_channel_generator(chan)) {
4055  }
4056  }
4057  }
4058  break;
4059  case AST_FRAME_VOICE:
4060  /* If media was received from a non-default stream don't perform any actions, let it just go through */
4061  if (stream != default_stream) {
4062  break;
4063  }
4064 
4065  /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
4066  * is reached , because we want to make sure we pass at least one
4067  * voice frame through before starting the next digit, to ensure a gap
4068  * between DTMF digits. */
4070  ast_log(LOG_WARNING, "!!! t5a\n");
4073  }
4074 
4075  if (dropaudio || ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
4076  ast_log(LOG_WARNING, "!!! t5b\n");
4077  if (dropaudio)
4078  ast_read_generator_actions(chan, f);
4079  ast_frfree(f);
4080  f = &ast_null_frame;
4081  }
4082 
4084  struct timeval now = ast_tvnow();
4085  ast_log(LOG_WARNING, "!!! t5c\n");
4088  ast_frfree(f);
4089  f = ast_channel_dtmff(chan);
4092  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
4093  ast_channel_dtmf_tv_set(chan, &now);
4094  if (ast_channel_audiohooks(chan)) {
4095  struct ast_frame *old_frame = f;
4097  if (old_frame != f)
4098  ast_frfree(old_frame);
4099  }
4100  ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
4101  } else {
4102  /* Drop voice frames while we're still in the middle of the digit */
4103  ast_frfree(f);
4104  f = &ast_null_frame;
4105  }
4106  break;
4107  }
4108  if (f->frametype != AST_FRAME_VOICE) {
4109  ast_log(LOG_WARNING, "!!! t5d\n");
4110  break;
4111  }
4114  struct ast_format *core_format;
4115 
4116  /*
4117  * Note: This frame may not be one of the current native
4118  * formats. We may have gotten it out of the read queue from
4119  * a previous multi-frame translation, from a framehook
4120  * injected frame, or the device we're talking to isn't
4121  * respecting negotiated formats. Regardless we will accept
4122  * all frames.
4123  *
4124  * Update the read translation path to handle the new format
4125  * that just came in. If the core wants slinear we need to
4126  * setup a new translation path because the core is usually
4127  * doing something with the audio itself and may not handle
4128  * any other format. e.g., Softmix bridge, holding bridge
4129  * announcer channel, recording, AMD... Otherwise, we'll
4130  * setup to pass the frame as is to the core. In this case
4131  * the core doesn't care. The channel is likely in
4132  * autoservice, safesleep, or the channel is in a bridge.
4133  * Let the bridge technology deal with format compatibility
4134  * between the channels in the bridge.
4135  *
4136  * Beware of the transcode_via_slin and genericplc options as
4137  * they force any transcoding to go through slin on a bridge.
4138  * Unfortunately transcode_via_slin is enabled by default and
4139  * genericplc is enabled in the codecs.conf.sample file.
4140  *
4141  * XXX Only updating translation to slinear frames has some
4142  * corner cases if slinear is one of the native formats and
4143  * there are different sample rates involved. We might wind
4144  * up with conflicting translation paths between channels
4145  * where the read translation path on this channel reduces
4146  * the sample rate followed by a write translation path on
4147  * the peer channel that increases the sample rate.
4148  */
4149  core_format = ast_channel_readformat(chan);
4150  if (!ast_format_cache_is_slinear(core_format)) {
4151  core_format = f->subclass.format;
4152  }
4153  ast_log(LOG_WARNING, "!!! t5f\n");
4154  if (ast_set_read_format_path(chan, f->subclass.format, core_format)) {
4155  /* Drop frame. We couldn't make it compatible with the core. */
4156  ast_frfree(f);
4157  f = &ast_null_frame;
4158  break;
4159  }
4160  }
4161  /*
4162  * Send frame to audiohooks if present, if frametype is linear, to preserve
4163  * functional compatibility with previous behavior. If not linear, hold off
4164  * until transcoding is done where we are more likely to have a linear frame
4165  */
4167  /* Place hooked after declaration */
4168  struct ast_frame *old_frame = f;
4169  hooked = 1;
4170  ast_log(LOG_WARNING, "!!! t5h\n");
4172  if (old_frame != f) {
4173  ast_frfree(old_frame);
4174  }
4175  }
4176 
4177  if (ast_channel_monitor(chan) && ast_channel_monitor(chan)->read_stream) {
4178  /* XXX what does this do ? */
4179 #ifndef MONITOR_CONSTANT_DELAY
4180  int jump = ast_channel_outsmpl(chan) - ast_channel_insmpl(chan) - 4 * f->samples;
4181  if (jump >= 0) {
4184  ast_format_get_sample_rate(ast_channel_monitor(chan)->read_stream->fmt->format));
4185  if (ast_seekstream(ast_channel_monitor(chan)->read_stream, jump, SEEK_FORCECUR) == -1) {
4186  ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
4187  }
4189  } else {
4191  }
4192 #else
4193  int jump = calc_monitor_jump((ast_channel_outsmpl(chan) - ast_channel_insmpl(chan)),
4195  ast_format_get_sample_rate(ast_channel_monitor(chan)->read_stream->fmt->format));
4196  if (jump - MONITOR_DELAY >= 0) {
4197  if (ast_seekstream(ast_channel_monitor(chan)->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) {
4198  ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
4199  }
4201  } else {
4202  ast_channel_insmpl(chan) += f->samples;
4203  }
4204 #endif
4206  if (ast_writestream(ast_channel_monitor(chan)->read_stream, f) < 0)
4207  ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n");
4208  }
4209  ast_log(LOG_WARNING, "!!! t5jj\n");
4210  }
4211 
4212  if (ast_channel_readtrans(chan)
4214  f = ast_translate(ast_channel_readtrans(chan), f, 1);
4215  if (!f) {
4216  f = &ast_null_frame;
4217  }
4218  }
4219 
4220  /* Second chance at hooking a linear frame, also the last chance */
4221  if (ast_channel_audiohooks(chan) && !hooked) {
4222  struct ast_frame *old_frame = f;
4224  if (old_frame != f) {
4225  ast_frfree(old_frame);
4226  }
4227  }
4228 
4229  /*
4230  * It is possible for the translation process on the channel to have
4231  * produced multiple frames from the single input frame we passed it; if
4232  * this happens, queue the additional frames *before* the frames we may
4233  * have queued earlier. if the readq was empty, put them at the head of
4234  * the queue, and if it was not, put them just after the frame that was
4235  * at the end of the queue.
4236  */
4237  if (AST_LIST_NEXT(f, frame_list)) {
4238  struct ast_frame *cur, *multi_frame = AST_LIST_NEXT(f, frame_list);
4239  ast_log(LOG_WARNING, "!!! t5k\n");
4240  /* Mark these frames as being re-queued */
4241  for (cur = multi_frame; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
4243  }
4244 
4245  if (!readq_tail) {
4246  ast_queue_frame_head(chan, multi_frame);
4247  } else {
4248  __ast_queue_frame(chan, multi_frame, 0, readq_tail);
4249  }
4250  ast_frfree(multi_frame);
4252  }
4253 
4254  /*
4255  * Run generator sitting on the line if timing device not available
4256  * and synchronous generation of outgoing frames is necessary
4257  */
4258  ast_read_generator_actions(chan, f);
4259  break;
4260  case AST_FRAME_RTCP:
4261  /* Incoming RTCP feedback needs to get to the translator for
4262  * outgoing media, which means we treat it as an ast_write */
4263  if (ast_channel_writetrans(chan)) {
4265  }
4266  break;
4267  default:
4268  /* Just pass it on! */
4269  break;
4270  }
4271  } else {
4272  /* Make sure we always return NULL in the future */
4275  }
4276  if (cause)
4277  ast_channel_hangupcause_set(chan, cause);
4278  if (ast_channel_generator(chan))
4280  /* We no longer End the CDR here */
4281  }
4282 
4283  /* High bit prints debugging */
4284  if (ast_channel_fin(chan) & DEBUGCHAN_FLAG)
4285  ast_frame_dump(ast_channel_name(chan), f, "<<");
4287 
4288 done:
4290  ast_channel_generator(chan)->digit(chan, f->subclass.integer);
4291  }
4292 
4294  /* The list gets recreated if audiohooks are added again later */
4297  }
4298  ast_channel_unlock(chan);
4299  return f;
4300 }
void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
void ast_channel_fdno_set(struct ast_channel *chan, int value)
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame.
Definition: channel.c:1231
int ast_channel_fd_isset(const struct ast_channel *chan, int which)
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2945
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition: format.c:354
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
void * ast_channel_generatordata(const struct ast_channel *chan)
static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
Definition: channel.c:1015
void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value)
unsigned int option_dtmfminduration
Definition: options.c:83
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
#define DEBUGCHAN_FLAG
Definition: channel.h:858
static int calc_monitor_jump(int samples, int sample_rate, int seek_rate)
calculates the number of samples to jump forward with in a monitor stream.
Definition: channel.c:3516
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void send_dtmf_begin_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit)
Definition: channel.c:3378
void ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
Definition: audiohook.c:594
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
#define AST_DEFAULT_EMULATE_DTMF_DURATION
Definition: channel.c:102
int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
Determine if a audiohook_list is empty or not.
Definition: audiohook.c:1112
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition: channel.c:8881
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_framehook_list * ast_channel_framehooks(const struct ast_channel *chan)
#define LOG_WARNING
Definition: logger.h:274
unsigned long ast_channel_insmpl(const struct ast_channel *chan)
ast_timer_event
Definition: timing.h:57
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology)
Provide notice to a channel that the stream topology has changed.
Definition: channel.c:11197
#define AST_MIN_DTMF_GAP
Definition: channel.c:112
static int tmp()
Definition: bt_open.c:389
struct ast_frame *(*const read_stream)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame.h), with stream num.
Definition: channel.h:748
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:108
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
Structure used to transport a message through the frame core.
Definition: message.c:1406
ast_channel_state
ast_channel states
Definition: channelstate.h:35
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
Definition: main/frame.c:731
Definition of a media format.
Definition: format.c:43
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2022
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int is_frame)
Run a connected line interception macro and update a channel&#39;s connected line information.
Definition: channel.c:10435
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
static void send_flash_event(struct ast_channel *chan)
Definition: channel.c:3411
static int should_skip_dtmf(struct ast_channel *chan)
Determine whether or not we should ignore DTMF in the readq.
Definition: channel.c:3489
int(* generate)(struct ast_channel *chan, void *data, int len, int samples)
Definition: channel.h:234
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
Definition: translate.c:565
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
Definition: stream.c:788
#define NULL
Definition: resample.c:96
static void set_channel_answer_time(struct ast_channel *chan)
Definition: channel.c:2637
static int should_trigger_dtmf_emulating(struct ast_channel *chan)
Determine whether or not we have to trigger dtmf emulating using 50 fps timer events especially when ...
Definition: channel.c:2864
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
struct ast_frame_subclass subclass
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
int done
Definition: test_amihooks.c:48
struct ast_readq_list * ast_channel_readq(struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Checks to see if a channel is needing hang up.
Definition: channel.c:445
int ast_indicate_data(struct ast_channel *chan, int _condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4698
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
unsigned int ast_channel_fin(const struct ast_channel *chan)
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2072
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
struct ast_stream * ast_channel_get_default_stream(struct ast_channel *chan, enum ast_media_type type)
Retrieve the default stream of a specific media type on a channel.
void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
struct ast_trans_pvt * ast_channel_writetrans(const struct ast_channel *chan)
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
int ast_timer_disable_continuous(const struct ast_timer *handle)
Disable continuous mode.
Definition: timing.c:181
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define AST_GENERATOR_FD
Definition: channel.h:204
int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback...
Definition: channel.c:4796
void * ast_channel_timingdata(const struct ast_channel *chan)
int(* ast_timing_func_t)(const void *data)
Definition: channel.h:900
int ast_format_cache_is_slinear(struct ast_format *format)
Determines if a format is one of the cached slin formats.
Definition: format_cache.c:542
void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
int ast_channel_fdno(const struct ast_channel *chan)
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2031
int ast_channel_timingfd(const struct ast_channel *chan)
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
Definition: timing.c:171
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4854
#define LOG_ERROR
Definition: logger.h:285
struct ast_generator * ast_channel_generator(const struct ast_channel *chan)
struct ast_frame * ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass a frame off to be handled by the audiohook core.
Definition: audiohook.c:1127
struct timeval * ast_channel_dtmf_tv(struct ast_channel *chan)
#define AST_TIMING_FD
Definition: channel.h:202
Connected Line/Party information.
Definition: channel.h:457
enum ast_frame_read_action action
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
Definition: file.c:1038
void(* digit)(struct ast_channel *chan, char digit)
Definition: channel.h:236
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define SEEK_FORCECUR
Definition: file.h:51
struct ast_frame *(*const exception)(struct ast_channel *chan)
Handle an exception, reading a frame.
Definition: channel.h:766
#define FRAMECOUNT_INC(x)
Definition: channel.h:861
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2902
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
Definition: timing.c:166
#define ast_clear_flag(p, flag)
Definition: utils.h:77
struct ast_frame *(*const read)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame.h)
Definition: channel.h:735
char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define LOG_DTMF
Definition: logger.h:307
int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
Set specific read path on channel.
Definition: channel.c:5575
int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
static void send_dtmf_end_event(struct ast_channel *chan, enum DtmfDirection direction, const char digit, long duration_ms)
Definition: channel.c:3394
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10746
const char * ast_channel_name(const struct ast_channel *chan)
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Definition: file.c:209
void * ast_channel_music_state(const struct ast_channel *chan)
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
#define ast_frfree(fr)
Data structure associated with a single frame of data.
void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
#define AST_JITTERBUFFER_FD
Definition: channel.h:205
unsigned long ast_channel_outsmpl(const struct ast_channel *chan)
union ast_frame::@263 data
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
enum ast_frame_type frametype
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_format * format
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
static void queue_dtmf_readq(struct ast_channel *chan, struct ast_frame *f)
Definition: channel.c:3470
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
enum ast_timer_event ast_timer_get_event(const struct ast_timer *handle)
Retrieve timing event.
Definition: timing.c:186
int ast_stream_get_position(const struct ast_stream *stream)
Get the position of the stream in the topology.
Definition: stream.c:500
char connected
Definition: eagi_proxy.c:82
struct ast_channel_monitor * ast_channel_monitor(const struct ast_channel *chan)
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
struct ast_frame * ast_channel_dtmff(struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
Definition: channel.c:3416
struct ast_frame * ast_framehook_list_read_event(struct ast_framehook_list *framehooks, struct ast_frame *frame)
This is used by the channel API push a frame read event to a channel&#39;s framehook list.
Definition: framehook.c:318
int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
Change the state of a channel.
Definition: channel.c:7486
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
Run a connected line interception subroutine and update a channel&#39;s connected line information...
Definition: channel.c:10539
int ast_channel_alert_write(struct ast_channel *chan)
struct ast_timer * ast_channel_timer(const struct ast_channel *chan)
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
Queue one or more frames to the head of a channel&#39;s frame queue.
Definition: channel.c:1144

◆ __ast_request_and_dial()

struct ast_channel* __ast_request_and_dial ( const char *  type,
struct ast_format_cap cap,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  addr,
int  timeout,
int *  reason,
const char *  cid_num,
const char *  cid_name,
struct outgoing_helper oh 
)

Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.

Parameters
typetype of channel to request
capformat capabilities for requested channel
assignedidsUnique Id to assign to channel
requestorchannel requesting data
addrdestination of the call
timeoutmaximum amount of time to wait for an answer
reasonwhy unsuccessful (if unsuccessful)
cid_numCaller-ID Number
cid_nameCaller-ID Name (ascii)
ohOutgoing helper
Returns
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 6066 of file channel.c.

References outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_channel_call_forward(), ast_channel_connected(), ast_channel_context_set(), ast_channel_datastore_inherit(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_hangupcause_hash_set(), ast_channel_hangupcause_set(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, ast_channel_priority_set(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_set_connected_line(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_FLAG_ORIGINATED, AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log, ast_max_forwards_decrement(), ast_party_connected_line_set_init(), AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, ast_read(), ast_remaining_ms(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero, ast_tvnow(), ast_waitfor(), chanlist::chan, outgoing_helper::cid_name, outgoing_helper::cid_num, outgoing_helper::connect_on_early_media, outgoing_helper::context, ast_frame::data, ast_frame::datalen, outgoing_helper::exten, ast_frame::frametype, handle_cause(), ast_party_connected_line::id, ast_frame_subclass::integer, LOG_NOTICE, ast_party_id::name, NULL, ast_party_id::number, outgoing_helper::parent_channel, ast_party_name::presentation, ast_party_number::presentation, outgoing_helper::priority, ast_frame::ptr, ast_party_name::str, ast_party_number::str, ast_frame::subclass, ast_party_name::valid, ast_party_number::valid, and outgoing_helper::vars.

Referenced by announce_to_dial(), and ast_request_and_dial().

6067 {
6068  int dummy_outstate;
6069  int cause = 0;
6070  struct ast_channel *chan;
6071  int res = 0;
6072  int last_subclass = 0;
6074 
6075  if (outstate)
6076  *outstate = 0;
6077  else
6078  outstate = &dummy_outstate; /* make outstate always a valid pointer */
6079 
6080  chan = ast_request(type, cap, assignedids, requestor, addr, &cause);
6081  if (!chan) {
6082  ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, addr);
6083  handle_cause(cause, outstate);
6084  return NULL;
6085  }
6086 
6087  if (oh) {
6088  if (oh->vars) {
6089  ast_channel_lock(chan);
6090  ast_set_variables(chan, oh->vars);
6091  ast_channel_unlock(chan);
6092  }
6093  if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
6094  /*
6095  * Use the oh values instead of the function parameters for the
6096  * outgoing CallerID.
6097  */
6098  cid_num = oh->cid_num;
6099  cid_name = oh->cid_name;
6100  }
6101  if (oh->parent_channel) {
6102  /* Safely inherit variables and datastores from the parent channel. */
6108  ast_channel_unlock(chan);
6109  }
6110  if (!ast_strlen_zero(oh->account)) {
6111  ast_channel_lock(chan);
6113  ast_channel_accountcode_set(chan, oh->account);
6114  ast_channel_peeraccount_set(chan, oh->account);
6116  ast_channel_unlock(chan);
6117  }
6118  }
6119 
6120  /*
6121  * I seems strange to set the CallerID on an outgoing call leg
6122  * to whom we are calling, but this function's callers are doing
6123  * various Originate methods. This call leg goes to the local
6124  * user. Once the local user answers, the dialplan needs to be
6125  * able to access the CallerID from the CALLERID function as if
6126  * the local user had placed this call.
6127  */
6129 
6130  ast_channel_lock(chan);
6132  ast_channel_unlock(chan);
6134  if (cid_num) {
6135  connected.id.number.valid = 1;
6136  connected.id.number.str = (char *) cid_num;
6137  connected.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
6138  }
6139  if (cid_name) {
6140  connected.id.name.valid = 1;
6141  connected.id.name.str = (char *) cid_name;
6143  }
6145  if (requestor) {
6146  ast_channel_lock_both(chan, (struct ast_channel *) requestor);
6148  ast_channel_unlock(chan);
6149  ast_channel_unlock((struct ast_channel *) requestor);
6150  }
6151 
6152  if (ast_call(chan, addr, 0)) { /* ast_call failed... */
6153  ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, addr);
6154  } else {
6155  struct timeval start = ast_tvnow();
6156  res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
6157  while (timeout && ast_channel_state(chan) != AST_STATE_UP) {
6158  struct ast_frame *f;
6159  int ms = ast_remaining_ms(start, timeout);
6160 
6161  res = ast_waitfor(chan, ms);
6162  if (res == 0) { /* timeout, treat it like ringing */
6163  *outstate = AST_CONTROL_RINGING;
6164  break;
6165  }
6166  if (res < 0) /* error or done */
6167  break;
6169  if (!(chan = ast_call_forward(NULL, chan, NULL, cap, oh, outstate))) {
6170  return NULL;
6171  }
6172  continue;
6173  }
6174 
6175  f = ast_read(chan);
6176  if (!f) {
6177  *outstate = AST_CONTROL_HANGUP;
6178  res = 0;
6179  break;
6180  }
6181  if (f->frametype == AST_FRAME_CONTROL) {
6182  switch (f->subclass.integer) {
6183  case AST_CONTROL_RINGING: /* record but keep going */
6184  *outstate = f->subclass.integer;
6185  break;
6186 
6187  case AST_CONTROL_BUSY:
6188  *outstate = f->subclass.integer;
6189  timeout = 0;
6190  break;
6191 
6193  *outstate = AST_CONTROL_CONGESTION;
6194  timeout = 0;
6195  break;
6196 
6198  *outstate = f->subclass.integer;
6199  timeout = 0;
6200  break;
6201 
6202  case AST_CONTROL_ANSWER:
6203  *outstate = f->subclass.integer;
6204  timeout = 0; /* trick to force exit from the while() */
6205  break;
6206 
6209  break;
6210 
6211  case AST_CONTROL_PROGRESS:
6212  if (oh && oh->connect_on_early_media) {
6213  *outstate = f->subclass.integer;
6214  timeout = 0; /* trick to force exit from the while() */
6215  break;
6216  }
6217  /* Fallthrough */
6218  /* Ignore these */
6220  case AST_CONTROL_HOLD:
6221  case AST_CONTROL_UNHOLD:
6222  case AST_CONTROL_VIDUPDATE:
6223  case AST_CONTROL_SRCUPDATE:
6224  case AST_CONTROL_SRCCHANGE:
6227  case AST_CONTROL_CC:
6228  case -1: /* Ignore -- just stopping indications */
6229  break;
6230 
6231  default:
6232  ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
6233  }
6234  last_subclass = f->subclass.integer;
6235  }
6236  ast_frfree(f);
6237  }
6238  }
6239 
6240  /* Final fixups */
6241  if (oh) {
6242  if (!ast_strlen_zero(oh->context))
6243  ast_channel_context_set(chan, oh->context);
6244  if (!ast_strlen_zero(oh->exten))
6245  ast_channel_exten_set(chan, oh->exten);
6246  if (oh->priority)
6248  }
6249  if (ast_channel_state(chan) == AST_STATE_UP)
6250  *outstate = AST_CONTROL_ANSWER;
6251 
6252  if (res <= 0) {
6253  ast_channel_lock(chan);
6254  if (AST_CONTROL_RINGING == last_subclass) {
6256  }
6257  ast_channel_unlock(chan);
6258  ast_hangup(chan);
6259  chan = NULL;
6260  }
6261  return chan;
6262 }
static const char type[]
Definition: chan_ooh323.c:109
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
const char * cid_num
Definition: channel.h:1110
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation...
Definition: channel.c:2045
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8404
struct ast_channel * parent_channel
Definition: channel.h:1114
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
#define ast_set_flag(p, flag)
Definition: utils.h:70
static int timeout
Definition: cdr_mysql.c:86
ast_channel_state
ast_channel states
Definition: channelstate.h:35
int connect_on_early_media
Definition: channel.h:1109
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6866
#define NULL
Definition: resample.c:96
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:329
const char * ast_channel_call_forward(const struct ast_channel *chan)
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
struct ast_variable * vars
Definition: channel.h:1113
struct ast_frame_subclass subclass
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2373
struct ast_channel * ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
Forwards a call to a new channel specified by the original channel&#39;s call_forward str...
Definition: channel.c:5988
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
const char * exten
Definition: channel.h:1107
const char * cid_name
Definition: channel.h:1111
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6553
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
const char * account
Definition: channel.h:1112
static void handle_cause(int cause, int *outstate)
Definition: channel.c:5936
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6526
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2033
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition: channel.c:7434
Connected Line/Party information.
Definition: channel.h:457
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
#define LOG_NOTICE
Definition: logger.h:263
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel. ...
Definition: channel.c:4391
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2952
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition: channel.c:6444
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
void ast_channel_context_set(struct ast_channel *chan, const char *value)
const char * context
Definition: channel.h:1106
int ast_waitfor(struct ast_channel *c, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ast_frfree(fr)
void ast_hangup(struct ast_channel *chan)
Hangup a channel.
Definition: channel.c:2548
Data structure associated with a single frame of data.
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
char connected
Definition: eagi_proxy.c:82
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8217

◆ __init_state2str_threadbuf()

static void __init_state2str_threadbuf ( void  )
static

Definition at line 97 of file channel.c.

115 {

◆ adjust_frame_for_plc()

static void adjust_frame_for_plc ( struct ast_channel chan,
struct ast_frame frame,
struct ast_datastore datastore 
)
static

Definition at line 5098 of file channel.c.

References ast_calloc, ast_channel_datastore_remove(), ast_datastore_free(), ast_free, AST_FRIENDLY_OFFSET, ast_datastore::data, ast_frame::data, ast_frame::datalen, plc_ds::num_samples, ast_frame::offset, plc_fillin(), plc_rx(), plc_ds::plc_state, ast_frame::ptr, ast_frame::samples, and plc_ds::samples_buf.

Referenced by apply_plc().

5099 {
5100  int num_new_samples = frame->samples;
5101  struct plc_ds *plc = datastore->data;
5102 
5103  /* As a general note, let me explain the somewhat odd calculations used when taking
5104  * the frame offset into account here. According to documentation in frame.h, the frame's
5105  * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf
5106  * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN
5107  * samples. So I had two choices to make here with the offset.
5108  *
5109  * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that
5110  * I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer
5111  * arithmetic come out right. I would have to do some odd casting or division for this to
5112  * work as I wanted.
5113  * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic
5114  * to work out better with the plc->samples_buf. The downside here is that the buffer's
5115  * allocation contains an extra 64 bytes of unused space.
5116  *
5117  * I decided to go with option 2. This is why in the calloc statement and the statement that
5118  * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2.
5119  */
5120 
5121  /* If this audio frame has no samples to fill in, ignore it */
5122