]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_chanspy.c: resolving the issue writing frame to whisper audiohook.
authorTinet-mucw <mucw@ti-net.com.cn>
Tue, 10 Sep 2024 04:01:21 +0000 (12:01 +0800)
committerTinet-mucw <mucw@ti-net.com.cn>
Wed, 11 Sep 2024 11:39:48 +0000 (11:39 +0000)
ChanSpy(${channel}, qEoSw): because flags set o, ast_audiohook_set_frame_feed_direction(audiohook, AST_AUDIOHOOK_DIRECTION_READ); this will effect whisper audiohook and spy audiohook, this makes writing frame to whisper audiohook impossible. So add function start_whispering to starting whisper audiohook.

Resolves: #876

apps/app_broadcast.c
apps/app_chanspy.c

index 7ab646af03eddfe91371903c2518649ec9f92e2a..0abdbda50984bd7554147501faade5fc5ca09dd4 100644 (file)
@@ -264,6 +264,25 @@ static int start_spying(struct ast_autochan *autochan, const char *spychan_name,
        return res;
 }
 
+static int start_whispering(struct ast_autochan *autochan, const char *spychan_name, struct ast_audiohook *audiohook, struct ast_flags *flags)
+{
+       int res;
+
+       ast_autochan_channel_lock(autochan);
+       ast_verb(3, "Attaching spy channel %s to %s\n",
+               spychan_name, ast_channel_name(autochan->chan));
+
+       ast_set_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC);
+       if (ast_test_flag(flags, OPTION_LONG_QUEUE)) {
+               ast_debug(9, "Using a long queue to store audio frames in whisper audiohook\n");
+       } else {
+               ast_set_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE);
+       }
+       res = ast_audiohook_attach(autochan->chan, audiohook);
+       ast_autochan_channel_unlock(autochan);
+       return res;
+}
+
 static int attach_barge(struct ast_autochan *spyee_autochan, struct ast_autochan **spyee_bridge_autochan,
        struct ast_audiohook *bridge_whisper_audiohook, const char *spyer_name, const char *name, struct ast_flags *flags)
 {
@@ -295,7 +314,7 @@ static int attach_barge(struct ast_autochan *spyee_autochan, struct ast_autochan
                return -1;
        }
 
-       if (start_spying(internal_bridge_autochan, spyer_name, bridge_whisper_audiohook, flags)) {
+       if (start_whispering(internal_bridge_autochan, spyer_name, bridge_whisper_audiohook, flags)) {
                ast_log(LOG_WARNING, "Unable to attach barge audiohook on spyee '%s'. Barge mode disabled.\n", name);
                retval = -1;
        }
@@ -396,7 +415,7 @@ static int do_broadcast(struct ast_channel *chan, struct ast_flags *flags, const
                        mac->connected = 1;
                        ast_audiohook_init(&mac->whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "Broadcast", 0);
                        /* Inject audio from our channel to this target. */
-                       if (start_spying(mac->autochan, next, &mac->whisper_audiohook, flags)) {
+                       if (start_whispering(mac->autochan, next, &mac->whisper_audiohook, flags)) {
                                ast_log(LOG_WARNING, "Unable to attach whisper audiohook to %s\n", next);
                                multi_autochan_free(mac);
                                continue;
index f6907a5e033ebe549baeb9d1078de6da52326397..74492fd426f2a7c42ede7ca23986fc0e7b06fe08 100644 (file)
@@ -585,6 +585,25 @@ static int start_spying(struct ast_autochan *autochan, const char *spychan_name,
        return res;
 }
 
+static int start_whispering(struct ast_autochan *autochan, const char *spychan_name, struct ast_audiohook *audiohook, struct ast_flags *flags)
+{
+       int res;
+
+       ast_autochan_channel_lock(autochan);
+       ast_verb(3, "Attaching spy channel %s to %s\n",
+               spychan_name, ast_channel_name(autochan->chan));
+
+       ast_set_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC);
+       if (ast_test_flag(flags, OPTION_LONG_QUEUE)) {
+               ast_debug(9, "Using a long queue to store audio frames in whisper audiohook\n");
+       } else {
+               ast_set_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE);
+       }
+       res = ast_audiohook_attach(autochan->chan, audiohook);
+       ast_autochan_channel_unlock(autochan);
+       return res;
+}
+
 static void change_spy_mode(const char digit, struct ast_flags *flags)
 {
        if (digit == '4') {
@@ -685,7 +704,7 @@ static int attach_barge(struct ast_autochan *spyee_autochan,
                return -1;
        }
 
-       if (start_spying(internal_bridge_autochan, spyer_name, bridge_whisper_audiohook, flags)) {
+       if (start_whispering(internal_bridge_autochan, spyer_name, bridge_whisper_audiohook, flags)) {
                ast_log(LOG_WARNING, "Unable to attach barge audiohook on spyee '%s'. Barge mode disabled.\n", name);
                retval = -1;
        }
@@ -747,7 +766,7 @@ static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_auto
                */
                ast_audiohook_init(&csth.whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "ChanSpy", 0);
 
-               if (start_spying(spyee_autochan, spyer_name, &csth.whisper_audiohook, flags)) {
+               if (start_whispering(spyee_autochan, spyer_name, &csth.whisper_audiohook, flags)) {
                        ast_log(LOG_WARNING, "Unable to attach whisper audiohook to spyee %s. Whisper mode disabled!\n", name);
                }
        }