--- ../asterisk-1.6.2.13/utils/Makefile 2010-11-08 11:32:07.000000000 -0500 +++ utils/Makefile 2010-11-08 09:21:15.000000000 -0500 @@ -27,7 +27,7 @@ # changes are made to ast_expr2.y or ast_expr2.fl (or the corresponding .c files), # as a regression test. Others (mere mortals?) need not bother, but they are # more than welcome to play! The regression test itself is in expr2.testinput. -ALL_UTILS:=astman smsq stereorize streamplayer muted hashtest2 hashtest astcanary refcounter aelparse conf2ael +ALL_UTILS:=astman smsq stereorize streamnoblock streamplayer muted hashtest2 hashtest astcanary refcounter aelparse conf2ael UTILS:=$(ALL_UTILS) LIBS += $(BKTR_LIB) # astobj2 with devmode uses backtrace @@ -198,6 +198,8 @@ streamplayer: streamplayer.o +streamnoblock: streamnoblock.o + muted: muted.o muted: LIBS+=$(AUDIO_LIBS) muted: _ASTCFLAGS:=$(filter-out -Werror,$(_ASTCFLAGS)) --- /dev/null 2009-10-22 12:07:51.000000000 -0400 +++ utils/streamnoblock.c 2010-11-08 11:27:44.000000000 -0500 @@ -0,0 +1,80 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 1999 - 2005, Digium, Inc. + * + * Russell Bryant + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! + * \file + * \author Russell Bryant , Michel Belleau + * + * \brief A utility helping stream from live sources to Music-On-Hold + * + * This application is quite simple. It just reads the data from stdin + * and dumps it straight to stdout. Due to the way Asterisk handles + * music on hold sources, this application checks to make sure writing + * to stdout will not be a blocking operation before doing so. If so, the data + * is just thrown away. This ensures that the stream will continue to be + * serviced, even if Asterisk is not currently using the source. + * + * This utility, when used as the final pipe of a MOH live streaming source makes this error disappear: + * [Nov 8 09:30:31] NOTICE[24617] res_musiconhold.c: Request to schedule in the past?!?! + * + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + int s; + int res; + char buf[2048]; + fd_set wfds; + struct timeval tv; + + if (argc != 1) { + fprintf(stderr, "streamnoblock -- A utility for reading from stdin and passing to stdout only if not blocking.\n"); + fprintf(stderr, "Written for use with Asterisk (http://www.asterisk.org)\n"); + fprintf(stderr, "Usage: ./streamnoblock\n"); + exit(1); + } + + while (1) { + res = read(0, buf, sizeof(buf)); + + if (res < 1) + break; + + memset(&tv, 0, sizeof(tv)); + FD_ZERO(&wfds); + FD_SET(1, &wfds); + + select(2, NULL, &wfds, NULL, &tv); + + if (FD_ISSET(1, &wfds)) { + if (write(1, buf, res) < 1) { + break; + } + } + } + + exit(res); +}