1 Index: include/asterisk/slinfactory.h
2 ===================================================================
3 --- include/asterisk/slinfactory.h (wersja 113295)
4 +++ include/asterisk/slinfactory.h (wersja 113296)
6 int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f);
7 int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples);
8 unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf);
9 +void ast_slinfactory_flush(struct ast_slinfactory *sf);
11 #if defined(__cplusplus) || defined(c_plusplus)
13 Index: main/slinfactory.c
14 ===================================================================
15 --- main/slinfactory.c (wersja 113295)
16 +++ main/slinfactory.c (wersja 113296)
22 +void ast_slinfactory_flush(struct ast_slinfactory *sf)
24 + struct ast_frame *fr = NULL;
27 + ast_translator_free_path(sf->trans);
31 + while ((fr = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list)))
34 + sf->size = sf->holdlen = 0;
35 + sf->offset = sf->hold;
39 Index: main/audiohook.c
40 ===================================================================
41 --- main/audiohook.c (wersja 113295)
42 +++ main/audiohook.c (wersja 113296)
44 int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame)
46 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
47 - struct timeval *time = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time);
48 + struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
49 + struct timeval *time = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *time;
51 + /* Update last feeding time to be current */
52 + *time = ast_tvnow();
54 + /* 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 */
55 + 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))) {
57 + ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook);
58 + ast_slinfactory_flush(factory);
59 + ast_slinfactory_flush(other_factory);
62 /* Write frame out to respective factory */
63 ast_slinfactory_feed(factory, frame);
65 - /* Update last fed time for the above factory */
66 - *time = ast_tvnow();
68 /* If we need to notify the respective handler of this audiohook, do so */
69 if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
70 ast_cond_signal(&audiohook->trigger);