Fri Jul 3 20:35:39 2009

Asterisk developer's documentation


ooh323cDriver.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2005 by Objective Systems, Inc.
00003  *
00004  * This software is furnished under an open source license and may be 
00005  * used and copied only in accordance with the terms of this license. 
00006  * The text of the license may generally be found in the root 
00007  * directory of this installation in the COPYING file.  It 
00008  * can also be viewed online at the following URL:
00009  *
00010  *   http://www.obj-sys.com/open/license.html
00011  *
00012  * Any redistributions of this file including modified versions must 
00013  * maintain this copyright notice.
00014  *
00015  *****************************************************************************/
00016 
00017 #include "ooh323cDriver.h"
00018 
00019 #include <asterisk/pbx.h>
00020 #include <asterisk/logger.h>
00021 
00022 extern OOBOOL gH323Debug;
00023 /* ooh323c stack thread. */
00024 static pthread_t ooh323c_thread = AST_PTHREADT_NULL;
00025 static int grxframes = 240;
00026 
00027 static int gtxframes = 20;
00028 
00029 int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
00030 int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel);
00031 int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
00032 int ooh323c_stop_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel);
00033 
00034 void* ooh323c_stack_thread(void* dummy)
00035 {
00036 
00037   ooMonitorChannels();
00038   return dummy;
00039 }
00040 
00041 int ooh323c_start_stack_thread()
00042 {
00043    if(ast_pthread_create(&ooh323c_thread, NULL, ooh323c_stack_thread, NULL) < 0)
00044    {
00045       ast_log(LOG_ERROR, "Unable to start ooh323c thread.\n");
00046       return -1;
00047    }
00048    return 0;
00049 }
00050 
00051 int ooh323c_stop_stack_thread(void)
00052 {
00053    if(ooh323c_thread !=  AST_PTHREADT_NULL)
00054    {
00055       ooStopMonitor();
00056       pthread_join(ooh323c_thread, NULL);
00057       ooh323c_thread =  AST_PTHREADT_NULL;
00058    }
00059    return 0;
00060 }
00061 
00062 int ooh323c_set_capability
00063    (struct ast_codec_pref *prefs, int capability, int dtmf)
00064 {
00065    int ret, x, format=0;
00066    if(gH323Debug)
00067      ast_verbose("\tAdding capabilities to H323 endpoint\n");
00068    
00069    for(x=0; 0 != (format=ast_codec_pref_index(prefs, x)); x++)
00070    {
00071       if(format & AST_FORMAT_ULAW)
00072       {
00073          if(gH323Debug)
00074             ast_verbose("\tAdding g711 ulaw capability to H323 endpoint\n");
00075          ret= ooH323EpAddG711Capability(OO_G711ULAW64K, gtxframes, grxframes, 
00076                                      OORXANDTX, &ooh323c_start_receive_channel,
00077                                      &ooh323c_start_transmit_channel,
00078                                      &ooh323c_stop_receive_channel, 
00079                                      &ooh323c_stop_transmit_channel);
00080       }
00081       if(format & AST_FORMAT_ALAW)
00082       {
00083          if(gH323Debug)
00084             ast_verbose("\tAdding g711 alaw capability to H323 endpoint\n");
00085          ret= ooH323EpAddG711Capability(OO_G711ALAW64K, gtxframes, grxframes, 
00086                                      OORXANDTX, &ooh323c_start_receive_channel,
00087                                      &ooh323c_start_transmit_channel,
00088                                      &ooh323c_stop_receive_channel, 
00089                                      &ooh323c_stop_transmit_channel);
00090       }
00091 
00092       if(format & AST_FORMAT_G729A)
00093       {
00094          if(gH323Debug)
00095             ast_verbose("\tAdding g729A capability to H323 endpoint\n");
00096          ret = ooH323EpAddG729Capability(OO_G729A, 2, 24, 
00097                                      OORXANDTX, &ooh323c_start_receive_channel,
00098                                      &ooh323c_start_transmit_channel,
00099                                      &ooh323c_stop_receive_channel, 
00100                                      &ooh323c_stop_transmit_channel);
00101 
00102          if(gH323Debug)
00103             ast_verbose("\tAdding g729 capability to H323 endpoint\n");
00104          ret |= ooH323EpAddG729Capability(OO_G729, 2, 24, 
00105                                      OORXANDTX, &ooh323c_start_receive_channel,
00106                                      &ooh323c_start_transmit_channel,
00107                                      &ooh323c_stop_receive_channel, 
00108                                      &ooh323c_stop_transmit_channel);
00109       }
00110 
00111       if(format & AST_FORMAT_G723_1)
00112       {
00113          if(gH323Debug)
00114             ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
00115          ret = ooH323EpAddG7231Capability(OO_G7231, 4, 7, FALSE, 
00116                                      OORXANDTX, &ooh323c_start_receive_channel,
00117                                      &ooh323c_start_transmit_channel,
00118                                      &ooh323c_stop_receive_channel, 
00119                                      &ooh323c_stop_transmit_channel);
00120 
00121       }
00122 
00123       if(format & AST_FORMAT_H263)
00124       {
00125          if(gH323Debug)
00126             ast_verbose("\tAdding h263 capability to H323 endpoint\n");
00127          ret = ooH323EpAddH263VideoCapability(OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024, 
00128                                      OORXANDTX, &ooh323c_start_receive_channel,
00129                                      &ooh323c_start_transmit_channel,
00130                                      &ooh323c_stop_receive_channel, 
00131                                      &ooh323c_stop_transmit_channel);
00132 
00133       }
00134 
00135       if(format & AST_FORMAT_GSM)
00136       {
00137          if(gH323Debug)
00138             ast_verbose("\tAdding gsm capability to H323 endpoint\n");
00139          ret = ooH323EpAddGSMCapability(OO_GSMFULLRATE, 4, FALSE, FALSE, 
00140                                      OORXANDTX, &ooh323c_start_receive_channel,
00141                                      &ooh323c_start_transmit_channel,
00142                                      &ooh323c_stop_receive_channel, 
00143                                      &ooh323c_stop_transmit_channel);
00144 
00145       }
00146       
00147    }
00148    
00149    if(dtmf & H323_DTMF_RFC2833)
00150       ret |= ooH323EpEnableDTMFRFC2833(0);
00151    else if(dtmf & H323_DTMF_H245ALPHANUMERIC)
00152       ret |= ooH323EpEnableDTMFH245Alphanumeric();
00153    else if(dtmf & H323_DTMF_H245SIGNAL)
00154       ret |= ooH323EpEnableDTMFH245Signal();
00155 
00156    return ret;
00157 }
00158 
00159 int ooh323c_set_capability_for_call
00160    (ooCallData *call, struct ast_codec_pref *prefs, int capability, int dtmf)
00161 {
00162    int ret, x, txframes, rxframes;
00163    int format=0;
00164    if(gH323Debug)
00165      ast_verbose("\tAdding capabilities to call(%s, %s)\n", call->callType, 
00166                                                             call->callToken);
00167    if(dtmf & H323_DTMF_RFC2833)
00168       ret |= ooCallEnableDTMFRFC2833(call,0);
00169    else if(dtmf & H323_DTMF_H245ALPHANUMERIC)
00170       ret |= ooCallEnableDTMFH245Alphanumeric(call);
00171    else if(dtmf & H323_DTMF_H245SIGNAL)
00172       ret |= ooCallEnableDTMFH245Signal(call);
00173 
00174 
00175    for(x=0; 0 !=(format=ast_codec_pref_index(prefs, x)); x++)
00176    {
00177       if(format & AST_FORMAT_ULAW)
00178       {
00179          if(gH323Debug)
00180             ast_verbose("\tAdding g711 ulaw capability to call(%s, %s)\n", 
00181                                               call->callType, call->callToken);
00182     txframes = prefs->framing[x];
00183          ret= ooCallAddG711Capability(call, OO_G711ULAW64K, txframes, 
00184                                       grxframes, OORXANDTX, 
00185                                       &ooh323c_start_receive_channel,
00186                                       &ooh323c_start_transmit_channel,
00187                                       &ooh323c_stop_receive_channel, 
00188                                       &ooh323c_stop_transmit_channel);
00189       }
00190       if(format & AST_FORMAT_ALAW)
00191       {
00192          if(gH323Debug)
00193             ast_verbose("\tAdding g711 alaw capability to call(%s, %s)\n",
00194                                             call->callType, call->callToken);
00195          txframes = prefs->framing[x];
00196          ret= ooCallAddG711Capability(call, OO_G711ALAW64K, txframes, 
00197                                      grxframes, OORXANDTX, 
00198                                      &ooh323c_start_receive_channel,
00199                                      &ooh323c_start_transmit_channel,
00200                                      &ooh323c_stop_receive_channel, 
00201                                      &ooh323c_stop_transmit_channel);
00202       }
00203 
00204       if(format & AST_FORMAT_G729A)
00205       {
00206          if(gH323Debug)
00207             ast_verbose("\tAdding g729A capability to call(%s, %s)\n",
00208                                             call->callType, call->callToken);
00209          txframes = (prefs->framing[x])/10;
00210          ret= ooCallAddG729Capability(call, OO_G729A, txframes, 24, 
00211                                      OORXANDTX, &ooh323c_start_receive_channel,
00212                                      &ooh323c_start_transmit_channel,
00213                                      &ooh323c_stop_receive_channel, 
00214                                      &ooh323c_stop_transmit_channel);
00215 
00216          if(gH323Debug)
00217             ast_verbose("\tAdding g729 capability to call(%s, %s)\n",
00218                                             call->callType, call->callToken);
00219          ret|= ooCallAddG729Capability(call, OO_G729, txframes, 24, 
00220                                      OORXANDTX, &ooh323c_start_receive_channel,
00221                                      &ooh323c_start_transmit_channel,
00222                                      &ooh323c_stop_receive_channel, 
00223                                      &ooh323c_stop_transmit_channel);
00224       }
00225 
00226       if(format & AST_FORMAT_G723_1)
00227       {
00228          if(gH323Debug)
00229             ast_verbose("\tAdding g7231 capability to call (%s, %s)\n",
00230                                            call->callType, call->callToken);
00231          ret = ooCallAddG7231Capability(call, OO_G7231, 4, 7, FALSE, 
00232                                      OORXANDTX, &ooh323c_start_receive_channel,
00233                                      &ooh323c_start_transmit_channel,
00234                                      &ooh323c_stop_receive_channel, 
00235                                      &ooh323c_stop_transmit_channel);
00236 
00237       }
00238 
00239       if(format & AST_FORMAT_H263)
00240       {
00241          if(gH323Debug)
00242             ast_verbose("\tAdding h263 capability to call (%s, %s)\n",
00243                                            call->callType, call->callToken);
00244          ret = ooCallAddH263VideoCapability(call, OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024, 
00245                                      OORXANDTX, &ooh323c_start_receive_channel,
00246                                      &ooh323c_start_transmit_channel,
00247                                      &ooh323c_stop_receive_channel, 
00248                                      &ooh323c_stop_transmit_channel);
00249 
00250       }
00251 
00252       if(format & AST_FORMAT_GSM)
00253       {
00254          if(gH323Debug)
00255             ast_verbose("\tAdding gsm capability to call(%s, %s)\n", 
00256                                              call->callType, call->callToken);
00257          ret = ooCallAddGSMCapability(call, OO_GSMFULLRATE, 4, FALSE, FALSE, 
00258                                      OORXANDTX, &ooh323c_start_receive_channel,
00259                                      &ooh323c_start_transmit_channel,
00260                                      &ooh323c_stop_receive_channel, 
00261                                      &ooh323c_stop_transmit_channel);
00262       }
00263    }
00264 }
00265 
00266 int ooh323c_set_aliases(ooAliases * aliases)
00267 {
00268    ooAliases *cur = aliases;
00269    while(cur)
00270    {
00271       switch(cur->type)
00272       { 
00273       case T_H225AliasAddress_dialedDigits:
00274          ooH323EpAddAliasDialedDigits(cur->value);
00275          break;
00276       case T_H225AliasAddress_h323_ID:
00277          ooH323EpAddAliasH323ID(cur->value);
00278          break;
00279       case T_H225AliasAddress_url_ID:
00280          ooH323EpAddAliasURLID(cur->value);
00281          break;
00282       case T_H225AliasAddress_email_ID:
00283          ooH323EpAddAliasEmailID(cur->value);
00284          break;
00285       default:
00286          ast_log(LOG_DEBUG, "Ignoring unknown alias type\n");
00287       }
00288       cur = cur->next;
00289    }
00290    return 1;
00291 }
00292    
00293 int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
00294 {
00295    int fmt=-1;
00296    fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
00297    if(fmt>0)
00298       ooh323_set_read_format(call, fmt);
00299    else{
00300      ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
00301                                                           call->callToken);
00302      return -1;
00303    }
00304    return 1;
00305 }
00306 
00307 int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
00308 {
00309    int fmt=-1;
00310    fmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
00311    if(fmt>0)
00312       ooh323_set_write_format(call, fmt);
00313    else{
00314       ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
00315                                                           call->callToken);
00316       return -1;
00317    }
00318    setup_rtp_connection(call, pChannel->remoteIP, pChannel->remoteMediaPort);
00319     return 1;
00320 }
00321 
00322 int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
00323 {
00324    return 1;
00325 }
00326 
00327 int ooh323c_stop_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
00328 {
00329    close_rtp_connection(call);
00330    return 1;
00331 }
00332 
00333 int convertH323CapToAsteriskCap(int cap)
00334 {
00335 
00336    switch(cap)
00337    {
00338       case OO_G711ULAW64K:
00339          return AST_FORMAT_ULAW;
00340       case OO_G711ALAW64K:
00341          return AST_FORMAT_ALAW;
00342       case OO_GSMFULLRATE:
00343          return AST_FORMAT_GSM;
00344       case OO_G729:
00345          return AST_FORMAT_G729A;
00346       case OO_G729A:
00347          return AST_FORMAT_G729A;
00348       case OO_G7231:
00349          return AST_FORMAT_G723_1;
00350       case OO_H263VIDEO:
00351          return AST_FORMAT_H263;
00352       default:
00353          ast_log(LOG_DEBUG, "Cap %d is not supported by driver yet\n");
00354          return -1;
00355    }
00356 
00357    return -1;
00358 }
00359 
00360  

Generated on Fri Jul 3 20:35:39 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9