[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser] 63/73: Bug 1755700: Use AgileReference for cross-apartment AudioSessionControl use r=Jamie, a=RyanVM
This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch geckoview-102.3.0esr-12.0-1
in repository tor-browser.
commit a592e02f6803ddb5d8d12fccc0be6aa5ddf76694
Author: David Parks <daparks@xxxxxxxxxxx>
AuthorDate: Fri Jul 29 19:32:14 2022 +0000
Bug 1755700: Use AgileReference for cross-apartment AudioSessionControl use r=Jamie, a=RyanVM
A deadlock issue with our main thread audio playback handling arises when we try to destroy the AudioSessionControl from the MTA, despite it being an MTA object. We therefore dispatch its destruction to the main thread (STA) so the deadlock is impossible. In order to use it from the STA, we should wrap it in an AgileReference.
Differential Revision: https://phabricator.services.mozilla.com/D152301
---
widget/windows/AudioSession.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/widget/windows/AudioSession.cpp b/widget/windows/AudioSession.cpp
index c696f2f50af21..a9d683195e33d 100644
--- a/widget/windows/AudioSession.cpp
+++ b/widget/windows/AudioSession.cpp
@@ -22,6 +22,7 @@
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "mozilla/Attributes.h"
+#include "mozilla/mscom/AgileReference.h"
#include "mozilla/mscom/Utils.h"
#include "mozilla/Mutex.h"
#include "mozilla/WindowsVersion.h"
@@ -249,9 +250,23 @@ void AudioSession::StopInternal(const MutexAutoLock& aProofOfLock) {
// Deleting the IAudioSessionControl COM object requires the STA/main thread.
// Audio code may concurrently be running on the main thread and it may
// block waiting for this to complete, creating deadlock. So we destroy the
- // IAudioSessionControl on the main thread instead.
+ // IAudioSessionControl on the main thread instead. In order to do that, we
+ // need to marshall the object to the main thread's apartment with an
+ // AgileReference.
+ const IID IID_IAudioSessionControl = __uuidof(IAudioSessionControl);
+ auto agileAsc = MakeUnique<mozilla::mscom::AgileReference>(
+ IID_IAudioSessionControl, mAudioSessionControl);
+ mAudioSessionControl = nullptr;
NS_DispatchToMainThread(NS_NewRunnableFunction(
- "FreeAudioSession", [asc = std::move(mAudioSessionControl)] { /* */ }));
+ "FreeAudioSession",
+ [agileAsc = std::move(agileAsc), IID_IAudioSessionControl] {
+ RefPtr<IAudioSessionControl> toDelete;
+ [[maybe_unused]] HRESULT hr = agileAsc->Resolve(
+ IID_IAudioSessionControl, getter_AddRefs(toDelete));
+ MOZ_ASSERT(SUCCEEDED(hr));
+ // Now release the AgileReference which holds our only reference to the
+ // IAudioSessionControl.
+ }));
}
void CopynsID(nsID& lhs, const nsID& rhs) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits