[asterisk-commits] dvossel: trunk r270940 - in /trunk: ./ channels/ formats/ include/asterisk/ m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 16 14:03:29 CDT 2010
Author: dvossel
Date: Wed Jun 16 14:03:24 2010
New Revision: 270940
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=270940
Log:
additon 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)
Added:
trunk/formats/format_g719.c (with props)
Modified:
trunk/CHANGES
trunk/channels/chan_iax2.c
trunk/channels/chan_sip.c
trunk/include/asterisk/frame.h
trunk/main/channel.c
trunk/main/frame.c
trunk/main/rtp_engine.c
trunk/res/res_rtp_asterisk.c
Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Wed Jun 16 14:03:24 2010
@@ -67,6 +67,7 @@
to each other
* Added the 'snom_aoc_enabled' option to turn on support for sending Advice of
Charge messages to snom phones.
+ * Added support for G.719 media streams.
IAX2 Changes
-----------
@@ -498,6 +499,8 @@
significant increase in performance (about 3X) for installations using this switchtype.
* Distributed devicestate now supports the use of the XMPP protocol, in addition to
AIS. For more information, please see doc/distributed_devstate-XMPP.txt
+ * The addition of G.719 pass-through support.
+
CLI Changes
-----------
Modified: trunk/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Jun 16 14:03:24 2010
@@ -316,6 +316,7 @@
~AST_FORMAT_SLINEAR16 & \
~AST_FORMAT_SIREN7 & \
~AST_FORMAT_SIREN14 & \
+ ~AST_FORMAT_G719 & \
~AST_FORMAT_ULAW & \
~AST_FORMAT_ALAW & \
~AST_FORMAT_G722)
Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Jun 16 14:03:24 2010
@@ -8520,6 +8520,15 @@
}
}
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;
+ }
+ }
}
}
}
@@ -9770,6 +9779,10 @@
case AST_FORMAT_SIREN14:
/* Indicate that we only expect 48Kbps */
ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code);
+ 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;
}
Added: trunk/formats/format_g719.c
URL: http://svnview.digium.com/svn/asterisk/trunk/formats/format_g719.c?view=auto&rev=270940
==============================================================================
--- trunk/formats/format_g719.c (added)
+++ trunk/formats/format_g719.c Wed Jun 16 14:03:24 2010
@@ -1,0 +1,143 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2010, Anthony Minessale and Digium, Inc.
+ * Anthony Minessale (anthmct at yahoo.com)
+ * Kevin P. Fleming <kpfleming at 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,
+);
+
Propchange: trunk/formats/format_g719.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/formats/format_g719.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: trunk/formats/format_g719.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: trunk/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/frame.h?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/include/asterisk/frame.h (original)
+++ trunk/include/asterisk/frame.h Wed Jun 16 14:03:24 2010
@@ -294,6 +294,8 @@
/*! Maximum text mask */
#define AST_FORMAT_MAX_TEXT (1ULL << 28)
#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) */
#define AST_FORMAT_TESTLAW (1ULL << 47)
/*! Reserved bit - do not use */
@@ -746,6 +748,8 @@
return 16000;
case AST_FORMAT_SIREN14:
return 32000;
+ case AST_FORMAT_G719:
+ return 48000;
default:
return 8000;
}
Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Wed Jun 16 14:03:24 2010
@@ -792,6 +792,7 @@
AST_FORMAT_ULAW,
/*! Unless of course, you're a silly European, so then prefer ALAW */
AST_FORMAT_ALAW,
+ AST_FORMAT_G719,
AST_FORMAT_SIREN14,
AST_FORMAT_SIREN7,
AST_FORMAT_TESTLAW,
Modified: trunk/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/frame.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/main/frame.c (original)
+++ trunk/main/frame.c Wed Jun 16 14:03:24 2010
@@ -120,6 +120,7 @@
{ 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_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, };
@@ -1491,6 +1492,10 @@
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */
samples = (int) f->datalen * ((float) 32000 / 6000);
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:
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 @@
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */
len = (int) samples / ((float) 32000 / 6000);
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:
ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
}
Modified: trunk/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/rtp_engine.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/main/rtp_engine.c (original)
+++ trunk/main/rtp_engine.c Wed Jun 16 14:03:24 2010
@@ -122,6 +122,7 @@
{{1, AST_FORMAT_T140}, "text", "T140", 1000},
{{1, AST_FORMAT_SIREN7}, "audio", "G7221", 16000},
{{1, AST_FORMAT_SIREN14}, "audio", "G7221", 32000},
+ {{1, AST_FORMAT_G719}, "audio", "G719", 48000},
};
/*!
@@ -169,6 +170,7 @@
[111] = {1, AST_FORMAT_G726},
[112] = {1, AST_FORMAT_G726_AAL2},
[115] = {1, AST_FORMAT_SIREN14},
+ [116] = {1, AST_FORMAT_G719},
[121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */
};
Modified: trunk/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_rtp_asterisk.c?view=diff&rev=270940&r1=270939&r2=270940
==============================================================================
--- trunk/res/res_rtp_asterisk.c (original)
+++ trunk/res/res_rtp_asterisk.c Wed Jun 16 14:03:24 2010
@@ -1231,6 +1231,7 @@
case AST_FORMAT_G723_1:
case AST_FORMAT_SIREN7:
case AST_FORMAT_SIREN14:
+ case AST_FORMAT_G719:
/* these are all frame-based codecs and cannot be safely run through
a smoother */
break;
More information about the asterisk-commits
mailing list