From patchwork Tue Dec 20 08:19:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Faiz X-Patchwork-Id: 45439 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0E29427BBED; Tue, 20 Dec 2022 08:21:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 91C9127BBE9 for ; Tue, 20 Dec 2022 08:21:25 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7XsD-0002U0-OG; Tue, 20 Dec 2022 03:21:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7Xry-0002PE-SR for guix-patches@gnu.org; Tue, 20 Dec 2022 03:21:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p7Xry-0002Yk-IH for guix-patches@gnu.org; Tue, 20 Dec 2022 03:21:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p7Xry-0008UW-Cf for guix-patches@gnu.org; Tue, 20 Dec 2022 03:21:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60214] [PATCH core-updates] gnu: webrtc-audio-processing: Update to 1.0. Resent-From: Adam Faiz Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 20 Dec 2022 08:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60214 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60214@debbugs.gnu.org Cc: paren@disroot.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.167152441332593 (code B ref -1); Tue, 20 Dec 2022 08:21:02 +0000 Received: (at submit) by debbugs.gnu.org; 20 Dec 2022 08:20:13 +0000 Received: from localhost ([127.0.0.1]:43303 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7Xr7-0008Tb-O7 for submit@debbugs.gnu.org; Tue, 20 Dec 2022 03:20:13 -0500 Received: from lists.gnu.org ([209.51.188.17]:49920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7Xr5-0008TV-Jx for submit@debbugs.gnu.org; Tue, 20 Dec 2022 03:20:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7Xqg-0002Em-Hd for guix-patches@gnu.org; Tue, 20 Dec 2022 03:19:59 -0500 Received: from knopi.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7XqZ-0001cX-LD for guix-patches@gnu.org; Tue, 20 Dec 2022 03:19:39 -0500 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id B459040D6D; Tue, 20 Dec 2022 09:19:30 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R2dKODkZV3FB; Tue, 20 Dec 2022 09:19:26 +0100 (CET) Message-ID: <06c3f1db-b41b-2314-b597-0d16c549605e@disroot.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1671524366; bh=488kZ5YsGvkqlLpxfPzKODeP/dzLvbWhUinb375PY44=; h=Date:To:From:Subject:Cc; b=EgLjZnp7lo491L1MVQfmfcN/NsLm4zXzYin8YkiUdjmOeAEwfLuVfsGONN7lKDqqA W3G8Kij+kk/hnTcZi4SClVuNi7cDvWyQzOvsG/VUI8t1EQrpLG1bP6jLdt6d/S6YST IpchofV3/aMmHb9H+1eEWhy+A19/z07QhV9do86y0AkSeKFNrzOS6fq7dguS1eZt9I F4cNmUszD7mXDTWOmVE3pBK0uITj/+xdnWISor55EQGKGi/3PlBA536mycQqVSrysm mqW2H88+KmbAdLsIh5p/Qc2sJpziVdlavv0uCFfNkVWZ9ddAc5Ll0Bw9su8Y5lMlnt z/0qS97/2Q4Vw== Date: Tue, 20 Dec 2022 16:19:21 +0800 MIME-Version: 1.0 Content-Language: en-US Received-SPF: pass client-ip=178.21.23.139; envelope-from=adam.faiz@disroot.org; helo=knopi.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Adam Faiz X-ACL-Warn: , Adam Faiz via Guix-patches X-Patchwork-Original-From: Adam Faiz via Guix-patches via From: Adam Faiz Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From 64c8e00eab770ca697c39feabfbc60927e4ccd57 Mon Sep 17 00:00:00 2001 From: AwesomeAdam54321 Date: Tue, 20 Dec 2022 15:18:58 +0800 Subject: [PATCH] gnu: webrtc-audio-processing: Update to 1.0. * gnu/packages/audio.scm (webrtc-audio-processing): Update to 1.0. [source]: Add snippet that fixes building on riscv and powerpc architectures. [arguments]: Remove patch-source phase. [build-system]: Update to meson-build-system. [inputs]: Add abseil-cpp as input. * gnu/packages/patches/webrtc-audio-processing-big-endian.patch: Update to 1.0. * gnu/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. --- gnu/local.mk | 1 + gnu/packages/audio.scm | 77 +++--- .../webrtc-audio-processing-big-endian.patch | 249 ++++++++++++------ ...dio-processing-wav-header-big-endian.patch | 152 +++++++++++ 4 files changed, 357 insertions(+), 122 deletions(-) create mode 100644 gnu/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch +++ b/gnu/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch @@ -0,0 +1,152 @@ +https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/127 +https://github.com/desktop-app/tg_owt/commit/65f002e + +--- webrtc-audio-processing-1.0/webrtc/common_audio/wav_header.cc 2020-11-28 03:30:53.000000000 +0800 ++++ webrtc-audio-processing-1.0/webrtc/common_audio/wav_header.cc 2022-12-19 20:28:31.511187824 +0800 +@@ -15,6 +15,8 @@ + + #include "common_audio/wav_header.h" + ++#include ++ + #include + #include + #include +@@ -26,10 +28,6 @@ + namespace webrtc { + namespace { + +-#ifndef WEBRTC_ARCH_LITTLE_ENDIAN +-#error "Code not working properly for big endian platforms." +-#endif +- + #pragma pack(2) + struct ChunkHeader { + uint32_t ID; +@@ -80,6 +78,7 @@ + // read audio samples. + #pragma pack(2) + struct WavHeaderPcm { ++ WavHeaderPcm() = default; + WavHeaderPcm(const WavHeaderPcm&) = default; + WavHeaderPcm& operator=(const WavHeaderPcm&) = default; + RiffHeader riff; +@@ -95,6 +94,7 @@ + // WAV implementation. + #pragma pack(2) + struct WavHeaderIeeeFloat { ++ WavHeaderIeeeFloat() = default; + WavHeaderIeeeFloat(const WavHeaderIeeeFloat&) = default; + WavHeaderIeeeFloat& operator=(const WavHeaderIeeeFloat&) = default; + RiffHeader riff; +@@ -172,6 +172,8 @@ + if (readable->Read(chunk_header, sizeof(*chunk_header)) != + sizeof(*chunk_header)) + return false; // EOF. ++ chunk_header->Size = le32toh(chunk_header->Size); ++ + if (ReadFourCC(chunk_header->ID) == sought_chunk_id) + return true; // Sought chunk found. + // Ignore current chunk by skipping its payload. +@@ -185,6 +187,13 @@ + if (readable->Read(&(fmt_subchunk->AudioFormat), kFmtPcmSubchunkSize) != + kFmtPcmSubchunkSize) + return false; ++ fmt_subchunk->AudioFormat = le16toh(fmt_subchunk->AudioFormat); ++ fmt_subchunk->NumChannels = le16toh(fmt_subchunk->NumChannels); ++ fmt_subchunk->SampleRate = le32toh(fmt_subchunk->SampleRate); ++ fmt_subchunk->ByteRate = le32toh(fmt_subchunk->ByteRate); ++ fmt_subchunk->BlockAlign = le16toh(fmt_subchunk->BlockAlign); ++ fmt_subchunk->BitsPerSample = le16toh(fmt_subchunk->BitsPerSample); ++ + const uint32_t fmt_size = fmt_subchunk->header.Size; + if (fmt_size != kFmtPcmSubchunkSize) { + // There is an optional two-byte extension field permitted to be present +@@ -212,19 +221,22 @@ + auto header = rtc::MsanUninitialized({}); + const size_t bytes_in_payload = bytes_per_sample * num_samples; + +- header.riff.header.ID = PackFourCC('R', 'I', 'F', 'F'); +- header.riff.header.Size = RiffChunkSize(bytes_in_payload, *header_size); +- header.riff.Format = PackFourCC('W', 'A', 'V', 'E'); +- header.fmt.header.ID = PackFourCC('f', 'm', 't', ' '); +- header.fmt.header.Size = kFmtPcmSubchunkSize; +- header.fmt.AudioFormat = MapWavFormatToHeaderField(WavFormat::kWavFormatPcm); +- header.fmt.NumChannels = static_cast(num_channels); +- header.fmt.SampleRate = sample_rate; +- header.fmt.ByteRate = ByteRate(num_channels, sample_rate, bytes_per_sample); +- header.fmt.BlockAlign = BlockAlign(num_channels, bytes_per_sample); +- header.fmt.BitsPerSample = static_cast(8 * bytes_per_sample); +- header.data.header.ID = PackFourCC('d', 'a', 't', 'a'); +- header.data.header.Size = static_cast(bytes_in_payload); ++ header.riff.header.ID = htole32(PackFourCC('R', 'I', 'F', 'F')); ++ header.riff.header.Size = ++ htole32(RiffChunkSize(bytes_in_payload, *header_size)); ++ header.riff.Format = htole32(PackFourCC('W', 'A', 'V', 'E')); ++ header.fmt.header.ID = htole32(PackFourCC('f', 'm', 't', ' ')); ++ header.fmt.header.Size = htole32(kFmtPcmSubchunkSize); ++ header.fmt.AudioFormat = ++ htole16(MapWavFormatToHeaderField(WavFormat::kWavFormatPcm)); ++ header.fmt.NumChannels = htole16(num_channels); ++ header.fmt.SampleRate = htole32(sample_rate); ++ header.fmt.ByteRate = ++ htole32(ByteRate(num_channels, sample_rate, bytes_per_sample)); ++ header.fmt.BlockAlign = htole16(BlockAlign(num_channels, bytes_per_sample)); ++ header.fmt.BitsPerSample = htole16(8 * bytes_per_sample); ++ header.data.header.ID = htole32(PackFourCC('d', 'a', 't', 'a')); ++ header.data.header.Size = htole32(bytes_in_payload); + + // Do an extra copy rather than writing everything to buf directly, since buf + // might not be correctly aligned. +@@ -243,24 +255,26 @@ + auto header = rtc::MsanUninitialized({}); + const size_t bytes_in_payload = bytes_per_sample * num_samples; + +- header.riff.header.ID = PackFourCC('R', 'I', 'F', 'F'); +- header.riff.header.Size = RiffChunkSize(bytes_in_payload, *header_size); +- header.riff.Format = PackFourCC('W', 'A', 'V', 'E'); +- header.fmt.header.ID = PackFourCC('f', 'm', 't', ' '); +- header.fmt.header.Size = kFmtIeeeFloatSubchunkSize; ++ header.riff.header.ID = htole32(PackFourCC('R', 'I', 'F', 'F')); ++ header.riff.header.Size = ++ htole32(RiffChunkSize(bytes_in_payload, *header_size)); ++ header.riff.Format = htole32(PackFourCC('W', 'A', 'V', 'E')); ++ header.fmt.header.ID = htole32(PackFourCC('f', 'm', 't', ' ')); ++ header.fmt.header.Size = htole32(kFmtIeeeFloatSubchunkSize); + header.fmt.AudioFormat = +- MapWavFormatToHeaderField(WavFormat::kWavFormatIeeeFloat); +- header.fmt.NumChannels = static_cast(num_channels); +- header.fmt.SampleRate = sample_rate; +- header.fmt.ByteRate = ByteRate(num_channels, sample_rate, bytes_per_sample); +- header.fmt.BlockAlign = BlockAlign(num_channels, bytes_per_sample); +- header.fmt.BitsPerSample = static_cast(8 * bytes_per_sample); +- header.fmt.ExtensionSize = 0; +- header.fact.header.ID = PackFourCC('f', 'a', 'c', 't'); +- header.fact.header.Size = 4; +- header.fact.SampleLength = static_cast(num_channels * num_samples); +- header.data.header.ID = PackFourCC('d', 'a', 't', 'a'); +- header.data.header.Size = static_cast(bytes_in_payload); ++ htole16(MapWavFormatToHeaderField(WavFormat::kWavFormatIeeeFloat)); ++ header.fmt.NumChannels = htole16(num_channels); ++ header.fmt.SampleRate = htole32(sample_rate); ++ header.fmt.ByteRate = ++ htole32(ByteRate(num_channels, sample_rate, bytes_per_sample)); ++ header.fmt.BlockAlign = htole16(BlockAlign(num_channels, bytes_per_sample)); ++ header.fmt.BitsPerSample = htole16(8 * bytes_per_sample); ++ header.fmt.ExtensionSize = htole16(0); ++ header.fact.header.ID = htole32(PackFourCC('f', 'a', 'c', 't')); ++ header.fact.header.Size = htole32(4); ++ header.fact.SampleLength = htole32(num_channels * num_samples); ++ header.data.header.ID = htole32(PackFourCC('d', 'a', 't', 'a')); ++ header.data.header.Size = htole32(bytes_in_payload); + + // Do an extra copy rather than writing everything to buf directly, since buf + // might not be correctly aligned. +@@ -389,6 +403,7 @@ + return false; + if (ReadFourCC(header.riff.Format) != "WAVE") + return false; ++ header.riff.header.Size = le32toh(header.riff.header.Size); + + // Find "fmt " and "data" chunks. While the official Wave file specification + // does not put requirements on the chunks order, it is uncommon to find the diff --git a/gnu/local.mk b/gnu/local.mk index af570125bd..4dfc03acce 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1996,6 +1996,7 @@ dist_patch_DATA = \ %D%/packages/patches/warsow-qfusion-fix-bool-return-type.patch \ %D%/packages/patches/webkitgtk-adjust-bubblewrap-paths.patch \ %D%/packages/patches/webrtc-audio-processing-big-endian.patch \ + %D%/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch \ %D%/packages/patches/webrtc-for-telegram-desktop-fix-gcc12-cstdint.patch \ %D%/packages/patches/websocketpp-fix-for-cmake-3.15.patch \ %D%/packages/patches/widelands-add-missing-map-include.patch \ diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm index e480ce9e58..140eeb2e1d 100644 --- a/gnu/packages/audio.scm +++ b/gnu/packages/audio.scm @@ -67,6 +67,7 @@ (define-module (gnu packages audio) #:use-module (gnu packages boost) #:use-module (gnu packages check) #:use-module (gnu packages compression) + #:use-module (gnu packages cpp) #:use-module (gnu packages curl) #:use-module (gnu packages dbm) #:use-module (gnu packages documentation) @@ -249,55 +250,45 @@ (define-public wildmidi (define-public webrtc-audio-processing (package (name "webrtc-audio-processing") - (version "0.3.1") + (version "1.0") (source (origin (method url-fetch) (uri (string-append "http://freedesktop.org/software/pulseaudio/" - name "/" name "-" version ".tar.xz")) + name "/" name "-" version ".tar.gz")) (sha256 - (base32 "1gsx7k77blfy171b6g3m0k0s0072v6jcawhmx1kjs9w5zlwdkzd0")))) - (build-system gnu-build-system) - (arguments - ;; 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* (#: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) - '())) + (base32 "0vwkw5xw8l37f5vbzbkipjsf03r7b8nnrfbfbhab8bkvf79306j4")) + (modules '((guix build utils))) + (snippet + #~(begin + ;; https://gitlab.freedesktop.org/pulseaudio/webrtc-audio-processing/-/issues/4 + (substitute* "meson.build" + (("absl_flags_registry") "absl_flags_reflection")) + (substitute* "webrtc/rtc_base/system/arch.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))"))))) + (patches + (search-patches + "webrtc-audio-processing-big-endian.patch" + "webrtc-audio-processing-wav-header-big-endian.patch")))) + (build-system meson-build-system) + (inputs + (list abseil-cpp)) (synopsis "WebRTC's Audio Processing Library") (description "WebRTC-Audio-Processing library based on Google's implementation of WebRTC.") diff --git a/gnu/packages/patches/webrtc-audio-processing-big-endian.patch b/gnu/packages/patches/webrtc-audio-processing-big-endian.patch index 78333fe7b7..c77fd87c1f 100644 --- a/gnu/packages/patches/webrtc-audio-processing-big-endian.patch +++ b/gnu/packages/patches/webrtc-audio-processing-big-endian.patch @@ -1,93 +1,184 @@ https://bugs.freedesktop.org/show_bug.cgi?id=95738 -https://bugs.freedesktop.org/attachment.cgi?id=124025 +https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/127 +https://github.com/desktop-app/tg_owt/commit/65f002e -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() { +--- webrtc-audio-processing-1.0/webrtc/common_audio/wav_file.cc 2020-11-28 03:30:53.000000000 +0800 ++++ webrtc-audio-processing-1.0/webrtc/common_audio/wav_file.cc 2022-12-20 12:54:22.058539694 +0800 +@@ -10,6 +10,7 @@ + + #include "common_audio/wav_file.h" + ++#include + #include + + #include +@@ -34,6 +35,38 @@ + format == WavFormat::kWavFormatIeeeFloat; } - - size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) { + ++template ++void TranslateEndianness(T* destination, const T* source, size_t length) { ++ static_assert(sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8, ++ "no converter, use integral types"); ++ if (sizeof(T) == 2) { ++ const uint16_t* src = reinterpret_cast(source); ++ uint16_t* dst = reinterpret_cast(destination); ++ for (size_t index = 0; index < length; index++) { ++ dst[index] = bswap_16(src[index]); ++ } ++ } ++ if (sizeof(T) == 4) { ++ const uint32_t* src = reinterpret_cast(source); ++ uint32_t* dst = reinterpret_cast(destination); ++ for (size_t index = 0; index < length; index++) { ++ dst[index] = bswap_32(src[index]); ++ } ++ } ++ if (sizeof(T) == 8) { ++ const uint64_t* src = reinterpret_cast(source); ++ uint64_t* dst = reinterpret_cast(destination); ++ for (size_t index = 0; index < length; index++) { ++ dst[index] = bswap_64(src[index]); ++ } ++ } ++} ++ ++template ++void TranslateEndianness(T* buffer, size_t length) { ++ TranslateEndianness(buffer, buffer, length); ++} ++ + // Doesn't take ownership of the file handle and won't close it. + class WavHeaderFileReader : public WavHeaderReader { + public: +@@ -90,10 +123,6 @@ + + size_t WavReader::ReadSamples(const size_t num_samples, + int16_t* const 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(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(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); -+ } +- + size_t num_samples_left_to_read = num_samples; + size_t next_chunk_start = 0; + while (num_samples_left_to_read > 0 && num_unread_samples_ > 0) { +@@ -105,6 +134,9 @@ + num_bytes_read = file_.Read(samples_to_convert.data(), + chunk_size * sizeof(samples_to_convert[0])); + num_samples_read = num_bytes_read / sizeof(samples_to_convert[0]); ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(samples_to_convert.data(), num_samples_read); ++#endif + + for (size_t j = 0; j < num_samples_read; ++j) { + samples[next_chunk_start + j] = FloatToS16(samples_to_convert[j]); +@@ -114,6 +146,10 @@ + num_bytes_read = file_.Read(&samples[next_chunk_start], + chunk_size * sizeof(samples[0])); + num_samples_read = num_bytes_read / sizeof(samples[0]); ++ ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(&samples[next_chunk_start], num_samples_read); +#endif - return read; + } + RTC_CHECK(num_samples_read == 0 || (num_bytes_read % num_samples_read) == 0) + << "Corrupt file: file ended in the middle of a sample."; +@@ -129,10 +165,6 @@ } - -@@ -120,10 +123,17 @@ WavWriter::~WavWriter() { - + + size_t WavReader::ReadSamples(const size_t num_samples, float* const samples) { +-#ifndef WEBRTC_ARCH_LITTLE_ENDIAN +-#error "Need to convert samples to big-endian when reading from WAV file" +-#endif +- + size_t num_samples_left_to_read = num_samples; + size_t next_chunk_start = 0; + while (num_samples_left_to_read > 0 && num_unread_samples_ > 0) { +@@ -145,6 +177,9 @@ + num_bytes_read = file_.Read(samples_to_convert.data(), + chunk_size * sizeof(samples_to_convert[0])); + num_samples_read = num_bytes_read / sizeof(samples_to_convert[0]); ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(samples_to_convert.data(), num_samples_read); ++#endif + + for (size_t j = 0; j < num_samples_read; ++j) { + samples[next_chunk_start + j] = +@@ -155,6 +190,9 @@ + num_bytes_read = file_.Read(&samples[next_chunk_start], + chunk_size * sizeof(samples[0])); + num_samples_read = num_bytes_read / sizeof(samples[0]); ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(&samples[next_chunk_start], num_samples_read); ++#endif + + for (size_t j = 0; j < num_samples_read; ++j) { + samples[next_chunk_start + j] = +@@ -213,24 +251,32 @@ + } + void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) { - #ifndef WEBRTC_ARCH_LITTLE_ENDIAN +-#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; +- + for (size_t i = 0; i < num_samples; i += kMaxChunksize) { + const size_t num_remaining_samples = num_samples - i; + const size_t num_samples_to_write = + std::min(kMaxChunksize, num_remaining_samples); + + if (format_ == WavFormat::kWavFormatPcm) { ++#ifndef WEBRTC_ARCH_BIG_ENDIAN + RTC_CHECK( + file_.Write(&samples[i], num_samples_to_write * sizeof(samples[0]))); +#else - const size_t written = - fwrite(samples, sizeof(*samples), num_samples, file_handle_); ++ std::array converted_samples; ++ TranslateEndianness(converted_samples.data(), &samples[i], ++ num_samples_to_write); ++ RTC_CHECK( ++ file_.Write(converted_samples.data(), ++ num_samples_to_write * sizeof(converted_samples[0]))); ++#endif + } else { + RTC_CHECK_EQ(format_, WavFormat::kWavFormatIeeeFloat); + std::array converted_samples; + for (size_t j = 0; j < num_samples_to_write; ++j) { + converted_samples[j] = S16ToFloat(samples[i + j]); + } ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(converted_samples.data(), num_samples_to_write); +#endif - RTC_CHECK_EQ(num_samples, written); - num_samples_ += static_cast(written); - RTC_CHECK(written <= std::numeric_limits::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(&x), 4); + RTC_CHECK( + file_.Write(converted_samples.data(), + num_samples_to_write * sizeof(converted_samples[0]))); +@@ -243,10 +289,6 @@ } - #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(uint32_t bytes_in_payload) { + + void WavWriter::WriteSamples(const float* samples, size_t num_samples) { +-#ifndef WEBRTC_ARCH_LITTLE_ENDIAN +-#error "Need to convert samples to little-endian when writing to WAV file" +-#endif +- + for (size_t i = 0; i < num_samples; i += kMaxChunksize) { + const size_t num_remaining_samples = num_samples - i; + const size_t num_samples_to_write = +@@ -257,6 +299,9 @@ + for (size_t j = 0; j < num_samples_to_write; ++j) { + converted_samples[j] = FloatS16ToS16(samples[i + j]); + } ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(converted_samples.data(), num_samples_to_write); ++#endif + RTC_CHECK( + file_.Write(converted_samples.data(), + num_samples_to_write * sizeof(converted_samples[0]))); +@@ -266,6 +311,9 @@ + for (size_t j = 0; j < num_samples_to_write; ++j) { + converted_samples[j] = FloatS16ToFloat(samples[i + j]); + } ++#ifdef WEBRTC_ARCH_BIG_ENDIAN ++ TranslateEndianness(converted_samples.data(), num_samples_to_write); ++#endif + RTC_CHECK( + file_.Write(converted_samples.data(), + num_samples_to_write * sizeof(converted_samples[0]))); diff --git a/gnu/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch b/gnu/packages/patches/webrtc-audio-processing-wav-header-big-endian.patch new file mode 100644 index 0000000000..b25c2e364f --- /dev/null