Add PreferredAudioOutputDeviceManager implementation. [chromium/src : main]

3 views
Skip to first unread message

Sunggook Chue (Gerrit)

unread,
Jun 27, 2024, 9:09:13 PMJun 27
to Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
Attention needed from Olga Sharonova

Sunggook Chue added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Sunggook Chue . resolved

Thanks for reviewing!

Open in Gerrit

Related details

Attention is currently required from:
  • Olga Sharonova
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
Gerrit-Change-Number: 5664173
Gerrit-PatchSet: 1
Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
Gerrit-Attention: Olga Sharonova <ol...@google.com>
Gerrit-Comment-Date: Fri, 28 Jun 2024 01:09:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Olga Sharonova (Gerrit)

unread,
Jun 28, 2024, 4:22:08 AMJun 28
to Sunggook Chue, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
Attention needed from Olga Sharonova and Sunggook Chue

Olga Sharonova added 8 comments

File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
Line 92, Patchset 1 (Latest): std::string preferred_sin_id;
Olga Sharonova . unresolved

preferred_sink_id

Line 59, Patchset 1 (Latest): AudioOutputDeviceSwitcher* broker,
Olga Sharonova . unresolved

It's not a broker, it's AudioOutputDeviceSwitcher - let's not make leaky abstractions by disclosing implementation details via names.

Line 29, Patchset 1 (Latest):// streaming is active. The cached sink id will be used to set the
// preferred sink id for the audio service when the audio service is started.
Olga Sharonova . unresolved

I don't quite understand this part.

Line 28, Patchset 1 (Latest):// forwards the request to the corresponding active audio controler if
Olga Sharonova . unresolved

There is no concept of audio controller at this layer, it's deep in the audio service.

Line 28, Patchset 1 (Latest):// forwards the request to the corresponding active audio controler if
Olga Sharonova . unresolved

"controler" is a possible misspelling of "controller".

Please fix.

Line 27, Patchset 1 (Latest):// It caches the preferred sink id with each top RenderFrameHost ojbect and
Olga Sharonova . unresolved

"ojbect" is a possible misspelling of "object".

Please fix.

File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
Line 200, Patchset 1 (Latest): weak_ptr_factory_.GetWeakPtr(), broker,
Olga Sharonova . unresolved

Which thread PreferredAudioOutputDeviceManager is destroyed on?
weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

File third_party/blink/public/mojom/mediastream/media_devices.mojom
Line 148, Patchset 1 (Latest): SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
Olga Sharonova . unresolved

Why this is a part of this CL?

Open in Gerrit

Related details

