1999-11-21 02:26:43 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
2004-12-03 23:46:09 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-11-21 02:26:43 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1999-11-21 02:26:43 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2006-06-01 19:48:31 +00:00
|
|
|
* \brief Frame and codec manipulation routines
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2012-03-22 19:51:16 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
1999-11-21 02:26:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2007-11-20 22:18:21 +00:00
|
|
|
#include "asterisk/_private.h"
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/frame.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/term.h"
|
|
|
|
#include "asterisk/utils.h"
|
2006-08-29 20:50:36 +00:00
|
|
|
#include "asterisk/threadstorage.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
Merged revisions 98943 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed. Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code. The reason this
happens is that the channel might get masqueraded during this time. During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way. (This one is
for you, paravoid!)
It changes an int in ast_frame to be used as flag bits. The 1 bit is still used
to indicate that the frame contains timing information. Also, a second flag has
been added to indicate that the frame came from a translator. When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed. At this point, the flag gets
cleared. Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack. But, it does fix the issue, and I was not able
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-01-15 23:31:53 +00:00
|
|
|
#include "asterisk/translate.h"
|
2008-04-17 16:40:12 +00:00
|
|
|
#include "asterisk/dsp.h"
|
2008-11-20 18:20:00 +00:00
|
|
|
#include "asterisk/file.h"
|
2001-10-04 20:02:12 +00:00
|
|
|
|
2007-01-04 18:19:55 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
2006-08-29 20:50:36 +00:00
|
|
|
static void frame_cache_cleanup(void *data);
|
|
|
|
|
|
|
|
/*! \brief A per-thread cache of frame headers */
|
2006-10-19 01:00:57 +00:00
|
|
|
AST_THREADSTORAGE_CUSTOM(frame_cache, NULL, frame_cache_cleanup);
|
2006-08-29 20:50:36 +00:00
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/*!
|
2006-08-29 20:50:36 +00:00
|
|
|
* \brief Maximum ast_frame cache size
|
|
|
|
*
|
|
|
|
* In most cases where the frame header cache will be useful, the size
|
|
|
|
* of the cache will stay very small. However, it is not always the case that
|
|
|
|
* the same thread that allocates the frame will be the one freeing them, so
|
|
|
|
* sometimes a thread will never have any frames in its cache, or the cache
|
2012-03-22 19:51:16 +00:00
|
|
|
* will never be pulled from. For the latter case, we limit the maximum size.
|
|
|
|
*/
|
2006-08-29 20:50:36 +00:00
|
|
|
#define FRAME_CACHE_MAX_SIZE 10
|
|
|
|
|
|
|
|
/*! \brief This is just so ast_frames, a list head struct for holding a list of
|
|
|
|
* ast_frame structures, is defined. */
|
|
|
|
AST_LIST_HEAD_NOLOCK(ast_frames, ast_frame);
|
|
|
|
|
|
|
|
struct ast_frame_cache {
|
|
|
|
struct ast_frames list;
|
|
|
|
size_t size;
|
|
|
|
};
|
2007-01-04 18:19:55 +00:00
|
|
|
#endif
|
2006-08-29 20:50:36 +00:00
|
|
|
|
2002-06-19 02:35:40 +00:00
|
|
|
#define SMOOTHER_SIZE 8000
|
|
|
|
|
2006-02-21 19:24:01 +00:00
|
|
|
enum frame_type {
|
|
|
|
TYPE_HIGH, /* 0x0 */
|
|
|
|
TYPE_LOW, /* 0x1 */
|
|
|
|
TYPE_SILENCE, /* 0x2 */
|
|
|
|
TYPE_DONTSEND /* 0x3 */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TYPE_MASK 0x3
|
2005-05-14 23:57:44 +00:00
|
|
|
|
2002-06-19 02:35:40 +00:00
|
|
|
struct ast_smoother {
|
|
|
|
int size;
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format format;
|
2004-03-14 18:01:29 +00:00
|
|
|
int flags;
|
2003-02-05 19:26:49 +00:00
|
|
|
float samplesperbyte;
|
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@180373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-05 18:29:38 +00:00
|
|
|
unsigned int opt_needs_swap:1;
|
2002-06-19 02:35:40 +00:00
|
|
|
struct ast_frame f;
|
2004-03-13 03:52:14 +00:00
|
|
|
struct timeval delivery;
|
2002-06-19 02:35:40 +00:00
|
|
|
char data[SMOOTHER_SIZE];
|
|
|
|
char framedata[SMOOTHER_SIZE + AST_FRIENDLY_OFFSET];
|
2003-02-16 06:00:12 +00:00
|
|
|
struct ast_frame *opt;
|
2002-06-19 02:35:40 +00:00
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
2006-01-31 17:18:58 +00:00
|
|
|
struct ast_frame ast_null_frame = { AST_FRAME_NULL, };
|
|
|
|
|
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@180373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-05 18:29:38 +00:00
|
|
|
static int smoother_frame_feed(struct ast_smoother *s, struct ast_frame *f, int swap)
|
|
|
|
{
|
|
|
|
if (s->flags & AST_SMOOTHER_FLAG_G729) {
|
|
|
|
if (s->len % 10) {
|
|
|
|
ast_log(LOG_NOTICE, "Dropping extra frame of G.729 since we already have a VAD frame at the end\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (swap) {
|
|
|
|
ast_swapcopy_samples(s->data + s->len, f->data.ptr, f->samples);
|
|
|
|
} else {
|
|
|
|
memcpy(s->data + s->len, f->data.ptr, f->datalen);
|
|
|
|
}
|
|
|
|
/* If either side is empty, reset the delivery time */
|
|
|
|
if (!s->len || ast_tvzero(f->delivery) || ast_tvzero(s->delivery)) { /* XXX really ? */
|
|
|
|
s->delivery = f->delivery;
|
|
|
|
}
|
|
|
|
s->len += f->datalen;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_smoother_reset(struct ast_smoother *s, int bytes)
|
2003-02-05 19:26:49 +00:00
|
|
|
{
|
2006-02-21 19:24:01 +00:00
|
|
|
memset(s, 0, sizeof(*s));
|
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@180373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-05 18:29:38 +00:00
|
|
|
s->size = bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_smoother_reconfigure(struct ast_smoother *s, int bytes)
|
|
|
|
{
|
|
|
|
/* if there is no change, then nothing to do */
|
|
|
|
if (s->size == bytes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* set the new desired output size */
|
|
|
|
s->size = bytes;
|
|
|
|
/* if there is no 'optimized' frame in the smoother,
|
|
|
|
* then there is nothing left to do
|
|
|
|
*/
|
|
|
|
if (!s->opt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* there is an 'optimized' frame here at the old size,
|
|
|
|
* but it must now be put into the buffer so the data
|
|
|
|
* can be extracted at the new size
|
|
|
|
*/
|
|
|
|
smoother_frame_feed(s, s->opt, s->opt_needs_swap);
|
|
|
|
s->opt = NULL;
|
2003-02-05 19:26:49 +00:00
|
|
|
}
|
|
|
|
|
2002-06-19 02:35:40 +00:00
|
|
|
struct ast_smoother *ast_smoother_new(int size)
|
|
|
|
{
|
|
|
|
struct ast_smoother *s;
|
2002-09-03 15:11:04 +00:00
|
|
|
if (size < 1)
|
|
|
|
return NULL;
|
2006-02-21 19:24:01 +00:00
|
|
|
if ((s = ast_malloc(sizeof(*s))))
|
2003-02-05 19:26:49 +00:00
|
|
|
ast_smoother_reset(s, size);
|
2002-06-19 02:35:40 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-03-14 18:01:29 +00:00
|
|
|
int ast_smoother_get_flags(struct ast_smoother *s)
|
|
|
|
{
|
|
|
|
return s->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_smoother_set_flags(struct ast_smoother *s, int flags)
|
|
|
|
{
|
|
|
|
s->flags = flags;
|
|
|
|
}
|
|
|
|
|
2006-09-18 23:32:57 +00:00
|
|
|
int ast_smoother_test_flag(struct ast_smoother *s, int flag)
|
|
|
|
{
|
|
|
|
return (s->flags & flag);
|
|
|
|
}
|
|
|
|
|
2005-04-03 22:57:18 +00:00
|
|
|
int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap)
|
2002-06-19 02:35:40 +00:00
|
|
|
{
|
|
|
|
if (f->frametype != AST_FRAME_VOICE) {
|
|
|
|
ast_log(LOG_WARNING, "Huh? Can't smooth a non-voice frame!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-03 16:22:10 +00:00
|
|
|
if (!s->format.id) {
|
|
|
|
ast_format_copy(&s->format, &f->subclass.format);
|
2003-02-05 19:26:49 +00:00
|
|
|
s->samplesperbyte = (float)f->samples / (float)f->datalen;
|
2011-02-03 16:22:10 +00:00
|
|
|
} else if (ast_format_cmp(&s->format, &f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
|
2009-11-04 14:05:12 +00:00
|
|
|
ast_log(LOG_WARNING, "Smoother was working on %s format frames, now trying to feed %s?\n",
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_getformatname(&s->format), ast_getformatname(&f->subclass.format));
|
2002-06-19 02:35:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (s->len + f->datalen > SMOOTHER_SIZE) {
|
|
|
|
ast_log(LOG_WARNING, "Out of smoother space\n");
|
|
|
|
return -1;
|
|
|
|
}
|
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@180373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-05 18:29:38 +00:00
|
|
|
if (((f->datalen == s->size) ||
|
|
|
|
((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729))) &&
|
|
|
|
!s->opt &&
|
|
|
|
!s->len &&
|
|
|
|
(f->offset >= AST_MIN_OFFSET)) {
|
|
|
|
/* Optimize by sending the frame we just got
|
|
|
|
on the next read, thus eliminating the douple
|
|
|
|
copy */
|
|
|
|
if (swap)
|
|
|
|
ast_swapcopy_samples(f->data.ptr, f->data.ptr, f->samples);
|
|
|
|
s->opt = f;
|
|
|
|
s->opt_needs_swap = swap ? 1 : 0;
|
|
|
|
return 0;
|
2004-03-14 18:01:29 +00:00
|
|
|
}
|
Merged revisions 180372 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r180372 | kpfleming | 2009-03-05 12:22:16 -0600 (Thu, 05 Mar 2009) | 9 lines
Fix problems when RTP packet frame size is changed
During some code analysis, I found that calling ast_rtp_codec_setpref() on an ast_rtp session does not work as expected; it does not adjust the smoother that may on the RTP session, in fact it summarily drops it, even if it has data in it, even if the current format's framing size has not changed. This is not good.
This patch changes this behavior, so that if the packetization size for the current format changes, any existing smoother is safely updated to use the new size, and if no smoother was present, one is created. A new API call for smoothers, ast_smoother_reconfigure(), was required to implement these changes.
Review: http://reviewboard.digium.com/r/184/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@180373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-05 18:29:38 +00:00
|
|
|
|
|
|
|
return smoother_frame_feed(s, f, swap);
|
2002-06-19 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_frame *ast_smoother_read(struct ast_smoother *s)
|
|
|
|
{
|
2003-02-16 06:00:12 +00:00
|
|
|
struct ast_frame *opt;
|
2004-03-14 18:01:29 +00:00
|
|
|
int len;
|
2006-06-01 19:48:31 +00:00
|
|
|
|
2003-02-16 06:00:12 +00:00
|
|
|
/* IF we have an optimization frame, send it */
|
|
|
|
if (s->opt) {
|
2004-07-19 15:52:57 +00:00
|
|
|
if (s->opt->offset < AST_FRIENDLY_OFFSET)
|
2006-09-28 18:09:01 +00:00
|
|
|
ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).\n",
|
2004-07-19 15:52:57 +00:00
|
|
|
s->opt->offset);
|
2003-02-16 06:00:12 +00:00
|
|
|
opt = s->opt;
|
|
|
|
s->opt = NULL;
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
2002-06-19 02:35:40 +00:00
|
|
|
/* Make sure we have enough data */
|
2002-09-03 15:11:04 +00:00
|
|
|
if (s->len < s->size) {
|
2004-03-14 18:01:29 +00:00
|
|
|
/* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
|
2009-05-18 15:53:26 +00:00
|
|
|
if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->len % 10)))
|
2004-03-14 18:01:29 +00:00
|
|
|
return NULL;
|
2002-09-03 15:11:04 +00:00
|
|
|
}
|
2004-03-14 18:01:29 +00:00
|
|
|
len = s->size;
|
|
|
|
if (len > s->len)
|
|
|
|
len = s->len;
|
2002-06-19 02:35:40 +00:00
|
|
|
/* Make frame */
|
|
|
|
s->f.frametype = AST_FRAME_VOICE;
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_format_copy(&s->f.subclass.format, &s->format);
|
2008-05-22 16:29:54 +00:00
|
|
|
s->f.data.ptr = s->framedata + AST_FRIENDLY_OFFSET;
|
2002-06-19 02:35:40 +00:00
|
|
|
s->f.offset = AST_FRIENDLY_OFFSET;
|
2004-03-14 18:01:29 +00:00
|
|
|
s->f.datalen = len;
|
|
|
|
/* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
|
2005-07-15 23:00:47 +00:00
|
|
|
s->f.samples = len * s->samplesperbyte; /* XXX rounding */
|
2004-03-13 03:52:14 +00:00
|
|
|
s->f.delivery = s->delivery;
|
2002-06-19 02:35:40 +00:00
|
|
|
/* Fill Data */
|
2008-05-22 16:29:54 +00:00
|
|
|
memcpy(s->f.data.ptr, s->data, len);
|
2004-03-14 18:01:29 +00:00
|
|
|
s->len -= len;
|
2002-06-19 02:35:40 +00:00
|
|
|
/* Move remaining data to the front if applicable */
|
2004-03-13 03:52:14 +00:00
|
|
|
if (s->len) {
|
2004-03-14 18:01:29 +00:00
|
|
|
/* In principle this should all be fine because if we are sending
|
|
|
|
G.729 VAD, the next timestamp will take over anyawy */
|
|
|
|
memmove(s->data, s->data + len, s->len);
|
2005-07-15 23:00:47 +00:00
|
|
|
if (!ast_tvzero(s->delivery)) {
|
2004-04-22 03:02:27 +00:00
|
|
|
/* If we have delivery time, increment it, otherwise, leave it at 0 */
|
2011-02-03 16:22:10 +00:00
|
|
|
s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_format_rate(&s->format)));
|
2004-03-13 03:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-19 02:35:40 +00:00
|
|
|
/* Return frame */
|
|
|
|
return &s->f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_smoother_free(struct ast_smoother *s)
|
|
|
|
{
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(s);
|
2002-06-19 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2001-10-04 20:02:12 +00:00
|
|
|
static struct ast_frame *ast_frame_header_new(void)
|
|
|
|
{
|
2006-08-29 20:50:36 +00:00
|
|
|
struct ast_frame *f;
|
2007-01-04 18:19:55 +00:00
|
|
|
|
|
|
|
#if !defined(LOW_MEMORY)
|
2006-08-29 20:50:36 +00:00
|
|
|
struct ast_frame_cache *frames;
|
|
|
|
|
|
|
|
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
|
|
|
if ((f = AST_LIST_REMOVE_HEAD(&frames->list, frame_list))) {
|
|
|
|
size_t mallocd_len = f->mallocd_hdr_len;
|
|
|
|
memset(f, 0, sizeof(*f));
|
|
|
|
f->mallocd_hdr_len = mallocd_len;
|
|
|
|
f->mallocd = AST_MALLOCD_HDR;
|
|
|
|
frames->size--;
|
|
|
|
return f;
|
|
|
|
}
|
2001-10-04 20:02:12 +00:00
|
|
|
}
|
2006-12-27 18:33:44 +00:00
|
|
|
if (!(f = ast_calloc_cache(1, sizeof(*f))))
|
2006-08-29 20:50:36 +00:00
|
|
|
return NULL;
|
2007-01-04 21:59:06 +00:00
|
|
|
#else
|
|
|
|
if (!(f = ast_calloc(1, sizeof(*f))))
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2006-08-29 20:50:36 +00:00
|
|
|
|
|
|
|
f->mallocd_hdr_len = sizeof(*f);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2001-10-04 20:02:12 +00:00
|
|
|
return f;
|
|
|
|
}
|
1999-11-21 02:26:43 +00:00
|
|
|
|
2007-01-04 18:19:55 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
2006-08-29 20:50:36 +00:00
|
|
|
static void frame_cache_cleanup(void *data)
|
|
|
|
{
|
|
|
|
struct ast_frame_cache *frames = data;
|
|
|
|
struct ast_frame *f;
|
|
|
|
|
|
|
|
while ((f = AST_LIST_REMOVE_HEAD(&frames->list, frame_list)))
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(f);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(frames);
|
2006-08-29 20:50:36 +00:00
|
|
|
}
|
2007-01-04 18:19:55 +00:00
|
|
|
#endif
|
2006-08-29 20:50:36 +00:00
|
|
|
|
2009-06-16 18:54:30 +00:00
|
|
|
static void __frame_free(struct ast_frame *fr, int cache)
|
1999-11-21 02:26:43 +00:00
|
|
|
{
|
2006-08-29 20:50:36 +00:00
|
|
|
if (!fr->mallocd)
|
|
|
|
return;
|
|
|
|
|
2007-01-04 18:19:55 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
2006-09-03 23:14:54 +00:00
|
|
|
if (cache && fr->mallocd == AST_MALLOCD_HDR) {
|
2012-03-22 19:51:16 +00:00
|
|
|
/* Cool, only the header is malloc'd, let's just cache those for now
|
2006-08-29 20:50:36 +00:00
|
|
|
* to keep things simple... */
|
|
|
|
struct ast_frame_cache *frames;
|
|
|
|
|
2009-06-16 18:54:30 +00:00
|
|
|
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) &&
|
|
|
|
(frames->size < FRAME_CACHE_MAX_SIZE)) {
|
2006-08-29 20:50:36 +00:00
|
|
|
AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list);
|
|
|
|
frames->size++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-01-04 18:19:55 +00:00
|
|
|
#endif
|
2012-03-22 19:51:16 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
if (fr->mallocd & AST_MALLOCD_DATA) {
|
2012-03-22 19:51:16 +00:00
|
|
|
if (fr->data.ptr)
|
2008-05-22 16:29:54 +00:00
|
|
|
ast_free(fr->data.ptr - fr->offset);
|
1999-11-21 02:26:43 +00:00
|
|
|
}
|
|
|
|
if (fr->mallocd & AST_MALLOCD_SRC) {
|
|
|
|
if (fr->src)
|
2009-06-16 18:54:30 +00:00
|
|
|
ast_free((void *) fr->src);
|
1999-11-21 02:26:43 +00:00
|
|
|
}
|
|
|
|
if (fr->mallocd & AST_MALLOCD_HDR) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(fr);
|
1999-11-21 02:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 18:54:30 +00:00
|
|
|
|
|
|
|
void ast_frame_free(struct ast_frame *frame, int cache)
|
|
|
|
{
|
|
|
|
struct ast_frame *next;
|
|
|
|
|
|
|
|
for (next = AST_LIST_NEXT(frame, frame_list);
|
|
|
|
frame;
|
|
|
|
frame = next, next = frame ? AST_LIST_NEXT(frame, frame_list) : NULL) {
|
|
|
|
__frame_free(frame, cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:00:38 +00:00
|
|
|
/*!
|
|
|
|
* \brief 'isolates' a frame by duplicating non-malloc'ed components
|
2005-05-15 05:46:34 +00:00
|
|
|
* (header, src, data).
|
|
|
|
* On return all components are malloc'ed
|
|
|
|
*/
|
1999-11-21 02:26:43 +00:00
|
|
|
struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
|
|
|
{
|
|
|
|
struct ast_frame *out;
|
2006-05-06 02:31:22 +00:00
|
|
|
void *newdata;
|
Merged revisions 98943 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed. Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code. The reason this
happens is that the channel might get masqueraded during this time. During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way. (This one is
for you, paravoid!)
It changes an int in ast_frame to be used as flag bits. The 1 bit is still used
to indicate that the frame contains timing information. Also, a second flag has
been added to indicate that the frame came from a translator. When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed. At this point, the flag gets
cleared. Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack. But, it does fix the issue, and I was not able
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-01-15 23:31:53 +00:00
|
|
|
|
2009-06-16 18:54:30 +00:00
|
|
|
/* if none of the existing frame is malloc'd, let ast_frdup() do it
|
|
|
|
since it is more efficient
|
|
|
|
*/
|
|
|
|
if (fr->mallocd == 0) {
|
|
|
|
return ast_frdup(fr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if everything is already malloc'd, we are done */
|
|
|
|
if ((fr->mallocd & (AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) ==
|
|
|
|
(AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) {
|
|
|
|
return fr;
|
|
|
|
}
|
Merged revisions 98943 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed. Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code. The reason this
happens is that the channel might get masqueraded during this time. During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way. (This one is
for you, paravoid!)
It changes an int in ast_frame to be used as flag bits. The 1 bit is still used
to indicate that the frame contains timing information. Also, a second flag has
been added to indicate that the frame came from a translator. When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed. At this point, the flag gets
cleared. Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack. But, it does fix the issue, and I was not able
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-01-15 23:31:53 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
if (!(fr->mallocd & AST_MALLOCD_HDR)) {
|
|
|
|
/* Allocate a new header if needed */
|
2009-06-16 18:54:30 +00:00
|
|
|
if (!(out = ast_frame_header_new())) {
|
1999-11-21 02:26:43 +00:00
|
|
|
return NULL;
|
2009-06-16 18:54:30 +00:00
|
|
|
}
|
1999-11-21 02:26:43 +00:00
|
|
|
out->frametype = fr->frametype;
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_format_copy(&out->subclass.format, &fr->subclass.format);
|
2005-05-15 05:46:34 +00:00
|
|
|
out->datalen = fr->datalen;
|
2003-02-05 19:26:49 +00:00
|
|
|
out->samples = fr->samples;
|
2005-05-15 05:46:34 +00:00
|
|
|
out->offset = fr->offset;
|
2006-05-31 16:56:50 +00:00
|
|
|
/* Copy the timing data */
|
2011-06-30 18:19:31 +00:00
|
|
|
ast_copy_flags(out, fr, AST_FLAGS_ALL);
|
Merged revisions 98943 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed. Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code. The reason this
happens is that the channel might get masqueraded during this time. During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way. (This one is
for you, paravoid!)
It changes an int in ast_frame to be used as flag bits. The 1 bit is still used
to indicate that the frame contains timing information. Also, a second flag has
been added to indicate that the frame came from a translator. When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed. At this point, the flag gets
cleared. Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack. But, it does fix the issue, and I was not able
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-01-15 23:31:53 +00:00
|
|
|
if (ast_test_flag(fr, AST_FRFLAG_HAS_TIMING_INFO)) {
|
2006-05-31 16:56:50 +00:00
|
|
|
out->ts = fr->ts;
|
|
|
|
out->len = fr->len;
|
|
|
|
out->seqno = fr->seqno;
|
|
|
|
}
|
2009-06-16 18:54:30 +00:00
|
|
|
} else {
|
1999-11-21 02:26:43 +00:00
|
|
|
out = fr;
|
2009-06-16 18:54:30 +00:00
|
|
|
}
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2009-06-16 18:54:30 +00:00
|
|
|
if (!(fr->mallocd & AST_MALLOCD_SRC) && fr->src) {
|
|
|
|
if (!(out->src = ast_strdup(fr->src))) {
|
|
|
|
if (out != fr) {
|
|
|
|
ast_free(out);
|
2006-06-08 16:59:44 +00:00
|
|
|
}
|
2009-06-16 18:54:30 +00:00
|
|
|
return NULL;
|
2006-06-08 16:59:44 +00:00
|
|
|
}
|
2009-06-16 18:54:30 +00:00
|
|
|
} else {
|
1999-11-21 02:26:43 +00:00
|
|
|
out->src = fr->src;
|
2009-06-16 18:54:30 +00:00
|
|
|
fr->src = NULL;
|
|
|
|
fr->mallocd &= ~AST_MALLOCD_SRC;
|
|
|
|
}
|
2012-03-22 19:51:16 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
if (!(fr->mallocd & AST_MALLOCD_DATA)) {
|
2010-01-26 18:07:57 +00:00
|
|
|
if (!fr->datalen) {
|
|
|
|
out->data.uint32 = fr->data.uint32;
|
|
|
|
out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC;
|
|
|
|
return out;
|
|
|
|
}
|
2006-05-06 02:31:22 +00:00
|
|
|
if (!(newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET))) {
|
2009-06-16 18:54:30 +00:00
|
|
|
if (out->src != fr->src) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free((void *) out->src);
|
2009-06-16 18:54:30 +00:00
|
|
|
}
|
|
|
|
if (out != fr) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(out);
|
2009-06-16 18:54:30 +00:00
|
|
|
}
|
1999-11-21 02:26:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-05-06 02:31:22 +00:00
|
|
|
newdata += AST_FRIENDLY_OFFSET;
|
2000-01-07 10:54:40 +00:00
|
|
|
out->offset = AST_FRIENDLY_OFFSET;
|
|
|
|
out->datalen = fr->datalen;
|
2008-05-22 16:29:54 +00:00
|
|
|
memcpy(newdata, fr->data.ptr, fr->datalen);
|
|
|
|
out->data.ptr = newdata;
|
2009-06-16 18:54:30 +00:00
|
|
|
} else {
|
|
|
|
out->data = fr->data;
|
|
|
|
memset(&fr->data, 0, sizeof(fr->data));
|
|
|
|
fr->mallocd &= ~AST_MALLOCD_DATA;
|
1999-11-21 02:26:43 +00:00
|
|
|
}
|
2006-05-06 02:31:22 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
1999-11-21 02:26:43 +00:00
|
|
|
return out;
|
|
|
|
}
|
2000-01-07 10:54:40 +00:00
|
|
|
|
2006-07-28 18:59:59 +00:00
|
|
|
struct ast_frame *ast_frdup(const struct ast_frame *f)
|
2000-01-07 10:54:40 +00:00
|
|
|
{
|
2006-09-22 14:04:46 +00:00
|
|
|
struct ast_frame *out = NULL;
|
2004-04-28 17:54:01 +00:00
|
|
|
int len, srclen = 0;
|
2006-08-29 20:50:36 +00:00
|
|
|
void *buf = NULL;
|
|
|
|
|
2007-01-04 18:19:55 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
|
|
|
struct ast_frame_cache *frames;
|
|
|
|
#endif
|
|
|
|
|
2003-03-18 06:00:18 +00:00
|
|
|
/* Start with standard stuff */
|
2006-02-21 19:24:01 +00:00
|
|
|
len = sizeof(*out) + AST_FRIENDLY_OFFSET + f->datalen;
|
2003-03-18 06:00:18 +00:00
|
|
|
/* If we have a source, add space for it */
|
2005-05-15 05:46:34 +00:00
|
|
|
/*
|
|
|
|
* XXX Watch out here - if we receive a src which is not terminated
|
|
|
|
* properly, we can be easily attacked. Should limit the size we deal with.
|
|
|
|
*/
|
2004-04-28 17:54:01 +00:00
|
|
|
if (f->src)
|
|
|
|
srclen = strlen(f->src);
|
|
|
|
if (srclen > 0)
|
|
|
|
len += srclen + 1;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-01-04 18:19:55 +00:00
|
|
|
#if !defined(LOW_MEMORY)
|
2006-08-29 20:50:36 +00:00
|
|
|
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
|
|
|
|
if (out->mallocd_hdr_len >= len) {
|
|
|
|
size_t mallocd_len = out->mallocd_hdr_len;
|
2007-11-08 05:28:47 +00:00
|
|
|
|
|
|
|
AST_LIST_REMOVE_CURRENT(frame_list);
|
2006-08-29 20:50:36 +00:00
|
|
|
memset(out, 0, sizeof(*out));
|
|
|
|
out->mallocd_hdr_len = mallocd_len;
|
|
|
|
buf = out;
|
|
|
|
frames->size--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
2006-08-29 20:50:36 +00:00
|
|
|
}
|
2007-01-04 18:19:55 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-29 20:50:36 +00:00
|
|
|
if (!buf) {
|
2006-12-27 18:33:44 +00:00
|
|
|
if (!(buf = ast_calloc_cache(1, len)))
|
2006-08-29 20:50:36 +00:00
|
|
|
return NULL;
|
|
|
|
out = buf;
|
|
|
|
out->mallocd_hdr_len = len;
|
|
|
|
}
|
|
|
|
|
2003-03-18 06:00:18 +00:00
|
|
|
out->frametype = f->frametype;
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_format_copy(&out->subclass.format, &f->subclass.format);
|
2003-03-18 06:00:18 +00:00
|
|
|
out->datalen = f->datalen;
|
|
|
|
out->samples = f->samples;
|
2004-03-13 03:52:14 +00:00
|
|
|
out->delivery = f->delivery;
|
2012-07-24 16:54:26 +00:00
|
|
|
/* Even though this new frame was allocated from the heap, we can't mark it
|
|
|
|
* with AST_MALLOCD_HDR, AST_MALLOCD_DATA and AST_MALLOCD_SRC, because that
|
|
|
|
* would cause ast_frfree() to attempt to individually free each of those
|
|
|
|
* under the assumption that they were separately allocated. Since this frame
|
|
|
|
* was allocated in a single allocation, we'll only mark it as if the header
|
|
|
|
* was heap-allocated; this will result in the entire frame being properly freed.
|
|
|
|
*/
|
2003-03-18 06:00:18 +00:00
|
|
|
out->mallocd = AST_MALLOCD_HDR;
|
|
|
|
out->offset = AST_FRIENDLY_OFFSET;
|
2006-07-17 23:31:24 +00:00
|
|
|
if (out->datalen) {
|
2008-05-22 16:29:54 +00:00
|
|
|
out->data.ptr = buf + sizeof(*out) + AST_FRIENDLY_OFFSET;
|
2012-03-22 19:51:16 +00:00
|
|
|
memcpy(out->data.ptr, f->data.ptr, out->datalen);
|
2008-12-15 21:53:30 +00:00
|
|
|
} else {
|
|
|
|
out->data.uint32 = f->data.uint32;
|
2006-07-17 23:31:24 +00:00
|
|
|
}
|
2004-04-28 17:54:01 +00:00
|
|
|
if (srclen > 0) {
|
2008-12-02 00:37:21 +00:00
|
|
|
/* This may seem a little strange, but it's to avoid a gcc (4.2.4) compiler warning */
|
|
|
|
char *src;
|
2006-07-18 00:43:57 +00:00
|
|
|
out->src = buf + sizeof(*out) + AST_FRIENDLY_OFFSET + f->datalen;
|
2008-12-02 00:37:21 +00:00
|
|
|
src = (char *) out->src;
|
2003-03-18 06:00:18 +00:00
|
|
|
/* Must have space since we allocated for it */
|
2008-12-02 00:37:21 +00:00
|
|
|
strcpy(src, f->src);
|
2006-07-17 23:31:24 +00:00
|
|
|
}
|
2011-06-30 18:19:31 +00:00
|
|
|
ast_copy_flags(out, f, AST_FLAGS_ALL);
|
Merged revisions 51311 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged. So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio. However,
since there was no audio coming in, the DTMF_END was never generated. This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf). If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback. This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-01-19 18:06:03 +00:00
|
|
|
out->ts = f->ts;
|
|
|
|
out->len = f->len;
|
|
|
|
out->seqno = f->seqno;
|
2003-03-18 06:00:18 +00:00
|
|
|
return out;
|
2000-01-07 10:54:40 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 02:13:40 +00:00
|
|
|
void ast_swapcopy_samples(void *dst, const void *src, int samples)
|
2005-04-03 22:57:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned short *dst_s = dst;
|
2005-04-04 02:13:40 +00:00
|
|
|
const unsigned short *src_s = src;
|
2005-04-03 22:57:18 +00:00
|
|
|
|
2006-06-01 19:48:31 +00:00
|
|
|
for (i = 0; i < samples; i++)
|
2005-04-03 22:57:18 +00:00
|
|
|
dst_s[i] = (src_s[i]<<8) | (src_s[i]>>8);
|
|
|
|
}
|
|
|
|
|
2012-06-15 16:17:12 +00:00
|
|
|
void ast_frame_subclass2str(struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen)
|
2003-03-12 06:00:18 +00:00
|
|
|
{
|
|
|
|
switch(f->frametype) {
|
2006-08-31 18:21:00 +00:00
|
|
|
case AST_FRAME_DTMF_BEGIN:
|
2012-06-15 16:17:12 +00:00
|
|
|
if (slen > 1) {
|
|
|
|
subclass[0] = f->subclass.integer;
|
|
|
|
subclass[1] = '\0';
|
|
|
|
}
|
2006-08-31 18:21:00 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_DTMF_END:
|
2012-06-15 16:17:12 +00:00
|
|
|
if (slen > 1) {
|
|
|
|
subclass[0] = f->subclass.integer;
|
|
|
|
subclass[1] = '\0';
|
|
|
|
}
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_CONTROL:
|
2009-11-04 14:05:12 +00:00
|
|
|
switch (f->subclass.integer) {
|
2003-03-12 06:00:18 +00:00
|
|
|
case AST_CONTROL_HANGUP:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Hangup", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_RING:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Ring", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_RINGING:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Ringing", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_ANSWER:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Answer", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_BUSY:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Busy", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_TAKEOFFHOOK:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Take Off Hook", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_OFFHOOK:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Line Off Hook", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_CONGESTION:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Congestion", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_FLASH:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Flash", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_WINK:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Wink", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_OPTION:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Option", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_RADIO_KEY:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Key Radio", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_RADIO_UNKEY:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Unkey Radio", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
2008-02-18 22:54:25 +00:00
|
|
|
case AST_CONTROL_HOLD:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Hold", slen);
|
2008-02-18 22:54:25 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_UNHOLD:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Unhold", slen);
|
2008-02-18 22:54:25 +00:00
|
|
|
break;
|
2012-06-15 16:17:12 +00:00
|
|
|
case AST_CONTROL_T38_PARAMETERS: {
|
|
|
|
char *message = "Unknown";
|
2009-09-01 19:50:48 +00:00
|
|
|
if (f->datalen != sizeof(struct ast_control_t38_parameters)) {
|
2009-06-26 19:27:24 +00:00
|
|
|
message = "Invalid";
|
|
|
|
} else {
|
|
|
|
struct ast_control_t38_parameters *parameters = f->data.ptr;
|
|
|
|
enum ast_control_t38 state = parameters->request_response;
|
|
|
|
if (state == AST_T38_REQUEST_NEGOTIATE)
|
|
|
|
message = "Negotiation Requested";
|
|
|
|
else if (state == AST_T38_REQUEST_TERMINATE)
|
|
|
|
message = "Negotiation Request Terminated";
|
|
|
|
else if (state == AST_T38_NEGOTIATED)
|
|
|
|
message = "Negotiated";
|
|
|
|
else if (state == AST_T38_TERMINATED)
|
|
|
|
message = "Terminated";
|
|
|
|
else if (state == AST_T38_REFUSED)
|
|
|
|
message = "Refused";
|
|
|
|
}
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "T38_Parameters/%s", message);
|
2009-06-26 19:27:24 +00:00
|
|
|
break;
|
2012-06-15 16:17:12 +00:00
|
|
|
}
|
2004-11-06 21:33:01 +00:00
|
|
|
case -1:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Stop generators", slen);
|
2004-11-06 21:33:01 +00:00
|
|
|
break;
|
2003-03-12 06:00:18 +00:00
|
|
|
default:
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "Unknown control '%d'", f->subclass.integer);
|
2003-03-12 06:00:18 +00:00
|
|
|
}
|
2004-11-06 21:33:01 +00:00
|
|
|
break;
|
2003-03-12 06:00:18 +00:00
|
|
|
case AST_FRAME_NULL:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "N/A", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_IAX:
|
|
|
|
/* Should never happen */
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "IAX Frametype %d", f->subclass.integer);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_TEXT:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "N/A", slen);
|
|
|
|
if (moreinfo) {
|
|
|
|
ast_copy_string(moreinfo, f->data.ptr, mlen);
|
|
|
|
}
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_IMAGE:
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "Image format %s\n", ast_getformatname(&f->subclass.format));
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_FRAME_HTML:
|
2009-11-04 14:05:12 +00:00
|
|
|
switch (f->subclass.integer) {
|
2003-03-12 06:00:18 +00:00
|
|
|
case AST_HTML_URL:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "URL", slen);
|
|
|
|
if (moreinfo) {
|
|
|
|
ast_copy_string(moreinfo, f->data.ptr, mlen);
|
|
|
|
}
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_DATA:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Data", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_BEGIN:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Begin", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_END:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "End", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_LDCOMPLETE:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Load Complete", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_NOSUPPORT:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "No Support", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_LINKURL:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Link URL", slen);
|
|
|
|
if (moreinfo) {
|
|
|
|
ast_copy_string(moreinfo, f->data.ptr, mlen);
|
|
|
|
}
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_UNLINK:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Unlink", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
case AST_HTML_LINKREJECT:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Link Reject", slen);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "Unknown HTML frame '%d'\n", f->subclass.integer);
|
2003-03-12 06:00:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-13 19:38:41 +00:00
|
|
|
case AST_FRAME_MODEM:
|
2009-11-04 14:05:12 +00:00
|
|
|
switch (f->subclass.integer) {
|
2006-06-13 19:38:41 +00:00
|
|
|
case AST_MODEM_T38:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "T.38", slen);
|
2006-06-13 19:38:41 +00:00
|
|
|
break;
|
|
|
|
case AST_MODEM_V150:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "V.150", slen);
|
2006-06-13 19:38:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-06-15 16:17:12 +00:00
|
|
|
snprintf(subclass, slen, "Unknown MODEM frame '%d'\n", f->subclass.integer);
|
2006-06-13 19:38:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2003-03-12 06:00:18 +00:00
|
|
|
default:
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_copy_string(subclass, "Unknown Subclass", slen);
|
2013-01-31 18:15:49 +00:00
|
|
|
break;
|
2003-03-12 06:00:18 +00:00
|
|
|
}
|
2012-06-15 16:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ast_frame_type2str(enum ast_frame_type frame_type, char *ftype, size_t len)
|
|
|
|
{
|
|
|
|
switch (frame_type) {
|
|
|
|
case AST_FRAME_DTMF_BEGIN:
|
|
|
|
ast_copy_string(ftype, "DTMF Begin", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_DTMF_END:
|
|
|
|
ast_copy_string(ftype, "DTMF End", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_CONTROL:
|
|
|
|
ast_copy_string(ftype, "Control", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_NULL:
|
|
|
|
ast_copy_string(ftype, "Null Frame", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_IAX:
|
|
|
|
/* Should never happen */
|
|
|
|
ast_copy_string(ftype, "IAX Specific", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_TEXT:
|
|
|
|
ast_copy_string(ftype, "Text", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_IMAGE:
|
|
|
|
ast_copy_string(ftype, "Image", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_HTML:
|
|
|
|
ast_copy_string(ftype, "HTML", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_MODEM:
|
|
|
|
ast_copy_string(ftype, "Modem", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_VOICE:
|
|
|
|
ast_copy_string(ftype, "Voice", len);
|
|
|
|
break;
|
|
|
|
case AST_FRAME_VIDEO:
|
|
|
|
ast_copy_string(ftype, "Video", len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(ftype, len, "Unknown Frametype '%d'", frame_type);
|
2013-01-31 18:15:49 +00:00
|
|
|
break;
|
2012-06-15 16:17:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Dump a frame for debugging purposes */
|
|
|
|
void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
|
|
|
|
{
|
|
|
|
const char noname[] = "unknown";
|
|
|
|
char ftype[40] = "Unknown Frametype";
|
|
|
|
char cft[80];
|
|
|
|
char subclass[40] = "Unknown Subclass";
|
|
|
|
char csub[80];
|
|
|
|
char moreinfo[40] = "";
|
|
|
|
char cn[60];
|
|
|
|
char cp[40];
|
|
|
|
char cmn[40];
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = noname;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f) {
|
|
|
|
ast_verb(-1, "%s [ %s (NULL) ] [%s]\n",
|
|
|
|
term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
|
|
|
|
term_color(cft, "HANGUP", COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
|
|
|
|
term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* XXX We should probably print one each of voice and video when the format changes XXX */
|
|
|
|
if (f->frametype == AST_FRAME_VOICE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VIDEO) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_frame_type2str(f->frametype, ftype, sizeof(ftype));
|
|
|
|
ast_frame_subclass2str(f, subclass, sizeof(subclass), moreinfo, sizeof(moreinfo));
|
|
|
|
|
2004-05-09 07:51:44 +00:00
|
|
|
if (!ast_strlen_zero(moreinfo))
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_verb(-1, "%s [ TYPE: %s (%d) SUBCLASS: %s (%d) '%s' ] [%s]\n",
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
|
|
|
|
term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
|
2012-03-22 19:51:16 +00:00
|
|
|
f->frametype,
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
|
2012-03-22 19:51:16 +00:00
|
|
|
f->subclass.integer,
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(cmn, moreinfo, COLOR_BRGREEN, COLOR_BLACK, sizeof(cmn)),
|
|
|
|
term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
|
2003-03-12 06:00:18 +00:00
|
|
|
else
|
2012-06-15 16:17:12 +00:00
|
|
|
ast_verb(-1, "%s [ TYPE: %s (%d) SUBCLASS: %s (%d) ] [%s]\n",
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(cp, prefix, COLOR_BRMAGENTA, COLOR_BLACK, sizeof(cp)),
|
|
|
|
term_color(cft, ftype, COLOR_BRRED, COLOR_BLACK, sizeof(cft)),
|
2012-03-22 19:51:16 +00:00
|
|
|
f->frametype,
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(csub, subclass, COLOR_BRCYAN, COLOR_BLACK, sizeof(csub)),
|
2012-03-22 19:51:16 +00:00
|
|
|
f->subclass.integer,
|
2006-02-01 23:05:28 +00:00
|
|
|
term_color(cn, name, COLOR_YELLOW, COLOR_BLACK, sizeof(cn)));
|
2003-03-12 06:00:18 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
int ast_parse_allow_disallow(struct ast_codec_pref *pref, struct ast_format_cap *cap, const char *list, int allowing)
|
2008-01-17 22:50:13 +00:00
|
|
|
{
|
2011-09-07 00:54:36 +00:00
|
|
|
int errors = 0, framems = 0, all = 0, iter_allowing;
|
2006-09-19 15:36:25 +00:00
|
|
|
char *parse = NULL, *this = NULL, *psize = NULL;
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format format;
|
2005-09-29 17:40:24 +00:00
|
|
|
|
|
|
|
parse = ast_strdupa(list);
|
|
|
|
while ((this = strsep(&parse, ","))) {
|
2011-09-07 00:54:36 +00:00
|
|
|
iter_allowing = allowing;
|
2006-09-18 23:32:57 +00:00
|
|
|
framems = 0;
|
2011-09-07 00:54:36 +00:00
|
|
|
if (*this == '!') {
|
|
|
|
this++;
|
|
|
|
iter_allowing = !allowing;
|
|
|
|
}
|
2006-09-18 23:32:57 +00:00
|
|
|
if ((psize = strrchr(this, ':'))) {
|
2006-09-19 15:36:25 +00:00
|
|
|
*psize++ = '\0';
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "Packetization for codec: %s is %s\n", this, psize);
|
2006-09-19 15:36:25 +00:00
|
|
|
framems = atoi(psize);
|
2007-01-01 19:48:31 +00:00
|
|
|
if (framems < 0) {
|
2006-09-18 23:32:57 +00:00
|
|
|
framems = 0;
|
2007-01-01 19:48:31 +00:00
|
|
|
errors++;
|
|
|
|
ast_log(LOG_WARNING, "Bad packetization value for codec %s\n", this);
|
|
|
|
}
|
2006-09-18 23:32:57 +00:00
|
|
|
}
|
2011-02-03 16:22:10 +00:00
|
|
|
all = strcasecmp(this, "all") ? 0 : 1;
|
|
|
|
|
|
|
|
if (!all && !ast_getformatbyname(this, &format)) {
|
2011-09-07 00:54:36 +00:00
|
|
|
ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", iter_allowing ? "allow" : "disallow", this);
|
2007-01-01 19:48:31 +00:00
|
|
|
errors++;
|
2005-09-29 17:40:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if (cap) {
|
2011-09-07 00:54:36 +00:00
|
|
|
if (iter_allowing) {
|
2011-02-03 16:22:10 +00:00
|
|
|
if (all) {
|
|
|
|
ast_format_cap_add_all(cap);
|
|
|
|
} else {
|
|
|
|
ast_format_cap_add(cap, &format);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (all) {
|
|
|
|
ast_format_cap_remove_all(cap);
|
|
|
|
} else {
|
|
|
|
ast_format_cap_remove(cap, &format);
|
|
|
|
}
|
|
|
|
}
|
2004-12-02 21:57:45 +00:00
|
|
|
}
|
2005-09-29 17:40:24 +00:00
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if (pref) {
|
|
|
|
if (!all) {
|
2011-09-07 00:54:36 +00:00
|
|
|
if (iter_allowing) {
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_codec_pref_append(pref, &format);
|
|
|
|
ast_codec_pref_setsize(pref, &format, framems);
|
|
|
|
} else {
|
|
|
|
ast_codec_pref_remove(pref, &format);
|
2006-09-18 23:32:57 +00:00
|
|
|
}
|
2011-09-07 00:54:36 +00:00
|
|
|
} else if (!iter_allowing) {
|
2005-09-29 17:40:24 +00:00
|
|
|
memset(pref, 0, sizeof(*pref));
|
2004-12-02 21:57:45 +00:00
|
|
|
}
|
2005-09-29 17:40:24 +00:00
|
|
|
}
|
2004-12-02 21:57:45 +00:00
|
|
|
}
|
2007-01-01 19:48:31 +00:00
|
|
|
return errors;
|
2004-12-02 21:57:45 +00:00
|
|
|
}
|
|
|
|
|
2005-05-14 23:57:44 +00:00
|
|
|
static int g723_len(unsigned char buf)
|
|
|
|
{
|
2006-02-21 19:24:01 +00:00
|
|
|
enum frame_type type = buf & TYPE_MASK;
|
|
|
|
|
|
|
|
switch(type) {
|
2005-05-14 23:57:44 +00:00
|
|
|
case TYPE_DONTSEND:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case TYPE_SILENCE:
|
|
|
|
return 4;
|
|
|
|
break;
|
|
|
|
case TYPE_HIGH:
|
|
|
|
return 24;
|
|
|
|
break;
|
|
|
|
case TYPE_LOW:
|
|
|
|
return 20;
|
|
|
|
break;
|
|
|
|
default:
|
2006-02-21 19:24:01 +00:00
|
|
|
ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", type);
|
2005-05-14 23:57:44 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int g723_samples(unsigned char *buf, int maxlen)
|
|
|
|
{
|
|
|
|
int pos = 0;
|
|
|
|
int samples = 0;
|
|
|
|
int res;
|
|
|
|
while(pos < maxlen) {
|
|
|
|
res = g723_len(buf[pos]);
|
|
|
|
if (res <= 0)
|
|
|
|
break;
|
|
|
|
samples += 240;
|
|
|
|
pos += res;
|
|
|
|
}
|
|
|
|
return samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char get_n_bits_at(unsigned char *data, int n, int bit)
|
|
|
|
{
|
|
|
|
int byte = bit / 8; /* byte containing first bit */
|
|
|
|
int rem = 8 - (bit % 8); /* remaining bits in first byte */
|
|
|
|
unsigned char ret = 0;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2005-05-14 23:57:44 +00:00
|
|
|
if (n <= 0 || n > 8)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (rem < n) {
|
|
|
|
ret = (data[byte] << (n - rem));
|
|
|
|
ret |= (data[byte + 1] >> (8 - n + rem));
|
|
|
|
} else {
|
|
|
|
ret = (data[byte] >> (rem - n));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret & (0xff >> (8 - n)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int speex_get_wb_sz_at(unsigned char *data, int len, int bit)
|
|
|
|
{
|
2009-05-21 21:13:09 +00:00
|
|
|
static const int SpeexWBSubModeSz[] = {
|
2010-06-17 17:23:43 +00:00
|
|
|
4, 36, 112, 192,
|
2005-05-14 23:57:44 +00:00
|
|
|
352, 0, 0, 0 };
|
|
|
|
int off = bit;
|
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
/* skip up to two wideband frames */
|
2012-03-22 19:51:16 +00:00
|
|
|
if (((len * 8 - off) >= 5) &&
|
2005-05-14 23:57:44 +00:00
|
|
|
get_n_bits_at(data, 1, off)) {
|
|
|
|
c = get_n_bits_at(data, 3, off + 1);
|
|
|
|
off += SpeexWBSubModeSz[c];
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
if (((len * 8 - off) >= 5) &&
|
2005-05-14 23:57:44 +00:00
|
|
|
get_n_bits_at(data, 1, off)) {
|
|
|
|
c = get_n_bits_at(data, 3, off + 1);
|
|
|
|
off += SpeexWBSubModeSz[c];
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
if (((len * 8 - off) >= 5) &&
|
2005-05-14 23:57:44 +00:00
|
|
|
get_n_bits_at(data, 1, off)) {
|
|
|
|
ast_log(LOG_WARNING, "Encountered corrupt speex frame; too many wideband frames in a row.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return off - bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int speex_samples(unsigned char *data, int len)
|
|
|
|
{
|
2009-05-21 21:13:09 +00:00
|
|
|
static const int SpeexSubModeSz[] = {
|
2008-03-04 23:04:29 +00:00
|
|
|
5, 43, 119, 160,
|
2012-03-22 19:51:16 +00:00
|
|
|
220, 300, 364, 492,
|
2005-05-14 23:57:44 +00:00
|
|
|
79, 0, 0, 0,
|
|
|
|
0, 0, 0, 0 };
|
2012-03-22 19:51:16 +00:00
|
|
|
static const int SpeexInBandSz[] = {
|
2005-05-14 23:57:44 +00:00
|
|
|
1, 1, 4, 4,
|
|
|
|
4, 4, 4, 4,
|
|
|
|
8, 8, 16, 16,
|
|
|
|
32, 32, 64, 64 };
|
|
|
|
int bit = 0;
|
|
|
|
int cnt = 0;
|
2006-02-21 19:24:01 +00:00
|
|
|
int off;
|
2005-05-14 23:57:44 +00:00
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
while ((len * 8 - bit) >= 5) {
|
|
|
|
/* skip wideband frames */
|
|
|
|
off = speex_get_wb_sz_at(data, len, bit);
|
|
|
|
if (off < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Had error while reading wideband frames for speex samples\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bit += off;
|
|
|
|
|
2010-06-17 17:23:43 +00:00
|
|
|
if ((len * 8 - bit) < 5)
|
2010-06-11 18:31:14 +00:00
|
|
|
break;
|
2005-05-14 23:57:44 +00:00
|
|
|
|
|
|
|
/* get control bits */
|
|
|
|
c = get_n_bits_at(data, 5, bit);
|
|
|
|
bit += 5;
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
if (c == 15) {
|
2005-05-14 23:57:44 +00:00
|
|
|
/* terminator */
|
2012-03-22 19:51:16 +00:00
|
|
|
break;
|
2005-05-14 23:57:44 +00:00
|
|
|
} else if (c == 14) {
|
|
|
|
/* in-band signal; next 4 bits contain signal id */
|
|
|
|
c = get_n_bits_at(data, 4, bit);
|
|
|
|
bit += 4;
|
|
|
|
bit += SpeexInBandSz[c];
|
|
|
|
} else if (c == 13) {
|
2010-06-17 17:23:43 +00:00
|
|
|
/* user in-band; next 4 bits contain msg len */
|
|
|
|
c = get_n_bits_at(data, 4, bit);
|
|
|
|
bit += 4;
|
|
|
|
/* after which it's 5-bit signal id + c bytes of data */
|
|
|
|
bit += 5 + c * 8;
|
2005-05-14 23:57:44 +00:00
|
|
|
} else if (c > 8) {
|
|
|
|
/* unknown */
|
2010-06-17 17:23:43 +00:00
|
|
|
ast_log(LOG_WARNING, "Unknown speex control frame %d\n", c);
|
2005-05-14 23:57:44 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* skip number bits for submode (less the 5 control bits) */
|
|
|
|
bit += SpeexSubModeSz[c] - 5;
|
|
|
|
cnt += 160; /* new frame */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_codec_get_samples(struct ast_frame *f)
|
|
|
|
{
|
Add basic (passthrough, playback, record) support for ITU G.722.1 and G.722.1C (also known as Siren7 and Siren14)
This patch adds passthrough, file recording and file playback support for the codecs listed above, with negotiation over SIP/SDP supported. Due to Asterisk's current limitation of treating a codec/bitrate combination as a unique codec, only G.722.1 at 32 kbps and G.722.1C at 48 kbps are supported.
Along the way, some related work was done:
1) The rtpPayloadType structure definition, used as a return result for an API call in rtp.h, was moved from rtp.c to rtp.h so that the API call was actually usable. The only previous used of the API all was chan_h323.c, which had a duplicate of the structure definition instead of doing it the right way.
2) The hardcoded SDP sample rates for various codecs in chan_sip.c were removed, in favor of storing these sample rates in rtp.c along with the codec definitions there. A new API call was added to allow retrieval of the sample rate for a given codec.
3) Some basic 'a=fmtp' parsing for SDP was added to chan_sip, because chan_sip *must* decline any media streams offered for these codecs that are not at the bitrates that we support (otherwise Bad Things (TM) would result).
Review: http://reviewboard.digium.com/r/158/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175508 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-13 13:35:24 +00:00
|
|
|
int samples = 0;
|
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
switch (f->subclass.format.id) {
|
2005-05-14 23:57:44 +00:00
|
|
|
case AST_FORMAT_SPEEX:
|
2008-05-22 16:29:54 +00:00
|
|
|
samples = speex_samples(f->data.ptr, f->datalen);
|
2005-05-14 23:57:44 +00:00
|
|
|
break;
|
2010-06-17 17:23:43 +00:00
|
|
|
case AST_FORMAT_SPEEX16:
|
|
|
|
samples = 2 * speex_samples(f->data.ptr, f->datalen);
|
|
|
|
break;
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
case AST_FORMAT_SPEEX32:
|
|
|
|
samples = 4 * speex_samples(f->data.ptr, f->datalen);
|
|
|
|
break;
|
2005-05-14 23:57:44 +00:00
|
|
|
case AST_FORMAT_G723_1:
|
2008-05-22 16:29:54 +00:00
|
|
|
samples = g723_samples(f->data.ptr, f->datalen);
|
2005-05-14 23:57:44 +00:00
|
|
|
break;
|
|
|
|
case AST_FORMAT_ILBC:
|
|
|
|
samples = 240 * (f->datalen / 50);
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_GSM:
|
|
|
|
samples = 160 * (f->datalen / 33);
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_G729A:
|
|
|
|
samples = f->datalen * 8;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_SLINEAR:
|
2007-11-06 22:51:48 +00:00
|
|
|
case AST_FORMAT_SLINEAR16:
|
2005-05-14 23:57:44 +00:00
|
|
|
samples = f->datalen / 2;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_LPC10:
|
2007-11-06 22:51:48 +00:00
|
|
|
/* assumes that the RTP packet contains one LPC10 frame */
|
2005-05-14 23:57:44 +00:00
|
|
|
samples = 22 * 8;
|
2008-05-22 16:29:54 +00:00
|
|
|
samples += (((char *)(f->data.ptr))[7] & 0x1) * 8;
|
2005-05-14 23:57:44 +00:00
|
|
|
break;
|
|
|
|
case AST_FORMAT_ULAW:
|
|
|
|
case AST_FORMAT_ALAW:
|
2009-11-04 14:05:12 +00:00
|
|
|
case AST_FORMAT_TESTLAW:
|
2005-05-14 23:57:44 +00:00
|
|
|
samples = f->datalen;
|
|
|
|
break;
|
2008-01-11 03:37:19 +00:00
|
|
|
case AST_FORMAT_G722:
|
2005-05-14 23:57:44 +00:00
|
|
|
case AST_FORMAT_ADPCM:
|
|
|
|
case AST_FORMAT_G726:
|
2006-07-12 22:42:13 +00:00
|
|
|
case AST_FORMAT_G726_AAL2:
|
2005-05-14 23:57:44 +00:00
|
|
|
samples = f->datalen * 2;
|
|
|
|
break;
|
Add basic (passthrough, playback, record) support for ITU G.722.1 and G.722.1C (also known as Siren7 and Siren14)
This patch adds passthrough, file recording and file playback support for the codecs listed above, with negotiation over SIP/SDP supported. Due to Asterisk's current limitation of treating a codec/bitrate combination as a unique codec, only G.722.1 at 32 kbps and G.722.1C at 48 kbps are supported.
Along the way, some related work was done:
1) The rtpPayloadType structure definition, used as a return result for an API call in rtp.h, was moved from rtp.c to rtp.h so that the API call was actually usable. The only previous used of the API all was chan_h323.c, which had a duplicate of the structure definition instead of doing it the right way.
2) The hardcoded SDP sample rates for various codecs in chan_sip.c were removed, in favor of storing these sample rates in rtp.c along with the codec definitions there. A new API call was added to allow retrieval of the sample rate for a given codec.
3) Some basic 'a=fmtp' parsing for SDP was added to chan_sip, because chan_sip *must* decline any media streams offered for these codecs that are not at the bitrates that we support (otherwise Bad Things (TM) would result).
Review: http://reviewboard.digium.com/r/158/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175508 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-13 13:35:24 +00:00
|
|
|
case AST_FORMAT_SIREN7:
|
|
|
|
/* 16,000 samples per second at 32kbps is 4,000 bytes per second */
|
|
|
|
samples = f->datalen * (16000 / 4000);
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_SIREN14:
|
|
|
|
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */
|
|
|
|
samples = (int) f->datalen * ((float) 32000 / 6000);
|
|
|
|
break;
|
2010-06-16 19:03:24 +00:00
|
|
|
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;
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
case AST_FORMAT_SILK:
|
|
|
|
if (!(ast_format_isset(&f->subclass.format,
|
|
|
|
SILK_ATTR_KEY_SAMP_RATE,
|
|
|
|
SILK_ATTR_VAL_SAMP_24KHZ,
|
|
|
|
AST_FORMAT_ATTR_END))) {
|
|
|
|
return 480;
|
|
|
|
} else if (!(ast_format_isset(&f->subclass.format,
|
|
|
|
SILK_ATTR_KEY_SAMP_RATE,
|
|
|
|
SILK_ATTR_VAL_SAMP_16KHZ,
|
|
|
|
AST_FORMAT_ATTR_END))) {
|
|
|
|
return 320;
|
|
|
|
} else if (!(ast_format_isset(&f->subclass.format,
|
|
|
|
SILK_ATTR_KEY_SAMP_RATE,
|
|
|
|
SILK_ATTR_VAL_SAMP_12KHZ,
|
|
|
|
AST_FORMAT_ATTR_END))) {
|
|
|
|
return 240;
|
|
|
|
} else {
|
|
|
|
return 160;
|
|
|
|
}
|
2011-07-07 19:39:17 +00:00
|
|
|
case AST_FORMAT_CELT:
|
|
|
|
/* TODO The assumes 20ms delivery right now, which is incorrect */
|
|
|
|
samples = ast_format_rate(&f->subclass.format) / 50;
|
|
|
|
break;
|
2005-05-14 23:57:44 +00:00
|
|
|
default:
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(&f->subclass.format));
|
2005-05-14 23:57:44 +00:00
|
|
|
}
|
|
|
|
return samples;
|
|
|
|
}
|
2004-12-02 21:57:45 +00:00
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
int ast_codec_get_len(struct ast_format *format, int samples)
|
2005-08-22 19:29:29 +00:00
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/* XXX Still need speex, and lpc10 XXX */
|
2011-02-03 16:22:10 +00:00
|
|
|
switch(format->id) {
|
2006-11-13 22:01:43 +00:00
|
|
|
case AST_FORMAT_G723_1:
|
|
|
|
len = (samples / 240) * 20;
|
|
|
|
break;
|
2005-08-22 19:29:29 +00:00
|
|
|
case AST_FORMAT_ILBC:
|
|
|
|
len = (samples / 240) * 50;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_GSM:
|
|
|
|
len = (samples / 160) * 33;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_G729A:
|
|
|
|
len = samples / 8;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_SLINEAR:
|
2007-11-06 22:51:48 +00:00
|
|
|
case AST_FORMAT_SLINEAR16:
|
2005-08-22 19:29:29 +00:00
|
|
|
len = samples * 2;
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_ULAW:
|
|
|
|
case AST_FORMAT_ALAW:
|
2009-11-04 14:05:12 +00:00
|
|
|
case AST_FORMAT_TESTLAW:
|
2005-08-22 19:29:29 +00:00
|
|
|
len = samples;
|
|
|
|
break;
|
2008-01-11 03:37:19 +00:00
|
|
|
case AST_FORMAT_G722:
|
2005-08-22 19:29:29 +00:00
|
|
|
case AST_FORMAT_ADPCM:
|
|
|
|
case AST_FORMAT_G726:
|
2006-07-12 22:42:13 +00:00
|
|
|
case AST_FORMAT_G726_AAL2:
|
2005-08-22 19:29:29 +00:00
|
|
|
len = samples / 2;
|
|
|
|
break;
|
Add basic (passthrough, playback, record) support for ITU G.722.1 and G.722.1C (also known as Siren7 and Siren14)
This patch adds passthrough, file recording and file playback support for the codecs listed above, with negotiation over SIP/SDP supported. Due to Asterisk's current limitation of treating a codec/bitrate combination as a unique codec, only G.722.1 at 32 kbps and G.722.1C at 48 kbps are supported.
Along the way, some related work was done:
1) The rtpPayloadType structure definition, used as a return result for an API call in rtp.h, was moved from rtp.c to rtp.h so that the API call was actually usable. The only previous used of the API all was chan_h323.c, which had a duplicate of the structure definition instead of doing it the right way.
2) The hardcoded SDP sample rates for various codecs in chan_sip.c were removed, in favor of storing these sample rates in rtp.c along with the codec definitions there. A new API call was added to allow retrieval of the sample rate for a given codec.
3) Some basic 'a=fmtp' parsing for SDP was added to chan_sip, because chan_sip *must* decline any media streams offered for these codecs that are not at the bitrates that we support (otherwise Bad Things (TM) would result).
Review: http://reviewboard.digium.com/r/158/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175508 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-13 13:35:24 +00:00
|
|
|
case AST_FORMAT_SIREN7:
|
|
|
|
/* 16,000 samples per second at 32kbps is 4,000 bytes per second */
|
|
|
|
len = samples / (16000 / 4000);
|
|
|
|
break;
|
|
|
|
case AST_FORMAT_SIREN14:
|
|
|
|
/* 32,000 samples per second at 48kbps is 6,000 bytes per second */
|
|
|
|
len = (int) samples / ((float) 32000 / 6000);
|
|
|
|
break;
|
2010-06-16 19:03:24 +00:00
|
|
|
case AST_FORMAT_G719:
|
|
|
|
/* 48,000 samples per second at 64kbps is 8,000 bytes per second */
|
|
|
|
len = (int) samples / ((float) 48000 / 8000);
|
|
|
|
break;
|
2005-08-22 19:29:29 +00:00
|
|
|
default:
|
|
|
|
ast_log(LOG_WARNING, "Unable to calculate sample length for format %s\n", ast_getformatname(format));
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2005-10-28 16:20:44 +00:00
|
|
|
|
|
|
|
int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
|
|
|
|
{
|
|
|
|
int count;
|
2008-05-22 16:29:54 +00:00
|
|
|
short *fdata = f->data.ptr;
|
2005-10-31 18:15:02 +00:00
|
|
|
short adjust_value = abs(adjustment);
|
2005-10-28 16:20:44 +00:00
|
|
|
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
if ((f->frametype != AST_FRAME_VOICE) || !(ast_format_is_slinear(&f->subclass.format))) {
|
2005-10-28 16:20:44 +00:00
|
|
|
return -1;
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
}
|
2005-10-28 16:20:44 +00:00
|
|
|
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
if (!adjustment) {
|
2005-10-31 18:15:02 +00:00
|
|
|
return 0;
|
Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio ConfBridge, and other stuff
-Functional changes
1. Dynamic global format list build by codecs defined in codecs.conf
2. SILK 8khz, 12khz, 16khz, and 24khz with custom attributes defined in codecs.conf
3. Negotiation of SILK attributes in chan_sip.
4. SPEEX 32khz with translation
5. SLINEAR 8khz, 12khz, 24khz, 32khz, 44.1khz, 48khz, 96khz, 192khz with translation
using codec_resample.c
6. Various changes to RTP code required to properly handle the dynamic format list
and formats with attributes.
7. ConfBridge now dynamically jumps to the best possible sample rate. This allows
for conferences to take advantage of HD audio (Which sounds awesome)
8. Audiohooks are no longer limited to 8khz audio, and most effects have been
updated to take advantage of this such as Volume, DENOISE, PITCH_SHIFT.
9. codec_resample now uses its own code rather than depending on libresample.
-Organizational changes
Global format list is moved from frame.c to format.c
Various format specific functions moved from frame.c to format.c
Review: https://reviewboard.asterisk.org/r/1104/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@308582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-22 23:04:49 +00:00
|
|
|
}
|
2005-10-31 18:15:02 +00:00
|
|
|
|
2005-10-28 16:20:44 +00:00
|
|
|
for (count = 0; count < f->samples; count++) {
|
|
|
|
if (adjustment > 0) {
|
2005-10-31 18:15:02 +00:00
|
|
|
ast_slinear_saturated_multiply(&fdata[count], &adjust_value);
|
2005-10-28 16:20:44 +00:00
|
|
|
} else if (adjustment < 0) {
|
2005-10-31 18:15:02 +00:00
|
|
|
ast_slinear_saturated_divide(&fdata[count], &adjust_value);
|
2005-10-28 16:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-28 21:49:27 +00:00
|
|
|
|
|
|
|
int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
short *data1, *data2;
|
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass.format.id != AST_FORMAT_SLINEAR))
|
2005-10-28 21:49:27 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-02-03 16:22:10 +00:00
|
|
|
if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass.format.id != AST_FORMAT_SLINEAR))
|
2005-10-28 21:49:27 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (f1->samples != f2->samples)
|
|
|
|
return -1;
|
|
|
|
|
2008-05-22 16:29:54 +00:00
|
|
|
for (count = 0, data1 = f1->data.ptr, data2 = f2->data.ptr;
|
2005-10-28 21:49:27 +00:00
|
|
|
count < f1->samples;
|
|
|
|
count++, data1++, data2++)
|
2005-10-31 18:15:02 +00:00
|
|
|
ast_slinear_saturated_add(data1, data2);
|
2005-10-28 21:49:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-04-21 11:27:27 +00:00
|
|
|
|
|
|
|
int ast_frame_clear(struct ast_frame *frame)
|
|
|
|
{
|
|
|
|
struct ast_frame *next;
|
|
|
|
|
|
|
|
for (next = AST_LIST_NEXT(frame, frame_list);
|
|
|
|
frame;
|
|
|
|
frame = next, next = frame ? AST_LIST_NEXT(frame, frame_list) : NULL) {
|
|
|
|
memset(frame->data.ptr, 0, frame->datalen);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|