From 5782a47829599b9548c13f7d4f54d79df79338c2 Mon Sep 17 00:00:00 2001 From: Vitaly Zaitsev Date: Tue, 20 Feb 2018 14:00:02 +0100 Subject: [PATCH 1/2] Fixed build of libtgvoip on Big-Endian architectures. --- .../webrtc/common_audio/wav_file.cc | 20 ++++++++--- .../webrtc/common_audio/wav_header.cc | 34 ++++++++++++++++++- .../libtgvoip/webrtc_dsp/webrtc/typedefs.h | 14 +++++++- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_file.cc b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_file.cc index 2b9098a6c..4f99da712 100644 --- a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_file.cc +++ b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_file.cc @@ -77,9 +77,6 @@ size_t WavReader::num_samples() const { } size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) { -#ifndef WEBRTC_ARCH_LITTLE_ENDIAN -#error "Need to convert samples to big-endian when reading from WAV file" -#endif // There could be metadata after the audio; ensure we don't read it. num_samples = std::min(num_samples, num_samples_remaining_); const size_t read = @@ -88,6 +85,12 @@ size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) { RTC_CHECK(read == num_samples || feof(file_handle_)); RTC_CHECK_LE(read, num_samples_remaining_); num_samples_remaining_ -= read; +#ifndef WEBRTC_ARCH_LITTLE_ENDIAN + //convert to big-endian + for(size_t idx = 0; idx < num_samples; idx++) { + samples[idx] = (samples[idx]<<8) | (samples[idx]>>8); + } +#endif return read; } @@ -144,10 +147,17 @@ size_t WavWriter::num_samples() const { void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) { #ifndef WEBRTC_ARCH_LITTLE_ENDIAN -#error "Need to convert samples to little-endian when writing to WAV file" -#endif + int16_t * le_samples = new int16_t[num_samples]; + for(size_t idx = 0; idx < num_samples; idx++) { + le_samples[idx] = (samples[idx]<<8) | (samples[idx]>>8); + } + const size_t written = + fwrite(le_samples, sizeof(*le_samples), num_samples, file_handle_); + delete []le_samples; +#else const size_t written = fwrite(samples, sizeof(*samples), num_samples, file_handle_); +#endif RTC_CHECK_EQ(num_samples, written); num_samples_ += written; RTC_CHECK(num_samples_ >= written); // detect size_t overflow diff --git a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_header.cc b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_header.cc index 402ea1791..b11ee58c6 100644 --- a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_header.cc +++ b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/common_audio/wav_header.cc @@ -127,7 +127,39 @@ static inline std::string ReadFourCC(uint32_t x) { return std::string(reinterpret_cast(&x), 4); } #else -#error "Write be-to-le conversion functions" +static inline void WriteLE16(uint16_t* f, uint16_t x) { + *f = ((x << 8) & 0xff00) | ( ( x >> 8) & 0x00ff); +} + +static inline void WriteLE32(uint32_t* f, uint32_t x) { + *f = ( (x & 0x000000ff) << 24 ) + | ((x & 0x0000ff00) << 8) + | ((x & 0x00ff0000) >> 8) + | ((x & 0xff000000) >> 24 ); +} + +static inline void WriteFourCC(uint32_t* f, char a, char b, char c, char d) { + *f = (static_cast(a) << 24 ) + | (static_cast(b) << 16) + | (static_cast(c) << 8) + | (static_cast(d) ); +} + +static inline uint16_t ReadLE16(uint16_t x) { + return (( x & 0x00ff) << 8 )| ((x & 0xff00)>>8); +} + +static inline uint32_t ReadLE32(uint32_t x) { + return ( (x & 0x000000ff) << 24 ) + | ( (x & 0x0000ff00) << 8 ) + | ( (x & 0x00ff0000) >> 8) + | ( (x & 0xff000000) >> 24 ); +} + +static inline std::string ReadFourCC(uint32_t x) { + x = ReadLE32(x); + return std::string(reinterpret_cast(&x), 4); +} #endif static inline uint32_t RiffChunkSize(size_t bytes_in_payload) { diff --git a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/typedefs.h b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/typedefs.h index c960d95a4..22528557c 100644 --- a/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/typedefs.h +++ b/Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/typedefs.h @@ -48,7 +48,19 @@ #define WEBRTC_ARCH_32_BITS #define WEBRTC_ARCH_LITTLE_ENDIAN #else -#error Please add support for your architecture in typedefs.h +/* instead of failing, use typical unix defines... */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define WEBRTC_ARCH_BIG_ENDIAN +#else +#error __BYTE_ORDER__ is not defined +#endif +#if defined(__LP64__) +#define WEBRTC_ARCH_64_BITS +#else +#define WEBRTC_ARCH_32_BITS +#endif #endif #if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN)) From d77786c50009b231012852ee5d2f251bd1708a08 Mon Sep 17 00:00:00 2001 From: Vitaly Zaitsev Date: Tue, 20 Feb 2018 14:11:34 +0100 Subject: [PATCH 2/2] Allow to build Kepka on other than x86 architectures: armv7, aarch64, ppc64le, etc. --- Telegram/SourceFiles/base/build_config.h | 27 ++++++++++++++++++++++++ Telegram/SourceFiles/config.h.in | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/base/build_config.h b/Telegram/SourceFiles/base/build_config.h index 3bf067451..ea584c3e8 100644 --- a/Telegram/SourceFiles/base/build_config.h +++ b/Telegram/SourceFiles/base/build_config.h @@ -56,10 +56,37 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #define ARCH_CPU_X86_FAMILY 1 #define ARCH_CPU_X86_64 1 #define ARCH_CPU_64_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 #elif defined(_M_IX86) || defined(__i386__) #define ARCH_CPU_X86_FAMILY 1 #define ARCH_CPU_X86 1 #define ARCH_CPU_32_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#elif defined(__ARMEL__) +#define ARCH_CPU_ARM_FAMILY 1 +#define ARCH_CPU_ARMEL 1 +#define ARCH_CPU_32_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#elif defined(__aarch64__) +#define ARCH_CPU_ARM_FAMILY 1 +#define ARCH_CPU_ARM64 1 +#define ARCH_CPU_64_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#elif defined(__pnacl__) +#define ARCH_CPU_32_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#elif defined(__MIPSEL__) +#if defined(__LP64__) +#define ARCH_CPU_MIPS64_FAMILY 1 +#define ARCH_CPU_MIPS64EL 1 +#define ARCH_CPU_64_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#else +#define ARCH_CPU_MIPS_FAMILY 1 +#define ARCH_CPU_MIPSEL 1 +#define ARCH_CPU_32_BITS 1 +#define ARCH_CPU_LITTLE_ENDIAN 1 +#endif #else #error Please add support for your architecture in base/build_config.h #endif diff --git a/Telegram/SourceFiles/config.h.in b/Telegram/SourceFiles/config.h.in index 5ab8a6072..783ed1516 100644 --- a/Telegram/SourceFiles/config.h.in +++ b/Telegram/SourceFiles/config.h.in @@ -251,7 +251,7 @@ static const char *ApiHash = "344583e45741c457fe1862106095a5eb"; #endif #if Q_BYTE_ORDER == Q_BIG_ENDIAN -#error "Only little endian is supported!" +#warning "Big endian support in Kepka is experimental. Proceed with caution!" #endif // Q_BYTE_ORDER == Q_BIG_ENDIAN #ifndef BETA_VERSION_MACRO