<p>Sam Wierema has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9178">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>Change-Id: I242f8ab8534e07122934f8dd22f0e8628f09f7ad<br>---<br>M apps/app_mp3.c<br>1 file changed, 26 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/78/9178/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 05afe54..2f3c561 100644<br>--- a/apps/app_mp3.c<br>+++ b/apps/app_mp3.c<br>@@ -37,6 +37,7 @@<br> ASTERISK_REGISTER_FILE()<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>+ 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/errored out with %d\n", res);<br> return -1;<br> }<br>+<br> return read(fd, data, datalen);<br> <br> }<br>@@ -156,11 +174,12 @@<br> static int mp3_exec(struct ast_channel *chan, const char *data)<br> {<br> int res=0;<br>+ int mpg123pid;<br> int fds[2];<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>@@ -206,9 +225,9 @@<br> myf.f.delivery.tv_usec = 0;<br> myf.f.data.ptr = myf.frdata;<br> <br>- res = mp3play(data, sampling_rate, fds[1]);<br>+ mpg123pid = 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 +239,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, mpg123pid);<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/9178">change 9178</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/9178"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I242f8ab8534e07122934f8dd22f0e8628f09f7ad </div>
<div style="display:none"> Gerrit-Change-Number: 9178 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sam Wierema <sam@messagebird.com> </div>