Diff
Modified: branches/safari-612.3.6.0-branch/Source/WebCore/ChangeLog (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebCore/ChangeLog 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebCore/ChangeLog 2021-11-12 00:43:42 UTC (rev 285689)
@@ -1,3 +1,24 @@
+2021-11-11 Alan Coon <[email protected]>
+
+ Apply patch. rdar://problem/83673859
+
+ 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-11 Kocsen Chung <[email protected]>
Cherry-pick r285531. rdar://problem/83381842
Modified: branches/safari-612.3.6.0-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-11-12 00:43:42 UTC (rev 285689)
@@ -4358,7 +4358,7 @@
CD336F6417FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6317FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h */; };
CD336F6717FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD336F6517FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp */; };
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: branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/cocoa/AudioSampleBufferList.h 2021-11-12 00:43:42 UTC (rev 285689)
@@ -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: branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.h (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-11-12 00:43:42 UTC (rev 285689)
@@ -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: branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-11-12 00:43:42 UTC (rev 285689)
@@ -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: branches/safari-612.3.6.0-branch/Source/WebKit/ChangeLog (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebKit/ChangeLog 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebKit/ChangeLog 2021-11-12 00:43:42 UTC (rev 285689)
@@ -1,3 +1,24 @@
+2021-11-11 Alan Coon <[email protected]>
+
+ Apply patch. rdar://problem/83673859
+
+ 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-11 Kocsen Chung <[email protected]>
Cherry-pick r285550. rdar://problem/85075538
Modified: branches/safari-612.3.6.0-branch/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp (285688 => 285689)
--- branches/safari-612.3.6.0-branch/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp 2021-11-12 00:00:54 UTC (rev 285688)
+++ branches/safari-612.3.6.0-branch/Source/WebKit/GPUProcess/webrtc/RemoteAudioMediaStreamTrackRendererInternalUnitManager.cpp 2021-11-12 00:43:42 UTC (rev 285689)
@@ -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> {
@@ -61,6 +66,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;
@@ -72,6 +81,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)
@@ -127,6 +141,9 @@
: m_identifier(identifier)
, m_connection(WTFMove(connection))
, m_localUnit(WebCore::AudioMediaStreamTrackRendererInternalUnit::createLocalInternalUnit(renderCallback(*this)))
+#if PLATFORM(IOS_FAMILY)
+ , m_categoryChangeObserver([this](auto&, auto category) { categoryDidChange(category); })
+#endif
{
m_localUnit->retrieveFormatDescription([weakThis = makeWeakPtr(this), this, callback = WTFMove(callback)](auto&& description) mutable {
if (!weakThis || !description) {
@@ -138,6 +155,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()
@@ -155,6 +175,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();
}
@@ -178,6 +201,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;
@@ -188,6 +216,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)