summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2022-02-07 15:41:51 +0200
committerEfraim Flashner <efraim@flashner.co.il>2022-02-07 22:08:19 +0200
commit55e871844c0fe89123135b1cf598d167dd49eeb4 (patch)
tree8ea25a1ec8c8cf5f581d7b05608a79441695eb19 /gnu
parent3fe905ebdd949360b986144082734f8bdb2b6017 (diff)
gnu: webrtc-audio-processing: Fix building on powerpc architectures.
* gnu/packages/audio.scm (webrtc-audio-processing)[arguments]: Adjust custom arguments list to also fix building on all powerpc architectures. [native-inputs]: Add patch, local-file on riscv64-linux and powerpc architectures. * gnu/packages/patches/webrtc-audio-processing-big-endian.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/packages/audio.scm40
-rw-r--r--gnu/packages/patches/webrtc-audio-processing-big-endian.patch93
3 files changed, 127 insertions, 7 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index 09dd9acc2f..2a2fbf79d4 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1965,6 +1965,7 @@ dist_patch_DATA = \
%D%/packages/patches/warsow-qfusion-fix-bool-return-type.patch \
%D%/packages/patches/webkitgtk-share-store.patch \
%D%/packages/patches/webkitgtk-bind-all-fonts.patch \
+ %D%/packages/patches/webrtc-audio-processing-big-endian.patch \
%D%/packages/patches/websocketpp-fix-for-cmake-3.15.patch \
%D%/packages/patches/wicd-bitrate-none-fix.patch \
%D%/packages/patches/wicd-get-selected-profile-fix.patch \
diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm
index a8ecd32e4c..c2f85346bd 100644
--- a/gnu/packages/audio.scm
+++ b/gnu/packages/audio.scm
@@ -255,17 +255,43 @@ softsynth library that can be use with other applications.")
(base32 "1gsx7k77blfy171b6g3m0k0s0072v6jcawhmx1kjs9w5zlwdkzd0"))))
(build-system gnu-build-system)
(arguments
- ;; TODO: Move this to a snippet or remove with the upgrade to 1.0.
- (if (target-riscv64?)
+ ;; TODO: Move this to a snippet/patch or remove with the upgrade to 1.0.
+ (if (or (target-riscv64?)
+ (target-powerpc?))
(list
#:phases
#~(modify-phases %standard-phases
(add-after 'unpack 'patch-source
- (lambda _
- (substitute* "webrtc/typedefs.h"
- (("defined\\(__aarch64__\\)" all)
- (string-append
- all " || (defined(__riscv) && __riscv_xlen == 64)")))))))
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((patch-file
+ #$(local-file
+ (search-patch
+ "webrtc-audio-processing-big-endian.patch"))))
+ (invoke "patch" "--force" "-p1" "-i" patch-file)
+ (substitute* "webrtc/typedefs.h"
+ (("defined\\(__aarch64__\\)" all)
+ (string-append
+ ;; powerpc-linux
+ "(defined(__PPC__) && __SIZEOF_SIZE_T__ == 4)\n"
+ "#define WEBRTC_ARCH_32_BITS\n"
+ "#define WEBRTC_ARCH_BIG_ENDIAN\n"
+ ;; powerpc64-linux
+ "#elif (defined(__PPC64__) && defined(_BIG_ENDIAN))\n"
+ "#define WEBRTC_ARCH_64_BITS\n"
+ "#define WEBRTC_ARCH_BIG_ENDIAN\n"
+ ;; aarch64-linux
+ "#elif " all
+ ;; riscv64-linux
+ " || (defined(__riscv) && __riscv_xlen == 64)"
+ ;; powerpc64le-linux
+ " || (defined(__PPC64__) && defined(_LITTLE_ENDIAN))"))))))))
+ '()))
+ (native-inputs
+ (if (or (target-riscv64?)
+ (target-powerpc?))
+ (list
+ (local-file (search-patch "webrtc-audio-processing-big-endian.patch"))
+ patch)
'()))
(synopsis "WebRTC's Audio Processing Library")
(description "WebRTC-Audio-Processing library based on Google's
diff --git a/gnu/packages/patches/webrtc-audio-processing-big-endian.patch b/gnu/packages/patches/webrtc-audio-processing-big-endian.patch
new file mode 100644
index 0000000000..78333fe7b7
--- /dev/null
+++ b/gnu/packages/patches/webrtc-audio-processing-big-endian.patch
@@ -0,0 +1,93 @@
+https://bugs.freedesktop.org/show_bug.cgi?id=95738
+https://bugs.freedesktop.org/attachment.cgi?id=124025
+
+diff -up webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc.than webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc
+--- webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc.than 2016-05-24 08:28:45.749940095 -0400
++++ webrtc-audio-processing-0.2/webrtc/common_audio/wav_file.cc 2016-05-24 08:50:30.361020010 -0400
+@@ -64,9 +64,6 @@ WavReader::~WavReader() {
+ }
+
+ 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(rtc::checked_cast<uint32_t>(num_samples),
+ num_samples_remaining_);
+@@ -76,6 +73,12 @@ size_t WavReader::ReadSamples(size_t num
+ RTC_CHECK(read == num_samples || feof(file_handle_));
+ RTC_CHECK_LE(read, num_samples_remaining_);
+ num_samples_remaining_ -= rtc::checked_cast<uint32_t>(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;
+ }
+
+@@ -120,10 +123,17 @@ WavWriter::~WavWriter() {
+
+ 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_ += static_cast<uint32_t>(written);
+ RTC_CHECK(written <= std::numeric_limits<uint32_t>::max() ||
+diff -up webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc.than webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc
+--- webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc.than 2016-05-24 08:50:52.591379263 -0400
++++ webrtc-audio-processing-0.2/webrtc/common_audio/wav_header.cc 2016-05-24 08:52:08.552606848 -0400
+@@ -129,7 +129,39 @@ static inline std::string ReadFourCC(uin
+ return std::string(reinterpret_cast<char*>(&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<uint32_t>(a) << 24 )
++ | (static_cast<uint32_t>(b) << 16)
++ | (static_cast<uint32_t>(c) << 8)
++ | (static_cast<uint32_t>(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<char*>(&x), 4);
++}
+ #endif
+
+ static inline uint32_t RiffChunkSize(uint32_t bytes_in_payload) {