<p>Sam Wierema has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9190">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_mp3: remove 10 seconds of silence after mp3 playback<br><br>This patch changes the way asterisk polls output from mpg123, instead<br>of waiting for 10 seconds(when playing an http url) it now uses a<br>timeout of one second and iterates 10 times using this same timeout.<br><br>The main difference is that for every timeout asterisk receives it now<br>checks if mpg123 is still running before poll again.<br><br>ASTERISK-27752<br><br>Change-Id: Ib7df8462e3e380cb328011890ad9270d9e9b4620<br>---<br>M apps/app_mp3.c<br>1 file changed, 25 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/90/9190/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/apps/app_mp3.c b/apps/app_mp3.c<br>index 17f7874..c589c88 100644<br>--- a/apps/app_mp3.c<br>+++ b/apps/app_mp3.c<br>@@ -37,6 +37,7 @@<br> ASTERISK_FILE_VERSION(__FILE__, "$Revision$")<br> <br> #include <sys/time.h><br>+#include <sys/types.h><br> #include <signal.h><br> <br> #include "asterisk/lock.h"<br>@@ -138,17 +139,34 @@<br> _exit(0);<br> }<br> <br>-static int timed_read(int fd, void *data, int datalen, int timeout)<br>+static int timed_read(int fd, void *data, int datalen, int timeout, int pid)<br> {<br> int res;<br>+ int i;<br> struct pollfd fds[1];<br> fds[0].fd = fd;<br> fds[0].events = POLLIN;<br>- res = ast_poll(fds, 1, timeout);<br>- if (res < 1) {<br>- ast_log(LOG_NOTICE, "Poll timed out/errored out with %d\n", res);<br>+ for (i = 0; i < timeout; i++) {<br>+ res = ast_poll(fds, 1, 1000);<br>+ if (res > 0) {<br>+ break;<br>+ } else if (res == 0) {<br>+ /* is mpg123 still running? */<br>+ kill(pid, 0);<br>+ if (errno == ESRCH) {<br>+ return -1;<br>+ }<br>+ } else {<br>+ ast_log(LOG_NOTICE, "error polling mpg123: %s\n", strerror(errno));<br>+ return -1;<br>+ }<br>+ }<br>+<br>+ if (i == timeout) {<br>+ ast_log(LOG_NOTICE, "Poll timed out.\n");<br> return -1;<br> }<br>+<br> return read(fd, data, datalen);<br> <br> }<br>@@ -160,7 +178,7 @@<br> int ms = -1;<br> int pid = -1;<br> RAII_VAR(struct ast_format *, owriteformat, NULL, ao2_cleanup);<br>- int timeout = 2000;<br>+ int timeout = 2;<br> struct timeval next;<br> struct ast_frame *f;<br> struct myframe {<br>@@ -208,7 +226,7 @@<br> <br> res = mp3play(data, sampling_rate, fds[1]);<br> if (!strncasecmp(data, "http://", 7)) {<br>- timeout = 10000;<br>+ timeout = 10;<br> }<br> /* Wait 1000 ms first */<br> next = ast_tvnow();<br>@@ -220,7 +238,7 @@<br> for (;;) {<br> ms = ast_tvdiff_ms(next, ast_tvnow());<br> if (ms <= 0) {<br>- res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);<br>+ res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout, pid);<br> if (res > 0) {<br> myf.f.datalen = res;<br> myf.f.samples = res / 2;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9190">change 9190</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9190"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib7df8462e3e380cb328011890ad9270d9e9b4620 </div>
<div style="display:none"> Gerrit-Change-Number: 9190 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sam Wierema <sam@messagebird.com> </div>