- Revision
- 285576
- Author
- [email protected]
- Date
- 2021-11-10 07:47:05 -0800 (Wed, 10 Nov 2021)
Log Message
[iOS] Add audio gain in case category switches to PlayAndRecord
https://bugs.webkit.org/show_bug.cgi?id=232941
<rdar://85250248>
Reviewed by Eric Carlson.
Source/WebCore:
Add a audio category change observer.
Observer needs to be in the process where the actual iOS shared audio session is living (GPUProcess typically).
Manually tested.
* WebCore.xcodeproj/project.pbxproj:
* platform/audio/cocoa/AudioSampleBufferList.h:
* platform/audio/ios/AudioSessionIOS.h:
* platform/audio/ios/AudioSessionIOS.mm:
Source/WebKit:
In case of PlayAndRecord, apply a static gain of 5 to audio rendered from MediaStreamTracks.
For that purpose, observe changes to the AudioSession category and react upon it.
* GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp:
(WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::Unit):
(WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::start):
(WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::render):
(WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::categoryDidChange):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (285575 => 285576)
--- trunk/Source/WebCore/ChangeLog 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebCore/ChangeLog 2021-11-10 15:47:05 UTC (rev 285576)
@@ -1,3 +1,20 @@
+2021-11-10 Youenn Fablet <[email protected]>
+
+ [iOS] Add audio gain in case category switches to PlayAndRecord
+ https://bugs.webkit.org/show_bug.cgi?id=232941
+ <rdar://85250248>
+
+ Reviewed by Eric Carlson.
+
+ Add a audio category change observer.
+ Observer needs to be in the process where the actual iOS shared audio session is living (GPUProcess typically).
+ Manually tested.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/audio/cocoa/AudioSampleBufferList.h:
+ * platform/audio/ios/AudioSessionIOS.h:
+ * platform/audio/ios/AudioSessionIOS.mm:
+
2021-11-10 Tim Nguyen <[email protected]>
Migrate DialogElementEnabled from RuntimeFlags to Settings
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (285575 => 285576)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-11-10 15:47:05 UTC (rev 285576)
@@ -4409,7 +4409,7 @@
CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */; };
CD336F6417FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6317FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h */; };
CD336F6817FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */; };
- CD36C1622607E78600C8C529 /* AudioSessionIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CD36C1612607E78600C8C529 /* AudioSessionIOS.h */; };
+ CD36C1622607E78600C8C529 /* AudioSessionIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CD36C1612607E78600C8C529 /* AudioSessionIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD36C16B260A65CC00C8C529 /* SharedRoutingArbitrator.h in Headers */ = {isa = PBXBuildFile; fileRef = CD36C168260A63D300C8C529 /* SharedRoutingArbitrator.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD3A495F17A9D01B00274E42 /* MediaSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495617A9D01B00274E42 /* MediaSource.h */; };
CD3A496217A9D01B00274E42 /* SourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495917A9D01B00274E42 /* SourceBuffer.h */; };
Modified: trunk/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h (285575 => 285576)
--- trunk/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h 2021-11-10 15:47:05 UTC (rev 285576)
@@ -45,7 +45,7 @@
static inline size_t audioBufferListSizeForStream(const CAAudioStreamDescription&);
- static void applyGain(AudioBufferList&, float, AudioStreamDescription::PCMFormat);
+ WEBCORE_EXPORT static void applyGain(AudioBufferList&, float, AudioStreamDescription::PCMFormat);
void applyGain(float);
OSStatus copyFrom(const AudioSampleBufferList&, size_t count = SIZE_MAX);
Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h (285575 => 285576)
--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-11-10 15:47:05 UTC (rev 285576)
@@ -44,6 +44,9 @@
void setHostProcessAttribution(audit_token_t) final;
+ using CategoryChangedObserver = WTF::Observer<void(AudioSession&, CategoryType)>;
+ WEBCORE_EXPORT static void addAudioSessionCategoryChangedObserver(const CategoryChangedObserver&);
+
private:
// AudioSession
CategoryType category() const final;
Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm (285575 => 285576)
--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-11-10 15:47:05 UTC (rev 285576)
@@ -97,6 +97,18 @@
namespace WebCore {
+static WeakHashSet<AudioSessionIOS::CategoryChangedObserver>& audioSessionCategoryChangedObservers()
+{
+ static NeverDestroyed<WeakHashSet<AudioSessionIOS::CategoryChangedObserver>> observers;
+ return observers;
+}
+
+void AudioSessionIOS::addAudioSessionCategoryChangedObserver(const CategoryChangedObserver& observer)
+{
+ audioSessionCategoryChangedObservers().add(observer);
+ observer(AudioSession::sharedSession(), AudioSession::sharedSession().category());
+}
+
static void setEligibleForSmartRouting(bool eligible)
{
#if PLATFORM(IOS)
@@ -205,6 +217,8 @@
#if !PLATFORM(IOS_FAMILY_SIMULATOR) && !PLATFORM(MACCATALYST)
ASSERT(!error);
#endif
+ for (auto& observer : audioSessionCategoryChangedObservers())
+ observer(*this, category());
}
AudioSession::CategoryType AudioSessionIOS::category() const
Modified: trunk/Source/WebKit/ChangeLog (285575 => 285576)
--- trunk/Source/WebKit/ChangeLog 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebKit/ChangeLog 2021-11-10 15:47:05 UTC (rev 285576)
@@ -1,3 +1,20 @@
+2021-11-10 Youenn Fablet <[email protected]>
+
+ [iOS] Add audio gain in case category switches to PlayAndRecord
+ https://bugs.webkit.org/show_bug.cgi?id=232941
+ <rdar://85250248>
+
+ Reviewed by Eric Carlson.
+
+ In case of PlayAndRecord, apply a static gain of 5 to audio rendered from MediaStreamTracks.
+ For that purpose, observe changes to the AudioSession category and react upon it.
+
+ * GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp:
+ (WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::Unit):
+ (WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::start):
+ (WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::render):
+ (WebKit::RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::categoryDidChange):
+
2021-11-10 Tim Nguyen <[email protected]>
Migrate DialogElementEnabled from RuntimeFlags to Settings
Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp (285575 => 285576)
--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp 2021-11-10 15:11:20 UTC (rev 285575)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp 2021-11-10 15:47:05 UTC (rev 285576)
@@ -34,6 +34,7 @@
#include "IPCSemaphore.h"
#include "Logging.h"
#include <WebCore/AudioMediaStreamTrackRendererInternalUnit.h>
+#include <WebCore/AudioSampleBufferList.h>
#include <WebCore/AudioSession.h>
#include <WebCore/AudioUtilities.h>
#include <wtf/WeakPtr.h>
@@ -45,6 +46,10 @@
#include <WebCore/WebAudioBufferList.h>
#endif
+#if PLATFORM(IOS_FAMILY)
+#include <WebCore/AudioSessionIOS.h>
+#endif
+
namespace WebKit {
class RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit : public CanMakeWeakPtr<RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit> {
@@ -62,6 +67,10 @@
private:
void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription&, size_t);
+#if PLATFORM(IOS_FAMILY)
+ void categoryDidChange(WebCore::AudioSession::CategoryType);
+#endif
+
AudioMediaStreamTrackRendererInternalUnitIdentifier m_identifier;
Ref<IPC::Connection> m_connection;
UniqueRef<WebCore::AudioMediaStreamTrackRendererInternalUnit> m_localUnit;
@@ -73,6 +82,11 @@
std::unique_ptr<WebCore::CARingBuffer> m_ringBuffer;
#endif
bool m_isPlaying { false };
+#if PLATFORM(IOS_FAMILY)
+ float m_volume { 1.0 };
+ WebCore::AudioStreamDescription::PCMFormat m_format { WebCore::AudioStreamDescription::PCMFormat::Float32 };
+ WebCore::AudioSessionIOS::CategoryChangedObserver m_categoryChangeObserver;
+#endif
};
RemoteAudioMediaStreamTrackRendererInternalUnitManager::RemoteAudioMediaStreamTrackRendererInternalUnitManager(GPUConnectionToWebProcess& gpuConnectionToWebProcess)
@@ -135,6 +149,9 @@
: m_identifier(identifier)
, m_connection(WTFMove(connection))
, m_localUnit(WebCore::AudioMediaStreamTrackRendererInternalUnit::createLocalInternalUnit(renderCallback(*this), resetCallback(*this)))
+#if PLATFORM(IOS_FAMILY)
+ , m_categoryChangeObserver([this](auto&, auto category) { categoryDidChange(category); })
+#endif
{
m_localUnit->retrieveFormatDescription([weakThis = WeakPtr { *this }, this, callback = WTFMove(callback)](auto&& description) mutable {
if (!weakThis || !description) {
@@ -146,6 +163,9 @@
m_frameChunkSize = std::max(WebCore::AudioUtilities::renderQuantumSize, tenMsSampleSize);
callback(*description, m_frameChunkSize);
});
+#if PLATFORM(IOS_FAMILY)
+ WebCore::AudioSessionIOS::addAudioSessionCategoryChangedObserver(m_categoryChangeObserver);
+#endif
}
RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::~Unit()
@@ -168,6 +188,9 @@
m_isPlaying = true;
m_ringBuffer = WebCore::CARingBuffer::adoptStorage(makeUniqueRef<ReadOnlySharedRingBufferStorage>(handle), description, numberOfFrames).moveToUniquePtr();
m_renderSemaphore = WTFMove(semaphore);
+#if PLATFORM(IOS_FAMILY)
+ m_format = description.format();
+#endif
m_localUnit->start();
}
@@ -191,6 +214,11 @@
if (m_ringBuffer->fetchIfHasEnoughData(&list, sampleCount, m_readOffset)) {
m_readOffset += sampleCount;
status = noErr;
+
+#if PLATFORM(IOS_FAMILY)
+ if (m_volume != 1)
+ WebCore::AudioSampleBufferList::applyGain(list, m_volume, m_format);
+#endif
}
auto requestedSamplesCount = m_generateOffset;
@@ -201,6 +229,14 @@
return status;
}
+#if PLATFORM(IOS_FAMILY)
+void RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::categoryDidChange(WebCore::AudioSession::CategoryType type)
+{
+ m_volume = type == WebCore::AudioSession::CategoryType::PlayAndRecord ? 5 : 1;
+ RELEASE_LOG(WebRTC, "RemoteAudioMediaStreamTrackRendererInternalUnitManager::Unit::categoryDidChange %d, setting volume to %f", (int)type, m_volume);
+}
+#endif
+
} // namespace WebKit
#endif // ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)