asterisk-11.x-chan-dongle: fix audio endianess problem
[feed/telephony.git] / net / asterisk-11.x-chan-dongle / patches / 100-fix-audio-on-big-endian-systems.patch
1 Index: asterisk11-chan-dongle-1.1r35/channel.c
2 ===================================================================
3 --- asterisk11-chan-dongle-1.1r35.orig/channel.c
4 +++ asterisk11-chan-dongle-1.1r35/channel.c
5 @@ -495,6 +495,19 @@ again:
6 }
7 }
8
9 +// see https://github.com/openwrt/telephony/issues/7
10 +static inline void change_audio_endianness_to_le(struct iovec *iov, int iovcnt)
11 +{
12 +#if __BYTE_ORDER == __LITTLE_ENDIAN
13 + return; // nothing to do
14 +#else
15 + for(;iovcnt-->0;iov++)
16 + {
17 + ast_swapcopy_samples(iov->iov_base, iov->iov_base, iov->iov_len/2);
18 + }
19 +#endif
20 +}
21 +
22 #/* */
23 static void timing_write (struct pvt* pvt)
24 {
25 @@ -522,6 +535,7 @@ static void timing_write (struct pvt* pv
26 iovcnt = mixb_read_n_iov (&pvt->a_write_mixb, iov, FRAME_SIZE);
27 mixb_read_n_iov (&pvt->a_write_mixb, iov, FRAME_SIZE);
28 mixb_read_upd (&pvt->a_write_mixb, FRAME_SIZE);
29 + change_audio_endianness_to_le(iov, iovcnt);
30 }
31 else if (used > 0)
32 {
33 @@ -535,6 +549,7 @@ static void timing_write (struct pvt* pv
34 iov[iovcnt].iov_base = silence_frame;
35 iov[iovcnt].iov_len = FRAME_SIZE - used;
36 iovcnt++;
37 + change_audio_endianness_to_le(iov, iovcnt);
38 }
39 else
40 {
41 @@ -544,6 +559,7 @@ static void timing_write (struct pvt* pv
42 iov[0].iov_base = silence_frame;
43 iov[0].iov_len = FRAME_SIZE;
44 iovcnt = 1;
45 + // ignore endianness for zeros
46 // continue;
47 }
48