]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Binaural synthesis (confbridge): interleaved two-channel audio. 21/3521/3
authorfrahaase <fra.haase@googlemail.com>
Fri, 12 Aug 2016 16:22:02 +0000 (18:22 +0200)
committerDennis Guse <dennis.guse@alumni.tu-berlin.de>
Mon, 3 Oct 2016 08:12:50 +0000 (03:12 -0500)
Asterisk only supports mono audio at the moment.
This patch adds interleaved two-channel audio to Asterisk's channels.

ASTERISK-26292

Change-Id: I7a547cea0fd3c6d1e502709d9e7e39605035757a

include/asterisk/channel.h
include/asterisk/translate.h
main/channel.c

index 14bd32c0793dfec4bb9b60a1ae806e781867ddee..94f72b879a21b8073e2e00c2cb25e141f61bceea 100644 (file)
@@ -2016,6 +2016,16 @@ int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_ca
  */
 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);
 
+/*!
+ * \brief Sets write format for a channel.
+ * All internal data will than be handled in an interleaved format. (needed by binaural opus)
+ *
+ * \param chan channel to change
+ * \param format format to set for writing
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_set_write_format_interleaved_stereo(struct ast_channel *chan, struct ast_format *format);
+
 /*!
  * \brief Sends text to a channel
  *
index b8cd219713b5aebe61a825de96cf2887e697d30a..8188eb8ebfec52a31d14c5749b0ee63f8b9689ef 100644 (file)
@@ -231,6 +231,7 @@ struct ast_trans_pvt {
         * explicit_dst contains an attribute which describes whether both parties
         * want to do forward-error correction (FEC). */
        struct ast_format *explicit_dst;
+       int interleaved_stereo;     /*!< indicates if samples are in interleaved order, for stereo lin */
 };
 
 /*! \brief generic frameout function */
index 1f18d53b15ccdfd84356bbd18816a9533f5725c2..f8b218fd02e8a57f1410a0168588eaae05f06511 100644 (file)
@@ -5407,7 +5407,7 @@ static const struct set_format_access set_format_access_write = {
        .setoption = AST_OPTION_FORMAT_WRITE,
 };
 
-static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction)
+static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, const int direction, int interleaved_stereo)
 {
        struct ast_trans_pvt *trans_pvt;
        struct ast_format_cap *cap_native;
@@ -5509,16 +5509,20 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set,
        }
 
        /* Now we have a good choice for both. */
+       trans_pvt = access->get_trans(chan);
        if ((ast_format_cmp(rawformat, best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
                (ast_format_cmp(format, best_set_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
                ((ast_format_cmp(rawformat, format) != AST_FORMAT_CMP_NOT_EQUAL) || access->get_trans(chan))) {
-               /* the channel is already in these formats, so nothing to do */
-               ast_channel_unlock(chan);
-               return 0;
+               /* the channel is already in these formats, so nothing to do, unless the interleaved format is not set correctly */
+               if (trans_pvt != NULL) {
+                       if (trans_pvt->interleaved_stereo == interleaved_stereo) {
+                               ast_channel_unlock(chan);
+                               return 0;
+                       }
+               }
        }
 
        /* Free any translation we have right now */
-       trans_pvt = access->get_trans(chan);
        if (trans_pvt) {
                ast_translator_free_path(trans_pvt);
                access->set_trans(chan, NULL);
@@ -5536,9 +5540,11 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set,
                if (!direction) {
                        /* reading */
                        trans_pvt = ast_translator_build_path(best_set_fmt, best_native_fmt);
+                       trans_pvt->interleaved_stereo = 0;
                } else {
                        /* writing */
                        trans_pvt = ast_translator_build_path(best_native_fmt, best_set_fmt);
+                       trans_pvt->interleaved_stereo = interleaved_stereo;
                }
                access->set_trans(chan, trans_pvt);
                res = trans_pvt ? 0 : -1;
@@ -5578,7 +5584,7 @@ int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
        }
        ast_format_cap_append(cap, format, 0);
 
-       res = set_format(chan, cap, 0);
+       res = set_format(chan, cap, 0, 0);
 
        ao2_cleanup(cap);
        return res;
@@ -5586,7 +5592,25 @@ int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
 
 int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *cap)
 {
-       return set_format(chan, cap, 0);
+       return set_format(chan, cap, 0, 0);
+}
+
+int ast_set_write_format_interleaved_stereo(struct ast_channel *chan, struct ast_format *format)
+{
+       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+       int res;
+
+       ast_assert(format != NULL);
+
+       if (!cap) {
+               return -1;
+       }
+       ast_format_cap_append(cap, format, 0);
+
+       res = set_format(chan, cap, 1, 1);
+
+       ao2_cleanup(cap);
+       return res;
 }
 
 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
@@ -5601,7 +5625,7 @@ int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
        }
        ast_format_cap_append(cap, format, 0);
 
-       res = set_format(chan, cap, 1);
+       res = set_format(chan, cap, 1, 0);
 
        ao2_cleanup(cap);
        return res;
@@ -5609,7 +5633,7 @@ int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
 
 int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *cap)
 {
-       return set_format(chan, cap, 1);
+       return set_format(chan, cap, 1, 0);
 }
 
 const char *ast_channel_reason2str(int reason)