git: fd50b0334df1 - main - www/chromium: fix audio playback with ALSA

From: Rene Ladan <rene_at_FreeBSD.org>
Date: Sat, 05 Mar 2022 22:03:34 UTC
The branch main has been updated by rene:

URL: https://cgit.FreeBSD.org/ports/commit/?id=fd50b0334df1c720befc62ae613bfa8862efb336

commit fd50b0334df1c720befc62ae613bfa8862efb336
Author:     Robert Nagy <robert@openbsd.org>
AuthorDate: 2022-03-05 22:01:23 +0000
Commit:     Rene Ladan <rene@FreeBSD.org>
CommitDate: 2022-03-05 22:03:19 +0000

    www/chromium: fix audio playback with ALSA
    
    PR:             262365
    Reported by:    o.hushchenkov@gmail.com
    Tested by:      o.hushchenkov@gmail.com
---
 www/chromium/Makefile                              |  1 +
 .../patch-media_audio_alsa_audio__manager__alsa.cc | 54 ++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/www/chromium/Makefile b/www/chromium/Makefile
index b7ee68b405cf..e9c5492b11d5 100644
--- a/www/chromium/Makefile
+++ b/www/chromium/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	chromium
 PORTVERSION=	99.0.4844.51
+PORTREVISION=	1
 CATEGORIES=	www
 MASTER_SITES=	https://commondatastorage.googleapis.com/chromium-browser-official/ \
 		https://nerd.hu/distfiles/:fonts
diff --git a/www/chromium/files/patch-media_audio_alsa_audio__manager__alsa.cc b/www/chromium/files/patch-media_audio_alsa_audio__manager__alsa.cc
new file mode 100644
index 000000000000..deb7ec59d8a0
--- /dev/null
+++ b/www/chromium/files/patch-media_audio_alsa_audio__manager__alsa.cc
@@ -0,0 +1,54 @@
+--- media/audio/alsa/audio_manager_alsa.cc.orig	2022-03-05 18:42:44 UTC
++++ media/audio/alsa/audio_manager_alsa.cc
+@@ -89,7 +89,9 @@ void AudioManagerAlsa::GetAlsaAudioDevices(StreamType 
+   int card = -1;
+ 
+   // Loop through the sound cards to get ALSA device hints.
++#if !BUILDFLAG(IS_BSD)
+   while (!wrapper_->CardNext(&card) && card >= 0) {
++#endif
+     void** hints = NULL;
+     int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints);
+     if (!error) {
+@@ -101,7 +103,9 @@ void AudioManagerAlsa::GetAlsaAudioDevices(StreamType 
+       DLOG(WARNING) << "GetAlsaAudioDevices: unable to get device hints: "
+                     << wrapper_->StrError(error);
+     }
++#if !BUILDFLAG(IS_BSD)
+   }
++#endif
+ }
+ 
+ void AudioManagerAlsa::GetAlsaDevicesInfo(AudioManagerAlsa::StreamType type,
+@@ -184,7 +188,11 @@ bool AudioManagerAlsa::IsAlsaDeviceAvailable(
+   // goes through software conversion if needed (e.g. incompatible
+   // sample rate).
+   // TODO(joi): Should we prefer "hw" instead?
++#if BUILDFLAG(IS_BSD)
++  static const char kDeviceTypeDesired[] = "plug";
++#else
+   static const char kDeviceTypeDesired[] = "plughw";
++#endif
+   return strncmp(kDeviceTypeDesired, device_name,
+                  base::size(kDeviceTypeDesired) - 1) == 0;
+ }
+@@ -206,7 +214,9 @@ bool AudioManagerAlsa::HasAnyAlsaAudioDevice(
+   // Loop through the sound cards.
+   // Don't use snd_device_name_hint(-1,..) since there is an access violation
+   // inside this ALSA API with libasound.so.2.0.0.
++#if !BUILDFLAG(IS_BSD)
+   while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) {
++#endif
+     int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints);
+     if (!error) {
+       for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) {
+@@ -230,7 +240,9 @@ bool AudioManagerAlsa::HasAnyAlsaAudioDevice(
+       DLOG(WARNING) << "HasAnyAudioDevice: unable to get device hints: "
+                     << wrapper_->StrError(error);
+     }
++#if !BUILDFLAG(IS_BSD)
+   }
++#endif
+ 
+   return has_device;
+ }