Closed Bug 1617283 Opened 6 years ago Closed 4 years ago

AudioSession COM Cleanup

Categories

(Core :: Widget: Win32, task, P3)

Unspecified
Windows
task

Tracking

()

RESOLVED FIXED
101 Branch
Tracking Status
firefox99 --- wontfix
firefox100 --- wontfix
firefox101 --- fixed

People

(Reporter: bugzilla, Assigned: ssummar)

References

Details

Attachments

(2 files)

I see a few COMy things in AudioSession that we should clean up:

  • Remove CoInitialize and CoUninitialize calls; since mscom::ProcessRuntime is instantiated during startup, COM is always available by the time this code runs.
  • Since the thread started by SpawnASCReleaseThread does not declare its apartment, it implicitly lives inside the multi-threaded apartment. Unfortunately the IAudioSessionControl interface came from the main thread's single-threaded apartment, so calling Release on it from the multi-threaded apartment actually violates the rules of COM. At the very least the interface should be wrapped in a mscom::AgileReference while passing between threads.
  • We're using PR_CreateThread here; perhaps NS_DispatchBackgroundTask is better suited to this? I guess that depends on whether it is possible to block shutdown by using the latter...

Note that CLSID_MMDeviceEnumerator has a threading model of Both, which means that its objects are safe to use in either an STA or the MTA, but not simultaneously. Passing between apartments requires either marshaling or an agile reference.

Thanks Aaron. I believe we can remove the use of AudioSession entirely from content processes entirely because of audio remoting -- I'm trying that out in bug 1430907 comment 27. But AudioSession also runs in the plugin and main processes. Does what you're saying apply there as well? I don't know if you know how the plugin COM setup is done but I'm wondering about your first 2 points there and in main (where I assume the Co(Un)Initialize calls are redundant but I don't know about the STA/MTA of it all).

Flags: needinfo?(aklotz)

The good news is that I did some further investigation and found out that the MMDeviceEnumerator aggregates the free-threaded marshaler, which in plain English means that the STA/MTA threading stuff isn't an issue after all.

As helpful as audio remoting is, I think we should still take care of the first and third points. But which ever background thread we run the cleanup on, the runnable should be wrapped within a mscom::MTARegion

Flags: needinfo?(aklotz)
Assignee: nobody → ssummar.bee16seecs
Status: NEW → ASSIGNED
Severity: normal → S3
Priority: -- → P3
Pushed by daparks@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/14ef7c10fef4 Removed COM violations and shifted AudioSession to MTA r=handyman

Sorry about the backout. It's a very trivial issue. I'm working on it.

Flags: needinfo?(ssummar.bee16seecs)
Pushed by daparks@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e1b946a41694 Removed COM violations and shifted AudioSession to MTA r=handyman
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 99 Branch
Depends on: 1755700
Regressions: 1755700
Status: RESOLVED → REOPENED
Flags: needinfo?(ssummar.bee16seecs)
Resolution: FIXED → ---
Target Milestone: 99 Branch → ---
Flags: needinfo?(ssummar.bee16seecs)
Attachment #9259740 - Attachment description: Bug 1617283 - Removed COM violations and shifted AudioSession to MTA r=handyman → WIP: Bug 1617283 - Removed COM violations and shifted AudioSession to MTA r=handyman

Pointer to AudioSession object is made std::atomic to resolve crashes (bug 1755700) by atomically modifying/reading the pointer as an effort to make sure any update to the pointer is seen across other threads immediately while not using locks to maintain such concurrency and avoiding dataraces.

This patch is built upon the work done in D136377.

No longer blocks: 1753603
Pushed by daparks@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/6fd4b72c9a6c Shifted AudioSession to MTA and removed COM violations r=handyman

Thanks for notifying. I'm looking into it.

Flags: needinfo?(shazib)
Pushed by daparks@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2230bd66878c Shifted AudioSession to MTA and removed COM violations r=handyman
Regressions: 1763695
Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch

Since the status are different for nightly and release, what's the status for beta?
For more information, please visit auto_nag documentation.

No longer regressions: 1763695
No longer depends on: 1755700
Regressions: 1755717
Regressions: 1777518
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: