51#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
52#define MPG_123 "/usr/bin/mpg123"
80static char *
app =
"MP3Player";
82static int mp3play(
const char *filename,
unsigned int sampling_rate,
int fd)
85 char sampling_rate_str[8];
96 dup2(fd, STDOUT_FILENO);
99 snprintf(sampling_rate_str, 8,
"%u", sampling_rate);
102 if (!strncasecmp(filename,
"http://", 7) && strstr(filename,
".m3u")) {
103 char buffer_size_str[8];
104 snprintf(buffer_size_str, 8,
"%u", (
int) 0.5*2*sampling_rate/1000);
106 execl(
LOCAL_MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
108 execl(
MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
110 execlp(
"mpg123",
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
112 else if (!strncasecmp(filename,
"http://", 7)) {
113 char buffer_size_str[8];
114 snprintf(buffer_size_str, 8,
"%u", 6*2*sampling_rate/1000);
116 execl(
LOCAL_MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
118 execl(
MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
120 execlp(
"mpg123",
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-b", buffer_size_str,
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
122 else if (strstr(filename,
".m3u")) {
124 execl(
LOCAL_MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
126 execl(
MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
128 execlp(
"mpg123",
"mpg123",
"-e",
"s16",
"-q",
"-z",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str,
"-@", filename, (
char *)
NULL);
132 execl(
MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
134 execl(
LOCAL_MPG_123,
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
136 execlp(
"mpg123",
"mpg123",
"-e",
"s16",
"-q",
"-s",
"-f",
"8192",
"--mono",
"-r", sampling_rate_str, filename, (
char *)
NULL);
139 fprintf(stderr,
"Execute of mpg123 failed\n");
143static int timed_read(
int fd,
void *data,
int datalen,
int timeout,
int pid)
147 struct pollfd fds[1];
149 fds[0].events = POLLIN;
150 for (i = 0; i < timeout; i++) {
154 }
else if (res == 0) {
157 if (
errno == ESRCH) {
171 return read(fd, data, datalen);
194 unsigned int sampling_rate;
221 myf.f.subclass.format = write_format;
224 myf.f.src = __PRETTY_FUNCTION__;
225 myf.f.delivery.tv_sec = 0;
226 myf.f.delivery.tv_usec = 0;
227 myf.f.data.ptr = myf.frdata;
229 res =
mp3play(data, sampling_rate, fds[1]);
230 if (!strncasecmp(data,
"http://", 7)) {
243 res =
timed_read(fds[0], myf.frdata,
sizeof(myf.frdata), timeout, pid);
246 myf.f.samples = res / 2;
255 if (!strncasecmp(data,
"https://", 8)) {
274 ast_debug(1,
"Null frame == hangup() detected\n");
294 if (!res && owriteformat)
static int timed_read(int fd, void *data, int datalen, int timeout, int pid)
static int load_module(void)
static int unload_module(void)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Silly MP3 Application")
static int mp3play(const char *filename, unsigned int sampling_rate, int fd)
static int mp3_exec(struct ast_channel *chan, const char *data)
Asterisk main include file. File version handling, generic pbx functions.
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...
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
General Asterisk PBX channel definitions.
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.
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_frame * ast_read(struct ast_channel *chan)
Reads a frame.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child.
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
Asterisk internal frame definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define ast_debug(level,...)
Log a DEBUG message.
Asterisk locking-related definitions:
Asterisk module definitions.
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_unregister_application(const char *app)
Unregister an application.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ast_opt_high_priority
Core PBX routines and definitions.
#define ast_poll(a, b, c)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
enum ast_frame_type frametype
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 ...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Support for translation of data formats. translate.c.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.