addition of G.719 pass-through support

(closes issue #16293)
Reported by: malcolmd
Patches:
      g719.passthrough.patch.7 uploaded by malcolmd (license 924)
      format_g719.c uploaded by malcolmd (license 924)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@270940 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
David Vossel 16 years ago
parent 0bf94685fd
commit fcb055fb4e

@ -67,6 +67,7 @@ SIP Changes
to each other to each other
* Added the 'snom_aoc_enabled' option to turn on support for sending Advice of * Added the 'snom_aoc_enabled' option to turn on support for sending Advice of
Charge messages to snom phones. Charge messages to snom phones.
* Added support for G.719 media streams.
IAX2 Changes IAX2 Changes
----------- -----------
@ -498,6 +499,8 @@ Miscellaneous
significant increase in performance (about 3X) for installations using this switchtype. significant increase in performance (about 3X) for installations using this switchtype.
* Distributed devicestate now supports the use of the XMPP protocol, in addition to * Distributed devicestate now supports the use of the XMPP protocol, in addition to
AIS. For more information, please see doc/distributed_devstate-XMPP.txt AIS. For more information, please see doc/distributed_devstate-XMPP.txt
* The addition of G.719 pass-through support.
CLI Changes CLI Changes
----------- -----------

@ -316,6 +316,7 @@ static int (*iax2_regfunk)(const char *username, int onoff) = NULL;
~AST_FORMAT_SLINEAR16 & \ ~AST_FORMAT_SLINEAR16 & \
~AST_FORMAT_SIREN7 & \ ~AST_FORMAT_SIREN7 & \
~AST_FORMAT_SIREN14 & \ ~AST_FORMAT_SIREN14 & \
~AST_FORMAT_G719 & \
~AST_FORMAT_ULAW & \ ~AST_FORMAT_ULAW & \
~AST_FORMAT_ALAW & \ ~AST_FORMAT_ALAW & \
~AST_FORMAT_G722) ~AST_FORMAT_G722)

@ -8520,6 +8520,15 @@ static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_
} }
} }
break; break;
case AST_FORMAT_G719:
if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
if (bit_rate != 64000) {
ast_log(LOG_WARNING, "Got G.719 offer at %d bps, but only 64000 bps supported; ignoring.\n", bit_rate);
ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
} else {
found = TRUE;
}
}
} }
} }
} }
@ -9771,6 +9780,10 @@ static void add_codec_to_sdp(const struct sip_pvt *p, format_t codec,
/* Indicate that we only expect 48Kbps */ /* Indicate that we only expect 48Kbps */
ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code); ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code);
break; break;
case AST_FORMAT_G719:
/* Indicate that we only expect 64Kbps */
ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code);
break;
} }
if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size)) if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))

