diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-08 15:03:43 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-08 15:03:43 +0000 |
commit | 519910e84219b480c9d09fdf75560b14b03c4dc9 (patch) | |
tree | 17ca8b74acee8df257b708862d0213df621a109f /main | |
parent | 854db8a3ba6b65929bb6482a9a52b494f41a2cc4 (diff) |
If audio suddenly gets fed into one side of a channel after a lapse of frames flush the other factory so that old audio does not remain in the factory causing the sync code to not execute.
(closes issue #12296)
Reported by: jvandal
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@113296 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/audiohook.c | 17 | ||||
-rw-r--r-- | main/slinfactory.c | 18 |
2 files changed, 31 insertions, 4 deletions
diff --git a/main/audiohook.c b/main/audiohook.c index 8fd1501c9..c6f1abec8 100644 --- a/main/audiohook.c +++ b/main/audiohook.c @@ -128,14 +128,23 @@ int ast_audiohook_destroy(struct ast_audiohook *audiohook) int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame) { struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory); - struct timeval *time = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time); + struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory); + struct timeval *time = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *time; + + /* Update last feeding time to be current */ + *time = ast_tvnow(); + + /* If we are using a sync trigger and this factory suddenly got audio fed in after a lapse, then flush both factories to ensure they remain in sync */ + if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && ast_slinfactory_available(other_factory) && (ast_tvdiff_ms(*time, previous_time) > (ast_slinfactory_available(other_factory) / 8))) { + if (option_debug) + ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook); + ast_slinfactory_flush(factory); + ast_slinfactory_flush(other_factory); + } /* Write frame out to respective factory */ ast_slinfactory_feed(factory, frame); - /* Update last fed time for the above factory */ - *time = ast_tvnow(); - /* If we need to notify the respective handler of this audiohook, do so */ if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) { ast_cond_signal(&audiohook->trigger); diff --git a/main/slinfactory.c b/main/slinfactory.c index 0022c62de..bd5b8de4f 100644 --- a/main/slinfactory.c +++ b/main/slinfactory.c @@ -157,3 +157,21 @@ unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf) { return sf->size; } + +void ast_slinfactory_flush(struct ast_slinfactory *sf) +{ + struct ast_frame *fr = NULL; + + if (sf->trans) { + ast_translator_free_path(sf->trans); + sf->trans = NULL; + } + + while ((fr = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list))) + ast_frfree(fr); + + sf->size = sf->holdlen = 0; + sf->offset = sf->hold; + + return; +} |