diff options
author | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-16 06:00:12 +0000 |
---|---|---|
committer | matteo <matteo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-16 06:00:12 +0000 |
commit | 175c755fefa75d02deeff70541cd7821ce670678 (patch) | |
tree | 09bad30a14c0eef808c9d0d2720e797ff76c44f4 /frame.c | |
parent | dae2009f9537257ba729035caa92eb3661c93aa1 (diff) |
Sun Feb 16 07:00:01 CET 2003
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@616 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'frame.c')
-rwxr-xr-x | frame.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -35,10 +35,12 @@ struct ast_smoother { int size; int format; int readdata; + int optimizablestream; float samplesperbyte; struct ast_frame f; char data[SMOOTHER_SIZE]; char framedata[SMOOTHER_SIZE + AST_FRIENDLY_OFFSET]; + struct ast_frame *opt; int len; }; @@ -76,6 +78,28 @@ int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f) ast_log(LOG_WARNING, "Out of smoother space\n"); return -1; } + if ((f->datalen == s->size) && !s->opt) { + if (!s->len) { + /* Optimize by sending the frame we just got + on the next read, thus eliminating the douple + copy */ + s->opt = f; + return 0; + } else { + s->optimizablestream++; + if (s->optimizablestream > 10) { + /* For the past 10 rounds, we have input and output + frames of the correct size for this smoother, yet + we were unable to optimize because there was still + some cruft left over. Lets just drop the cruft so + we can move to a fully optimized path */ + s->len = 0; + s->opt = f; + return 0; + } + } + } else + s->optimizablestream = 0; memcpy(s->data + s->len, f->data, f->datalen); s->len += f->datalen; return 0; @@ -83,6 +107,15 @@ int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f) struct ast_frame *ast_smoother_read(struct ast_smoother *s) { + struct ast_frame *opt; + + /* IF we have an optimization frame, send it */ + if (s->opt) { + opt = s->opt; + s->opt = NULL; + return opt; + } + /* Make sure we have enough data */ if (s->len < s->size) { return NULL; |