asterisk-11.x-chan-dongle: fix audio endianess problem
authorDaniel Golle <daniel@makrotopia.org>
Wed, 24 Jun 2015 18:50:09 +0000 (20:50 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 24 Jun 2015 18:50:09 +0000 (20:50 +0200)
Github user @ljakob supplied a patch in
https://github.com/openwrt/telephony/issues/7
--
Hi, I've solved the problem myself - it was an endianness bug:

Here what gave me the correct clue:

    audio is broken in one direction only
    audio is fine if you disable any timing-source within asterisk (no good idea if you want to use IAX)
    audio was fine on my x86 box
    I had a long look into the code :)

The bug is in the audio handling of timing_write in channel.c, the data sent to the socket is not changed to the correct endianness if a timing device is used.

Here is my patch, it's untested (just one call yet) but it's trivial enough:
http://www.hugo.weite-welt.com/asterisk13_chan_dongle_endianess.patch
it is against asterisk13 branch in
https://github.com/oleg-krv/asterisk-chan-dongle.git
but should fit into other asterisk versions nicely
--
This commit imports the patch above to asterisk-11.x-chan-dongle.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
net/asterisk-11.x-chan-dongle/Makefile
net/asterisk-11.x-chan-dongle/patches/100-fix-audio-on-big-endian-systems.patch [new file with mode: 0644]

index 7c0b204db024630b774786d61372f52f5ac026b9..5a7ecbc210329b385d78b18f286eef3f2c45c515 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=asterisk11-chan-dongle
 PKG_VERSION:=1.1r35
 PKG_REV:=28a46567a88cebdc365db6f294e682246fd2dd7b
-PKG_RELEASE:=4
+PKG_RELEASE:=5
 
 PKG_SOURCE_SUBDIR:=asterisk11-chan-dongle-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz
diff --git a/net/asterisk-11.x-chan-dongle/patches/100-fix-audio-on-big-endian-systems.patch b/net/asterisk-11.x-chan-dongle/patches/100-fix-audio-on-big-endian-systems.patch
new file mode 100644 (file)
index 0000000..3fc546d
--- /dev/null
@@ -0,0 +1,48 @@
+Index: asterisk11-chan-dongle-1.1r35/channel.c
+===================================================================
+--- asterisk11-chan-dongle-1.1r35.orig/channel.c
++++ asterisk11-chan-dongle-1.1r35/channel.c
+@@ -495,6 +495,19 @@ again:
+       }
+ }
++// see https://github.com/openwrt/telephony/issues/7
++static inline void change_audio_endianness_to_le(struct iovec *iov, int iovcnt)
++{
++#if __BYTE_ORDER == __LITTLE_ENDIAN
++   return; // nothing to do
++#else
++   for(;iovcnt-->0;iov++)
++   {
++      ast_swapcopy_samples(iov->iov_base, iov->iov_base, iov->iov_len/2);
++   }
++#endif
++}
++
+ #/* */
+ static void timing_write (struct pvt* pvt)
+ {
+@@ -522,6 +535,7 @@ static void timing_write (struct pvt* pv
+                       iovcnt = mixb_read_n_iov (&pvt->a_write_mixb, iov, FRAME_SIZE);
+                       mixb_read_n_iov (&pvt->a_write_mixb, iov, FRAME_SIZE);
+                       mixb_read_upd (&pvt->a_write_mixb, FRAME_SIZE);
++                      change_audio_endianness_to_le(iov, iovcnt);
+               }
+               else if (used > 0)
+               {
+@@ -535,6 +549,7 @@ static void timing_write (struct pvt* pv
+                       iov[iovcnt].iov_base    = silence_frame;
+                       iov[iovcnt].iov_len     = FRAME_SIZE - used;
+                       iovcnt++;
++                      change_audio_endianness_to_le(iov, iovcnt);
+               }
+               else
+               {
+@@ -544,6 +559,7 @@ static void timing_write (struct pvt* pv
+                       iov[0].iov_base         = silence_frame;
+                       iov[0].iov_len          = FRAME_SIZE;
+                       iovcnt                  = 1;
++                      // ignore endianness for zeros
+ //                    continue;
+               }