[asterisk-commits] dlee: branch dlee/format_janitor r392762 - in /team/dlee/format_janitor: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 24 15:20:58 CDT 2013
Author: dlee
Date: Mon Jun 24 15:20:56 2013
New Revision: 392762
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392762
Log:
Moved the janitor work over that didn't make it in with the recording patch
Modified:
team/dlee/format_janitor/include/asterisk/channel.h
team/dlee/format_janitor/main/channel.c
Modified: team/dlee/format_janitor/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/format_janitor/include/asterisk/channel.h?view=diff&rev=392762&r1=392761&r2=392762
==============================================================================
--- team/dlee/format_janitor/include/asterisk/channel.h (original)
+++ team/dlee/format_janitor/include/asterisk/channel.h Mon Jun 24 15:20:56 2013
@@ -1837,6 +1837,31 @@
/*! \brief Send empty audio to prime a channel driver */
int ast_prod(struct ast_channel *chan);
+
+/*! \brief An object which resets a channel's formats on cleanup */
+struct ast_format_janitor;
+
+/*!
+ * \brief Creates a janitor object which resets a channel's format specifiers
+ * when the janitor is cleaned up. Meant for use with RAII_VAR().
+ *
+ * \code
+ * RAII_VAR(struct ast_format_janitor *, janitor,
+ * ast_format_janitor_create(chan), ast_format_janitor_dtor);
+ * \endocde
+ *
+ * \param chan Channel to reset at destruction.
+ * \return Janitor object.
+ * \return \c NULL on error.
+ */
+struct ast_format_janitor *ast_format_janitor_create(struct ast_channel *chan);
+
+/*!
+ * \brief Destroy a janitor object, created with ast_format_janitor_create().
+ *
+ * \param janitor Janitor object to destroy. May be \c NULL.
+ */
+void ast_format_janitor_dtor(struct ast_format_janitor *janitor);
/*!
* \brief Sets read format on channel chan from capabilities
Modified: team/dlee/format_janitor/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/format_janitor/main/channel.c?view=diff&rev=392762&r1=392761&r2=392762
==============================================================================
--- team/dlee/format_janitor/main/channel.c (original)
+++ team/dlee/format_janitor/main/channel.c Mon Jun 24 15:20:56 2013
@@ -5290,6 +5290,62 @@
}
ast_channel_unlock(chan);
return res;
+}
+
+struct ast_format_janitor {
+ struct ast_channel *channel;
+ struct ast_format rfmt;
+ struct ast_format wfmt;
+};
+
+struct ast_format_janitor *ast_format_janitor_create(struct ast_channel *chan)
+{
+ struct ast_format_janitor *janitor;
+
+ if (chan == NULL) {
+ return NULL;
+ }
+
+ janitor = ast_calloc(1, sizeof(*janitor));
+ if (janitor == NULL) {
+ return NULL;
+ }
+
+ janitor->channel = ast_channel_ref(chan);
+ ast_format_clear(&janitor->rfmt);
+ ast_format_copy(&janitor->rfmt, ast_channel_readformat(chan));
+ ast_format_clear(&janitor->wfmt);
+ ast_format_copy(&janitor->wfmt, ast_channel_writeformat(chan));
+
+ return janitor;
+}
+
+void ast_format_janitor_dtor(struct ast_format_janitor *janitor)
+{
+ int res;
+
+ if (janitor == NULL) {
+ return;
+ }
+
+ if (janitor->rfmt.id != ast_channel_readformat(janitor->channel)->id) {
+ res = ast_set_read_format(janitor->channel, &janitor->rfmt);
+ if (res != 0) {
+ ast_log(LOG_WARNING,
+ "Failed to reset channel read format");
+ }
+ }
+
+ if (janitor->wfmt.id != ast_channel_writeformat(janitor->channel)->id) {
+ res = ast_set_write_format(janitor->channel, &janitor->wfmt);
+ if (res != 0) {
+ ast_log(LOG_WARNING,
+ "Failed to reset channel write format");
+ }
+ }
+
+ janitor->channel = ast_channel_unref(janitor->channel);
+ ast_free(janitor);
}
struct set_format_trans_access {
More information about the asterisk-commits
mailing list