[asterisk-commits] file: branch group/media_formats r408262 - in /team/group/media_formats: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Feb 17 06:06:37 CST 2014
Author: file
Date: Mon Feb 17 06:06:31 2014
New Revision: 408262
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408262
Log:
res_musiconhold and res_parking done.
Modified:
team/group/media_formats/include/asterisk/codec.h
team/group/media_formats/main/codec.c
team/group/media_formats/res/parking/parking_applications.c
team/group/media_formats/res/res_musiconhold.c
Modified: team/group/media_formats/include/asterisk/codec.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/codec.h?view=diff&rev=408262&r1=408261&r2=408262
==============================================================================
--- team/group/media_formats/include/asterisk/codec.h (original)
+++ team/group/media_formats/include/asterisk/codec.h Mon Feb 17 06:06:31 2014
@@ -159,4 +159,14 @@
*/
unsigned int ast_codec_samples_count(struct ast_frame *frame);
+/*!
+ * \brief Get the length of media (in milliseconds) given a number of samples
+ *
+ * \param codec The codec itself
+ * \param samples The number of samples
+ *
+ * \retval length of media (in milliseconds)
+ */
+unsigned int ast_codec_determine_length(const struct ast_codec *codec, unsigned int samples);
+
#endif /* _AST_CODEC_H */
Modified: team/group/media_formats/main/codec.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/codec.c?view=diff&rev=408262&r1=408261&r2=408262
==============================================================================
--- team/group/media_formats/main/codec.c (original)
+++ team/group/media_formats/main/codec.c Mon Feb 17 06:06:31 2014
@@ -340,4 +340,13 @@
}
return frame->subclass.format->codec->get_samples(frame);
+}
+
+unsigned int ast_codec_determine_length(const struct ast_codec *codec, unsigned int samples)
+{
+ if (!codec->get_length) {
+ return 0;
+ }
+
+ return codec->get_length(samples);
}
Modified: team/group/media_formats/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/parking/parking_applications.c?view=diff&rev=408262&r1=408261&r2=408262
==============================================================================
--- team/group/media_formats/res/parking/parking_applications.c (original)
+++ team/group/media_formats/res/parking/parking_applications.c Mon Feb 17 06:06:31 2014
@@ -37,6 +37,7 @@
#include "asterisk/app.h"
#include "asterisk/say.h"
#include "asterisk/bridge_basic.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="Park" language="en_US">
@@ -687,11 +688,10 @@
struct ast_channel *dchan;
struct outgoing_helper oh = { 0, };
int outstate;
- struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
char buf[13];
char *dial_tech;
char *cur_announce;
- struct ast_format tmpfmt;
dial_tech = strsep(&dial_string, "/");
ast_verb(3, "Dial Tech,String: (%s,%s)\n", dial_tech, dial_string);
@@ -700,7 +700,7 @@
ast_log(LOG_WARNING, "PARK: Failed to announce park.\n");
goto announce_cleanup;
}
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+ ast_format_cap_add(cap_slin, ast_format_slin, 0);
snprintf(buf, sizeof(buf), "%d", parkingspace);
oh.vars = ast_variable_new("_PARKEDAT", buf, "");
@@ -736,7 +736,7 @@
ast_hangup(dchan);
announce_cleanup:
- cap_slin = ast_format_cap_destroy(cap_slin);
+ ao2_cleanup(cap_slin);
}
static void park_announce_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Modified: team/group/media_formats/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_musiconhold.c?view=diff&rev=408262&r1=408261&r2=408262
==============================================================================
--- team/group/media_formats/res/res_musiconhold.c (original)
+++ team/group/media_formats/res/res_musiconhold.c Mon Feb 17 06:06:31 2014
@@ -164,8 +164,8 @@
/*! Holds a reference to the MOH class. */
struct mohclass *class;
char name[MAX_MUSICCLASS];
- struct ast_format origwfmt;
- struct ast_format mohwfmt;
+ struct ast_format *origwfmt;
+ struct ast_format *mohwfmt;
int announcement;
int samples;
int sample_queue;
@@ -204,7 +204,7 @@
int total_files;
unsigned int flags;
/*! The format from the MOH source, not applicable to "files" mode */
- struct ast_format format;
+ struct ast_format *format;
/*! The pid of the external application delivering MOH */
int pid;
time_t start;
@@ -222,7 +222,7 @@
struct mohdata {
int pipe[2];
- struct ast_format origwfmt;
+ struct ast_format *origwfmt;
struct mohclass *parent;
struct ast_frame f;
AST_LIST_ENTRY(mohdata) list;
@@ -281,9 +281,11 @@
ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
- ast_format_clear(&state->mohwfmt); /* make sure to clear this format before restoring the original format. */
- if (state->origwfmt.id && ast_set_write_format(chan, &state->origwfmt)) {
- ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan), ast_getformatname(&state->origwfmt));
+ ao2_ref(state->mohwfmt, -1);
+ state->mohwfmt = NULL; /* make sure to clear this format before restoring the original format */
+ if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) {
+ ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan),
+ state->origwfmt->codec->name);
}
state->save_pos = state->pos;
@@ -397,15 +399,16 @@
/* In order to prevent a recursive call to this function as a result
* of setting the moh write format back on the channel. Clear
* the moh write format before setting the write format on the channel.*/
- if (&state->origwfmt.id) {
- struct ast_format tmp;
-
- ast_format_copy(&tmp, ast_channel_writeformat(chan));
- if (state->mohwfmt.id) {
- ast_format_clear(&state->origwfmt);
- ast_set_write_format(chan, &state->mohwfmt);
- }
- ast_format_copy(&state->origwfmt, &tmp);
+ if (state->origwfmt) {
+ struct ast_format *tmp;
+
+ tmp = ast_format_copy(ast_channel_writeformat(chan));
+ if (state->mohwfmt) {
+ ao2_cleanup(state->origwfmt);
+ state->origwfmt = NULL;
+ ast_set_write_format(chan, state->mohwfmt);
+ }
+ state->origwfmt = tmp;
}
}
@@ -429,8 +432,9 @@
ast_channel_unlock(chan);
state->samples += f->samples;
state->sample_queue -= f->samples;
- if (ast_format_cmp(&f->subclass.format, &state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
- ast_format_copy(&state->mohwfmt, &f->subclass.format);
+ if (ast_format_cmp(f->subclass.format, state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
+ ao2_cleanup(state->mohwfmt);
+ state->mohwfmt = ast_format_copy(f->subclass.format);
}
res = ast_write(chan, f);
ast_frfree(f);
@@ -478,8 +482,8 @@
}
state->class = mohclass_ref(class, "Reffing music class for channel");
- ast_format_copy(&state->origwfmt, ast_channel_writeformat(chan));
- ast_format_copy(&state->mohwfmt, ast_channel_writeformat(chan));
+ state->origwfmt = ast_format_copy(ast_channel_writeformat(chan));
+ state->mohwfmt = ast_format_copy(ast_channel_writeformat(chan));
/* For comparison on restart of MOH (see above) */
ast_copy_string(state->name, class->name, sizeof(state->name));
@@ -730,7 +734,7 @@
if ((strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir")) && AST_LIST_EMPTY(&class->members))
continue;
/* Read mp3 audio */
- len = ast_codec_get_len(&class->format, res);
+ len = ast_codec_determine_length(class->format->codec, res);
if ((res2 = read(class->srcfd, sbuf, len)) != len) {
if (!res2) {
@@ -934,7 +938,7 @@
fcntl(moh->pipe[1], F_SETFL, flags | O_NONBLOCK);
moh->f.frametype = AST_FRAME_VOICE;
- ast_format_copy(&moh->f.subclass.format, &cl->format);
+ moh->f.subclass.format = cl->format;
moh->f.offset = AST_FRIENDLY_OFFSET;
moh->parent = mohclass_ref(cl, "Reffing music class for mohdata parent");
@@ -950,7 +954,7 @@
{
struct mohdata *moh = data;
struct mohclass *class = moh->parent;
- struct ast_format oldwfmt;
+ struct ast_format *oldwfmt;
ao2_lock(class);
AST_LIST_REMOVE(&moh->parent->members, moh, list);
@@ -959,7 +963,7 @@
close(moh->pipe[0]);
close(moh->pipe[1]);
- ast_format_copy(&oldwfmt, &moh->origwfmt);
+ oldwfmt = moh->origwfmt;
moh->parent = class = mohclass_unref(class, "unreffing moh->parent upon deactivation of generator");
@@ -972,13 +976,15 @@
if (state && state->class) {
state->class = mohclass_unref(state->class, "Unreffing channel's music class upon deactivation of generator");
}
- if (oldwfmt.id && ast_set_write_format(chan, &oldwfmt)) {
+ if (oldwfmt && ast_set_write_format(chan, oldwfmt)) {
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n",
- ast_channel_name(chan), ast_getformatname(&oldwfmt));
+ ast_channel_name(chan), oldwfmt->codec->name);
}
ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
}
+
+ ao2_cleanup(oldwfmt);
}
static void *moh_alloc(struct ast_channel *chan, void *params)
@@ -1004,9 +1010,10 @@
}
if ((res = mohalloc(class))) {
- ast_format_copy(&res->origwfmt, ast_channel_writeformat(chan));
- if (ast_set_write_format(chan, &class->format)) {
- ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan), ast_codec2str(&class->format));
+ res->origwfmt = ast_format_copy(ast_channel_writeformat(chan));
+ if (ast_set_write_format(chan, class->format)) {
+ ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan),
+ class->format->codec->name);
moh_release(NULL, res);
res = NULL;
} else {
@@ -1023,7 +1030,7 @@
short buf[1280 + AST_FRIENDLY_OFFSET / 2];
int res;
- len = ast_codec_get_len(&moh->parent->format, samples);
+ len = ast_codec_determine_length(moh->parent->format->codec, samples);
if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, ast_channel_name(chan));
@@ -1035,7 +1042,7 @@
moh->f.datalen = res;
moh->f.data.ptr = buf + AST_FRIENDLY_OFFSET / 2;
- moh->f.samples = ast_codec_get_samples(&moh->f);
+ moh->f.samples = ast_codec_samples_count(&moh->f);
if (ast_write(chan, &moh->f) < 0) {
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
@@ -1342,6 +1349,8 @@
mohclass_unref(state->class, "Uh Oh. Cleaning up MOH with an active class");
ast_log(LOG_WARNING, "Uh Oh. Cleaning up MOH with an active class\n");
}
+ ao2_cleanup(state->origwfmt);
+ ao2_cleanup(state->mohwfmt);
ast_free(ast_channel_music_state(chan));
ast_channel_music_state_set(chan, NULL);
/* Only held a module reference if we had a music state */
@@ -1368,7 +1377,7 @@
ao2_alloc(sizeof(*class), moh_class_destructor)
#endif
)) {
- ast_format_set(&class->format, AST_FORMAT_SLINEAR, 0);
+ class->format = ao2_bump(ast_format_slin);
class->srcfd = -1;
}
@@ -1448,10 +1457,10 @@
else if (!strcasecmp(tmp->name, "sort") && !strcasecmp(tmp->value, "alpha"))
ast_set_flag(mohclass, MOH_SORTALPHA);
else if (!strcasecmp(tmp->name, "format")) {
- ast_getformatbyname(tmp->value, &mohclass->format);
- if (!mohclass->format.id) {
+ mohclass->format = ast_format_cache_get(tmp->value);
+ if (!mohclass->format) {
ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", tmp->value);
- ast_format_set(&mohclass->format, AST_FORMAT_SLINEAR, 0);
+ mohclass->format = ao2_bump(ast_format_slin);
}
}
}
@@ -1707,6 +1716,8 @@
class->timer = NULL;
}
+ ao2_cleanup(class->format);
+
/* Finally, collect the exit status of the monitor thread */
if (tid > 0) {
pthread_join(tid, NULL);
@@ -1801,10 +1812,10 @@
} else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "alpha")) {
ast_set_flag(class, MOH_SORTALPHA);
} else if (!strcasecmp(var->name, "format")) {
- ast_getformatbyname(var->value, &class->format);
- if (!class->format.id) {
+ class->format = ast_format_cache_get(var->value);
+ if (!class->format) {
ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
- ast_format_set(&class->format, AST_FORMAT_SLINEAR, 0);
+ class->format = ao2_bump(ast_format_slin);
}
}
}
@@ -1941,7 +1952,7 @@
ast_cli(a->fd, "\tApplication: %s\n", S_OR(class->args, "<none>"));
}
if (strcasecmp(class->mode, "files")) {
- ast_cli(a->fd, "\tFormat: %s\n", ast_getformatname(&class->format));
+ ast_cli(a->fd, "\tFormat: %s\n", class->format->codec->name);
}
}
ao2_iterator_destroy(&i);
More information about the asterisk-commits
mailing list