--- /home/tsgan/asterisk-addons-1.4.5/asterisk-ooh323c/src/chan_h323.c 2007-07-21 15:17:52.000000000 +0800 +++ /usr/local/voip/asterisk-addons-1.4.5/asterisk-ooh323c/src/chan_h323.c 2008-02-11 17:32:38.000000000 +0800 @@ -42,8 +42,9 @@ /* Channel Definition */ -static struct ast_channel *ooh323_request(const char *type, int format, - void *data, int *cause); +//static struct ast_channel *ooh323_request(const char *type, int format, void *data, int *cause); +static struct ast_channel *ooh323_request(const char *type, const struct ast_codec_pref *format, void *data, int *cause); + static int ooh323_digit_begin(struct ast_channel *ast, char digit); static int ooh323_digit_end(struct ast_channel *ast, char digit, unsigned int duration); static int ooh323_call(struct ast_channel *ast, char *dest, int timeout); @@ -57,8 +58,7 @@ static enum ast_rtp_get_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp); static enum ast_rtp_get_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp); -static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, - struct ast_rtp *vrtp, int codecs, int nat_active); +static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, const struct ast_codec_pref *codecs, int nat_active); static void print_codec_to_cli(int fd, struct ast_codec_pref *pref); static void ast_ooh323c_exit(); @@ -258,10 +258,21 @@ ast_mutex_lock(&ch->lock); ch->tech = &ooh323_tech; - ch->nativeformats = i->capability; +ast_string_field_build(ch, name, "H323/%s", host); +//if (!(fmt = i->capability)) + fmt = i->capability; + +// ch->nativeformats = i->capability; + +//ch->nativeformats = ast_codec_choose(&(i->prefs), fmt, 1)/* | (i->jointcapability & AST_FORMAT_VIDEO_MASK)*/; +ch->nativeformats = i->prefs; +// fmt = ast_best_codec(ch->nativeformats); + +// ast_codec_pref_append_missing2(&ch->nativeformats, ast_codec_choose(&i->prefs, fmt, 1)); +// i->nativeformats = ast_codec_pref_bits(&ch->nativeformats); +// fmt = ast_best_codec(i->nativeformats); - fmt = ast_best_codec(ch->nativeformats); ch->fds[0] = ast_rtp_fd(i->rtp); ch->fds[1] = ast_rtcp_fd(i->rtp); @@ -451,8 +462,7 @@ /* Possible data values - peername, exten/peername, exten@ip */ -static struct ast_channel *ooh323_request(const char *type, int format, - void *data, int *cause) +static struct ast_channel *ooh323_request(const char *type, const struct ast_codec_pref *formats, void *data, int *cause) { struct ast_channel *chan=NULL; @@ -461,22 +471,21 @@ char *dest = NULL; char *ext = NULL; char tmp[256]; - char formats[512]; - int oldformat; +// char formats[512]; +// int oldformat; char *sport = NULL; int port = 0; if(gH323Debug) - ast_verbose("--- ooh323_request - data %s format %s\n", (char*)data, - ast_getformatname_multiple(formats,512,format) ); + ast_verbose("--- ooh323_request - data %s format %s\n", (char*)data, ast_codec_pref_dump(tmp, sizeof(tmp), formats) ); - oldformat = format; - format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1); - if (!format) { - ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format " - "'%d'\n", format); - return NULL; - } +// oldformat = format; +// format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1); +// if (!format) { +// ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format " +// "'%d'\n", format); +// return NULL; +// } p = ooh323_alloc(0,0); /* Initial callRef is zero */ @@ -536,11 +545,11 @@ if(ext) strncpy(p->exten, ext, sizeof(p->exten)-1); - if(peer->capability & format) - p->capability = peer->capability & format; - else{ +// if(peer->capability & format) +// p->capability = peer->capability & format; +// else{ p->capability = peer->capability; - } +// } memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref)); p->dtmfmode = peer->dtmfmode; strncpy(p->accountcode, peer->accountcode, sizeof(p->accountcode)-1); @@ -971,11 +980,11 @@ if(f->frametype == AST_FRAME_VOICE) { - if(!(f->subclass & ast->nativeformats)) + if(!(f->subclass & ast->nativeformats.audio_bits)) { ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native " "formats is %d (read/write = %d/%d)\n", - f->subclass, ast->nativeformats, ast->readformat, + f->subclass, ast->nativeformats.audio_bits, ast->readformat, ast->writeformat); return 0; } @@ -2219,12 +2228,12 @@ int x, codec; for(x = 0; x < 32 ; x++) { - codec = ast_codec_pref_index(pref, x); + codec = ast_codec_pref_index_audio(pref, x); if (!codec) break; ast_cli(fd, "%s", ast_getformatname(codec)); - ast_cli(fd, ":%d", pref->framing[x]); - if (x < 31 && ast_codec_pref_index(pref, x + 1)) + ast_cli(fd, ":%d", pref->audio_framing[x]); + if (x < 31 && ast_codec_pref_index_audio(pref, x + 1)) ast_cli(fd, ","); } if (!x) @@ -3020,13 +3029,13 @@ (ooCallData *call, struct ast_codec_pref *prefs) { int i=0; - int codec = ast_codec_pref_index(prefs, i); + int codec = ast_codec_pref_index_audio(prefs, i); ooResetCapPrefs(call); while(codec) { ooAppendCapToCapPrefs(call, ooh323_convertAsteriskCapToH323Cap(codec)); - codec = ast_codec_pref_index(prefs, ++i); + codec = ast_codec_pref_index_audio(prefs, ++i); } return 0; @@ -3058,7 +3067,7 @@ static int ooh323_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, - int codecs, int nat_active) + const struct ast_codec_pref *codecs, int nat_active) { /* XXX Deal with Video */ struct ooh323_pvt *p; @@ -3106,7 +3115,7 @@ strncpy(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP)-1); mediaInfo.lMediaPort = ntohs(us.sin_port); mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1; - for(x=0; 0 != (format=ast_codec_pref_index(&p->prefs, x)); x++) + for(x=0; 0 != (format=ast_codec_pref_index_audio(&p->prefs, x)); x++) { strcpy(mediaInfo.dir, "transmit"); mediaInfo.cap = ooh323_convertAsteriskCapToH323Cap(format); @@ -3250,10 +3259,13 @@ /* We already hold the channel lock */ if (f->frametype == AST_FRAME_VOICE) { - if (f->subclass != p->owner->nativeformats) + if (f->subclass != p->owner->nativeformats.audio_bits) { ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); - p->owner->nativeformats = f->subclass; + p->owner->nativeformats.audio_bits = f->subclass; +// ast_codec_pref_append(&p->owner->nativeformats, f->subclass); +// p->nativeformats |= f->subclass; +// ast_codec_pref_set2(&p->owner->nativeformats, p->nativeformats); ast_set_read_format(p->owner, p->owner->readformat); ast_set_write_format(p->owner, p->owner->writeformat); }