@ -0,0 +1,143 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2010, Anthony Minessale and Digium, Inc.
* Anthony Minessale (anthmct@yahoo.com)
* Kevin P. Fleming <kpfleming@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief ITU G.719 , 64kbps bitrate only
* \arg File name extensions: g719
* \ingroup formats
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
#define BUF_SIZE 160 /* 20 milliseconds == 160 bytes, 960 samples */
#define SAMPLES_TO_BYTES(x) ((typeof(x)) x / ((float) 960 / 160))
#define BYTES_TO_SAMPLES(x) ((typeof(x)) x * ((float) 960 / 160))
static struct ast_frame *g719read(struct ast_filestream *s, int *whennext)
{
int res;
/* Send a frame from the file to the appropriate channel */
s->fr.frametype = AST_FRAME_VOICE;
s->fr.subclass.codec = AST_FORMAT_G719;
s->fr.mallocd = 0;
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
if (res)
ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
return NULL;
}
*whennext = s->fr.samples = BYTES_TO_SAMPLES(res);
return &s->fr;
}
static int g719write(struct ast_filestream *fs, struct ast_frame *f)
{
int res;
if (f->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
return -1;
}
if (f->subclass.codec != AST_FORMAT_G719) {
ast_log(LOG_WARNING, "Asked to write non-G.719 frame (%s)!\n", ast_getformatname(f->subclass.codec));
return -1;
}
if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
}
return 0;
}
static int g719seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
off_t offset = 0, min = 0, cur, max;
sample_offset = SAMPLES_TO_BYTES(sample_offset);
cur = ftello(fs->f);
fseeko(fs->f, 0, SEEK_END);
max = ftello(fs->f);
if (whence == SEEK_SET)
offset = sample_offset;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
offset = sample_offset + cur;
else if (whence == SEEK_END)
offset = max - sample_offset;
if (whence != SEEK_FORCECUR)
offset = (offset > max) ? max : offset;
/* always protect against seeking past begining. */
offset = (offset < min) ? min : offset;
return fseeko(fs->f, offset, SEEK_SET);
}
static int g719trunc(struct ast_filestream *fs)
{
return ftruncate(fileno(fs->f), ftello(fs->f));
}
static off_t g719tell(struct ast_filestream *fs)
{
return BYTES_TO_SAMPLES(ftello(fs->f));
}
static const struct ast_format g719_f = {
.name = "g719",
.exts = "g719",
.format = AST_FORMAT_G719,
.write = g719write,
.seek = g719seek,
.trunc = g719trunc,
.tell = g719tell,
.read = g719read,
.buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,
};
static int load_module(void)
{
if (ast_format_register(&g719_f))
return AST_MODULE_LOAD_DECLINE;
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
return ast_format_unregister(g719_f.name);
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,"ITU G.719",
.load = load_module,
.unload = unload_module,
.load_pri = 10,
);

@ -294,6 +294,8 @@ extern struct ast_frame ast_null_frame;
/*! Maximum text mask */ /*! Maximum text mask */
#define AST_FORMAT_MAX_TEXT (1ULL << 28) #define AST_FORMAT_MAX_TEXT (1ULL << 28)
#define AST_FORMAT_TEXT_MASK (((1ULL << 30)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK)) #define AST_FORMAT_TEXT_MASK (((1ULL << 30)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK))
/*! G.719 (64 kbps assumed) */
#define AST_FORMAT_G719 (1ULL << 32)
/*! Raw mu-law data (G.711) */ /*! Raw mu-law data (G.711) */
#define AST_FORMAT_TESTLAW (1ULL << 47) #define AST_FORMAT_TESTLAW (1ULL << 47)
/*! Reserved bit - do not use */ /*! Reserved bit - do not use */
@ -746,6 +748,8 @@ static force_inline int ast_format_rate(format_t format)
return 16000; return 16000;
case AST_FORMAT_SIREN14: case AST_FORMAT_SIREN14:
return 32000; return 32000;
case AST_FORMAT_G719:
return 48000;
default: default:
return 8000; return 8000;
} }

@ -792,6 +792,7 @@ format_t ast_best_codec(format_t fmts)
AST_FORMAT_ULAW, AST_FORMAT_ULAW,
/*! Unless of course, you're a silly European, so then prefer ALAW */ /*! Unless of course, you're a silly European, so then prefer ALAW */
AST_FORMAT_ALAW, AST_FORMAT_ALAW,
AST_FORMAT_G719,
AST_FORMAT_SIREN14, AST_FORMAT_SIREN14,
AST_FORMAT_SIREN7, AST_FORMAT_SIREN7,
AST_FORMAT_TESTLAW, AST_FORMAT_TESTLAW,

