[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300566 - in /team/dvossel/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 5 00:08:33 UTC 2011
Author: dvossel
Date: Tue Jan 4 18:08:29 2011
New Revision: 300566
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300566
Log:
beginning changes to channel.c required for ast_format conversion
Modified:
team/dvossel/fixtheworld_phase1_step3/include/asterisk/channel.h
team/dvossel/fixtheworld_phase1_step3/include/asterisk/data.h
team/dvossel/fixtheworld_phase1_step3/main/channel.c
team/dvossel/fixtheworld_phase1_step3/main/data.c
Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/channel.h?view=diff&rev=300566&r1=300565&r2=300566
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/channel.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/channel.h Tue Jan 4 18:08:29 2011
@@ -824,7 +824,7 @@
int fdno; /*!< Which fd had an event detected on */
int streamid; /*!< For streaming playback, the schedule ID */
int vstreamid; /*!< For streaming video playback, the schedule ID */
- struct ast_format *oldwriteformat; /*!< Original writer format */
+ struct ast_format oldwriteformat; /*!< Original writer format */
int timingfd; /*!< Timing fd */
enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */
int rings; /*!< Number of rings so far */
Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/data.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/data.h?view=diff&rev=300566&r1=300565&r2=300566
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/data.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/data.h Tue Jan 4 18:08:29 2011
@@ -800,6 +800,16 @@
}
/*!
+ * \brief Add the codec in the root node based on the format parameter.
+ * \param[in] root The astdata root node where to add the codec node.
+ * \param[in] node_name The name of the node where we are going to add the codec.
+ * \param[in] format The codec allowed.
+ * \return < 0 on error.
+ * \return 0 on success.
+ */
+int ast_data_add_codec(struct ast_data *root, const char *node_name, struct ast_format *format);
+
+/*!
* \brief Add the list of codecs in the root node based on the capability parameter.
* \param[in] root The astdata root node where to add the codecs node.
* \param[in] node_name The name of the node where we are going to add the list of
Modified: team/dvossel/fixtheworld_phase1_step3/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/channel.c?view=diff&rev=300566&r1=300565&r2=300566
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/channel.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/channel.c Tue Jan 4 18:08:29 2011
@@ -372,12 +372,12 @@
}
}
- ast_data_add_codecs(tree, "oldwriteformat", chan->oldwriteformat);
+ ast_data_add_codec(tree, "oldwriteformat", &chan->oldwriteformat);
+ ast_data_add_codec(tree, "readformat", &chan->readformat);
+ ast_data_add_codec(tree, "writeformat", &chan->writeformat);
+ ast_data_add_codec(tree, "rawreadformat", &chan->rawreadformat);
+ ast_data_add_codec(tree, "rawwriteformat", &chan->rawwriteformat);
ast_data_add_codecs(tree, "nativeformats", chan->nativeformats);
- ast_data_add_codecs(tree, "readformat", chan->readformat);
- ast_data_add_codecs(tree, "writeformat", chan->writeformat);
- ast_data_add_codecs(tree, "rawreadformat", chan->rawreadformat);
- ast_data_add_codecs(tree, "rawwriteformat", chan->rawwriteformat);
/* state */
enum_node = ast_data_add_node(tree, "state");
@@ -593,7 +593,7 @@
(cl->tech->devicestate) ? "yes" : "no",
(cl->tech->indicate) ? "yes" : "no",
(cl->tech->transfer) ? "yes" : "no",
- ast_getformatname_multiple(buf, sizeof(buf), (cl->tech->capabilities) ? cl->tech->capabilities : -1),
+ ast_getformatname_multiple(buf, sizeof(buf), cl->tech->capabilities),
(cl->tech->send_digit_begin) ? "yes" : "no",
(cl->tech->send_digit_end) ? "yes" : "no",
(cl->tech->send_html) ? "yes" : "no",
@@ -1031,15 +1031,14 @@
AST_FORMAT_G723_1,
};
char buf[512];
-
- ast_cap_iter_start(cap);
- while (!ast_cap_iter_next(cap, result)) {
- if (result->id == prefs[x]) {
- ast_cap_iter_end(cap);
+ int x;
+
+ /* Find the first preferred codec in the format given */
+ for (x = 0; x < ARRAY_LEN(prefs); x++) {
+ if (ast_cap_iscompatible(cap, ast_format_set(result, prefs[x], 0))) {
return result;
}
}
- ast_cap_iter_end(cap);
memset(result, 0, sizeof(*result));
ast_log(LOG_WARNING, "Don't know any of %s formats\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
@@ -2962,7 +2961,7 @@
if (!tmp || !generate)
return 0;
- res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50);
+ res = generate(chan, tmp, 0, ast_format_rate(&chan->writeformat) / 50);
chan->generatordata = tmp;
@@ -3523,9 +3522,9 @@
chan->generatordata = NULL; /* reset, to let writes go through */
- if (f->subclass.codec != chan->writeformat) {
+ if (ast_format_cmp(&f->subclass.format, &chan->writeformat) == AST_FORMAT_CMP_NOT_EQUAL) {
float factor;
- factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass.codec));
+ factor = ((float) ast_format_rate(&chan->writeformat)) / ((float) ast_format_rate(&f->subclass.format));
samples = (int) ( ((float) f->samples) * factor );
} else {
samples = f->samples;
@@ -4041,11 +4040,11 @@
ast_frfree(f);
f = &ast_null_frame;
}
- } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass.codec & chan->nativeformats)) {
+ } else if ((f->frametype == AST_FRAME_VOICE) && !ast_cap_iscompatible(chan->nativeformats, &f->subclass.format)) {
/* This frame is not one of the current native formats -- drop it on the floor */
char to[200];
ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n",
- chan->name, ast_getformatname(f->subclass.codec), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats));
+ chan->name, ast_getformatname(&f->subclass.format), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats));
ast_frfree(f);
f = &ast_null_frame;
} else if ((f->frametype == AST_FRAME_VOICE)) {
@@ -4061,7 +4060,7 @@
#ifndef MONITOR_CONSTANT_DELAY
int jump = chan->outsmpl - chan->insmpl - 4 * f->samples;
if (jump >= 0) {
- jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass.codec), ast_format_rate(chan->monitor->read_stream->fmt->format));
+ jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(&f->subclass.format), ast_format_rate(&chan->monitor->read_stream->fmt->format));
if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1)
ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
chan->insmpl += (chan->outsmpl - chan->insmpl) + f->samples;
@@ -4522,12 +4521,11 @@
int ast_prod(struct ast_channel *chan)
{
struct ast_frame a = { AST_FRAME_VOICE };
- char nothing[128];
/* Send an empty audio frame to get things moving */
if (chan->_state != AST_STATE_UP) {
ast_debug(1, "Prodding channel '%s'\n", chan->name);
- a.subclass.codec = chan->rawwriteformat;
+ ast_format_copy(&chan->rawwriteformat, &a.subclass.format);
a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
a.src = "ast_prod"; /* this better match check in ast_write */
if (ast_write(chan, &a))
@@ -4778,12 +4776,12 @@
if (chan->tech->write == NULL)
break; /*! \todo XXX should return 0 maybe ? */
- if (ast_opt_generic_plc && fr->subclass.codec == AST_FORMAT_SLINEAR) {
+ if (ast_opt_generic_plc && fr->subclass.format.id == AST_FORMAT_SLINEAR) {
apply_plc(chan, fr);
}
/* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
- if (fr->subclass.codec == chan->rawwriteformat)
+ if (ast_format_cmp(&fr->subclass.format, &chan->rawwriteformat) != AST_FORMAT_CMP_NOT_EQUAL)
f = fr;
else
f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
Modified: team/dvossel/fixtheworld_phase1_step3/main/data.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/data.c?view=diff&rev=300566&r1=300565&r2=300566
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/data.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/data.c Tue Jan 4 18:08:29 2011
@@ -3100,7 +3100,7 @@
return RESULT_SUCCESS;
}
-int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability)
+int ast_data_add_codec(struct ast_data *root, const char *node_name, struct ast_format *format)
{
struct ast_data *codecs, *codec;
size_t fmlist_size;
@@ -3113,7 +3113,36 @@
}
fmlist = ast_get_format_list(&fmlist_size);
for (x = 0; x < fmlist_size; x++) {
- if (fmlist[x].bits & capability) {
+ if (fmlist[x].id == format->id) {
+ codec = ast_data_add_node(codecs, "codec");
+ if (!codec) {
+ return -1;
+ }
+ ast_data_add_str(codec, "name", fmlist[x].name);
+ ast_data_add_int(codec, "samplespersecond", fmlist[x].samplespersecond);
+ ast_data_add_str(codec, "description", fmlist[x].desc);
+ ast_data_add_int(codec, "frame_length", fmlist[x].fr_len);
+ }
+ }
+
+ return 0;
+}
+
+int ast_data_add_codecs(struct ast_data *root, const char *node_name, struct ast_cap *cap)
+{
+ struct ast_data *codecs, *codec;
+ size_t fmlist_size;
+ const struct ast_format_list *fmlist;
+ struct ast_format tmp_fmt;
+ int x;
+
+ codecs = ast_data_add_node(root, node_name);
+ if (!codecs) {
+ return -1;
+ }
+ fmlist = ast_get_format_list(&fmlist_size);
+ for (x = 0; x < fmlist_size; x++) {
+ if (ast_cap_iscompatible(cap, ast_set_format(&tmp_fmt, fmlist[x].id, 0))) {
codec = ast_data_add_node(codecs, "codec");
if (!codec) {
return -1;
More information about the asterisk-commits
mailing list