<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9189">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><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;">diff --git a/apps/app_mp3.c b/apps/app_mp3.c<br>index e48cf09..8d049da 100644<br>--- a/apps/app_mp3.c<br>+++ b/apps/app_mp3.c<br>@@ -35,6 +35,7 @@<br> #include "asterisk.h"<br> <br> #include <sys/time.h><br>+#include <sys/types.h><br> #include <signal.h><br> <br> #include "asterisk/lock.h"<br>@@ -136,17 +137,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>@@ -158,7 +176,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>@@ -206,7 +224,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>@@ -218,7 +236,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/9189">change 9189</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/9189"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib7df8462e3e380cb328011890ad9270d9e9b4620 </div>
<div style="display:none"> Gerrit-Change-Number: 9189 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sam Wierema <sam@messagebird.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>