Wed Jan 8 2020 09:49:42

Asterisk developer's documentation


bridge_simple.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2007, Digium, Inc.
5  *
6  * Joshua Colp <jcolp@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Simple two channel bridging module
22  *
23  * \author Joshua Colp <jcolp@digium.com>
24  *
25  * \ingroup bridges
26  */
27 
28 /*** MODULEINFO
29  <support_level>core</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 
42 #include "asterisk/module.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/bridging.h"
46 #include "asterisk/frame.h"
47 
48 static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
49 {
50  struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan, *c1 = AST_LIST_LAST(&bridge->channels)->chan;
51 
52  /* If this is the first channel we can't make it compatible... unless we make it compatible with itself O.o */
53  if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
54  return 0;
55  }
56 
57  /* See if we need to make these compatible */
58  if (((c0->writeformat == c1->readformat) && (c0->readformat == c1->writeformat) && (c0->nativeformats == c1->nativeformats))) {
59  return 0;
60  }
61 
62  /* BOOM! We do. */
63  return ast_channel_make_compatible(c0, c1);
64 }
65 
66 static enum ast_bridge_write_result simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
67 {
68  struct ast_bridge_channel *other = NULL;
69 
70  /* If this is the only channel in this bridge then immediately exit */
71  if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
73  }
74 
75  /* Find the channel we actually want to write to */
76  if (!(other = (AST_LIST_FIRST(&bridge->channels) == bridge_channel ? AST_LIST_LAST(&bridge->channels) : AST_LIST_FIRST(&bridge->channels)))) {
78  }
79 
80  /* Write the frame out if they are in the waiting state... don't worry about freeing it, the bridging core will take care of it */
81  if (other->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
82  ast_write(other->chan, frame);
83  }
84 
86 }
87 
89  .name = "simple_bridge",
91  .preference = AST_BRIDGE_PREFERENCE_MEDIUM,
93  .join = simple_bridge_join,
94  .write = simple_bridge_write,
95 };
96 
97 static int unload_module(void)
98 {
99  return ast_bridge_technology_unregister(&simple_bridge);
100 }
101 
102 static int load_module(void)
103 {
104  return ast_bridge_technology_register(&simple_bridge);
105 }
106 
107 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
format_t writeformat
Definition: channel.h:854
static struct ast_bridge_technology simple_bridge
Definition: bridge_simple.c:88
format_t nativeformats
Definition: channel.h:852
#define ast_bridge_technology_register(technology)
See __ast_bridge_technology_register()
General Asterisk PBX channel definitions.
Asterisk internal frame definitions.
Channel Bridging API.
#define AST_FORMAT_TEXT_MASK
Definition: frame.h:297
Channel Bridging API.
int ast_bridge_technology_unregister(struct ast_bridge_technology *technology)
Unregister a bridge technology from use.
Definition: bridging.c:99
Structure that contains information about a bridge.
Definition: bridging.h:149
static enum ast_bridge_write_result simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
Definition: bridge_simple.c:66
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
struct ast_bridge * bridge
Definition: channel.h:865
#define AST_FORMAT_VIDEO_MASK
Definition: frame.h:290
#define AST_FORMAT_AUDIO_MASK
Definition: frame.h:274
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:4916
static int unload_module(void)
Definition: bridge_simple.c:97
struct ast_channel * chan
Definition: bridging.h:125
Structure that contains information regarding a channel in a bridge.
Definition: bridging.h:117
int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1)
Makes two channel formats compatible.
Definition: channel.c:5970
format_t readformat
Definition: channel.h:853
Structure that is the essence of a bridge technology.
static int load_module(void)
ast_bridge_write_result
Return values for bridge technology write function.
Definition: bridging.h:102
Data structure associated with a single frame of data.
Definition: frame.h:142
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
enum ast_bridge_channel_state state
Definition: bridging.h:123
static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Definition: bridge_simple.c:48
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180