38 #include <sys/types.h> 51 #define LOCAL_MPG_123 "/usr/local/bin/mpg123" 52 #define MPG_123 "/usr/bin/mpg123" 77 static char *
app =
"MP3Player";
79 static int mp3play(
const char *filename,
unsigned int sampling_rate,
int fd)
82 char sampling_rate_str[8];
93 dup2(fd, STDOUT_FILENO);
96 snprintf(sampling_rate_str, 8,
"%u", sampling_rate);
99 if (!strncasecmp(filename,
"http://", 7) && strstr(filename,
".m3u")) {
100 char buffer_size_str[8];
101 snprintf(buffer_size_str, 8,
"%u", (
int) 0.5*2*sampling_rate/1000);
103 execl(
LOCAL_MPG_123,
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
105 execl(
MPG_123,
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)NULL);
107 execlp(
"mpg123",
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)NULL);
109 else if (!strncasecmp(filename,
"http://", 7)) {
110 char buffer_size_str[8];
111 snprintf(buffer_size_str, 8,
"%u", 6*2*sampling_rate/1000);
113 execl(
LOCAL_MPG_123,
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
115 execl(
MPG_123,
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)NULL);
117 execlp(
"mpg123",
"mpg123",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)NULL);
119 else if (strstr(filename,
".m3u")) {
121 execl(
LOCAL_MPG_123,
"mpg123",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
123 execl(
MPG_123,
"mpg123",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)NULL);
125 execlp(
"mpg123",
"mpg123",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)NULL);
129 execl(
MPG_123,
"mpg123",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
131 execl(
LOCAL_MPG_123,
"mpg123",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)NULL);
133 execlp(
"mpg123",
"mpg123",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)NULL);
136 fprintf(stderr,
"Execute of mpg123 failed\n");
144 struct pollfd fds[1];
146 fds[0].events = POLLIN;
147 for (i = 0; i <
timeout; i++) {
151 }
else if (res == 0) {
154 if (
errno == ESRCH) {
168 return read(fd, data, datalen);
190 unsigned int sampling_rate;
217 myf.f.subclass.format = write_format;
220 myf.f.src = __PRETTY_FUNCTION__;
221 myf.f.delivery.tv_sec = 0;
222 myf.f.delivery.tv_usec = 0;
223 myf.f.data.ptr = myf.frdata;
225 res =
mp3play(data, sampling_rate, fds[1]);
226 if (!strncasecmp(data,
"http://", 7)) {
239 res =
timed_read(fds[0], myf.frdata,
sizeof(myf.frdata), timeout, pid);
242 myf.f.samples = res / 2;
263 ast_debug(1,
"Null frame == hangup() detected\n");
283 if (!res && owriteformat)
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
Support for translation of data formats. translate.c.
static int mp3play(const char *filename, unsigned int sampling_rate, int fd)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Silly MP3 Application")
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
static int unload_module(void)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
#define ast_strlen_zero(foo)
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_poll(a, b, c)
Asterisk internal frame definitions.
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Core PBX routines and definitions.
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Data structure associated with a single frame of data.
static int load_module(void)
enum ast_frame_type frametype
static int timed_read(int fd, void *data, int datalen, int timeout, int pid)
#define ASTERISK_GPL_KEY
The text the key() function should return.
static int mp3_exec(struct ast_channel *chan, const char *data)
Asterisk module definitions.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ast_opt_high_priority