반응형

Index: include/asterisk/audiohook.h
===================================================================
--- include/asterisk/audiohook.h (revision 147197)
+++ include/asterisk/audiohook.h (working copy)
@@ -56,6 +56,8 @@
  AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 2),  /*!< Audiohook wants to be triggered when both sides have combined audio available */
 };
 
+#define AST_AUDIOHOOK_SYNC_TOLERANCE 100 /*< Tolerance in milliseconds for audiohooks synchronization */
+
 struct ast_audiohook;
 
 /*! \brief Callback function for manipulate audiohook type
Index: main/audiohook.c
===================================================================
--- main/audiohook.c (revision 147197)
+++ main/audiohook.c (working copy)
@@ -130,12 +130,19 @@
  struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
  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;
+ int our_factory_ms;
+ int other_factory_samples;
+ int other_factory_ms;
 
  /* Update last feeding time to be current */
  *time = ast_tvnow();
 
+ our_factory_ms = ast_tvdiff_ms(*time, previous_time) + (ast_slinfactory_available(factory) / 8);
+ other_factory_samples = ast_slinfactory_available(other_factory);
+ other_factory_ms = other_factory_samples / 8;
+
  /* 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 (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
   if (option_debug)
    ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook);
   ast_slinfactory_flush(factory);

 

반응형

+ Recent posts