]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
AMI PlayDTMF Action: Make not compete with channel's media thread.
authorRichard Mudgett <rmudgett@digium.com>
Wed, 13 Jun 2018 18:05:03 +0000 (13:05 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 19 Jun 2018 19:13:07 +0000 (14:13 -0500)
There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: Ia341f1a6f4d54f2022261abec9021fe5b2eb4905

apps/app_senddtmf.c
include/asterisk/channel.h
main/channel.c

index 25444a323adb24bf3ab04de82eb7ab0b08b589ae..5dde8dc336ca505ba140d1510a5d2a4d1f2c20fa 100644 (file)
@@ -169,7 +169,7 @@ static int manager_play_dtmf(struct mansession *s, const struct message *m)
                return 0;
        }
 
-       ast_senddigit(chan, *digit, duration_ms);
+       ast_senddigit_external(chan, *digit, duration_ms);
 
        chan = ast_channel_unref(chan);
 
index 8ec74e613606bb7795a3ba30d5fc7ed5b6377745..0fc236af4bafc30e6b6dc6def3f6e832c830e1ef 100644 (file)
@@ -2111,13 +2111,31 @@ int ast_recvchar(struct ast_channel *chan, int timeout);
 
 /*!
  * \brief Send a DTMF digit to a channel.
+ *
  * \param chan channel to act upon
  * \param digit the DTMF digit to send, encoded in ASCII
  * \param duration the duration of the digit ending in ms
+ *
+ * \pre This must only be called by the channel's media handler thread.
+ *
  * \return 0 on success, -1 on failure
  */
 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
 
+/*!
+ * \brief Send a DTMF digit to a channel from an external thread.
+ *
+ * \param chan channel to act upon
+ * \param digit the DTMF digit to send, encoded in ASCII
+ * \param duration the duration of the digit ending in ms
+ *
+ * \pre This must only be called by threads that are not the channel's
+ * media handler thread.
+ *
+ * \return 0 on success, -1 on failure
+ */
+int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration);
+
 /*!
  * \brief Send a DTMF digit to a channel.
  * \param chan channel to act upon
index a5cc4e7e9fcedcdeca55ea07a998bd765e14f61b..27a959a4b9bc1683ead70fbe1cba521d131416ad 100644 (file)
@@ -5029,12 +5029,28 @@ int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duratio
 
 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
 {
+       if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
+               duration = AST_DEFAULT_EMULATE_DTMF_DURATION;
+       }
+       if (ast_channel_tech(chan)->send_digit_begin) {
+               ast_senddigit_begin(chan, digit);
+               ast_safe_sleep(chan, duration);
+       }
+
+       return ast_senddigit_end(chan, digit, duration);
+}
+
+int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
+{
+       if (duration < AST_DEFAULT_EMULATE_DTMF_DURATION) {
+               duration = AST_DEFAULT_EMULATE_DTMF_DURATION;
+       }
        if (ast_channel_tech(chan)->send_digit_begin) {
                ast_senddigit_begin(chan, digit);
-               ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
+               usleep(duration * 1000);
        }
 
-       return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
+       return ast_senddigit_end(chan, digit, duration);
 }
 
 int ast_prod(struct ast_channel *chan)