Merge "app_stasis: Don't hang up if app is not registered"
[asterisk/asterisk.git] / addons / ooh323cDriver.c
index 21a733e..3096d1e 100644 (file)
@@ -121,7 +121,7 @@ void* ooh323c_call_thread(void* dummy)
 
  close(mycthread->thePipe[0]);
  close(mycthread->thePipe[1]);
- free(mycthread);
+ ast_free(mycthread);
  ast_module_unref(myself);
  ast_update_use_count();
  return NULL;
@@ -155,7 +155,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
        ast_module_ref(myself);
        if ((socketpair(PF_LOCAL, SOCK_STREAM, 0, cur->thePipe)) == -1) {
                ast_log(LOG_ERROR, "Can't create thread pipe for call %s\n", call->callToken);
-               free(cur);
+               ast_free(cur);
                return -1;
        }
        cur->inUse = TRUE;
@@ -173,7 +173,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
                ast_mutex_destroy(&cur->lock);
                close(cur->thePipe[0]);
                close(cur->thePipe[1]);
-               free(cur);
+               ast_free(cur);
                return -1;
        }
 
@@ -225,29 +225,32 @@ int ooh323c_stop_stack_thread(void)
 }
 
 int ooh323c_set_capability
-   (struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec)
+   (struct ast_format_cap *cap, int dtmf, int dtmfcodec)
 {
    int ret = 0, x;
-   struct ast_format tmpfmt;
-   if(gH323Debug)
-     ast_verbose("\tAdding capabilities to H323 endpoint\n");
-   
-   for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
+   if (gH323Debug) {
+     ast_verb(0, "\tAdding capabilities to H323 endpoint\n");
+   }
+
+   for(x=0; x<ast_format_cap_count(cap); x++)
    {
-      if(tmpfmt.id == AST_FORMAT_ULAW)
+    struct ast_format *format = ast_format_cap_get_format(cap, x);
+      if(ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g711 ulaw capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g711 ulaw capability to H323 endpoint\n");
+        }
          ret= ooH323EpAddG711Capability(OO_G711ULAW64K, gtxframes, grxframes, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
       }
-      if(tmpfmt.id == AST_FORMAT_ALAW)
+      if(ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g711 alaw capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g711 alaw capability to H323 endpoint\n");
+        }
          ret= ooH323EpAddG711Capability(OO_G711ALAW64K, gtxframes, grxframes, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -255,25 +258,28 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(tmpfmt.id == AST_FORMAT_G729A)
+      if(ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g729A capability to H323 endpoint\n");
+         if (gH323Debug) {
+           ast_verb(0, "\tAdding g729A capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddG729Capability(OO_G729A, 2, 24, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
 
-         if(gH323Debug)
-            ast_verbose("\tAdding g729 capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g729 capability to H323 endpoint\n");
+        }
          ret |= ooH323EpAddG729Capability(OO_G729, 2, 24, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
-         if(gH323Debug)
-            ast_verbose("\tAdding g729b capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g729b capability to H323 endpoint\n");
+        }
          ret |= ooH323EpAddG729Capability(OO_G729B, 2, 24, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -281,10 +287,11 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(tmpfmt.id == AST_FORMAT_G723_1)
+      if(ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g7231 capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddG7231Capability(OO_G7231, 1, 1, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -293,10 +300,11 @@ int ooh323c_set_capability
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_G726)
+      if(ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g726 capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g726 capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddG726Capability(OO_G726, gtxframes, grxframes, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -305,10 +313,11 @@ int ooh323c_set_capability
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_G726_AAL2)
+      if(ast_format_cmp(format, ast_format_g726_aal2) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g726aal2 capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g726aal2 capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddG726Capability(OO_G726AAL2, gtxframes, grxframes, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -317,10 +326,11 @@ int ooh323c_set_capability
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_H263)
+      if(ast_format_cmp(format, ast_format_h263) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding h263 capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding h263 capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddH263VideoCapability(OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -329,10 +339,11 @@ int ooh323c_set_capability
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_GSM)
+      if(ast_format_cmp(format, ast_format_gsm) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding gsm capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding gsm capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddGSMCapability(OO_GSMFULLRATE, 4, FALSE, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -340,26 +351,12 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
 
       }
-      
-#ifdef AST_FORMAT_AMRNB
-      if(tmpfmt.id == AST_FORMAT_AMRNB)
-      {
-         if(gH323Debug)
-            ast_verbose("\tAdding amr nb capability to H323 endpoint\n");
-         ret = ooH323EpAddAMRNBCapability(OO_AMRNB, 4, 4, FALSE, 
-                                     OORXANDTX, &ooh323c_start_receive_channel,
-                                     &ooh323c_start_transmit_channel,
-                                     &ooh323c_stop_receive_channel, 
-                                     &ooh323c_stop_transmit_channel);
-
-      }
-#endif
 
-#ifdef AST_FORMAT_SPEEX
-      if(tmpfmt.id == AST_FORMAT_SPEEX)
+      if(ast_format_cmp(format, ast_format_speex) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding speex capability to H323 endpoint\n");
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding speex capability to H323 endpoint\n");
+        }
          ret = ooH323EpAddSpeexCapability(OO_SPEEX, 4, 4, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -367,8 +364,8 @@ int ooh323c_set_capability
                                      &ooh323c_stop_transmit_channel);
 
       }
-#endif
-      
+
+    ao2_ref(format, -1);      
    }
    
    if(dtmf & H323_DTMF_CISCO)
@@ -384,14 +381,14 @@ int ooh323c_set_capability
 }
 
 int ooh323c_set_capability_for_call
-   (ooCallData *call, struct ast_codec_pref *prefs, struct ast_format_cap *cap, int dtmf, int dtmfcodec,
+   (ooCallData *call, struct ast_format_cap *cap, int dtmf, int dtmfcodec,
                 int t38support, int g729onlyA)
 {
    int ret = 0, x, txframes;
-   struct ast_format tmpfmt;
-   if(gH323Debug)
-     ast_verbose("\tAdding capabilities to call(%s, %s)\n", call->callType, 
+   if (gH323Debug) {
+     ast_verb(0, "\tAdding capabilities to call(%s, %s)\n", call->callType, 
                                                             call->callToken);
+   }
    if(dtmf & H323_DTMF_CISCO || 1)
       ret |= ooCallEnableDTMFCISCO(call,dtmfcodec);
    if(dtmf & H323_DTMF_RFC2833 || 1)
@@ -409,14 +406,16 @@ int ooh323c_set_capability_for_call
                                        &ooh323c_stop_transmit_datachannel,
                                        0);
 
-   for(x=0; ast_codec_pref_index(prefs, x, &tmpfmt); x++)
+   for(x=0; x<ast_format_cap_count(cap); x++)
    {
-      if(tmpfmt.id == AST_FORMAT_ULAW)
+    struct ast_format *format = ast_format_cap_get_format(cap, x);
+      if(ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g711 ulaw capability to call(%s, %s)\n", 
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g711 ulaw capability to call(%s, %s)\n", 
                                               call->callType, call->callToken);
-        txframes = prefs->framing[x];
+        }
+        txframes = ast_format_cap_get_format_framing(cap, format);
          ret= ooCallAddG711Capability(call, OO_G711ULAW64K, txframes, 
                                       txframes, OORXANDTX, 
                                       &ooh323c_start_receive_channel,
@@ -424,12 +423,13 @@ int ooh323c_set_capability_for_call
                                       &ooh323c_stop_receive_channel, 
                                       &ooh323c_stop_transmit_channel);
       }
-      if(tmpfmt.id == AST_FORMAT_ALAW)
+      if(ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g711 alaw capability to call(%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g711 alaw capability to call(%s, %s)\n",
                                             call->callType, call->callToken);
-         txframes = prefs->framing[x];
+        }
+         txframes = ast_format_cap_get_format_framing(cap, format);
          ret= ooCallAddG711Capability(call, OO_G711ALAW64K, txframes, 
                                      txframes, OORXANDTX, 
                                      &ooh323c_start_receive_channel,
@@ -438,12 +438,13 @@ int ooh323c_set_capability_for_call
                                      &ooh323c_stop_transmit_channel);
       }
 
-      if(tmpfmt.id == AST_FORMAT_G726)
+      if(ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g726 capability to call (%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g726 capability to call (%s, %s)\n",
                                            call->callType, call->callToken);
-        txframes = prefs->framing[x];
+        }
+        txframes = ast_format_cap_get_format_framing(cap, format);
          ret = ooCallAddG726Capability(call, OO_G726, txframes, grxframes, FALSE,
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -452,12 +453,13 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_G726_AAL2)
+      if(ast_format_cmp(format, ast_format_g726_aal2) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g726aal2 capability to call (%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g726aal2 capability to call (%s, %s)\n",
                                            call->callType, call->callToken);
-        txframes = prefs->framing[x];
+        }
+        txframes = ast_format_cap_get_format_framing(cap, format);
          ret = ooCallAddG726Capability(call, OO_G726AAL2, txframes, grxframes, FALSE,
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -466,13 +468,14 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_G729A)
+      if(ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL)
       {
       
-         txframes = (prefs->framing[x])/10;
-         if(gH323Debug)
-            ast_verbose("\tAdding g729A capability to call(%s, %s)\n",
+         txframes = (ast_format_cap_get_format_framing(cap, format))/10;
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g729A capability to call(%s, %s)\n",
                                             call->callType, call->callToken);
+        }
          ret= ooCallAddG729Capability(call, OO_G729A, txframes, txframes, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -480,17 +483,19 @@ int ooh323c_set_capability_for_call
                                      &ooh323c_stop_transmit_channel);
         if (g729onlyA)
                continue;
-         if(gH323Debug)
-            ast_verbose("\tAdding g729 capability to call(%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g729 capability to call(%s, %s)\n",
                                             call->callType, call->callToken);
+        }
          ret|= ooCallAddG729Capability(call, OO_G729, txframes, txframes, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
-         if(gH323Debug)
-            ast_verbose("\tAdding g729B capability to call(%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g729B capability to call(%s, %s)\n",
                                             call->callType, call->callToken);
+        }
          ret|= ooCallAddG729Capability(call, OO_G729B, txframes, txframes, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -499,11 +504,12 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_G723_1)
+      if(ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding g7231 capability to call (%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding g7231 capability to call (%s, %s)\n",
                                            call->callType, call->callToken);
+        }
          ret = ooCallAddG7231Capability(call, OO_G7231, 1, 1, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -512,11 +518,12 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_H263)
+      if(ast_format_cmp(format, ast_format_h263) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding h263 capability to call (%s, %s)\n",
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding h263 capability to call (%s, %s)\n",
                                            call->callType, call->callToken);
+        }
          ret = ooCallAddH263VideoCapability(call, OO_H263VIDEO, 1, 0, 0, 0, 0, 320*1024, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -525,11 +532,12 @@ int ooh323c_set_capability_for_call
 
       }
 
-      if(tmpfmt.id == AST_FORMAT_GSM)
+      if(ast_format_cmp(format, ast_format_gsm) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding gsm capability to call(%s, %s)\n", 
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding gsm capability to call(%s, %s)\n", 
                                              call->callType, call->callToken);
+        }
          ret = ooCallAddGSMCapability(call, OO_GSMFULLRATE, 4, FALSE, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
@@ -537,32 +545,20 @@ int ooh323c_set_capability_for_call
                                      &ooh323c_stop_transmit_channel);
       }
 
-#ifdef AST_FORMAT_AMRNB
-      if(tmpfmt.id == AST_FORMAT_AMRNB)
-      {
-         if(gH323Debug)
-            ast_verbose("\tAdding AMR capability to call(%s, %s)\n", 
-                                             call->callType, call->callToken);
-         ret = ooCallAddAMRNBCapability(call, OO_AMRNB, 4, 4, FALSE, 
-                                     OORXANDTX, &ooh323c_start_receive_channel,
-                                     &ooh323c_start_transmit_channel,
-                                     &ooh323c_stop_receive_channel, 
-                                     &ooh323c_stop_transmit_channel);
-      }
-#endif
-#ifdef AST_FORMAT_SPEEX
-      if(tmpfmt.id == AST_FORMAT_SPEEX)
+      if(ast_format_cmp(format, ast_format_speex) == AST_FORMAT_CMP_EQUAL)
       {
-         if(gH323Debug)
-            ast_verbose("\tAdding Speex capability to call(%s, %s)\n", 
+         if (gH323Debug) {
+            ast_verb(0, "\tAdding Speex capability to call(%s, %s)\n", 
                                              call->callType, call->callToken);
+        }
          ret = ooCallAddSpeexCapability(call, OO_SPEEX, 4, 4, FALSE, 
                                      OORXANDTX, &ooh323c_start_receive_channel,
                                      &ooh323c_start_transmit_channel,
                                      &ooh323c_stop_receive_channel, 
                                      &ooh323c_stop_transmit_channel);
       }
-#endif
+
+      ao2_ref(format, -1);
    }
    return ret;
 }
@@ -596,9 +592,9 @@ int ooh323c_set_aliases(ooAliases * aliases)
    
 int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
 {
-   struct ast_format tmpfmt;
-   convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
-   if(tmpfmt.id) {
+   struct ast_format *tmpfmt = NULL;
+   tmpfmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
+   if(tmpfmt) {
       /* ooh323_set_read_format(call, fmt); */
    }else{
      ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
@@ -610,19 +606,17 @@ int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel)
 
 int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel)
 {
-   struct ast_format tmpfmt;
-   convertH323CapToAsteriskCap(pChannel->chanCap->cap, &tmpfmt);
-   if(tmpfmt.id) {
-      switch (tmpfmt.id) {
-      case AST_FORMAT_ALAW:
-      case AST_FORMAT_ULAW:
-       ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
-       break;
-      case AST_FORMAT_G729A:
-       ooh323_set_write_format(call, &tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
-       break;
-      default:
-       ooh323_set_write_format(call, &tmpfmt, 0);
+   struct ast_format *tmpfmt = NULL;
+   tmpfmt = convertH323CapToAsteriskCap(pChannel->chanCap->cap);
+
+   if (tmpfmt) {
+    if ((ast_format_cmp(tmpfmt, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ||
+      (ast_format_cmp(tmpfmt, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL)) {
+       ooh323_set_write_format(call, tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes);
+    } else if (ast_format_cmp(tmpfmt, ast_format_g729) == AST_FORMAT_CMP_EQUAL) {
+        ooh323_set_write_format(call, tmpfmt, ((OOCapParams *)(pChannel->chanCap->params))->txframes*10);
+  } else {
+       ooh323_set_write_format(call, tmpfmt, 0);
       }
    }else{
       ast_log(LOG_ERROR, "Invalid capability type for receive channel %s\n",
@@ -667,41 +661,32 @@ int ooh323c_stop_transmit_datachannel(ooCallData *call, ooLogicalChannel *pChann
    return 1;
 }
 
-struct ast_format *convertH323CapToAsteriskCap(int cap, struct ast_format *result)
+struct ast_format *convertH323CapToAsteriskCap(int cap)
 {
-   ast_format_clear(result);
    switch(cap)
    {
       case OO_G711ULAW64K:
-         return ast_format_set(result, AST_FORMAT_ULAW, 0);
+         return ast_format_ulaw;
       case OO_G711ALAW64K:
-         return ast_format_set(result, AST_FORMAT_ALAW, 0);
+         return ast_format_alaw;
       case OO_GSMFULLRATE:
-         return ast_format_set(result, AST_FORMAT_GSM, 0);
-
-#ifdef AST_FORMAT_AMRNB
-      case OO_AMRNB:
-         return ast_format_set(result, AST_FORMAT_AMRNB, 0);
-#endif
-#ifdef AST_FORMAT_SPEEX
+         return ast_format_gsm;
       case OO_SPEEX:
-         return ast_format_set(result, AST_FORMAT_SPEEX, 0);
-#endif
-
+         return ast_format_speex;
       case OO_G729:
-         return ast_format_set(result, AST_FORMAT_G729A, 0);
+         return ast_format_g729;
       case OO_G729A:
-         return ast_format_set(result, AST_FORMAT_G729A, 0);
+         return ast_format_g729;
       case OO_G729B:
-         return ast_format_set(result, AST_FORMAT_G729A, 0);
+         return ast_format_g729;
       case OO_G7231:
-         return ast_format_set(result, AST_FORMAT_G723_1, 0);
+         return ast_format_g723;
       case OO_G726:
-         return ast_format_set(result, AST_FORMAT_G726, 0);
+         return ast_format_g726;
       case OO_G726AAL2:
-         return ast_format_set(result, AST_FORMAT_G726_AAL2, 0);
+         return ast_format_g726_aal2;
       case OO_H263VIDEO:
-         return ast_format_set(result, AST_FORMAT_H263, 0);
+         return ast_format_h263;
       default:
          ast_debug(1, "Cap %d is not supported by driver yet\n", cap);
          return NULL;