00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00035
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <sys/types.h>
00040 #include <sys/stat.h>
00041
00042 #include "asterisk/module.h"
00043 #include "asterisk/channel.h"
00044 #include "asterisk/bridging.h"
00045 #include "asterisk/bridging_technology.h"
00046 #include "asterisk/frame.h"
00047
00048 static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
00049 {
00050 struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan, *c1 = AST_LIST_LAST(&bridge->channels)->chan;
00051
00052
00053 if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
00054 return 0;
00055 }
00056
00057
00058 if (((c0->writeformat == c1->readformat) && (c0->readformat == c1->writeformat) && (c0->nativeformats == c1->nativeformats))) {
00059 return 0;
00060 }
00061
00062
00063 return ast_channel_make_compatible(c0, c1);
00064 }
00065
00066 static enum ast_bridge_write_result simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
00067 {
00068 struct ast_bridge_channel *other = NULL;
00069
00070
00071 if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
00072 return AST_BRIDGE_WRITE_FAILED;
00073 }
00074
00075
00076 if (!(other = (AST_LIST_FIRST(&bridge->channels) == bridge_channel ? AST_LIST_LAST(&bridge->channels) : AST_LIST_FIRST(&bridge->channels)))) {
00077 return AST_BRIDGE_WRITE_FAILED;
00078 }
00079
00080
00081 if (other->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
00082 ast_write(other->chan, frame);
00083 }
00084
00085 return AST_BRIDGE_WRITE_SUCCESS;
00086 }
00087
00088 static struct ast_bridge_technology simple_bridge = {
00089 .name = "simple_bridge",
00090 .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_THREAD,
00091 .preference = AST_BRIDGE_PREFERENCE_MEDIUM,
00092 .formats = AST_FORMAT_AUDIO_MASK | AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK,
00093 .join = simple_bridge_join,
00094 .write = simple_bridge_write,
00095 };
00096
00097 static int unload_module(void)
00098 {
00099 return ast_bridge_technology_unregister(&simple_bridge);
00100 }
00101
00102 static int load_module(void)
00103 {
00104 return ast_bridge_technology_register(&simple_bridge);
00105 }
00106
00107 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");