[asterisk-commits] russell: branch
russell/ast_verbose_threadstorage r38440 - in /team/russell/a...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Jul 28 12:29:12 MST 2006
Author: russell
Date: Fri Jul 28 14:29:12 2006
New Revision: 38440
URL: http://svn.digium.com/view/asterisk?rev=38440&view=rev
Log:
Merged revisions 38418,38421-38422,38439 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r38418 | kpfleming | 2006-07-28 14:03:57 -0400 (Fri, 28 Jul 2006) | 4 lines
more slinfactory structure definition to inside implementation module
make read/write/hold work on samples, not bytes
add an API call to find out how many samples are available in a slinfactory
................
r38421 | file | 2006-07-28 14:53:43 -0400 (Fri, 28 Jul 2006) | 10 lines
Merged revisions 38420 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38420 | file | 2006-07-28 14:49:00 -0400 (Fri, 28 Jul 2006) | 2 lines
Make a copy of the request URI in check_user_full instead of modifying the one on the structure, and also strip params properly from the user portion of the SIP URI so as to preserve the domain (issue #7552 reported by dan42)
........
................
r38422 | kpfleming | 2006-07-28 14:59:59 -0400 (Fri, 28 Jul 2006) | 3 lines
move slinfactory structure definition back to header... it's just easier to use this way
add infrastructure for whispering onto a channel
................
r38439 | russell | 2006-07-28 15:17:56 -0400 (Fri, 28 Jul 2006) | 8 lines
As discussed and decided on the asterisk-dev mailing list ...
- Fix some breakage I introduced a while ago that made the timestamps option
not functional for CLI verbose output.
- Remove the use of the timestamps option for log output, since it was not
functional.
- clarify text referring to the timestamps option so that it is clear that it
only applies to CLI verbose output
................
Modified:
team/russell/ast_verbose_threadstorage/ (props changed)
team/russell/ast_verbose_threadstorage/asterisk.c
team/russell/ast_verbose_threadstorage/channel.c
team/russell/ast_verbose_threadstorage/channels/chan_sip.c
team/russell/ast_verbose_threadstorage/doc/asterisk-conf.txt
team/russell/ast_verbose_threadstorage/frame.c
team/russell/ast_verbose_threadstorage/include/asterisk/channel.h
team/russell/ast_verbose_threadstorage/include/asterisk/frame.h
team/russell/ast_verbose_threadstorage/include/asterisk/options.h
team/russell/ast_verbose_threadstorage/include/asterisk/slinfactory.h
team/russell/ast_verbose_threadstorage/logger.c
team/russell/ast_verbose_threadstorage/slinfactory.c
Propchange: team/russell/ast_verbose_threadstorage/
------------------------------------------------------------------------------
automerge = no
Propchange: team/russell/ast_verbose_threadstorage/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.
Propchange: team/russell/ast_verbose_threadstorage/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jul 28 14:29:12 2006
@@ -1,1 +1,1 @@
-/trunk:1-38398
+/trunk:1-38439
Modified: team/russell/ast_verbose_threadstorage/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/asterisk.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/asterisk.c (original)
+++ team/russell/ast_verbose_threadstorage/asterisk.c Fri Jul 28 14:29:12 2006
@@ -2197,7 +2197,7 @@
/* verbose level (-v at startup) */
if (!strcasecmp(v->name, "verbose")) {
option_verbose = atoi(v->value);
- /* whether or not to force timestamping. (-T at startup) */
+ /* whether or not to force timestamping in CLI verbose output. (-T at startup) */
} else if (!strcasecmp(v->name, "timestamp")) {
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TIMESTAMP);
/* whether or not to support #exec in config files */
Modified: team/russell/ast_verbose_threadstorage/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/channel.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/channel.c (original)
+++ team/russell/ast_verbose_threadstorage/channel.c Fri Jul 28 14:29:12 2006
@@ -67,6 +67,7 @@
#include "asterisk/devicestate.h"
#include "asterisk/sha1.h"
#include "asterisk/threadstorage.h"
+#include "asterisk/slinfactory.h"
struct channel_spy_trans {
int last_format;
@@ -77,6 +78,12 @@
struct channel_spy_trans read_translator;
struct channel_spy_trans write_translator;
AST_LIST_HEAD_NOLOCK(, ast_channel_spy) list;
+};
+
+struct ast_channel_whisper_buffer {
+ ast_mutex_t lock;
+ struct ast_slinfactory sf;
+ unsigned int original_format;
};
/* uncomment if you have problems with 'monitoring' synchronized files */
@@ -969,13 +976,16 @@
ast_copy_string(name, chan->name, sizeof(name));
/* Stop monitoring */
- if (chan->monitor) {
+ if (chan->monitor)
chan->monitor->stop( chan, 0 );
- }
/* If there is native format music-on-hold state, free it */
- if(chan->music_state)
+ if (chan->music_state)
ast_moh_cleanup(chan);
+
+ /* if someone is whispering on the channel, stop them */
+ if (chan->whisper)
+ ast_channel_whisper_stop(chan);
/* Free translators */
if (chan->readtrans)
@@ -2427,6 +2437,25 @@
}
}
+ if (ast_test_flag(chan, AST_FLAG_WHISPER)) {
+ /* frame is assumed to be in SLINEAR, since that is
+ required for whisper mode */
+ ast_frame_adjust_volume(f, -2);
+ if (ast_slinfactory_available(&chan->whisper->sf) >= f->samples) {
+ short buf[f->samples];
+ struct ast_frame whisper = {
+ .frametype = AST_FRAME_VOICE,
+ .subclass = AST_FORMAT_SLINEAR,
+ .data = buf,
+ .datalen = sizeof(buf),
+ .samples = f->samples,
+ };
+
+ if (ast_slinfactory_read(&chan->whisper->sf, buf, f->samples))
+ ast_frame_slinear_sum(f, &whisper);
+ }
+ }
+
res = chan->tech->write(chan, f);
}
break;
@@ -3153,6 +3182,16 @@
if (x != AST_GENERATOR_FD)
original->fds[x] = clone->fds[x];
}
+
+ /* move any whisperer over */
+ ast_channel_whisper_stop(original);
+ if (ast_test_flag(clone, AST_FLAG_WHISPER)) {
+ original->whisper = clone->whisper;
+ ast_set_flag(original, AST_FLAG_WHISPER);
+ clone->whisper = NULL;
+ ast_clear_flag(clone, AST_FLAG_WHISPER);
+ }
+
/* Move data stores over */
if (AST_LIST_FIRST(&clone->datastores))
AST_LIST_INSERT_TAIL(&original->datastores, AST_LIST_FIRST(&clone->datastores), entry);
@@ -4383,4 +4422,43 @@
return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd);
}
-/* end of file */
+int ast_channel_whisper_start(struct ast_channel *chan)
+{
+ if (chan->whisper)
+ return -1;
+
+ if (!(chan->whisper = ast_calloc(1, sizeof(*chan->whisper))))
+ return -1;
+
+ ast_mutex_init(&chan->whisper->lock);
+ ast_slinfactory_init(&chan->whisper->sf);
+ chan->whisper->original_format = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
+ ast_set_flag(chan, AST_FLAG_WHISPER);
+
+ return 0;
+}
+
+int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f)
+{
+ if (!chan->whisper)
+ return -1;
+
+ ast_mutex_lock(&chan->whisper->lock);
+ ast_slinfactory_feed(&chan->whisper->sf, f);
+ ast_mutex_unlock(&chan->whisper->lock);
+
+ return 0;
+}
+
+void ast_channel_whisper_stop(struct ast_channel *chan)
+{
+ if (!chan->whisper)
+ return;
+
+ ast_clear_flag(chan, AST_FLAG_WHISPER);
+ ast_set_write_format(chan, chan->whisper->original_format);
+ ast_slinfactory_destroy(&chan->whisper->sf);
+ ast_mutex_destroy(&chan->whisper->lock);
+ free(chan->whisper);
+ chan->whisper = NULL;
+}
Modified: team/russell/ast_verbose_threadstorage/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/channels/chan_sip.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/channels/chan_sip.c (original)
+++ team/russell/ast_verbose_threadstorage/channels/chan_sip.c Fri Jul 28 14:29:12 2006
@@ -8526,9 +8526,10 @@
int debug=sip_debug_test_addr(sin);
struct ast_variable *tmpvar = NULL, *v = NULL;
int usenatroute;
+ char *uri2 = ast_strdupa(uri);
/* Terminate URI */
- t = uri;
+ t = uri2;
while (*t && *t > 32 && *t != ';')
t++;
*t = '\0';
@@ -8548,7 +8549,7 @@
of = get_in_brackets(from);
if (ast_strlen_zero(p->exten)) {
- t = uri;
+ t = uri2;
if (!strncmp(t, "sip:", 4))
t+= 4;
ast_string_field_set(p, exten, t);
@@ -8621,7 +8622,7 @@
ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", usenatroute ? "On" : "Off");
ast_udptl_setnat(p->udptl, usenatroute);
}
- if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
+ if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
sip_cancel_destroy(p);
ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY);
ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
@@ -8748,7 +8749,7 @@
ast_string_field_free(p, peersecret);
ast_string_field_free(p, peermd5secret);
}
- if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
+ if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
/* If we have a call limit, set flag */
Modified: team/russell/ast_verbose_threadstorage/doc/asterisk-conf.txt
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/doc/asterisk-conf.txt?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/doc/asterisk-conf.txt (original)
+++ team/russell/ast_verbose_threadstorage/doc/asterisk-conf.txt Fri Jul 28 14:29:12 2006
@@ -49,7 +49,7 @@
nocolor = yes | no ; Disable ANSI colors (-n)
dumpcore = yes | no ; Dump core on failure (-g)
quiet = yes | no ; Run quietly (-q)
-timestamp = yes | no ; Force timestamping on log entries to console (-T)
+timestamp = yes | no ; Force timestamping in CLI verbose output (-T)
runuser = asterisk ; User to run asterisk as (-U) NOTE: will require changes to
; directory and device permisions
rungroup = asterisk ; Group to run asterisk as (-G)
Modified: team/russell/ast_verbose_threadstorage/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/frame.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/frame.c (original)
+++ team/russell/ast_verbose_threadstorage/frame.c Fri Jul 28 14:29:12 2006
@@ -359,7 +359,7 @@
return out;
}
-struct ast_frame *ast_frdup(struct ast_frame *f)
+struct ast_frame *ast_frdup(const struct ast_frame *f)
{
struct ast_frame *out;
int len, srclen = 0;
Modified: team/russell/ast_verbose_threadstorage/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/channel.h?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/channel.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/channel.h Fri Jul 28 14:29:12 2006
@@ -268,6 +268,7 @@
};
struct ast_channel_spy_list;
+struct ast_channel_whisper_buffer;
#define DEBUGCHAN_FLAG 0x80000000
#define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | ((x++) & ~DEBUGCHAN_FLAG) )
@@ -382,6 +383,7 @@
int rawwriteformat; /*!< Raw write format */
struct ast_channel_spy_list *spies; /*!< Chan Spy stuff */
+ struct ast_channel_whisper_buffer *whisper; /*!< Whisper Paging buffer */
AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */
struct ast_jb jb; /*!< The jitterbuffer state */
@@ -397,21 +399,20 @@
/*! \brief Channels have this property if they can create jitter; i.e. most VoIP channels */
#define AST_CHAN_TP_CREATESJITTER (1 << 1)
-/* This flag has been deprecated by the transfercapbilty data member in struct ast_channel */
-/* #define AST_FLAG_DIGITAL (1 << 0) */ /* if the call is a digital ISDN call */
#define AST_FLAG_DEFER_DTMF (1 << 1) /*!< if dtmf should be deferred */
#define AST_FLAG_WRITE_INT (1 << 2) /*!< if write should be interrupt generator */
#define AST_FLAG_BLOCKING (1 << 3) /*!< if we are blocking */
#define AST_FLAG_ZOMBIE (1 << 4) /*!< if we are a zombie */
#define AST_FLAG_EXCEPTION (1 << 5) /*!< if there is a pending exception */
#define AST_FLAG_MOH (1 << 6) /*!< XXX anthm promises me this will disappear XXX listening to moh */
-#define AST_FLAG_SPYING (1 << 7) /*!< XXX might also go away XXX is spying on someone */
+#define AST_FLAG_SPYING (1 << 7) /*!< is spying on someone */
#define AST_FLAG_NBRIDGE (1 << 8) /*!< is it in a native bridge */
#define AST_FLAG_IN_AUTOLOOP (1 << 9) /*!< the channel is in an auto-incrementing dialplan processor,
so when ->priority is set, it will get incremented before
- finding the next priority to run
- */
-#define AST_FLAG_OUTGOING (1 << 10) /*! Is this call outgoing */
+ finding the next priority to run */
+#define AST_FLAG_OUTGOING (1 << 10) /*!< Is this call outgoing */
+#define AST_FLAG_WHISPER (1 << 11) /*!< Is this channel being whispered on */
+
/* @} */
#define AST_FEATURE_PLAY_WARNING (1 << 0)
@@ -1277,6 +1278,38 @@
/*! \brief return an ast_variable list of channeltypes */
struct ast_variable *ast_channeltype_list(void);
+/*!
+ \brief Begin 'whispering' onto a channel
+ \param chan The channel to whisper onto
+ \return 0 for success, non-zero for failure
+
+ This function will add a whisper buffer onto a channel and set a flag
+ causing writes to the channel to reduce the volume level of the written
+ audio samples, and then to mix in audio from the whisper buffer if it
+ is available.
+
+ Note: This function performs no locking; you must hold the channel's lock before
+ calling this function.
+ */
+int ast_channel_whisper_start(struct ast_channel *chan);
+
+/*!
+ \brief Feed an audio frame into the whisper buffer on a channel
+ \param chan The channel to whisper onto
+ \return 0 for success, non-zero for failure
+ */
+int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f);
+
+/*!
+ \brief Stop 'whispering' onto a channel
+ \param chan The channel to whisper onto
+ \return 0 for success, non-zero for failure
+
+ Note: This function performs no locking; you must hold the channel's lock before
+ calling this function.
+ */
+void ast_channel_whisper_stop(struct ast_channel *chan);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/russell/ast_verbose_threadstorage/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/frame.h?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/frame.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/frame.h Fri Jul 28 14:29:12 2006
@@ -354,7 +354,7 @@
*/
void ast_frfree(struct ast_frame *fr);
-/*! \brief Copies a frame
+/*! \brief Makes a frame independent of any static storage
* \param fr frame to act upon
* Take a frame, and if it's not been malloc'd, make a malloc'd copy
* and if the data hasn't been malloced then make the
@@ -366,10 +366,10 @@
/*! \brief Copies a frame
* \param fr frame to copy
- * Dupliates a frame -- should only rarely be used, typically frisolate is good enough
+ * Duplicates a frame -- should only rarely be used, typically frisolate is good enough
* \return Returns a frame on success, NULL on error
*/
-struct ast_frame *ast_frdup(struct ast_frame *fr);
+struct ast_frame *ast_frdup(const struct ast_frame *fr);
/*! \brief Reads a frame from an fd
* Read a frame from a stream or packet fd, as written by fd_write
Modified: team/russell/ast_verbose_threadstorage/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/options.h?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/options.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/options.h Fri Jul 28 14:29:12 2006
@@ -60,7 +60,7 @@
AST_OPT_FLAG_DUMP_CORE = (1 << 12),
/*! Cache sound files */
AST_OPT_FLAG_CACHE_RECORD_FILES = (1 << 13),
- /*! Display timestamp in log messages */
+ /*! Display timestamp in CLI verbose output */
AST_OPT_FLAG_TIMESTAMP = (1 << 14),
/*! Override config */
AST_OPT_FLAG_OVERRIDE_CONFIG = (1 << 15),
Modified: team/russell/ast_verbose_threadstorage/include/asterisk/slinfactory.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/slinfactory.h?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/slinfactory.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/slinfactory.h Fri Jul 28 14:29:12 2006
@@ -27,7 +27,6 @@
#include <unistd.h>
#include <string.h>
-
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
@@ -37,17 +36,16 @@
struct ast_trans_pvt *trans;
short hold[1280];
short *offset;
- size_t holdlen;
- int size;
- int format;
+ size_t holdlen; /*!< in samples */
+ unsigned int size; /*!< in samples */
+ unsigned int format;
};
void ast_slinfactory_init(struct ast_slinfactory *sf);
void ast_slinfactory_destroy(struct ast_slinfactory *sf);
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
-int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t bytes);
-
-
+int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);
+unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);
#if defined(__cplusplus) || defined(c_plusplus)
}
Modified: team/russell/ast_verbose_threadstorage/logger.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/logger.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/logger.c (original)
+++ team/russell/ast_verbose_threadstorage/logger.c Fri Jul 28 14:29:12 2006
@@ -740,9 +740,8 @@
if (level != __LOG_VERBOSE) {
int res;
sprintf(linestr, "%d", line);
-
ast_dynamic_str_threadbuild(&buf, BUFSIZ, &log_buf,
- ast_opt_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
+ "[%s] %s[%ld]: %s:%s %s: ",
date,
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
(long)GETTID(),
@@ -762,7 +761,7 @@
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
int res;
ast_dynamic_str_threadbuild(&buf, BUFSIZ, &log_buf,
- ast_opt_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ",
+ "[%s] %s[%ld] %s: ",
date, levels[level], (long)GETTID(), file);
res = fprintf(chan->fileptr, "%s", buf->str);
if (res <= 0 && !ast_strlen_zero(buf->str)) { /* Error, no characters printed */
@@ -848,6 +847,20 @@
int res;
va_list ap;
+ if (ast_opt_timestamp) {
+ time_t t;
+ struct tm tm;
+ char date[40];
+ char *datefmt;
+
+ time(&t);
+ localtime_r(&t, &tm);
+ strftime(date, sizeof(date), dateformat, &tm);
+ datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
+ sprintf(datefmt, "[%s] %s", date, fmt);
+ fmt = datefmt;
+ }
+
if (!(buf = ast_dynamic_str_threadget(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
return;
Modified: team/russell/ast_verbose_threadstorage/slinfactory.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/slinfactory.c?rev=38440&r1=38439&r2=38440&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/slinfactory.c (original)
+++ team/russell/ast_verbose_threadstorage/slinfactory.c Fri Jul 28 14:29:12 2006
@@ -30,14 +30,14 @@
#include <string.h>
+#include "asterisk/frame.h"
#include "asterisk/slinfactory.h"
#include "asterisk/logger.h"
#include "asterisk/translate.h"
-
void ast_slinfactory_init(struct ast_slinfactory *sf)
{
- memset(sf, 0, sizeof(struct ast_slinfactory));
+ memset(sf, 0, sizeof(*sf));
sf->offset = sf->hold;
sf->queue = NULL;
}
@@ -51,7 +51,7 @@
sf->trans = NULL;
}
- while((f = sf->queue)) {
+ while ((f = sf->queue)) {
sf->queue = f->next;
ast_frfree(f);
}
@@ -60,10 +60,7 @@
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
{
struct ast_frame *frame, *frame_ptr;
-
- if (!f) {
- return 0;
- }
+ unsigned int x;
if (f->subclass != AST_FORMAT_SLINEAR) {
if (sf->trans && f->subclass != sf->format) {
@@ -80,52 +77,49 @@
}
}
- if (sf->trans) {
+ if (sf->trans)
frame = ast_translate(sf->trans, f, 0);
- } else {
+ else
frame = ast_frdup(f);
- }
- if (frame) {
- int x = 0;
- for (frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr = frame_ptr->next) {
- x++;
- }
- if (frame_ptr) {
- frame_ptr->next = frame;
- } else {
- sf->queue = frame;
- }
- frame->next = NULL;
- sf->size += frame->datalen;
- return x;
- }
+ if (!frame)
+ return 0;
- return 0;
-
+ for (x = 0, frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr = frame_ptr->next)
+ x++;
+
+ if (frame_ptr)
+ frame_ptr->next = frame;
+ else
+ sf->queue = frame;
+
+ frame->next = NULL;
+ sf->size += frame->samples;
+
+ return x;
}
-int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t bytes)
+int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
{
struct ast_frame *frame_ptr;
- int sofar = 0, ineed, remain;
+ unsigned int sofar = 0, ineed, remain;
short *frame_data, *offset = buf;
- while (sofar < bytes) {
- ineed = bytes - sofar;
+ while (sofar < samples) {
+ ineed = samples - sofar;
if (sf->holdlen) {
if ((sofar + sf->holdlen) <= ineed) {
- memcpy(offset, sf->hold, sf->holdlen);
+ memcpy(offset, sf->hold, sf->holdlen * sizeof(*offset));
sofar += sf->holdlen;
- offset += (sf->holdlen / sizeof(short));
+ offset += sf->holdlen;
sf->holdlen = 0;
sf->offset = sf->hold;
} else {
remain = sf->holdlen - ineed;
- memcpy(offset, sf->offset, ineed);
+ memcpy(offset, sf->offset, ineed * sizeof(*offset));
sofar += ineed;
- sf->offset += (ineed / sizeof(short));
+ sf->offset += ineed;
sf->holdlen = remain;
}
continue;
@@ -135,16 +129,16 @@
sf->queue = frame_ptr->next;
frame_data = frame_ptr->data;
- if ((sofar + frame_ptr->datalen) <= ineed) {
- memcpy(offset, frame_data, frame_ptr->datalen);
- sofar += frame_ptr->datalen;
- offset += (frame_ptr->datalen / sizeof(short));
+ if ((sofar + frame_ptr->samples) <= ineed) {
+ memcpy(offset, frame_data, frame_ptr->samples * sizeof(*offset));
+ sofar += frame_ptr->samples;
+ offset += frame_ptr->samples;
} else {
- remain = frame_ptr->datalen - ineed;
- memcpy(offset, frame_data, ineed);
+ remain = frame_ptr->samples - ineed;
+ memcpy(offset, frame_data, ineed * sizeof(*offset));
sofar += ineed;
- frame_data += (ineed / sizeof(short));
- memcpy(sf->hold, frame_data, remain);
+ frame_data += ineed;
+ memcpy(sf->hold, frame_data, remain * sizeof(*offset));
sf->holdlen = remain;
}
ast_frfree(frame_ptr);
@@ -156,3 +150,8 @@
sf->size -= sofar;
return sofar;
}
+
+unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
+{
+ return sf->size;
+}
More information about the asterisk-commits
mailing list