@ -120,6 +120,7 @@ static const struct ast_format_list AST_FORMAT_LIST[] = {
{ AST_FORMAT_SIREN7, "siren7", 16000, "ITU G.722.1 (Siren7, licensed from Polycom)", 80, 20, 80, 20, 20 }, /*!< Binary commercial distribution */ { AST_FORMAT_SIREN7, "siren7", 16000, "ITU G.722.1 (Siren7, licensed from Polycom)", 80, 20, 80, 20, 20 }, /*!< Binary commercial distribution */
{ AST_FORMAT_SIREN14, "siren14", 32000, "ITU G.722.1 Annex C, (Siren14, licensed from Polycom)", 120, 20, 80, 20, 20 }, /*!< Binary commercial distribution */ { AST_FORMAT_SIREN14, "siren14", 32000, "ITU G.722.1 Annex C, (Siren14, licensed from Polycom)", 120, 20, 80, 20, 20 }, /*!< Binary commercial distribution */
{ AST_FORMAT_TESTLAW, "testlaw", 8000, "G.711 test-law", 80, 10, 150, 10, 20 }, /*!< codec_ulaw.c */ { AST_FORMAT_TESTLAW, "testlaw", 8000, "G.711 test-law", 80, 10, 150, 10, 20 }, /*!< codec_ulaw.c */
{ AST_FORMAT_G719, "g719", 48000, "ITU G.719", 160, 20, 80, 20, 20 },
}; };
struct ast_frame ast_null_frame = { AST_FRAME_NULL, }; struct ast_frame ast_null_frame = { AST_FRAME_NULL, };
@ -1491,6 +1492,10 @@ int ast_codec_get_samples(struct ast_frame *f)
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */ /* 32,000 samples per second at 48kbps is 6,000 bytes per second */
samples = (int) f->datalen * ((float) 32000 / 6000); samples = (int) f->datalen * ((float) 32000 / 6000);
break; break;
case AST_FORMAT_G719:
/* 48,000 samples per second at 64kbps is 8,000 bytes per second */
samples = (int) f->datalen * ((float) 48000 / 8000);
break;
default: default:
ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), f->subclass.codec)); ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), f->subclass.codec));
} }
@ -1538,6 +1543,10 @@ int ast_codec_get_len(format_t format, int samples)
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */ /* 32,000 samples per second at 48kbps is 6,000 bytes per second */
len = (int) samples / ((float) 32000 / 6000); len = (int) samples / ((float) 32000 / 6000);
break; break;
case AST_FORMAT_G719:
/* 48,000 samples per second at 64kbps is 8,000 bytes per second */
len = (int) samples / ((float) 48000 / 8000);
break;
default: default:
ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format)); ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
} }

@ -122,6 +122,7 @@ static const struct ast_rtp_mime_type {
{{1, AST_FORMAT_T140}, "text", "T140", 1000}, {{1, AST_FORMAT_T140}, "text", "T140", 1000},
{{1, AST_FORMAT_SIREN7}, "audio", "G7221", 16000}, {{1, AST_FORMAT_SIREN7}, "audio", "G7221", 16000},
{{1, AST_FORMAT_SIREN14}, "audio", "G7221", 32000}, {{1, AST_FORMAT_SIREN14}, "audio", "G7221", 32000},
{{1, AST_FORMAT_G719}, "audio", "G719", 48000},
}; };
/*! /*!
@ -169,6 +170,7 @@ static const struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT] = {
[111] = {1, AST_FORMAT_G726}, [111] = {1, AST_FORMAT_G726},
[112] = {1, AST_FORMAT_G726_AAL2}, [112] = {1, AST_FORMAT_G726_AAL2},
[115] = {1, AST_FORMAT_SIREN14}, [115] = {1, AST_FORMAT_SIREN14},
[116] = {1, AST_FORMAT_G719},
[121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */ [121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */
}; };

@ -1231,6 +1231,7 @@ static int ast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *fr
case AST_FORMAT_G723_1: case AST_FORMAT_G723_1:
case AST_FORMAT_SIREN7: case AST_FORMAT_SIREN7:
case AST_FORMAT_SIREN14: case AST_FORMAT_SIREN14:
case AST_FORMAT_G719:
/* these are all frame-based codecs and cannot be safely run through /* these are all frame-based codecs and cannot be safely run through
a smoother */ a smoother */
break; break;

Loading…
Cancel
Save