[asterisk-dev] Streaming audio to asterisk

Darren Sessions dmsessions at gmail.com
Tue Jul 15 16:14:17 CDT 2008

Basically, the app I'm writing uses the Asterisk ODBC code to pull in  
binary audio data from the database using a custom query, and then I  
need to write that audio data to the channel. I've got the database  
stuff nailed already along with the core of the application itself,  
just getting it to the channel now is what I'm interested in doing.

My inexperience with the asterisk audio code here is going to shine  
through; basically, I'm still not 100% sure how to get set all the  
frame parameters via the frame struct and then getting that to  
ast_write. Like I said, still a bit fuzzy on the asterisk audio code,  
but it's slowly starting to make more sense. Most of my reference  
material has been looking over the app_swift code.

This is the meat of the code; presented as below, aud_buffer will have  
the entire binary audio stored in it when this runs. It's what I need  
to do with it after that.

I hope I'm making sense.


  - Darren Sessions

   obj = ast_odbc_request_obj(odbc_database, 1);
   if (obj) {
     do {
       snprintf(sql, sizeof(sql), "%s", query);
       stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
       if (!stmt) {
         ast_log(LOG_WARNING, "SQL execute error!\n[%s]\n\n", sql);
       res = SQLFetch(stmt);
       if (res == SQL_NO_DATA) {
               SQLFreeHandle(SQL_HANDLE_STMT, stmt);
       } else if ((res != SQL_SUCCESS) && (res !=  
               ast_log(LOG_WARNING, "SQL fetch error!\n[%s]\n\n", sql);
               SQLFreeHandle(SQL_HANDLE_STMT, stmt);

       res = SQLGetData(stmt, 1, SQL_BINARY, aud_buffer,  
sizeof(aud_buffer), &colsize);

       if (res == SQL_SUCCESS || res == SQL_SUCCESS_WITH_INFO) {
         <<something goes here>>

       SQLFreeHandle(SQL_HANDLE_STMT, stmt);
     } while (0);
   } else {
     ast_log(LOG_WARNING, "Failed to obtain database object for '%s'! 
\n", odbc_database);

On Jul 15, 2008, at 2:05 PM, Russell Bryant wrote:

> Darren Sessions wrote:
>> Is there a simple code example (C based of course) anywhere of
>> streaming audio to Asterisk from within an app (i.e. not from a  
>> file)?
>> I think the way I'm doing it is pretty cumbersome and/or unclean and
>> I'd like to see if there are any other methods or cleaner ways of
>> doing it. Just looking for something basic.
> Here are some places to look ...
> - Non-file based Music On Hold
> - EAGI
> - app_ices
> - app_jack
> Someone may be able to provide more useful advice if you give more
> information on what you're trying to accomplish.
> -- 
> Russell Bryant
> Senior Software Engineer
> Open Source Team Lead
> Digium, Inc.
> _______________________________________________
> --Bandwidth and Colocation Provided by http://www.api-digital.com--
> AstriCon 2008 - September 22 - 25 Phoenix, Arizona
> Register Now: http://www.astricon.net
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-dev

More information about the asterisk-dev mailing list