Attention is currently required from:
  • Olga Sharonova
  • Sunggook Chue
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
    Gerrit-CC: Olga Sharonova <ol...@chromium.org>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Fri, 28 Jun 2024 08:21:57 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Sunggook Chue (Gerrit)

    unread,
    Jun 28, 2024, 5:09:01 PMJun 28
    to Olga Sharonova, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Olga Sharonova and Olga Sharonova

    Sunggook Chue added 9 comments

    Patchset-level comments
    File-level comment, Patchset 2 (Latest):
    Sunggook Chue . resolved

    addressed and replied comments, thanks.

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 92, Patchset 1: std::string preferred_sin_id;
    Olga Sharonova . resolved

    preferred_sink_id

    Sunggook Chue

    Done

    Line 59, Patchset 1: AudioOutputDeviceSwitcher* broker,
    Olga Sharonova . resolved

    It's not a broker, it's AudioOutputDeviceSwitcher - let's not make leaky abstractions by disclosing implementation details via names.

    Sunggook Chue

    Done

    Line 29, Patchset 1:// streaming is active. The cached sink id will be used to set the

    // preferred sink id for the audio service when the audio service is started.
    Olga Sharonova . resolved

    I don't quite understand this part.

    Sunggook Chue

    Done

    Line 28, Patchset 1:// forwards the request to the corresponding active audio controler if
    Olga Sharonova . resolved

    There is no concept of audio controller at this layer, it's deep in the audio service.

    Sunggook Chue

    Done

    Line 28, Patchset 1:// forwards the request to the corresponding active audio controler if
    Olga Sharonova . resolved

    "controler" is a possible misspelling of "controller".

    Please fix.

    Sunggook Chue

    Done

    Line 27, Patchset 1:// It caches the preferred sink id with each top RenderFrameHost ojbect and
    Olga Sharonova . resolved

    "ojbect" is a possible misspelling of "object".

    Please fix.

    Sunggook Chue

    Done

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . unresolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    File third_party/blink/public/mojom/mediastream/media_devices.mojom
    Line 148, Patchset 1: SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
    Olga Sharonova . resolved

    Why this is a part of this CL?

    Sunggook Chue

    PreferredAudioOutputDeviceManager::SetPreferredSinkId function needs 'SetPreferredSinkIdCallback', which come from this.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Olga Sharonova
    • Olga Sharonova
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 2
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
    Gerrit-CC: Olga Sharonova <ol...@chromium.org>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Olga Sharonova <ol...@chromium.org>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Fri, 28 Jun 2024 21:08:49 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Olga Sharonova <ol...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Olga Sharonova (Gerrit)

    unread,
    Jul 1, 2024, 5:17:54 AMJul 1
    to Sunggook Chue, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Olga Sharonova and Sunggook Chue

    Olga Sharonova added 3 comments

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 30, Patchset 2 (Latest):// default audio output device
    Olga Sharonova . unresolved

    .

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . unresolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    Olga Sharonova

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    VideoCaptureManager is refcounted, so it's unknown on which thread it is destroyed. Also, it does not seem to use weak pointers?
    VideoCaptureController is the one who uses weak pointers, and not necessarily correctly, since it also seems to be refcounted. I don't know what guarantees the correctness there (probably nothing), we may need ask the authors of the code.

    Also, media stream manager does not seem to be destroyed on IO thread, rather IO thread is destroyed before: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/media/media_stream_manager.cc;l=1643;drc=7b232da0f22e8cdf555d43c52b6491baeb87f729;bpv=1;bpt=1

    Guido knows this part better.

    File third_party/blink/public/mojom/mediastream/media_devices.mojom
    Line 148, Patchset 1: SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
    Olga Sharonova . unresolved

    Why this is a part of this CL?

    Sunggook Chue

    PreferredAudioOutputDeviceManager::SetPreferredSinkId function needs 'SetPreferredSinkIdCallback', which come from this.

    Olga Sharonova

    It does not come from this one, it comes from AudioOutputDeviceSwitcher.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Olga Sharonova
    • Sunggook Chue
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 2
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
    Gerrit-CC: Olga Sharonova <ol...@chromium.org>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Mon, 01 Jul 2024 09:17:43 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Olga Sharonova <ol...@chromium.org>
    Comment-In-Reply-To: Sunggook Chue <sun...@microsoft.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Sunggook Chue (Gerrit)

    unread,
    Jul 1, 2024, 8:24:11 PMJul 1
    to Guido Urdaneta, Steve Becker, Gabriel Brito, Olga Sharonova, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova, Olga Sharonova and Steve Becker

    Sunggook Chue added 4 comments

    Sunggook Chue . resolved

    addressed and replied comments, thanks.

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 30, Patchset 2:// default audio output device
    Olga Sharonova . resolved

    .

    Sunggook Chue

    Done

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . unresolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    Olga Sharonova

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    VideoCaptureManager is refcounted, so it's unknown on which thread it is destroyed. Also, it does not seem to use weak pointers?
    VideoCaptureController is the one who uses weak pointers, and not necessarily correctly, since it also seems to be refcounted. I don't know what guarantees the correctness there (probably nothing), we may need ask the authors of the code.

    Also, media stream manager does not seem to be destroyed on IO thread, rather IO thread is destroyed before: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/media/media_stream_manager.cc;l=1643;drc=7b232da0f22e8cdf555d43c52b6491baeb87f729;bpv=1;bpt=1

    Guido knows this part better.

    Sunggook Chue

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop and MediaStreamManager is destroyed on non IO thread after this.

    File third_party/blink/public/mojom/mediastream/media_devices.mojom
    Line 148, Patchset 1: SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
    Olga Sharonova . resolved

    Why this is a part of this CL?

    Sunggook Chue

    PreferredAudioOutputDeviceManager::SetPreferredSinkId function needs 'SetPreferredSinkIdCallback', which come from this.

    Olga Sharonova

    It does not come from this one, it comes from AudioOutputDeviceSwitcher.

    Sunggook Chue

    if delete it from the media_devices, the compilation error.

    ../..\content/browser/renderer_host/media/media_devices_dispatcher_host.h(80,27): error: unknown type name 'SetPreferredSinkIdCallback'
    80 | SetPreferredSinkIdCallback callback) override;
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Gabriel Brito
    • Guido Urdaneta
    • Olga Sharonova
    • Olga Sharonova
    • Steve Becker
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 3
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
    Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
    Gerrit-CC: Olga Sharonova <ol...@chromium.org>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Steve Becker <ste...@microsoft.com>
    Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@chromium.org>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Tue, 02 Jul 2024 00:24:00 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Guido Urdaneta (Gerrit)

    unread,
    Jul 5, 2024, 6:30:15 AMJul 5
    to Sunggook Chue, Steve Becker, Gabriel Brito, Olga Sharonova, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Olga Sharonova, Olga Sharonova, Steve Becker and Sunggook Chue

    Guido Urdaneta added 1 comment

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . unresolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    Olga Sharonova

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    VideoCaptureManager is refcounted, so it's unknown on which thread it is destroyed. Also, it does not seem to use weak pointers?
    VideoCaptureController is the one who uses weak pointers, and not necessarily correctly, since it also seems to be refcounted. I don't know what guarantees the correctness there (probably nothing), we may need ask the authors of the code.

    Also, media stream manager does not seem to be destroyed on IO thread, rather IO thread is destroyed before: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/media/media_stream_manager.cc;l=1643;drc=7b232da0f22e8cdf555d43c52b6491baeb87f729;bpv=1;bpt=1

    Guido knows this part better.

    Sunggook Chue

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop and MediaStreamManager is destroyed on non IO thread after this.

    Guido Urdaneta

    Like Olga says, MediaStreamManager is **not** destroyed on the IO thread. It outlives the IO thread.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Gabriel Brito
    • Olga Sharonova
    • Olga Sharonova
    • Steve Becker
    • Sunggook Chue
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 4
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Reviewer: Olga Sharonova <ol...@google.com>
    Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
    Gerrit-CC: Olga Sharonova <ol...@chromium.org>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Steve Becker <ste...@microsoft.com>
    Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@chromium.org>
    Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Fri, 05 Jul 2024 10:30:04 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Guido Urdaneta (Gerrit)

    unread,
    Jul 5, 2024, 6:34:49 AMJul 5
    to Sunggook Chue, Steve Becker, Gabriel Brito, Olga Sharonova, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Olga Sharonova, Olga Sharonova, Steve Becker and Sunggook Chue

    Guido Urdaneta added 1 comment

    File content/browser/renderer_host/media/media_devices_dispatcher_host.cc
    Line 340, Patchset 4 (Latest): NOTIMPLEMENTED();
    Guido Urdaneta . unresolved

    Follow Olga's indications on how to split the CLs, and make sure this appears in the same CL where the method is added to the mojom file and that it has a real implementation.

    Gerrit-Comment-Date: Fri, 05 Jul 2024 10:34:37 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Olga Sharonova (Gerrit)

    unread,
    Jul 5, 2024, 7:38:41 AMJul 5
    to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova, Steve Becker and Sunggook Chue

    Olga Sharonova added 7 comments

    Patchset-level comments
    File-level comment, Patchset 4 (Latest):
    Olga Sharonova . resolved

    PreferredAudioOutputDeviceManger introduces 2 interaction surfaces: 1) Interface for brokers to register/undergister; 2) SetPreferredSinkId interface.

    We need to see the code
    1) handling PreferredAudioOutputDeviceManger lifetime.
    2) introducing an interaction between a broker and PreferredAudioOutputDeviceManger.
    3) introducing SetPreferredSinkId usage.

    It's impossible to reason about correctness here until we see the interactions with the class.

    This should likely be 3 separate CLs, but I leave it up to you to arrange it so it makes sense.

    Also a diagram of relationships would be very helpful.

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 41, Patchset 4 (Latest): void AddBrokerAndGetOverrideDeviceId(
    AudioOutputDeviceSwitcher* device_switcher,
    base::OnceCallback<void(const std::string&)> callback);
    void GetOverrideDeviceId(
    const int process_id,
    const int render_frame_id,
    base::OnceCallback<void(const std::string&)> callback);
    void RemoveBrokerEntry(AudioOutputDeviceSwitcher* device_switcher);
    void RemoveRenderFrameHostEntry(RenderFrameHost* render_frame_host);
    Olga Sharonova . unresolved

    I'd like to see a CL which clearly introduces usage of these interfaces. Only looking at it we can judge this one. Currently the usage is introduces in the last CL of the chain along with many other things, so we can't review effectively.

    Line 41, Patchset 4 (Latest): void AddBrokerAndGetOverrideDeviceId(
    Olga Sharonova . unresolved

    Re: naming: we agreed to used Switcher; this class is unaware of brokers. Please fix everywhere.

    Line 29, Patchset 4 (Latest):// streaming is active. The cached sink id will be used instead of the active
    Olga Sharonova . unresolved

    What does "streaming is active" mean?

    Line 28, Patchset 4 (Latest):// forwards the request to the corresponding active audio service if
    Olga Sharonova . unresolved

    What does it mean?

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . unresolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    Olga Sharonova

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    VideoCaptureManager is refcounted, so it's unknown on which thread it is destroyed. Also, it does not seem to use weak pointers?
    VideoCaptureController is the one who uses weak pointers, and not necessarily correctly, since it also seems to be refcounted. I don't know what guarantees the correctness there (probably nothing), we may need ask the authors of the code.

    Also, media stream manager does not seem to be destroyed on IO thread, rather IO thread is destroyed before: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/media/media_stream_manager.cc;l=1643;drc=7b232da0f22e8cdf555d43c52b6491baeb87f729;bpv=1;bpt=1

    Guido knows this part better.

    Sunggook Chue

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop and MediaStreamManager is destroyed on non IO thread after this.

    Guido Urdaneta

    Like Olga says, MediaStreamManager is **not** destroyed on the IO thread. It outlives the IO thread.

    Olga Sharonova

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop

    Please point to the place in the code you refer to.
    Also please document the reasoning bout the lifetime in the code. Why it's safe to use weak pointers, why the object will be destroyed on IO thread, etc.
    Also please document the object threading: created on thread x, requests are forwarded to thread y, destroyed on thread z.

    File third_party/blink/public/mojom/mediastream/media_devices.mojom
    Line 148, Patchset 1: SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
    Olga Sharonova . unresolved

    Why this is a part of this CL?

    Sunggook Chue

    PreferredAudioOutputDeviceManager::SetPreferredSinkId function needs 'SetPreferredSinkIdCallback', which come from this.

    Olga Sharonova

    It does not come from this one, it comes from AudioOutputDeviceSwitcher.

    Sunggook Chue

    if delete it from the media_devices, the compilation error.

    ../..\content/browser/renderer_host/media/media_devices_dispatcher_host.h(80,27): error: unknown type name 'SetPreferredSinkIdCallback'
    80 | SetPreferredSinkIdCallback callback) override;
    Olga Sharonova

    Because MediaDispatcherHost change is also irrelevant for this CL: it's not implemented.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Gabriel Brito
    • Guido Urdaneta
    Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@google.com>
    Gerrit-Comment-Date: Fri, 05 Jul 2024 11:38:29 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Guido Urdaneta <gui...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Olga Sharonova (Gerrit)

    unread,
    Jul 5, 2024, 7:50:36 AMJul 5
    to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Olga Sharonova, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova, Steve Becker and Sunggook Chue

    Olga Sharonova added 1 comment

    File content/browser/media/audio_output_stream_broker.h
    Line 27, Patchset 4 (Latest):class AudioOutputDeviceSwitcher {
    public:
    virtual ~AudioOutputDeviceSwitcher() = default;

    virtual void SwitchAudioOutputDeviceId(const std::string& device_id) = 0;

    virtual GlobalRenderFrameHostId GetGlobalRenderFrameHostId() const = 0;
    };
    Olga Sharonova . unresolved

    Introduce this and the device switch logic from https://chromium-review.googlesource.com/c/chromium/src/+/5530803/11 in the CL *preceding* this one.

    Otherwise this interface is hanging in the air without actual meaning, and we can only guess about the intentions by the fact that the device switcher was named "broker".

    Gerrit-Comment-Date: Fri, 05 Jul 2024 11:50:26 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Sunggook Chue (Gerrit)

    unread,
    Jul 8, 2024, 11:39:09 PMJul 8
    to Olga Sharonova, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova and Steve Becker

    Sunggook Chue added 9 comments

    Patchset-level comments
    File-level comment, Patchset 6 (Latest):
    Sunggook Chue . resolved

    addressed comments based on f2f meeting, thanks.

    File content/browser/media/audio_output_stream_broker.h
    Line 27, Patchset 4:class AudioOutputDeviceSwitcher {

    public:
    virtual ~AudioOutputDeviceSwitcher() = default;

    virtual void SwitchAudioOutputDeviceId(const std::string& device_id) = 0;

    virtual GlobalRenderFrameHostId GetGlobalRenderFrameHostId() const = 0;
    };
    Olga Sharonova . resolved

    Introduce this and the device switch logic from https://chromium-review.googlesource.com/c/chromium/src/+/5530803/11 in the CL *preceding* this one.

    Otherwise this interface is hanging in the air without actual meaning, and we can only guess about the intentions by the fact that the device switcher was named "broker".

    Sunggook Chue

    Done

    File content/browser/renderer_host/media/media_devices_dispatcher_host.cc
    Line 340, Patchset 4: NOTIMPLEMENTED();
    Guido Urdaneta . resolved

    Follow Olga's indications on how to split the CLs, and make sure this appears in the same CL where the method is added to the mojom file and that it has a real implementation.

    Sunggook Chue

    Done

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 41, Patchset 4: void AddBrokerAndGetOverrideDeviceId(

    AudioOutputDeviceSwitcher* device_switcher,
    base::OnceCallback<void(const std::string&)> callback);
    void GetOverrideDeviceId(
    const int process_id,
    const int render_frame_id,
    base::OnceCallback<void(const std::string&)> callback);
    void RemoveBrokerEntry(AudioOutputDeviceSwitcher* device_switcher);
    void RemoveRenderFrameHostEntry(RenderFrameHost* render_frame_host);
    Olga Sharonova . resolved

    I'd like to see a CL which clearly introduces usage of these interfaces. Only looking at it we can judge this one. Currently the usage is introduces in the last CL of the chain along with many other things, so we can't review effectively.

    Sunggook Chue

    These interfaces are essential for this class, so unit tests will give idea what these methods are.

    I think it is same with already added Audio Services where we implemented before its clients; bottom up approach what you suggested, instead of client first, which is my initial CLs.

    If we add methods with its clients, then the class can't have any methods yet all.

    Line 41, Patchset 4: void AddBrokerAndGetOverrideDeviceId(
    Olga Sharonova . resolved

    Re: naming: we agreed to used Switcher; this class is unaware of brokers. Please fix everywhere.

    Sunggook Chue

    Done

    Line 29, Patchset 4:// streaming is active. The cached sink id will be used instead of the active
    Olga Sharonova . resolved

    What does "streaming is active" mean?

    Sunggook Chue

    current playing.

    Line 28, Patchset 4:// forwards the request to the corresponding active audio service if
    Olga Sharonova . resolved

    What does it mean?

    Sunggook Chue

    audio output stream in the audio service.

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 200, Patchset 1: weak_ptr_factory_.GetWeakPtr(), broker,
    Olga Sharonova . resolved

    Which thread PreferredAudioOutputDeviceManager is destroyed on?
    weak_ptr can't be used on IO thread, if the PreferredAudioOutputDeviceManager is destroyed on UI thread (see base/memory/weak_ptr.h)

    Sunggook Chue

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    I don't find weak_ptr (WeakPtr) can't be on IO thread although it enforce use of same thread sequence.

    PreferredAudioOutputDeviceManager lifetime belongs MediaStreamManager that also has VideoCaptureManager, which has VideoCaptureController.

    VideoCaptureController is also created and destroyed like PreferredAudioOutputDeviceManager, and it is WeakPtrFactory.

    Can you point out any guideline, i might missed that?

    Olga Sharonova

    PreferredAudioOutputDeviceManager is created and destroyed on IO thread like VideoCaptureManager.

    VideoCaptureManager is refcounted, so it's unknown on which thread it is destroyed. Also, it does not seem to use weak pointers?
    VideoCaptureController is the one who uses weak pointers, and not necessarily correctly, since it also seems to be refcounted. I don't know what guarantees the correctness there (probably nothing), we may need ask the authors of the code.

    Also, media stream manager does not seem to be destroyed on IO thread, rather IO thread is destroyed before: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/renderer_host/media/media_stream_manager.cc;l=1643;drc=7b232da0f22e8cdf555d43c52b6491baeb87f729;bpv=1;bpt=1

    Guido knows this part better.

    Sunggook Chue

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop and MediaStreamManager is destroyed on non IO thread after this.

    Guido Urdaneta

    Like Olga says, MediaStreamManager is **not** destroyed on the IO thread. It outlives the IO thread.

    Olga Sharonova

    VideoCaptureManager (PreferredAudioOutputDeviceManager) will be destroyed in the IO thread during DestructionObserver::WillDestroyCurrentMessageLoop

    Please point to the place in the code you refer to.
    Also please document the reasoning bout the lifetime in the code. Why it's safe to use weak pointers, why the object will be destroyed on IO thread, etc.
    Also please document the object threading: created on thread x, requests are forwarded to thread y, destroyed on thread z.

    Sunggook Chue

    Please take a look at the media_stream_manager.cc changes where it instantiates and destroyed at the IO thread. (same place with VideoCaptureManager).

    File third_party/blink/public/mojom/mediastream/media_devices.mojom
    Line 148, Patchset 1: SetPreferredSinkId(string sink_id) => (media.mojom.OutputDeviceStatus status);
    Olga Sharonova . resolved

    Why this is a part of this CL?

    Sunggook Chue

    PreferredAudioOutputDeviceManager::SetPreferredSinkId function needs 'SetPreferredSinkIdCallback', which come from this.

    Olga Sharonova

    It does not come from this one, it comes from AudioOutputDeviceSwitcher.

    Sunggook Chue

    if delete it from the media_devices, the compilation error.

    ../..\content/browser/renderer_host/media/media_devices_dispatcher_host.h(80,27): error: unknown type name 'SetPreferredSinkIdCallback'
    80 | SetPreferredSinkIdCallback callback) override;
    Olga Sharonova

    Because MediaDispatcherHost change is also irrelevant for this CL: it's not implemented.

    Sunggook Chue

    What I mean, PreferredAudioOutputDeviceManager::SetPreferredSinkId needs 'blink::mojom::MediaDevicesDispatcherHost::SetPreferredSinkIdCallback', which needs media_devices.mojom change.

    If we want to delete this one here, then we can't implement PreferredAudioOutputDeviceManager::SetPreferredSinkId as it misses

    PreferredAudioOutputDeviceManager class will be called from

    1. from the broker class: 3rd CL.

    2. from the renderer through MediaDispatcherHost host,
    Renderer -> MediaDispatcherHost-> MediaStreamManager->PreferredAudioOutputDeviceManager.

    Here, I will skip SetPreferredSinkId implementation, so,

    4th CL: PreferredAudioOutputDeviceManager with custom SetPreferredSinkIdCallback
    5th CL: Broker interact with PreferredAudioOutputDeviceManager.
    6th CL: Device Authorization.
    7th CL: MediaStreamManager instantiate PreferredAudioOutputDeviceManager and media_devices.mojom (MediaDispatcherHost), correct type of SetPreferredSinkIdCallback.
    8th CL: Renderer call MediaDispatcherHost with IDL.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Gabriel Brito
    • Guido Urdaneta
    • Olga Sharonova
    • Steve Becker
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Review
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
    Gerrit-Change-Number: 5664173
    Gerrit-PatchSet: 6
    Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
    Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Reviewer: Olga Sharonova <ol...@chromium.org>
    Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
    Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
    Gerrit-Attention: Steve Becker <ste...@microsoft.com>
    Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
    Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
    Gerrit-Attention: Olga Sharonova <ol...@chromium.org>
    Gerrit-Comment-Date: Tue, 09 Jul 2024 03:38:59 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Olga Sharonova (Gerrit)

    unread,
    Jul 9, 2024, 10:28:46 AMJul 9
    to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
    Attention needed from Gabriel Brito, Guido Urdaneta, Steve Becker and Sunggook Chue

    Olga Sharonova added 6 comments

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
    Line 86, Patchset 7 (Latest): std::map<RenderFrameHost*, WebContentsSinkId> web_contents_to_sink_ids_;
    Olga Sharonova . unresolved

    Document that it's only accessed on IO thread.

    Line 39, Patchset 7 (Latest): void SetPreferredSinkId(const std::string& sink_id,
    SetPreferredSinkIdCallback callback,
    GlobalRenderFrameHostId rfh_id);
    void AddSwitcherAndGetOverrideDeviceId(

    AudioOutputDeviceSwitcher* device_switcher,
    base::OnceCallback<void(const std::string&)> callback);
    void GetOverrideDeviceId(
    const int process_id,
    const int render_frame_id,
    base::OnceCallback<void(const std::string&)> callback);
    void RemoveSwitcherEntry(AudioOutputDeviceSwitcher* device_switcher);
    void RemoveRenderFrameHostEntry(RenderFrameHost* render_frame_host);
    Olga Sharonova . unresolved

    Please document the API: what are the parameters, on which threads which of the method is expected to be called, etc.

    Line 48, Patchset 7 (Latest): base::OnceCallback<void(const std::string&)> callback);
    Olga Sharonova . unresolved

    Ditto

    Line 44, Patchset 7 (Latest): base::OnceCallback<void(const std::string&)> callback);
    Olga Sharonova . unresolved

    What is this callback, on which thread it's expected to run? Please document.

    Line 34, Patchset 7 (Latest):class CONTENT_EXPORT PreferredAudioOutputDeviceManager {
    Olga Sharonova . unresolved

    I requested in one of the earlier CLs to document this class lifetime, which thread it's destroyed on, why weak pointers are safe, etc. - could you please do that?

    Also, since the methods hop through threads all the time - please provide sequence diagrams for them.

    File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
    Line 207, Patchset 7 (Latest):void PreferredAudioOutputDeviceManager::RemoveSwitcherEntry(
    Olga Sharonova . unresolved

    I don't think this works. This method is called in the broker destructor. When it exits, the device switcher pointer is no longer valid. However, we jump through UI thread and back to IO before actually removing it from the map. Meanwhile, there may be preferred device switch calls already scheduled on IO thread, and they will call the already deleted switcher before we get to RemoveSwitcherEntryOnIOThread().

    Please see above my request for sequence diagrams. There may be other problems like that, for example when web content is gone.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Gabriel Brito
    • Guido Urdaneta
    • Steve Becker
    • Sunggook Chue
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
      Gerrit-Change-Number: 5664173
      Gerrit-PatchSet: 7
      Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
      Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
      Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
      Gerrit-Reviewer: Olga Sharonova <ol...@chromium.org>
      Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
      Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
      Gerrit-Attention: Steve Becker <ste...@microsoft.com>
      Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
      Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
      Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
      Gerrit-Comment-Date: Tue, 09 Jul 2024 14:28:33 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Sunggook Chue (Gerrit)

      unread,
      Jul 10, 2024, 12:09:50 AMJul 10
      to Olga Sharonova, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
      Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova and Steve Becker

      Sunggook Chue added 7 comments

      Patchset-level comments
      File-level comment, Patchset 8 (Latest):
      Sunggook Chue . resolved

      addressed comments, thanks.

      File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
      Line 86, Patchset 7: std::map<RenderFrameHost*, WebContentsSinkId> web_contents_to_sink_ids_;
      Olga Sharonova . resolved

      Document that it's only accessed on IO thread.

      Sunggook Chue

      Done

      Line 39, Patchset 7: void SetPreferredSinkId(const std::string& sink_id,

      SetPreferredSinkIdCallback callback,
      GlobalRenderFrameHostId rfh_id);
      void AddSwitcherAndGetOverrideDeviceId(
      AudioOutputDeviceSwitcher* device_switcher,
      base::OnceCallback<void(const std::string&)> callback);
      void GetOverrideDeviceId(
      const int process_id,
      const int render_frame_id,
      base::OnceCallback<void(const std::string&)> callback);
      void RemoveSwitcherEntry(AudioOutputDeviceSwitcher* device_switcher);
      void RemoveRenderFrameHostEntry(RenderFrameHost* render_frame_host);
      Olga Sharonova . resolved

      Please document the API: what are the parameters, on which threads which of the method is expected to be called, etc.

      Sunggook Chue

      Done

      Line 48, Patchset 7: base::OnceCallback<void(const std::string&)> callback);
      Olga Sharonova . resolved

      Ditto

      Sunggook Chue

      Done

      Line 44, Patchset 7: base::OnceCallback<void(const std::string&)> callback);
      Olga Sharonova . resolved

      What is this callback, on which thread it's expected to run? Please document.

      Sunggook Chue

      Done

      Line 34, Patchset 7:class CONTENT_EXPORT PreferredAudioOutputDeviceManager {
      Olga Sharonova . resolved

      I requested in one of the earlier CLs to document this class lifetime, which thread it's destroyed on, why weak pointers are safe, etc. - could you please do that?

      Also, since the methods hop through threads all the time - please provide sequence diagrams for them.

      Sunggook Chue

      I added comments, feel free to suggest if needed.

      File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
      Line 207, Patchset 7:void PreferredAudioOutputDeviceManager::RemoveSwitcherEntry(
      Olga Sharonova . resolved

      I don't think this works. This method is called in the broker destructor. When it exits, the device switcher pointer is no longer valid. However, we jump through UI thread and back to IO before actually removing it from the map. Meanwhile, there may be preferred device switch calls already scheduled on IO thread, and they will call the already deleted switcher before we get to RemoveSwitcherEntryOnIOThread().

      Please see above my request for sequence diagrams. There may be other problems like that, for example when web content is gone.

      Sunggook Chue

      The current logic is same with 'NotifyFrameHostOfAudioStreamStopped', which is called in AudioOutputStreamBroker dtor and operate on UI thread.

      All it needs the RenderFrameHost object is alive on the UI thread, and it doesn't have to live when it back to the IO thread as it is nothing but a integer.

      It is called on the UI thread for WebContents, where it is even safer than broker since it doesn't have to switch to UI thread.

      It's not convenient to draw sequence diagram on the /h file, anyway, tried.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Gabriel Brito
      • Guido Urdaneta
      • Olga Sharonova
      • Steve Becker
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Review
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
      Gerrit-Change-Number: 5664173
      Gerrit-PatchSet: 8
      Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
      Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
      Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
      Gerrit-Reviewer: Olga Sharonova <ol...@chromium.org>
      Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
      Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
      Gerrit-Attention: Steve Becker <ste...@microsoft.com>
      Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
      Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
      Gerrit-Attention: Olga Sharonova <ol...@chromium.org>
      Gerrit-Comment-Date: Wed, 10 Jul 2024 04:09:39 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Olga Sharonova <ol...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Olga Sharonova (Gerrit)

      unread,
      Jul 10, 2024, 2:52:46 AMJul 10
      to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
      Attention needed from Gabriel Brito, Guido Urdaneta, Steve Becker and Sunggook Chue

      Olga Sharonova added 2 comments

      File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
      Line 44, Patchset 8 (Latest):// substitued for the new audio output stream if the requested stream is
      Olga Sharonova . unresolved

      "substitued" is a possible misspelling of "substituted" or "substitute".

      Please fix.

      File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
      Line 207, Patchset 7:void PreferredAudioOutputDeviceManager::RemoveSwitcherEntry(
      Olga Sharonova . unresolved

      I don't think this works. This method is called in the broker destructor. When it exits, the device switcher pointer is no longer valid. However, we jump through UI thread and back to IO before actually removing it from the map. Meanwhile, there may be preferred device switch calls already scheduled on IO thread, and they will call the already deleted switcher before we get to RemoveSwitcherEntryOnIOThread().

      Please see above my request for sequence diagrams. There may be other problems like that, for example when web content is gone.

      Sunggook Chue

      The current logic is same with 'NotifyFrameHostOfAudioStreamStopped', which is called in AudioOutputStreamBroker dtor and operate on UI thread.

      All it needs the RenderFrameHost object is alive on the UI thread, and it doesn't have to live when it back to the IO thread as it is nothing but a integer.

      It is called on the UI thread for WebContents, where it is even safer than broker since it doesn't have to switch to UI thread.

      It's not convenient to draw sequence diagram on the /h file, anyway, tried.

      Olga Sharonova

      I mean: *a* sequence diagram - in any readable format, not in .h file. Since we have not discussed this in a design doc, and the interactions are rather complex. Also, because I just described a problem with these sequences.

      I don't see how your comment addresses the situation I described though: SetPreferredSinkIdOnIOThread() being called while we jump here from IO thread to UI and back to removed a deleted switcher from the map.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Gabriel Brito
      • Guido Urdaneta
      • Steve Becker
      • Sunggook Chue
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: Ib304fd723a5e1c7dc1cb5d30646ced502cd98026
        Gerrit-Change-Number: 5664173
        Gerrit-PatchSet: 8
        Gerrit-Owner: Sunggook Chue <sun...@microsoft.com>
        Gerrit-Reviewer: Gabriel Brito <gabrie...@microsoft.com>
        Gerrit-Reviewer: Guido Urdaneta <gui...@chromium.org>
        Gerrit-Reviewer: Olga Sharonova <ol...@chromium.org>
        Gerrit-Reviewer: Steve Becker <ste...@microsoft.com>
        Gerrit-CC: Rijubrata Bhaumik <rijubrat...@intel.com>
        Gerrit-Attention: Steve Becker <ste...@microsoft.com>
        Gerrit-Attention: Guido Urdaneta <gui...@chromium.org>
        Gerrit-Attention: Gabriel Brito <gabrie...@microsoft.com>
        Gerrit-Attention: Sunggook Chue <sun...@microsoft.com>
        Gerrit-Comment-Date: Wed, 10 Jul 2024 06:52:35 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Olga Sharonova <ol...@chromium.org>
        Comment-In-Reply-To: Sunggook Chue <sun...@microsoft.com>
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Olga Sharonova (Gerrit)

        unread,
        Jul 10, 2024, 3:15:29 AMJul 10
        to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
        Attention needed from Gabriel Brito, Guido Urdaneta, Steve Becker and Sunggook Chue

        Olga Sharonova added 1 comment

        File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
        Line 238, Patchset 8 (Latest):void PreferredAudioOutputDeviceManager::RemoveRenderFrameHostEntry(
        Olga Sharonova . unresolved

        There may be SetPreferredSinkIdOnIOThread() scheduled before RemoveRenderFrameHostEntryEntryOnIOThread is called.

        Gerrit-Comment-Date: Wed, 10 Jul 2024 07:15:16 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Olga Sharonova (Gerrit)

        unread,
        Jul 10, 2024, 3:45:23 AMJul 10
        to Sunggook Chue, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
        Attention needed from Gabriel Brito, Guido Urdaneta, Steve Becker and Sunggook Chue

        Olga Sharonova added 1 comment

        File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
        Line 134, Patchset 8 (Latest): &GetRenderFrameHostOnUIThread,
        device_switcher->GetGlobalRenderFrameHostId(),
        Olga Sharonova . unresolved

        I think we should reconsider this part of PreferredAudioOutputDeviceManager. Why do we make it fetch the host, rather than providing it? For example, the host is known for the Broker aka Switcher during its creation, isn't it? So Switcher can have a getter for it, rather than for its id.
        If we make PreferredAudioOutputDeviceManager to work with main frame directly, the threading will be much simpler and safer.
        Am I missing something?

        Gerrit-Comment-Date: Wed, 10 Jul 2024 07:45:09 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Sunggook Chue (Gerrit)

        unread,
        Jul 11, 2024, 1:19:09 AMJul 11
        to Olga Sharonova, Guido Urdaneta, Steve Becker, Gabriel Brito, Tricium, chromium...@chromium.org, Rijubrata Bhaumik, edgecapab...@microsoft.com, alexmo...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, chfreme...@chromium.org, creis...@chromium.org, feature-me...@chromium.org, ipc-securi...@chromium.org, jophba...@chromium.org, kinuko...@chromium.org, mfoltz...@chromium.org, navigation...@chromium.org, tommyw+w...@chromium.org
        Attention needed from Gabriel Brito, Guido Urdaneta, Olga Sharonova and Steve Becker

        Sunggook Chue added 5 comments

        Patchset-level comments
        File-level comment, Patchset 9 (Latest):
        Sunggook Chue . resolved

        addressed and replied comments, thanks.

        File content/browser/renderer_host/media/preferred_audio_output_device_manager.h
        Line 44, Patchset 8:// substitued for the new audio output stream if the requested stream is
        Olga Sharonova . resolved

        "substitued" is a possible misspelling of "substituted" or "substitute".

        Please fix.

        Sunggook Chue

        Done

        File content/browser/renderer_host/media/preferred_audio_output_device_manager.cc
        Line 134, Patchset 8: &GetRenderFrameHostOnUIThread,
        device_switcher->GetGlobalRenderFrameHostId(),
        Olga Sharonova . resolved

        I think we should reconsider this part of PreferredAudioOutputDeviceManager. Why do we make it fetch the host, rather than providing it? For example, the host is known for the Broker aka Switcher during its creation, isn't it? So Switcher can have a getter for it, rather than for its id.
        If we make PreferredAudioOutputDeviceManager to work with main frame directly, the threading will be much simpler and safer.
        Am I missing something?

        Sunggook Chue

        Actually, Broker is on the IO thread only and its knowledge of the Host is limited to its integer ID (process id, frame id), not a RenderFrameHost object.

        We need to get RenderFrameHost to tell if it is main or sub, and RenderFrameHost can be acquired from the IDs only in the UI thread.

        Line 207, Patchset 7:void PreferredAudioOutputDeviceManager::RemoveSwitcherEntry(
        Olga Sharonova . resolved

        I don't think this works. This method is called in the broker destructor. When it exits, the device switcher pointer is no longer valid. However, we jump through UI thread and back to IO before actually removing it from the map. Meanwhile, there may be preferred device switch calls already scheduled on IO thread, and they will call the already deleted switcher before we get to RemoveSwitcherEntryOnIOThread().

        Please see above my request for sequence diagrams. There may be other problems like that, for example when web content is gone.

        Sunggook Chue

        The current logic is same with 'NotifyFrameHostOfAudioStreamStopped', which is called in AudioOutputStreamBroker dtor and operate on UI thread.

        All it needs the RenderFrameHost object is alive on the UI thread, and it doesn't have to live when it back to the IO thread as it is nothing but a integer.

        It is called on the UI thread for WebContents, where it is even safer than broker since it doesn't have to switch to UI thread.

        It's not convenient to draw sequence diagram on the /h file, anyway, tried.

        Olga Sharonova

        I mean: *a* sequence diagram - in any readable format, not in .h file. Since we have not discussed this in a design doc, and the interactions are rather complex. Also, because I just described a problem with these sequences.

        I don't see how your comment addresses the situation I described though: SetPreferredSinkIdOnIOThread() being called while we jump here from IO thread to UI and back to removed a deleted switcher from the map.

        Sunggook Chue

        That's good point, probably we will have to use WeakPtr for the store of the Switcher interface. updated.

        Line 238, Patchset 8:void PreferredAudioOutputDeviceManager::RemoveRenderFrameHostEntry(
        Olga Sharonova . resolved

        There may be SetPreferredSinkIdOnIOThread() scheduled before RemoveRenderFrameHostEntryEntryOnIOThread is called.

        Sunggook Chue

        Yes, it could be, but the worst case is that SetPreferredSinkIdOnIOThread will call the SwitchAudioOutputDeviceId of the broker, but the broker could have been called if not deleted from the list yey; The broker is a WeakPtr already that will be handled gracefully there whether the Broker is still alive or not.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Gabriel Brito
        • Guido Urdaneta
        • Olga Sharonova
        • Steve Becker
        Submit Requirements: