[asterisk-commits] branch oej/test-this-branch r13387 - in
/team/oej/test-this-branch: ./ channe...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Mar 18 02:50:31 MST 2006
Author: oej
Date: Sat Mar 18 03:50:22 2006
New Revision: 13387
URL: http://svn.digium.com/view/asterisk?rev=13387&view=rev
Log:
Adding support for passthrough and storage of G.722 (andrew, issue 5084)
Added:
team/oej/test-this-branch/formats/format_g722.c (with props)
Modified:
team/oej/test-this-branch/README.test-this-branch
team/oej/test-this-branch/channel.c
team/oej/test-this-branch/channels/chan_h323.c
team/oej/test-this-branch/channels/chan_iax2.c
team/oej/test-this-branch/frame.c
team/oej/test-this-branch/include/asterisk/frame.h
team/oej/test-this-branch/rtp.c
team/oej/test-this-branch/translate.c
Modified: team/oej/test-this-branch/README.test-this-branch
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/README.test-this-branch?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/README.test-this-branch (original)
+++ team/oej/test-this-branch/README.test-this-branch Sat Mar 18 03:50:22 2006
@@ -51,6 +51,7 @@
- Mute logging in remote console (mavetju, #6524)
- Manager playDTMF command (squinky, #6682)
(Note: I changed the name in this version...)
+- G.722 support in Asterisk (passthrough, formats) (andrew, #5084)
Things that has been commited to svn trunk:
- Abandon Queue manager event (tim_ringenbach, #6459)
Modified: team/oej/test-this-branch/channel.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channel.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/channel.c (original)
+++ team/oej/test-this-branch/channel.c Sat Mar 18 03:50:22 2006
@@ -550,6 +550,8 @@
int x;
static int prefs[] =
{
+ /*! Best quality */
+ AST_FORMAT_G722,
/*! Okay, ulaw is used by all telephony equipment, so start with it */
AST_FORMAT_ULAW,
/*! Unless of course, you're a silly European, so then prefer ALAW */
Modified: team/oej/test-this-branch/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_h323.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_h323.c (original)
+++ team/oej/test-this-branch/channels/chan_h323.c Sat Mar 18 03:50:22 2006
@@ -2268,6 +2268,8 @@
return "ULAW";
case AST_FORMAT_ALAW:
return "ALAW";
+ case AST_FORMAT_G722:
+ return "G.722";
case AST_FORMAT_ADPCM:
return "G.728";
case AST_FORMAT_G729A:
Modified: team/oej/test-this-branch/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_iax2.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_iax2.c (original)
+++ team/oej/test-this-branch/channels/chan_iax2.c Sat Mar 18 03:50:22 2006
@@ -201,7 +201,8 @@
#define IAX_CAPABILITY_MEDBANDWIDTH (IAX_CAPABILITY_FULLBANDWIDTH & \
~AST_FORMAT_SLINEAR & \
~AST_FORMAT_ULAW & \
- ~AST_FORMAT_ALAW)
+ ~AST_FORMAT_ALAW & \
+ ~AST_FORMAT_G722)
/* A modem */
#define IAX_CAPABILITY_LOWBANDWIDTH (IAX_CAPABILITY_MEDBANDWIDTH & \
~AST_FORMAT_G726 & \
Added: team/oej/test-this-branch/formats/format_g722.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/formats/format_g722.c?rev=13387&view=auto
==============================================================================
--- team/oej/test-this-branch/formats/format_g722.c (added)
+++ team/oej/test-this-branch/formats/format_g722.c Sat Mar 18 03:50:22 2006
@@ -1,0 +1,236 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Save to raw, headerless G722 data.
+ *
+ * Base code copied from format_pcm.c by Mark Spencer
+ * Modified by Andrew Lindh <andrew at netplex.net>
+ *
+ * Copyright (C) 1999, Mark Spencer
+ * Mark Spencer <markster at linux-support.net>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <unistd.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/lock.h"
+#include "asterisk/channel.h"
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/sched.h"
+#include "asterisk/module.h"
+#include "asterisk/endian.h"
+
+#define BUF_SIZE 160 /* 160 samples */
+
+struct ast_filestream {
+ void *reserved[AST_RESERVED_POINTERS];
+ /* This is what a filestream means to us */
+ int fd; /* Descriptor */
+ struct ast_channel *owner;
+ struct ast_frame fr; /* Frame information */
+ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
+ char empty; /* Empty character */
+ unsigned char buf[BUF_SIZE]; /* Output Buffer */
+ struct timeval last;
+};
+
+
+AST_MUTEX_DEFINE_STATIC(g722_lock);
+static int glistcnt = 0;
+
+static char *name = "g722";
+static char *desc = "Raw G722 data";
+static char *exts = "g722";
+
+static struct ast_filestream *g722_open(int fd)
+{
+ /* We don't have any header to read or anything really, but
+ if we did, it would go here. We also might want to check
+ and be sure it's a valid file. */
+ struct ast_filestream *tmp;
+ if ((tmp = malloc(sizeof(struct ast_filestream)))) {
+ memset(tmp, 0, sizeof(struct ast_filestream));
+ if (ast_mutex_lock(&g722_lock)) {
+ ast_log(LOG_WARNING, "Unable to lock G722 list\n");
+ free(tmp);
+ return NULL;
+ }
+ tmp->fd = fd;
+ tmp->fr.data = tmp->buf;
+ tmp->fr.frametype = AST_FRAME_VOICE;
+ tmp->fr.subclass = AST_FORMAT_G722;
+ /* datalen will vary for each frame */
+ tmp->fr.src = name;
+ tmp->fr.mallocd = 0;
+ glistcnt++;
+ ast_mutex_unlock(&g722_lock);
+ ast_update_use_count();
+ }
+ return tmp;
+}
+
+static struct ast_filestream *g722_rewrite(int fd, const char *comment)
+{
+ /* We don't have any header to read or anything really, but
+ if we did, it would go here. We also might want to check
+ and be sure it's a valid file. */
+ struct ast_filestream *tmp;
+ if ((tmp = malloc(sizeof(struct ast_filestream)))) {
+ memset(tmp, 0, sizeof(struct ast_filestream));
+ if (ast_mutex_lock(&g722_lock)) {
+ ast_log(LOG_WARNING, "Unable to lock G722 list\n");
+ free(tmp);
+ return NULL;
+ }
+ tmp->fd = fd;
+ glistcnt++;
+ ast_mutex_unlock(&g722_lock);
+ ast_update_use_count();
+ } else
+ ast_log(LOG_WARNING, "Out of memory\n");
+ return tmp;
+}
+
+static void g722_close(struct ast_filestream *s)
+{
+ if (ast_mutex_lock(&g722_lock)) {
+ ast_log(LOG_WARNING, "Unable to lock G722 list\n");
+ return;
+ }
+ glistcnt--;
+ ast_mutex_unlock(&g722_lock);
+ ast_update_use_count();
+ close(s->fd);
+ free(s);
+ s = NULL;
+}
+
+static struct ast_frame *g722_read(struct ast_filestream *s, int *whennext)
+{
+ int res;
+ int delay;
+ /* Send a frame from the file to the appropriate channel */
+
+ s->fr.frametype = AST_FRAME_VOICE;
+ s->fr.subclass = AST_FORMAT_G722;
+ s->fr.offset = AST_FRIENDLY_OFFSET;
+ s->fr.mallocd = 0;
+ s->fr.data = s->buf;
+ if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+ if (res)
+ ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
+ return NULL;
+ }
+ s->fr.samples = res;
+ s->fr.datalen = res;
+ delay = s->fr.samples;
+ *whennext = delay;
+ return &s->fr;
+}
+
+static int g722_write(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 != AST_FORMAT_G722) {
+ ast_log(LOG_WARNING, "Asked to write non-G.722 frame (%d)!\n", f->subclass);
+ return -1;
+ }
+ if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+ ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+static int g722_seek(struct ast_filestream *fs, long sample_offset, int whence)
+{
+ off_t offset=0,min,cur,max;
+
+ min = 0;
+ cur = lseek(fs->fd, 0, SEEK_CUR);
+ max = lseek(fs->fd, 0, SEEK_END);
+ 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 lseek(fs->fd, offset, SEEK_SET);
+}
+
+static int g722_trunc(struct ast_filestream *fs)
+{
+ return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+}
+
+static long g722_tell(struct ast_filestream *fs)
+{
+ off_t offset;
+ offset = lseek(fs->fd, 0, SEEK_CUR);
+ return offset;
+}
+
+static char *g722_getcomment(struct ast_filestream *s)
+{
+ return NULL;
+}
+
+int load_module()
+{
+ return ast_format_register(name, exts, AST_FORMAT_G722,
+ g722_open,
+ g722_rewrite,
+ g722_write,
+ g722_seek,
+ g722_trunc,
+ g722_tell,
+ g722_read,
+ g722_close,
+ g722_getcomment);
+
+
+}
+
+int unload_module()
+{
+ return ast_format_unregister(name);
+}
+
+int usecount()
+{
+ return glistcnt;
+}
+
+char *description()
+{
+ return desc;
+}
+
+
+char *key()
+{
+ return ASTERISK_GPL_KEY;
+}
Propchange: team/oej/test-this-branch/formats/format_g722.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/oej/test-this-branch/formats/format_g722.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/oej/test-this-branch/formats/format_g722.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/oej/test-this-branch/frame.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/frame.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/frame.c (original)
+++ team/oej/test-this-branch/frame.c Sat Mar 18 03:50:22 2006
@@ -92,6 +92,7 @@
{ 1, AST_FORMAT_G729A, "g729", "G.729A" }, /*!< Binary commercial distribution */
{ 1, AST_FORMAT_SPEEX, "speex", "SpeeX" }, /*!< codec_speex.c */
{ 1, AST_FORMAT_ILBC, "ilbc", "iLBC"}, /*!< codec_ilbc.c */
+ { 1, AST_FORMAT_G722, "g722", "G722"}, /*!< codec_g722.c */
{ 0, 0, "nothing", "undefined" },
{ 0, 0, "nothing", "undefined" },
{ 0, 0, "nothing", "undefined" },
@@ -610,7 +611,7 @@
ast_cli(fd, "--------------------------------------------------------------------------------\n");
if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
found = 1;
- for (i=0;i<11;i++) {
+ for (i=0;i<12;i++) {
snprintf(hex,25,"(0x%x)",1<<i);
ast_cli(fd, "%11u (1 << %2d) %10s audio %5s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
}
@@ -1236,6 +1237,7 @@
break;
case AST_FORMAT_ULAW:
case AST_FORMAT_ALAW:
+ case AST_FORMAT_G722:
samples = f->datalen;
break;
case AST_FORMAT_ADPCM:
Modified: team/oej/test-this-branch/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/frame.h?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/frame.h (original)
+++ team/oej/test-this-branch/include/asterisk/frame.h Sat Mar 18 03:50:22 2006
@@ -215,6 +215,8 @@
#define AST_FORMAT_SPEEX (1 << 9)
/*! iLBC Free Compression */
#define AST_FORMAT_ILBC (1 << 10)
+/*! G.722 */
+#define AST_FORMAT_G722 (1 << 11)
/*! Maximum audio format */
#define AST_FORMAT_MAX_AUDIO (1 << 15)
/*! Maximum audio mask */
Modified: team/oej/test-this-branch/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/rtp.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/rtp.c (original)
+++ team/oej/test-this-branch/rtp.c Sat Mar 18 03:50:22 2006
@@ -919,6 +919,7 @@
{{1, AST_FORMAT_G729A}, "audio", "G729"},
{{1, AST_FORMAT_SPEEX}, "audio", "speex"},
{{1, AST_FORMAT_ILBC}, "audio", "iLBC"},
+ {{1, AST_FORMAT_G722}, "audio", "G722"},
{{0, AST_RTP_DTMF}, "audio", "telephone-event"},
{{0, AST_RTP_CISCO_DTMF}, "audio", "cisco-telephone-event"},
{{0, AST_RTP_CN}, "audio", "CN"},
@@ -944,6 +945,7 @@
[6] = {1, AST_FORMAT_ADPCM}, /* 16 kHz */
[7] = {1, AST_FORMAT_LPC10},
[8] = {1, AST_FORMAT_ALAW},
+ [9] = {1, AST_FORMAT_G722},
[10] = {1, AST_FORMAT_SLINEAR}, /* 2 channels */
[11] = {1, AST_FORMAT_SLINEAR}, /* 1 channel */
[13] = {0, AST_RTP_CN},
@@ -2015,6 +2017,7 @@
break;
case AST_FORMAT_ULAW:
case AST_FORMAT_ALAW:
+ case AST_FORMAT_G722:
if (!rtp->smoother) {
rtp->smoother = ast_smoother_new(160);
}
Modified: team/oej/test-this-branch/translate.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/translate.c?rev=13387&r1=13386&r2=13387&view=diff
==============================================================================
--- team/oej/test-this-branch/translate.c (original)
+++ team/oej/test-this-branch/translate.c Sat Mar 18 03:50:22 2006
@@ -356,9 +356,9 @@
/*! \brief CLI "show translation" command handler */
static int show_translation(int fd, int argc, char *argv[])
{
-#define SHOW_TRANS 11
+#define SHOW_TRANS 12
int x, y, z;
- char line[80];
+ char line[100];
if (argc > 4)
return RESULT_SHOWUSAGE;
More information about the asterisk-commits
mailing list