Asterisk - The Open Source Telephony Project
21.4.1
|
Multi-party software based channel mixing. More...
#include "asterisk.h"
#include <math.h>
#include "asterisk/stream.h"
#include "asterisk/test.h"
#include "asterisk/vector.h"
#include "asterisk/message.h"
#include "bridge_softmix/include/bridge_softmix_internal.h"
Go to the source code of this file.
Data Structures | |
struct | softmix_remb_collector |
struct | softmix_stats |
struct | softmix_translate_helper |
struct | softmix_translate_helper_entry |
Macros | |
#define | DEFAULT_SOFTMIX_INTERVAL 20 |
Interval at which mixing will take place. Valid options are 10, 20, and 40. | |
#define | DEFAULT_SOFTMIX_SILENCE_THRESHOLD 2500 |
Default time in ms of silence necessary to declare talking stopped by the bridge. More... | |
#define | DEFAULT_SOFTMIX_TALKING_THRESHOLD 160 |
#define | SOFTBRIDGE_VIDEO_DEST_LEN strlen(SOFTBRIDGE_VIDEO_DEST_PREFIX) |
#define | SOFTBRIDGE_VIDEO_DEST_PREFIX "softbridge_dest" |
#define | SOFTBRIDGE_VIDEO_DEST_SEPARATOR '_' |
#define | SOFTMIX_DATALEN(rate, interval) ((rate/50) * (interval / 10)) |
Size of the buffer used for sample manipulation. | |
#define | SOFTMIX_MIN_SAMPLE_RATE 8000 /* 8 kHz sample rate */ |
#define | SOFTMIX_SAMPLES(rate, interval) (SOFTMIX_DATALEN(rate, interval) / 2) |
Number of samples we are dealing with. | |
#define | SOFTMIX_STAT_INTERVAL 100 |
Number of mixing iterations to perform between gathering statistics. | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static unsigned int | analyse_softmix_stats (struct softmix_stats *stats, struct softmix_bridge_data *softmix_data, int binaural_active) |
static int | append_all_streams (struct ast_stream_topology *dest, const struct ast_stream_topology *source) |
static int | append_source_stream (struct ast_stream_topology *dest, const char *channel_name, const char *sdp_label, struct ast_stream *stream, int index) |
static int | append_source_streams (struct ast_stream_topology *dest, const char *channel_name, const char *sdp_label, const struct ast_stream_topology *source) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | clear_talking (struct ast_bridge_channel *bridge_channel) |
static void | gather_softmix_stats (struct softmix_stats *stats, const struct softmix_bridge_data *softmix_data, struct ast_bridge_channel *bridge_channel) |
static int | is_video_dest (const struct ast_stream *stream, const char *source_channel_name, int source_channel_stream_position) |
Determine if a stream is a video destination stream. More... | |
static int | is_video_source (const struct ast_stream *stream) |
Determine if a stream is a video source stream. More... | |
static int | load_module (void) |
static void | map_source_to_destinations (const char *source_channel_name, size_t bridge_stream_position, struct ast_bridge_channels_list *participants, int source_channel_stream_position) |
Map a source stream to all of its destination streams. More... | |
static void | remb_collect_report (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct softmix_bridge_data *softmix_data, struct softmix_channel *sc) |
static void | remb_collect_report_all (struct ast_bridge *bridge, struct softmix_bridge_data *softmix_data, float bitrate) |
static struct softmix_remb_collector * | remb_collector_alloc (void) |
Allocate a REMB collector. More... | |
static void | remb_enable_collection (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, size_t bridge_stream_position) |
Setup REMB collection for a particular bridge stream and channel. More... | |
static void | remb_send_report (struct ast_bridge_channel *bridge_channel, struct softmix_bridge_data *softmix_data, struct softmix_channel *sc) |
static int | remove_all_original_streams (struct ast_stream_topology *dest, const struct ast_stream_topology *source, const struct ast_stream_topology *original) |
static int | remove_destination_streams (struct ast_stream_topology *topology, const char *channel_name) |
static void | set_softmix_bridge_data (int rate, int interval, struct ast_bridge_channel *bridge_channel, int reset, int set_binaural, int binaural_pos_id, int is_announcement) |
static void | sfu_topologies_on_join (struct ast_bridge *bridge, struct ast_bridge_channel *joiner) |
Issue channel stream topology change requests. More... | |
static int | sfu_topologies_on_leave (struct ast_bridge_channel *leaver, struct ast_bridge_channels_list *participants) |
static void | sfu_topologies_on_source_change (struct ast_bridge *bridge, struct ast_bridge_channel *source) |
static void | softmix_bridge_check_voice (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) |
static int | softmix_bridge_create (struct ast_bridge *bridge) |
Function called when a bridge is created. | |
static void | softmix_bridge_data_destroy (struct softmix_bridge_data *softmix_data) |
static void | softmix_bridge_destroy (struct ast_bridge *bridge) |
Function called when a bridge is destroyed. | |
static int | softmix_bridge_join (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) |
Function called when a channel is joined into the bridge. | |
static void | softmix_bridge_leave (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) |
Function called when a channel leaves the bridge. | |
static void | softmix_bridge_stop (struct ast_bridge *bridge) |
static void | softmix_bridge_stream_sources_update (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct softmix_channel *sc) |
static void | softmix_bridge_stream_topology_changed (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) |
stream_topology_changed callback More... | |
static void | softmix_bridge_unsuspend (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel) |
Function called when a channel is unsuspended from the bridge. | |
static int | softmix_bridge_write (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static int | softmix_bridge_write_control (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static void | softmix_bridge_write_rtcp (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static void | softmix_bridge_write_text (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static void | softmix_bridge_write_video (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static void | softmix_bridge_write_voice (struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame) |
static void | softmix_mixing_array_destroy (struct softmix_mixing_array *mixing_array, unsigned int binaural_active) |
static int | softmix_mixing_array_grow (struct softmix_mixing_array *mixing_array, unsigned int num_entries, unsigned int binaural_active) |
static int | softmix_mixing_array_init (struct softmix_mixing_array *mixing_array, unsigned int starting_num_entries, unsigned int binaural_active) |
static int | softmix_mixing_loop (struct ast_bridge *bridge) |
Mixing loop. More... | |
static void * | softmix_mixing_thread (void *data) |
static void | softmix_pass_video_top_priority (struct ast_bridge *bridge, struct ast_frame *frame) |
static void | softmix_poke_thread (struct softmix_bridge_data *softmix_data) |
static int16_t * | softmix_process_read_audio (struct softmix_channel *sc, unsigned int num_samples) |
static void | softmix_process_write_audio (struct softmix_translate_helper *trans_helper, struct ast_format *raw_write_fmt, struct softmix_channel *sc, unsigned int default_sample_size) |
static void | softmix_translate_helper_change_rate (struct softmix_translate_helper *trans_helper, unsigned int sample_rate) |
static void | softmix_translate_helper_cleanup (struct softmix_translate_helper *trans_helper) |
static void | softmix_translate_helper_destroy (struct softmix_translate_helper *trans_helper) |
static struct softmix_translate_helper_entry * | softmix_translate_helper_entry_alloc (struct ast_format *dst) |
static void * | softmix_translate_helper_free_entry (struct softmix_translate_helper_entry *entry) |
static void | softmix_translate_helper_init (struct softmix_translate_helper *trans_helper, unsigned int sample_rate) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Multi-party software based channel mixing" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_bridge_technology | softmix_bridge |
Multi-party software based channel mixing.
Definition in file bridge_softmix.c.
#define DEFAULT_SOFTMIX_SILENCE_THRESHOLD 2500 |
Default time in ms of silence necessary to declare talking stopped by the bridge.
This is the time at which a channel's own audio will stop getting mixed out of its own write audio stream because it is no longer talking.
Definition at line 66 of file bridge_softmix.c.
#define DEFAULT_SOFTMIX_TALKING_THRESHOLD 160 |
Default minimum average magnitude threshold to determine talking by the DSP.
Definition at line 69 of file bridge_softmix.c.
#define SOFTMIX_MIN_SAMPLE_RATE 8000 /* 8 kHz sample rate */ |
The minimum sample rate of the bridge.
Definition at line 45 of file bridge_softmix.c.
Referenced by softmix_bridge_create().
|
static |
Determine if a stream is a video destination stream.
A source channel name can be provided to narrow this to a destination stream for a particular source channel. Further, a source stream name can be provided to narrow this to a particular source stream's destination. However, empty strings can be provided to match any destination video stream, regardless of source channel or source stream.
stream | The stream to test |
source_channel_name | The name of a source video channel to match |
source_channel_stream_position | The position of the video on the source channel |
1 | The stream is a video destination stream |
0 | The stream is not a video destination stream |
Definition at line 466 of file bridge_softmix.c.
References ast_alloca, ast_stream_get_name(), ast_stream_get_state(), ast_stream_get_type(), and AST_STREAM_STATE_REMOVED.
Referenced by map_source_to_destinations().
|
static |
Determine if a stream is a video source stream.
stream | The stream to test |
1 | The stream is a video source |
0 | The stream is not a video source |
Definition at line 439 of file bridge_softmix.c.
References ast_stream_get_name(), ast_stream_get_state(), ast_stream_get_type(), and AST_STREAM_STATE_REMOVED.
Referenced by softmix_bridge_stream_topology_changed().
|
static |
Map a source stream to all of its destination streams.
source_channel_name | Name of channel where the source stream originates |
bridge_stream_position | The slot in the bridge where source video will come from |
participants | The bridge_channels in the bridge |
source_channel_stream_position | The position of the stream on the source channel |
Definition at line 2168 of file bridge_softmix.c.
References ast_bridge_channel_lock, ast_bridge_channel_unlock, ast_channel_get_stream_topology(), AST_LIST_TRAVERSE, ast_stream_topology_get_count(), ast_stream_topology_get_stream(), AST_VECTOR_APPEND, AST_VECTOR_REPLACE, ast_bridge_channel::chan, is_video_dest(), ast_bridge_channel::tech_pvt, ast_bridge_channel::to_channel, and softmix_channel::video_sources.
Referenced by softmix_bridge_stream_topology_changed().
|
static |
Allocate a REMB collector.
non-NULL | success |
NULL | failure |
Definition at line 2208 of file bridge_softmix.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, AST_FRAME_RTCP, AST_RTP_RTCP_FMT_REMB, AST_RTP_RTCP_PSFB, ast_frame::data, ast_frame::datalen, softmix_remb_collector::feedback, ast_rtp_rtcp_feedback::fmt, softmix_remb_collector::frame, ast_frame::frametype, ast_frame_subclass::integer, and ast_frame::subclass.
Referenced by remb_enable_collection().
|
static |
Setup REMB collection for a particular bridge stream and channel.
bridge | The bridge |
bridge_channel | Channel that is collecting REMB information |
bridge_stream_position | The slot in the bridge where source video comes from |
Definition at line 2233 of file bridge_softmix.c.
References ao2_ref, AST_VECTOR_REPLACE, softmix_channel::remb_collector, remb_collector_alloc(), softmix_bridge_data::remb_collectors, ast_bridge_channel::tech_pvt, and ast_bridge::tech_pvt.
Referenced by softmix_bridge_stream_topology_changed().
|
static |
Issue channel stream topology change requests.
When in SFU mode, each participant needs to be able to send video directly to other participants in the bridge. This means that all participants need to have their topologies updated. The joiner needs to have destination streams for all current participants, and the current participants need to have destinations streams added for the joiner's sources.
bridge | |
joiner | The channel that is joining the softmix bridge |
Definition at line 619 of file bridge_softmix.c.
References ast_channel_get_stream_topology(), ast_channel_request_stream_topology_change(), AST_LIST_TRAVERSE, ast_stream_topology_alloc(), ast_stream_topology_clone(), ast_stream_topology_free(), ast_bridge_channel::chan, ast_bridge::channels, RAII_VAR, ast_bridge_softmix::send_sdp_label, ast_bridge::softmix, ast_bridge_channel::tech_pvt, and softmix_channel::topology.
Referenced by softmix_bridge_join().
|
static |
stream_topology_changed callback
For most video modes, nothing beyond the ordinary is required. For the SFU case, though, we need to completely remap the streams in order to ensure video gets directed where it is expected to go.
bridge | The bridge |
bridge_channel | Channel whose topology has changed |
Definition at line 2450 of file bridge_softmix.c.
References ao2_bump, ast_bridge_channel_lock, ast_bridge_channel_stream_map(), ast_bridge_channel_unlock, AST_BRIDGE_VIDEO_MODE_NONE, AST_BRIDGE_VIDEO_MODE_SFU, AST_BRIDGE_VIDEO_MODE_SINGLE_SRC, AST_BRIDGE_VIDEO_MODE_TALKER_SRC, ast_channel_get_stream_topology(), AST_LIST_TRAVERSE, ast_stream_get_state(), ast_stream_get_type(), AST_STREAM_STATE_REMOVED, ast_stream_topology_free(), ast_stream_topology_get_count(), ast_stream_topology_get_stream(), AST_VECTOR_APPEND, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_GET_INDEX_NTH, AST_VECTOR_INIT, AST_VECTOR_REPLACE, AST_VECTOR_RESET, AST_VECTOR_SIZE, ast_bridge_channel::chan, ast_bridge::channels, is_video_source(), map_source_to_destinations(), softmix_bridge_data::remb_collectors, remb_enable_collection(), ast_bridge::softmix, ast_bridge_channel::tech_pvt, ast_bridge::tech_pvt, ast_bridge_channel::to_bridge, ast_bridge_channel::to_channel, ast_stream::type, ast_bridge_softmix::video_mode, and softmix_channel::video_sources.
|
static |
Mixing loop.
0 | on success |
-1 | on failure |
Definition at line 1752 of file bridge_softmix.c.
References add_binaural_mixing(), ast_bridge_channel_queue_frame(), ast_bridge_lock, ast_bridge_unlock, AST_BRIDGE_VIDEO_MODE_SFU, ast_format_cache_get_slin_by_rate(), AST_LIST_TRAVERSE, ast_timer_ack(), ast_timer_fd(), ast_timer_set_rate(), ast_tvdiff_ms(), ast_tvnow(), ast_waitfor_n_fd(), softmix_channel::binaural, convolve_data::binaural_active, ast_bridge_softmix::binaural_active, binaural_mixing(), softmix_bridge_data::bitrate, ast_bridge_channel::chan, ast_bridge::channels, check_binaural_position_change(), softmix_bridge_data::convolve, create_binaural_frame(), ast_frame::datalen, softmix_bridge_data::default_sample_size, softmix_channel::final_buf, ast_frame_subclass::format, ast_bridge_softmix::internal_mixing_interval, ast_bridge_softmix::internal_sample_rate, softmix_bridge_data::last_remb_update, softmix_channel::lock, softmix_stats::locked_rate, softmix_stats::maximum_rate, ast_bridge_softmix::maximum_sample_rate, ast_bridge::num_active, ast_bridge::num_channels, ast_bridge_video_sfu_data::remb_send_interval, ast_frame::samples, ast_bridge::softmix, SOFTMIX_DATALEN, SOFTMIX_SAMPLES, SOFTMIX_STAT_INTERVAL, softmix_bridge_data::stop, ast_frame::subclass, ast_bridge_channel::suspended, ast_bridge_channel::tech_pvt, ast_bridge::tech_pvt, ast_bridge::uniqueid, ast_bridge_softmix::video_mode, and softmix_channel::write_frame.