Skip to content

Commit

Permalink
Support Asterisk 1.8.0
Browse files Browse the repository at this point in the history
Add various compatibility macros and functions. Convert audio
format variables to use format_t. Adapt to caller id related changes.
  • Loading branch information
fabled committed Oct 26, 2010
1 parent e62482c commit cb09cb1
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 49 deletions.
14 changes: 10 additions & 4 deletions konference/app_conference.c
Expand Up @@ -59,30 +59,36 @@ static char *app2 = "KonferenceCount";
static char *synopsis2 = "Channel Independent Conference Count";
static char *descrip2 = "Channel Independent Conference Count Application";

static int app_konference_main(struct ast_channel* chan, void* data)
#if ASTERISK_VERSION_NUM >= 10800
typedef const char *ast_application_parameter;
#else
typedef void *ast_application_parameter;
#endif

static int app_konference_main(struct ast_channel* chan, ast_application_parameter data)
{
int res ;
struct ast_module_user *u ;

u = ast_module_user_add(chan);

// call member thread function
res = member_exec( chan, data ) ;
res = member_exec(chan, (const char*) data);

ast_module_user_remove(u);

return res ;
}

static int app_konferencecount_main(struct ast_channel* chan, void* data)
static int app_konferencecount_main(struct ast_channel* chan, ast_application_parameter data)
{
int res ;
struct ast_module_user *u ;

u = ast_module_user_add(chan);

// call count thread function
res = count_exec( chan, data ) ;
res = count_exec(chan, (const char *) data);

ast_module_user_remove(u);

Expand Down
8 changes: 4 additions & 4 deletions konference/cli.c
Expand Up @@ -542,9 +542,9 @@ char *conference_mutechannel(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
EVENT_FLAG_CALL,
"ConferenceMemberMute",
"ConferenceName: %s\r\n"
"MemberId: %d\r\n",
"MemberId: %d\r\n"
"Channel: %s\r\n",
member->conf_name,
member->conf_name,
member->id,
channel
) ;
Expand Down Expand Up @@ -757,9 +757,9 @@ char *conference_unmutechannel(struct ast_cli_entry *e, int cmd, struct ast_cli_

manager_event(
EVENT_FLAG_CALL,
"ConferenceMemberUnmute",
"ConferenceMemberUnmute"
"ConferenceName: %s\r\n"
"MemberId: %d\r\n",
"MemberId: %d\r\n"
"Channel: %s\r\n",
member->conf_name,
member->id,
Expand Down
49 changes: 43 additions & 6 deletions konference/common.h
Expand Up @@ -32,16 +32,11 @@
#define _APP_CONF_COMMON_H

#include <asterisk/time.h>
#include <asterisk/version.h>

// typedef includes
#include "conf_frame.h"

// function includesee
//#include "member.h"
#include "conference.h"
#include "frame.h"
#include "cli.h"

/* Utility functions */

/* LOG the time taken to execute a function (like lock acquisition */
Expand All @@ -65,4 +60,46 @@

const char *argument_delimiter ;

// helper macros and functions to make building for different asterisk
// versions easier
#if ASTERISK_VERSION_NUM >= 10800
#define AST_FRAME_SUBCLASS_INT(f) ((f)->subclass.integer)
#define AST_FRAME_SUBCLASS_CODEC(f) ((f)->subclass.codec)
#define AST_FMT_FORMAT_T "%llu"

static inline const char *ast_channel_callerid_number(struct ast_channel *chan)
{
return S_COR(chan->caller.id.number.valid,
chan->caller.id.number.str, "<unknown>");
}

static inline const char *ast_channel_callerid_name(struct ast_channel *chan)
{
return S_COR(chan->caller.id.name.valid,
chan->caller.id.name.str, "<unknown>");
}
#else
typedef unsigned int format_t;

#define AST_FRAME_SUBCLASS_INT(f) ((f)->subclass)
#define AST_FRAME_SUBCLASS_CODEC(f) ((f)->subclass)
#define AST_FMT_FORMAT_T "%u"

static inline const char *ast_channel_callerid_number(struct ast_channel *chan)
{
return chan->cid.cid_num ? chan->cid.cid_num : "unknown";
}

static inline const char *ast_channel_callerid_name(struct ast_channel *chan)
{
return chan->cid.cid_name ? chan->cid.cid_name : "unknown";
}
#endif

// function includesee
//#include "member.h"
#include "conference.h"
#include "frame.h"
#include "cli.h"

#endif
41 changes: 31 additions & 10 deletions konference/conference.c
Expand Up @@ -29,6 +29,7 @@
*/

#include "asterisk/autoconfig.h"
#include "asterisk/version.h"
#include "conference.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
Expand All @@ -38,6 +39,7 @@

#include "asterisk/musiconhold.h"


//
// static variables
//
Expand Down Expand Up @@ -65,6 +67,7 @@ static int get_new_id(struct ast_conference *conf);
static int update_member_broadcasting(struct ast_conference *conf, struct ast_conf_member *member, struct conf_frame *cfr, struct timeval time);
#endif


//
// main conference function
//
Expand Down Expand Up @@ -1336,8 +1339,8 @@ void remove_member( struct ast_conf_member* member, struct ast_conference* conf
member->id,
member->flags,
member->channel_name,
member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown",
member->chan->cid.cid_name ? member->chan->cid.cid_name: "unknown",
ast_channel_callerid_number(member->chan),
ast_channel_callerid_name(member->chan),
tt,
moderators,
membercount
Expand Down Expand Up @@ -1420,7 +1423,9 @@ int show_conference_stats ( int fd )
// loop through conf list
while ( conf != NULL )
{
ast_cli( fd, "%-20.20s %-20d %-20d %-20ld\n", conf->name, conf->membercount, conf->volume, conf->bucket - conference_table ) ;
ast_cli(fd, "%-20.20s %-20d %-20d %-20d\n",
conf->name, conf->membercount, conf->volume,
(int)(conf->bucket - conference_table) ) ;
conf = conf->next ;
}

Expand Down Expand Up @@ -1475,14 +1480,30 @@ int show_conference_list ( int fd, const char *name )
if ( member->driven_member == NULL )
{
ast_cli( fd, "MemberId: %-20d CIDName: %-20.20s CID: %-20.20s Muted: %-20.20s UniqueID: %-20.20s ConfName: %-20.20s Channel: %-80s\n",
member->id, (member->chan->cid.cid_name ? member->chan->cid.cid_name: "unknown"), (member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown"), (member->mute_audio == 0 ? "False" : "True"), member->uniqueid, member->conf_name, member->channel_name);
member->id,
ast_channel_callerid_name(member->chan),
ast_channel_callerid_number(member->chan),
(member->mute_audio == 0 ? "False" : "True"),
member->uniqueid, member->conf_name, member->channel_name);
} else {
ast_cli( fd, "MemberId: %-20d CIDName: %-20.20s CID: %-20.20s Muted: %-20.20s UniqueID: %-20.20s ConfName: %-20.20s Speaking: %s Channel: %-80s\n",
member->id, (member->chan->cid.cid_name ? member->chan->cid.cid_name: "unknown"), (member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown"), (member->mute_audio == 0 ? "False" : "True"), member->uniqueid, member->conf_name, (( member->speaking_state == 1 ) ? "True" : "False"), member->channel_name);
member->id,
ast_channel_callerid_name(member->chan),
ast_channel_callerid_number(member->chan),
(member->mute_audio == 0 ? "False" : "True"),
member->uniqueid, member->conf_name,
(( member->speaking_state == 1 ) ? "True" : "False"),
member->channel_name);
}
#else
ast_cli( fd, "MemberId: %-20d CIDName: %-20.20s CID: %-20.20s Muted: %-20.20s UniqueID: %-20.20s ConfName: %-20.20s Speaking: %s Channel: %-80s\n",
member->id, (member->chan->cid.cid_name ? member->chan->cid.cid_name: "unknown"), (member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown"), (member->mute_audio == 0 ? "False" : "True"), member->uniqueid, member->conf_name, (( member->speaking_state == 1 ) ? "True" : "False"), member->channel_name);
ast_cli( fd, "MemberId: %-20d CIDName: %-20.20s CID: %-20.20s Muted: %-20.20s UniqueID: %-20.20s ConfName: %-20.20s Speaking: %s Channel: %-80s\n",
member->id,
ast_channel_callerid_name(member->chan),
ast_channel_callerid_number(member->chan),
(member->mute_audio == 0 ? "False" : "True"),
member->uniqueid, member->conf_name,
(( member->speaking_state == 1 ) ? "True" : "False"),
member->channel_name);
#endif
member = member->next;
}
Expand Down Expand Up @@ -1551,8 +1572,8 @@ int manager_conference_list( struct mansession *s, const struct message *m )
conf->name,
member->id,
member->channel_name,
member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown",
member->chan->cid.cid_name ? member->chan->cid.cid_name : "unknown",
ast_channel_callerid_number(member->chan),
ast_channel_callerid_name(member->chan),
member->mute_audio ? "YES" : "NO",
#ifdef VIDEO
member->mute_video ? "YES" : "NO",
Expand Down Expand Up @@ -3315,7 +3336,7 @@ int hash(const char *name)
return h;
}

int count_exec( struct ast_channel* chan, void* data )
int count_exec( struct ast_channel* chan, const char* data )
{
int res = 0;
struct ast_conference *conf;
Expand Down
2 changes: 1 addition & 1 deletion konference/conference.h
Expand Up @@ -155,7 +155,7 @@ struct ast_conference

int hash( const char *channel_name ) ;

int count_exec( struct ast_channel* chan, void* data ) ;
int count_exec( struct ast_channel* chan, const char *data ) ;

struct ast_conference* join_conference( struct ast_conf_member* member, const char* recfile, const char* recformat ) ;

Expand Down
6 changes: 3 additions & 3 deletions konference/frame.c
Expand Up @@ -383,7 +383,7 @@ struct ast_frame* convert_frame_to_slinear( struct ast_trans_pvt* trans, struct
// we don't need to duplicate this frame since
// the normal translation would free it anyway, so
// we'll just pretend we free'd and malloc'd a new one.
if ( fr->subclass == AST_CONF_FORMAT )
if ( AST_FRAME_SUBCLASS_CODEC(fr) == AST_CONF_FORMAT )
return fr ;

// check for null translator ( after we've checked that we need to translate )
Expand Down Expand Up @@ -414,7 +414,7 @@ struct ast_frame* convert_frame_from_slinear( struct ast_trans_pvt* trans, struc
}

// if the frame is not slinear, return an error
if ( fr->subclass != AST_CONF_FORMAT )
if ( AST_FRAME_SUBCLASS_CODEC(fr) != AST_CONF_FORMAT )
{
ast_log( LOG_ERROR, "unable to translate non-slinear frame\n" ) ;
return NULL ;
Expand Down Expand Up @@ -626,7 +626,7 @@ struct ast_frame* create_slinear_frame( char* data )
}

f->frametype = AST_FRAME_VOICE ;
f->subclass = AST_CONF_FORMAT ;
AST_FRAME_SUBCLASS_CODEC(f) = AST_CONF_FORMAT ;
f->samples = AST_CONF_BLOCK_SAMPLES ;
f->offset = AST_FRIENDLY_OFFSET ;
f->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_DATA ;
Expand Down
39 changes: 21 additions & 18 deletions konference/member.c
Expand Up @@ -91,7 +91,7 @@ static int process_incoming(struct ast_conf_member *member, struct ast_conferenc
if (member->dtmf_star_menu)
{
ast_mutex_lock( &member->lock ) ;
if (f->subclass == '*')
if (AST_FRAME_SUBCLASS_INT(f) == '*')
{
member->star_pressed = 1;
DEBUG( "star was pressed\n" );
Expand All @@ -103,7 +103,7 @@ static int process_incoming(struct ast_conf_member *member, struct ast_conferenc
member->star_pressed = 0;
if (menu)
{
switch (f->subclass) {
switch (AST_FRAME_SUBCLASS_INT(f)) {
case '1' :
if (member->mute_audio == 0)
{
Expand Down Expand Up @@ -179,9 +179,9 @@ static int process_incoming(struct ast_conf_member *member, struct ast_conferenc
member->type,
member->uniqueid,
member->channel_name,
member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown",
member->chan->cid.cid_name ? member->chan->cid.cid_name : "unknown",
f->subclass,
ast_channel_callerid_number(member->chan),
ast_channel_callerid_name(member->chan),
AST_FRAME_SUBCLASS_INT(f),
conf->membercount,
member->flags,
member->mute_audio
Expand Down Expand Up @@ -279,7 +279,7 @@ static int process_incoming(struct ast_conf_member *member, struct ast_conferenc
//
if (
member->dsp != NULL
&& f->subclass == AST_CONF_FORMAT
&& AST_FRAME_SUBCLASS_CODEC(f) == AST_CONF_FORMAT
&& f->datalen == AST_CONF_FRAME_DATA_SIZE
)
{
Expand Down Expand Up @@ -334,7 +334,7 @@ static int process_incoming(struct ast_conf_member *member, struct ast_conferenc
#endif
else if (
f->frametype == AST_FRAME_CONTROL
&& f->subclass == AST_CONTROL_HANGUP
&& AST_FRAME_SUBCLASS_INT(f) == AST_CONTROL_HANGUP
)
{
// hangup received
Expand Down Expand Up @@ -476,7 +476,7 @@ static struct ast_frame *get_next_soundframe(struct ast_conf_member *member, str
// if we get here, we've gotten to the end of the queue; reset write format
if ( ast_set_write_format( member->chan, member->write_format ) < 0 )
{
ast_log( LOG_ERROR, "unable to set write format to %d\n",
ast_log( LOG_ERROR, "unable to set write format to " AST_FMT_FORMAT_T "\n",
member->write_format ) ;
}
} else {
Expand Down Expand Up @@ -674,7 +674,7 @@ static int process_outgoing(struct ast_conf_member *member)
// main member thread function
//

int member_exec( struct ast_channel* chan, void* data )
int member_exec( struct ast_channel* chan, const char* data )
{
// struct timeval start, end ;
// start = ast_tvnow();
Expand Down Expand Up @@ -828,8 +828,8 @@ int member_exec( struct ast_channel* chan, void* data )
member->id,
member->flags,
member->channel_name,
member->chan->cid.cid_num ? member->chan->cid.cid_num : "unknown",
member->chan->cid.cid_name ? member->chan->cid.cid_name: "unknown",
ast_channel_callerid_number(member->chan),
ast_channel_callerid_name(member->chan),
(member->mute_audio == 0 ? "False" : "True"),
(member->speaking_state == 1 ? "True" : "False"),
conf->stats.moderators,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ struct ast_conf_member *check_active_video( int id, struct ast_conference *conf
}
#endif

static int convert_format_to_index(int format)
static int convert_format_to_index(format_t format)
{
switch ( format )
{
Expand Down Expand Up @@ -2961,8 +2961,8 @@ void send_state_change_notifications( struct ast_conf_member* member )
struct ast_packer {
int framesize; // number of frames per packet on the wire.
int size;
format_t format;
int packet_index;
int format;
int readdata;
int optimizablestream;
int flags;
Expand Down Expand Up @@ -3014,10 +3014,12 @@ int ast_packer_feed(struct ast_packer *s, const struct ast_frame *f)
return -1;
}
if (!s->format) {
s->format = f->subclass;
s->format = AST_FRAME_SUBCLASS_CODEC(f);
s->samples=0;
} else if (s->format != f->subclass) {
ast_log(LOG_WARNING, "Packer was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
} else if (s->format != AST_FRAME_SUBCLASS_CODEC(f)) {
ast_log(LOG_WARNING, "Packer was working on " AST_FMT_FORMAT_T " format frames, "
"now trying to feed " AST_FMT_FORMAT_T "?\n",
s->format, AST_FRAME_SUBCLASS_CODEC(f));
return -1;
}
if (s->len + f->datalen > PACKER_SIZE) {
Expand Down Expand Up @@ -3066,7 +3068,7 @@ struct ast_frame *ast_packer_read(struct ast_packer *s)
len = s->len;
/* Make frame */
s->f.frametype = AST_FRAME_VOICE;
s->f.subclass = s->format;
AST_FRAME_SUBCLASS_CODEC(&s->f) = s->format;
SETDATA2PTR(s->f.data, s->framedata + AST_FRIENDLY_OFFSET);
s->f.offset = AST_FRIENDLY_OFFSET;
s->f.datalen = len;
Expand Down Expand Up @@ -3284,7 +3286,8 @@ int queue_frame_for_speaker(
// short-cut pointer to the ast_frame
qf = frame->fr ;

if ( (qf->subclass == member->write_format) && (member->listen_volume == 0) )
if ( (AST_FRAME_SUBCLASS_CODEC(qf) == member->write_format) &&
(member->listen_volume == 0) )
{
// frame is already in correct format, so just queue it

Expand Down

0 comments on commit cb09cb1

Please sign in to comment.