]> git.pld-linux.org Git - packages/asterisk.git/blob - asterisk-audiohook.patch
f27d000f4c3bcccc54f3dbd5aebd4d8fee08b158
[packages/asterisk.git] / asterisk-audiohook.patch
1 Index: include/asterisk/slinfactory.h
2 ===================================================================
3 --- include/asterisk/slinfactory.h      (wersja 113295)
4 +++ include/asterisk/slinfactory.h      (wersja 113296)
5 @@ -48,6 +48,7 @@
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);
10  
11  #if defined(__cplusplus) || defined(c_plusplus)
12  }
13 Index: main/slinfactory.c
14 ===================================================================
15 --- main/slinfactory.c  (wersja 113295)
16 +++ main/slinfactory.c  (wersja 113296)
17 @@ -157,3 +157,21 @@
18  {
19         return sf->size;
20  }
21 +
22 +void ast_slinfactory_flush(struct ast_slinfactory *sf)
23 +{
24 +       struct ast_frame *fr = NULL;
25 +
26 +       if (sf->trans) {
27 +               ast_translator_free_path(sf->trans);
28 +               sf->trans = NULL;
29 +       }
30 +
31 +       while ((fr = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list)))
32 +               ast_frfree(fr);
33 +
34 +       sf->size = sf->holdlen = 0;
35 +       sf->offset = sf->hold;
36 +
37 +       return;
38 +}
39 Index: main/audiohook.c
40 ===================================================================
41 --- main/audiohook.c    (wersja 113295)
42 +++ main/audiohook.c    (wersja 113296)
43 @@ -128,14 +128,23 @@
44  int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame)
45  {
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;
50  
51 +       /* Update last feeding time to be current */
52 +       *time = ast_tvnow();
53 +
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))) {
56 +               if (option_debug)
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);
60 +       }
61 +
62         /* Write frame out to respective factory */
63         ast_slinfactory_feed(factory, frame);
64  
65 -       /* Update last fed time for the above factory */
66 -       *time = ast_tvnow();
67 -
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);
This page took 0.099345 seconds and 2 git commands to generate.