I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and elements that will be put into it is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners` I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see this can happen.
Bug 1699233 Comment 0 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and elements that will be put into it is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners`. There is no need to remove an element from a list that is never added into a list. I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see this can happen.
I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and elements that will be put into it is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners`. There is no need to remove an element from a list that is never added into a list. I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see if the above case can happen or not.
I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and elements that will be put into it is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners`. There is no need to remove an element from a list that is never added into a list. I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the following listener registration `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see if the above case can happen or not.
I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and elements that will be put into it is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners`. There is no need to remove an element from a list that is never added into a list. I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the following listener registration via `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see if the above case can happen or not.
I suspect [`listeners.RemoveElement(aID)`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#640) is wrong in `MediaTrackGraphImpl::OpenAudioInputImpl`. 1. `listeners.RemoveElement(aID)` is called when `listeners.IsEmpty()` is `true`. It makes no sense to remove an element from an empty list `listeners` 2. The type of `listeners` is `nsTArray<RefPtr<AudioDataListener>>`, and its element-type is [`AudioDataListener*`](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#646). If we want to remove element from `listeners`, we should use `listeners.RemoveElement(aListener)` instead of `listeners.RemoveElement(aID)`. `aID` is never put into the `listeners` and its type is wrong (`*void`). There is no need to remove an element from a list that is never added to a list. I guess what we want to do is `mInputDeviceUsers.Remove(aID)`? The side-effect I could see is that once a second device tries the register a listener into `mInputDeviceUsers`, the following listener registration via `OpenAudioInputImpl` no longer works. To be specific, here is the situation I could imagine: 1. Register listener `A` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `0` to `1` - `listeners` of `X` is empty so `A` will be put into `listeners` of `X` 2. Register listener `B` for device `Y` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `Y` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - `B` cannot be put into the `listeners` of `Y` 3. Remove listener `A` for device `X` from `mInputDeviceUsers` via `CloseAudioInputImpl` - Now `mInputDeviceUsers.Count()` is from `2` to `1`, [since `listeners` of `X` is empty now](https://searchfox.org/mozilla-central/rev/1a47a74bd5ba89f2474aa27c40bd478e853f3276/dom/media/MediaTrackGraph.cpp#715) 4. Register listener `C` for device `X` to `mInputDeviceUsers` - Now `mInputDeviceUsers.Count()` is from `1` to `2` - `listeners` of `X` is empty so `listeners.RemoveElement(aID)` is called but it does nothing. - Since `mInputDeviceUsers.Count()` is at least `1` now so we cannot register any new listener. We should be able to register a new listener at the 4. I am trying to write a test to see if the above case can happen or not.